@font-face {
  font-family: "Syne";
  src: url("./fonts/syne-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Syne";
  src: url("./fonts/syne-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Syne";
  src: url("./fonts/syne-latin-800-normal.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Figtree";
  src: url("./fonts/figtree-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Figtree";
  src: url("./fonts/figtree-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Figtree";
  src: url("./fonts/figtree-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root,
[data-theme='walnut'] {
  color-scheme: dark;
  --bg: #14110f;
  --bg-soft: #1c1713;
  --bg-deep: #0a0908;
  --panel: rgba(36, 28, 22, 0.88);
  --text: #f4ebe1;
  --muted: #b9a793;
  --accent: #d4a15a;
  --accent-strong: #e8b86a;
  --accent-ink: #1a120c;
  --border: rgba(244, 235, 225, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  --board-light: #e6c79a;
  --board-dark: #8b5a36;
  --board-light-piece: #fff8ef;
  --board-dark-piece: #1a120c;
  --piece-white-fill: #f7f1e6;
  --piece-white-stroke: #2a2118;
  --piece-white-detail: #2a2118;
  --piece-black-fill: #1b1510;
  --piece-black-stroke: #efe6d8;
  --piece-black-detail: #efe6d8;
  --status-bg: rgba(212, 161, 90, 0.12);
  --status-border: rgba(212, 161, 90, 0.28);
  --glow: rgba(212, 161, 90, 0.18);
  --grain: rgba(255, 236, 210, 0.03);
  --ghost-fill: rgba(255, 255, 255, 0.08);
  --error: #ff8f8f;
  --atmosphere-soft: rgba(255, 255, 255, 0.04);
}

[data-theme='ink'] {
  color-scheme: dark;
  --bg: #0a1218;
  --bg-soft: #10202b;
  --bg-deep: #050b10;
  --panel: rgba(14, 28, 38, 0.9);
  --text: #e8f1f6;
  --muted: #8eacbd;
  --accent: #4db6a4;
  --accent-strong: #6fd0bf;
  --accent-ink: #041018;
  --border: rgba(232, 241, 246, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  --board-light: #c9d7de;
  --board-dark: #35586a;
  --board-light-piece: #f5fbfd;
  --board-dark-piece: #08202c;
  --status-bg: rgba(77, 182, 164, 0.12);
  --status-border: rgba(77, 182, 164, 0.28);
  --glow: rgba(77, 182, 164, 0.16);
  --grain: rgba(180, 220, 230, 0.03);
  --ghost-fill: rgba(255, 255, 255, 0.08);
  --error: #ff8f8f;
  --atmosphere-soft: rgba(255, 255, 255, 0.04);
}

[data-theme='midnight'] {
  color-scheme: dark;
  --bg: #0c1020;
  --bg-soft: #151b32;
  --bg-deep: #070914;
  --panel: rgba(20, 26, 48, 0.9);
  --text: #e8ecf8;
  --muted: #9aa6c4;
  --accent: #7aa2ff;
  --accent-strong: #9bbcff;
  --accent-ink: #0a1020;
  --border: rgba(232, 236, 248, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  --board-light: #d5dced;
  --board-dark: #3a4668;
  --board-light-piece: #f4f6fc;
  --board-dark-piece: #10162a;
  --status-bg: rgba(122, 162, 255, 0.12);
  --status-border: rgba(122, 162, 255, 0.28);
  --glow: rgba(122, 162, 255, 0.16);
  --grain: rgba(180, 200, 255, 0.03);
  --ghost-fill: rgba(255, 255, 255, 0.08);
  --error: #ff8f8f;
  --atmosphere-soft: rgba(255, 255, 255, 0.04);
}

[data-theme='ember'] {
  color-scheme: dark;
  --bg: #160e0c;
  --bg-soft: #241612;
  --bg-deep: #0c0706;
  --panel: rgba(42, 24, 20, 0.9);
  --text: #f7ebe4;
  --muted: #c4a091;
  --accent: #e0704a;
  --accent-strong: #f08a62;
  --accent-ink: #1a0c08;
  --border: rgba(247, 235, 228, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
  --board-light: #ecc4a4;
  --board-dark: #7a3f2e;
  --board-light-piece: #fff4ec;
  --board-dark-piece: #1c0d09;
  --status-bg: rgba(224, 112, 74, 0.12);
  --status-border: rgba(224, 112, 74, 0.28);
  --glow: rgba(224, 112, 74, 0.16);
  --grain: rgba(255, 200, 170, 0.03);
  --ghost-fill: rgba(255, 255, 255, 0.08);
  --error: #ff8f8f;
  --atmosphere-soft: rgba(255, 255, 255, 0.04);
}

[data-theme='slate'] {
  color-scheme: dark;
  --bg: #121417;
  --bg-soft: #1b1f24;
  --bg-deep: #0a0b0d;
  --panel: rgba(30, 34, 40, 0.9);
  --text: #eceff3;
  --muted: #9aa3ad;
  --accent: #8fb0c4;
  --accent-strong: #a9c5d5;
  --accent-ink: #101418;
  --border: rgba(236, 239, 243, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
  --board-light: #d7dde3;
  --board-dark: #4d5762;
  --board-light-piece: #f7f9fb;
  --board-dark-piece: #14181c;
  --status-bg: rgba(143, 176, 196, 0.12);
  --status-border: rgba(143, 176, 196, 0.28);
  --glow: rgba(143, 176, 196, 0.14);
  --grain: rgba(210, 220, 230, 0.03);
  --ghost-fill: rgba(255, 255, 255, 0.08);
  --error: #ff8f8f;
  --atmosphere-soft: rgba(255, 255, 255, 0.04);
}

[data-theme='ocean'] {
  color-scheme: dark;
  --bg: #07151c;
  --bg-soft: #0d2430;
  --bg-deep: #041016;
  --panel: rgba(12, 36, 48, 0.9);
  --text: #e4f3f7;
  --muted: #86aab6;
  --accent: #3da9c9;
  --accent-strong: #5fc0db;
  --accent-ink: #041018;
  --border: rgba(228, 243, 247, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  --board-light: #c5dbe3;
  --board-dark: #2d6070;
  --board-light-piece: #f2fafc;
  --board-dark-piece: #062028;
  --status-bg: rgba(61, 169, 201, 0.12);
  --status-border: rgba(61, 169, 201, 0.28);
  --glow: rgba(61, 169, 201, 0.16);
  --grain: rgba(160, 220, 235, 0.03);
  --ghost-fill: rgba(255, 255, 255, 0.08);
  --error: #ff8f8f;
  --atmosphere-soft: rgba(255, 255, 255, 0.04);
}

[data-theme='meadow'] {
  color-scheme: light;
  --bg: #e7efe4;
  --bg-soft: #d7e5d2;
  --bg-deep: #c9d9c4;
  --panel: rgba(250, 252, 248, 0.92);
  --text: #1d2a1c;
  --muted: #5d705a;
  --accent: #2f6b45;
  --accent-strong: #255738;
  --accent-ink: #f4faf2;
  --border: rgba(29, 42, 28, 0.12);
  --shadow: 0 24px 60px rgba(47, 107, 69, 0.14);
  --board-light: #f2e5c2;
  --board-dark: #6f8f57;
  --board-light-piece: #ffffff;
  --board-dark-piece: #17301c;
  --status-bg: rgba(47, 107, 69, 0.1);
  --status-border: rgba(47, 107, 69, 0.22);
  --glow: rgba(47, 107, 69, 0.12);
  --grain: rgba(40, 70, 40, 0.03);
  --ghost-fill: rgba(29, 42, 28, 0.08);
  --error: #b42318;
  --atmosphere-soft: rgba(255, 255, 255, 0.35);
}

[data-theme='parchment'] {
  color-scheme: light;
  --bg: #ebe6dc;
  --bg-soft: #e0d8cb;
  --bg-deep: #d2c8b8;
  --panel: rgba(250, 247, 240, 0.94);
  --text: #2a241c;
  --muted: #6f6456;
  --accent: #3d6b5a;
  --accent-strong: #2f5648;
  --accent-ink: #f7faf8;
  --border: rgba(42, 36, 28, 0.12);
  --shadow: 0 24px 60px rgba(70, 55, 35, 0.12);
  --board-light: #efe2c4;
  --board-dark: #8a7354;
  --board-light-piece: #fffdf8;
  --board-dark-piece: #241c14;
  --status-bg: rgba(61, 107, 90, 0.1);
  --status-border: rgba(61, 107, 90, 0.22);
  --glow: rgba(61, 107, 90, 0.12);
  --grain: rgba(60, 45, 25, 0.03);
  --ghost-fill: rgba(42, 36, 28, 0.08);
  --error: #b42318;
  --atmosphere-soft: rgba(255, 255, 255, 0.4);
}

[data-theme='frost'] {
  color-scheme: light;
  --bg: #e8eef4;
  --bg-soft: #d9e3ec;
  --bg-deep: #c8d5e1;
  --panel: rgba(248, 251, 253, 0.94);
  --text: #1a2430;
  --muted: #5b6b7c;
  --accent: #2f6f8f;
  --accent-strong: #255a74;
  --accent-ink: #f3f9fc;
  --border: rgba(26, 36, 48, 0.12);
  --shadow: 0 24px 60px rgba(47, 90, 120, 0.12);
  --board-light: #e4edf4;
  --board-dark: #5d7d93;
  --board-light-piece: #ffffff;
  --board-dark-piece: #132231;
  --status-bg: rgba(47, 111, 143, 0.1);
  --status-border: rgba(47, 111, 143, 0.22);
  --glow: rgba(47, 111, 143, 0.12);
  --grain: rgba(40, 60, 80, 0.03);
  --ghost-fill: rgba(26, 36, 48, 0.08);
  --error: #b42318;
  --atmosphere-soft: rgba(255, 255, 255, 0.4);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Figtree", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  position: relative;
  overflow-x: hidden;
}

body.is-booted .site-header,
body.is-booted .app-shell,
body.is-booted .site-footer {
  animation: rise-in 0.7s ease both;
}

body.is-booted .app-shell {
  animation-delay: 0.08s;
}

body.is-booted .site-footer {
  animation-delay: 0.16s;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 15% -10%, var(--glow), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 10%, var(--atmosphere-soft), transparent 45%),
    linear-gradient(160deg, var(--bg-soft), var(--bg) 48%, var(--bg-deep));
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.45;
  background-image:
    linear-gradient(90deg, var(--grain) 1px, transparent 1px),
    linear-gradient(0deg, var(--grain) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 85%);
}

button,
input,
select,
textarea {
  font: inherit;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.site-header,
.app-shell,
.site-footer {
  position: relative;
  z-index: 1;
}

.site-header {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem 0.35rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-block {
  display: grid;
  gap: 0.15rem;
}

.brand {
  margin: 0;
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.github-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  padding-bottom: 0.1rem;
}

.github-link:hover {
  color: var(--accent-strong);
  border-bottom-color: var(--accent-strong);
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 2rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1.15fr) minmax(240px, 0.78fr) minmax(220px, 0.7fr);
  grid-template-areas:
    "board notation settings"
    "meta notation settings";
  align-items: start;
}

/* Lets board + notation + meta participate in the app-shell grid on desktop. */
.play-stage {
  display: contents;
}

.panel-board {
  grid-area: board;
}

.panel-board-meta {
  grid-area: meta;
}

.panel-notation {
  grid-area: notation;
}

.panel-settings {
  grid-area: settings;
}

/* Desktop keeps opponent setup above the moves field even though the form is first in the DOM. */
.panel-notation .panel-heading {
  order: 0;
}

.panel-notation .cpu-panel {
  order: 1;
}

.panel-notation .controls-stack {
  order: 2;
}

.notation-dock-handle {
  display: none;
  order: -1;
}

.board-extras {
  display: grid;
  gap: 0.75rem;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
}

.board-extras > summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.board-extras > summary::-webkit-details-marker {
  display: none;
}

@media (min-width: 801px) {
  .board-extras > summary {
    display: none;
  }
}

.panel,
.stage {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1.15rem;
  box-shadow: var(--shadow);
  padding: 1rem;
  backdrop-filter: blur(16px);
}

.panel-board,
.panel-board-meta,
.panel-notation,
.panel-settings {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

.board-toolbar,
.panel-heading,
.board-toolbar,
.panel-heading,
.storage-header,
.toolbar,
.actions,
.board-summary,
.board-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.storage-controls {
  display: grid;
  gap: 0.65rem;
}

.storage-controls .button {
  width: 100%;
}

.board-toolbar {
  align-items: stretch;
}

.board-toolbar .status-card {
  flex: 1 1 12rem;
  margin: 0;
}

.compact-heading {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0.3rem;
}

.settings-stack {
  display: grid;
  gap: 0.75rem;
}

.palette-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr));
  gap: 0.45rem;
}

.palette-swatch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0.2rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  min-height: 2.35rem;
}

.palette-swatch:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.palette-swatch.is-selected,
.palette-swatch[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}

.palette-swatch-chip {
  display: block;
  min-height: 1.85rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.palette-swatch-chip:first-child {
  border-radius: 0.4rem 0 0 0.4rem;
}

.palette-swatch-chip:last-child {
  border-radius: 0 0.4rem 0.4rem 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: "Syne", sans-serif;
  font-weight: 700;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

h2 {
  font-family: "Syne", sans-serif;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

h3 {
  font-size: 0.95rem;
}

.eyebrow,
.summary-label,
.field span,
.help-card summary,
.legend {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.compact-field {
  width: auto;
  min-width: 9.5rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  border-radius: 0.85rem;
  padding: 0.7rem 0.85rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

textarea {
  min-height: 11rem;
  resize: vertical;
  line-height: 1.45;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92rem;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 0.95rem;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.button[aria-pressed='true'] {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--text);
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.ghost {
  background: var(--ghost-fill);
  color: inherit;
}

.status-card,
.feedback,
.help-card {
  border: 1px solid var(--status-border);
  background: var(--status-bg);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
}

.feedback.is-error {
  color: var(--error);
}

.board-summary {
  align-items: flex-start;
}

#fen {
  display: block;
  margin-top: 0.35rem;
  word-break: break-all;
  color: var(--muted);
}

.board {
  display: grid;
  grid-template-columns: auto repeat(8, minmax(2.2rem, 1fr));
  gap: 0;
  align-self: stretch;
  width: 100%;
  max-width: 28rem;
  margin: 0 auto;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.board-layout {
  display: grid;
  grid-template-columns: minmax(3.5rem, 5.5rem) minmax(0, 1fr) minmax(3.5rem, 5.5rem);
  gap: 0.65rem;
  align-items: stretch;
}

.captures {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
  padding: 0.35rem 0;
}

.captures-heading {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
}

.captures-heading strong {
  color: var(--text);
}

.captures-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  align-content: flex-start;
}

.captures-empty {
  color: var(--muted);
  opacity: 0.55;
}

.captured-piece {
  display: grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
}

.captured-piece svg {
  width: 100%;
  height: 100%;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.85rem;
  align-items: center;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  font-weight: 600;
  font-size: 0.9rem;
}

.score-detail {
  color: var(--muted);
  font-size: 0.85rem;
}

.clock-panel {
  display: grid;
  gap: 0.65rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.03);
}

.clock-faces {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.clock-face {
  --clock-fill: transparent;
  --clock-stroke: var(--border);
  display: grid;
  gap: 0.2rem;
  padding: 0.7rem 0.8rem;
  border-radius: 0.85rem;
  border: 1px solid color-mix(in srgb, var(--clock-stroke) 55%, var(--border));
  background:
    linear-gradient(
      160deg,
      color-mix(in srgb, var(--clock-fill) 72%, transparent),
      color-mix(in srgb, var(--clock-fill) 28%, rgba(0, 0, 0, 0.18))
    );
  color: var(--clock-stroke);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.clock-face.is-light-side {
  color: #1a120c;
}

.clock-face.is-dark-side {
  color: #f4ebe1;
}

.clock-face.is-active {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent),
    0 10px 24px color-mix(in srgb, var(--accent) 18%, transparent);
}

.clock-face.is-low .clock-time {
  color: #f59e0b;
}

.clock-face.is-flagged {
  border-color: var(--error);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--error) 28%, transparent);
}

.clock-face.is-flagged .clock-time {
  color: var(--error);
}

.clock-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.72;
}

.clock-time {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.clock-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: end;
}

.clock-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.clock-panel.is-typing-paused .clock-face.is-active {
  opacity: 0.72;
}

.board.is-settling .board-square .piece {
  animation: piece-settle 0.35s ease both;
}

.board.is-animating .board-square .piece {
  animation: none;
}

.board-square .piece.is-hidden-for-anim {
  opacity: 0;
}

.piece-flyer,
.piece-victim {
  position: fixed;
  z-index: 40;
  display: grid;
  place-items: center;
  pointer-events: none;
  line-height: 0;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.35));
  will-change: transform, opacity;
}

.piece-victim {
  z-index: 39;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4));
}

.piece-flyer.white,
.piece-victim.white {
  --piece-fill: var(--piece-white-fill);
  --piece-stroke: var(--piece-white-stroke);
  --piece-detail: var(--piece-white-detail);
}

.piece-flyer.black,
.piece-victim.black {
  --piece-fill: var(--piece-black-fill);
  --piece-stroke: var(--piece-black-stroke);
  --piece-detail: var(--piece-black-detail);
}

.piece-flyer .piece-svg,
.piece-victim .piece-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.board-square.is-splash::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent) 55%, transparent) 0%,
    color-mix(in srgb, var(--accent) 18%, transparent) 42%,
    transparent 70%
  );
  animation: square-splash-fill 0.48s ease-out forwards;
  pointer-events: none;
  z-index: 1;
}

.board-square.is-splash::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent-strong) 85%, #fff);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
  animation: square-splash-ring 0.48s ease-out forwards;
  pointer-events: none;
  z-index: 2;
}

.board-square.is-capture-burst::before {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, #ffb457 70%, transparent) 0%,
    color-mix(in srgb, #e0704a 35%, transparent) 38%,
    transparent 72%
  );
  animation: capture-burst-fill 0.58s ease-out forwards;
  pointer-events: none;
  z-index: 1;
}

.board-square.is-capture-burst::after {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 18%;
  border: 2px solid color-mix(in srgb, #ffb457 80%, #fff);
  box-shadow:
    0 0 0 0 color-mix(in srgb, #e0704a 45%, transparent),
    inset 0 0 18px color-mix(in srgb, #e0704a 25%, transparent);
  animation: capture-burst-ring 0.58s ease-out forwards;
  pointer-events: none;
  z-index: 2;
}

.board-square.is-check {
  box-shadow:
    inset 0 0 0 3px color-mix(in srgb, #f0b429 85%, #fff),
    inset 0 0 22px color-mix(in srgb, #f0b429 45%, transparent);
  animation: check-square-pulse 0.85s ease-in-out 2;
}

.board-square.is-checkmate {
  box-shadow:
    inset 0 0 0 3px color-mix(in srgb, #ff6b6b 90%, #fff),
    inset 0 0 28px color-mix(in srgb, #ff6b6b 55%, transparent);
  animation: checkmate-square-pulse 1.2s ease-in-out both;
}

.board-square.is-checkmate::before {
  content: "";
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, #ff8f8f 80%, #fff);
  animation: checkmate-ring 1.15s ease-out forwards;
  pointer-events: none;
  z-index: 2;
}

.board-square.is-checkmate::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, #ff6b6b 55%, transparent),
    transparent 70%
  );
  animation: checkmate-glow 1.15s ease-out forwards;
  pointer-events: none;
  z-index: 1;
}

.board.is-mate-flash {
  animation: board-mate-flash 1.1s ease-out both;
}

.board.is-reviewing {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 4px;
}

.replay-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.85rem;
  align-items: end;
  justify-content: space-between;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.03);
}

.replay-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.replay-controls .button {
  min-width: 3.6rem;
}

.replay-controls .button.primary[aria-pressed='true'] {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

.replay-speed-field {
  min-width: 7rem;
}

.replay-position {
  margin: 0;
  margin-left: auto;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

.moves-list .ply-turn {
  color: var(--muted);
  margin-right: 0.15rem;
}

.moves-list .ply-jump {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0.05rem 0.2rem;
  border-radius: 0.35rem;
  cursor: pointer;
}

.moves-list .ply-jump:hover,
.moves-list .ply-jump:focus-visible {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  outline: none;
}

.moves-list .ply-jump.is-active-ply {
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 72%, #fff);
  font-weight: 600;
}

.board-cell,
.board .legend {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-weight: 600;
}

.board-square {
  position: relative;
}

.board-square.light {
  background: var(--board-light);
  color: var(--board-dark-piece);
}

.board-square.dark {
  background: var(--board-dark);
  color: var(--board-light-piece);
}

.board-square .piece {
  display: grid;
  place-items: center;
  width: 84%;
  height: 84%;
  line-height: 0;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.22));
}

.board-square .piece.white {
  --piece-fill: var(--piece-white-fill);
  --piece-stroke: var(--piece-white-stroke);
  --piece-detail: var(--piece-white-detail);
}

.board-square .piece.black {
  --piece-fill: var(--piece-black-fill);
  --piece-stroke: var(--piece-black-stroke);
  --piece-detail: var(--piece-black-detail);
}

.board-square .piece-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

[data-piece-set='line'] .board-square .piece.white {
  --piece-stroke: var(--piece-white-stroke);
  --piece-detail: var(--piece-white-detail);
}

[data-piece-set='line'] .board-square .piece.black {
  --piece-stroke: var(--piece-black-stroke);
  --piece-detail: var(--piece-black-detail);
}

.board-square .coordinate {
  position: absolute;
  right: 0.28rem;
  bottom: 0.18rem;
  font-size: 0.58rem;
  opacity: 0.5;
  font-family: "Figtree", sans-serif;
  font-weight: 500;
}

.moves-list,
.saved-games {
  display: grid;
  gap: 0.75rem;
}

.moves-list {
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  padding-left: 1.25rem;
  margin: 0;
  color: var(--muted);
}

.saved-games {
  margin-top: 1rem;
}

.saved-game {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  display: grid;
  gap: 0.7rem;
  background: rgba(255, 255, 255, 0.03);
}

.saved-game.empty-save {
  color: var(--muted);
}

.saved-game header,
.saved-game .saved-game-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.saved-game small,
.storage-header p {
  color: var(--muted);
}

.controls-stack {
  display: grid;
  gap: 1rem;
}

.cpu-panel {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: color-mix(in srgb, var(--status-bg) 70%, transparent);
}

.cpu-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.cpu-title {
  font-size: 1rem;
  margin: 0;
}

.cpu-controls {
  display: grid;
  gap: 0.55rem;
}

.cpu-handicap-row {
  display: grid;
  gap: 0.35rem;
}

.cpu-handicap-row .button {
  justify-self: start;
}

.cpu-panel.is-pace-on #cpu-handicap[aria-pressed='true'] {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.cpu-level-hint,
.cpu-status,
.coin-caption {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.cpu-status {
  color: var(--text);
  font-weight: 500;
}

.cpu-match {
  display: grid;
  gap: 0.65rem;
}

.coin-stage {
  display: grid;
  justify-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0 0.15rem;
}

.coin {
  position: relative;
  width: 3.1rem;
  height: 3.1rem;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
}

.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  background:
    radial-gradient(circle at 30% 28%, color-mix(in srgb, var(--accent-strong) 55%, #fff), transparent 42%),
    linear-gradient(145deg, color-mix(in srgb, var(--accent) 70%, #fff), var(--accent));
  color: var(--accent-ink);
  font-family: "Syne", sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  backface-visibility: hidden;
  box-shadow: 0 10px 22px color-mix(in srgb, var(--accent) 22%, transparent);
}

.coin-tails {
  transform: rotateY(180deg);
  background:
    radial-gradient(circle at 30% 28%, color-mix(in srgb, var(--muted) 35%, #fff), transparent 42%),
    linear-gradient(145deg, color-mix(in srgb, var(--text) 18%, var(--bg-soft)), var(--bg-soft));
  color: var(--text);
  border-color: var(--border);
}

.coin[data-face='tails'] {
  transform: rotateY(180deg);
}

.coin-stage.is-spinning .coin {
  animation: coin-flip 0.55s linear infinite;
}

.coin-stage.is-resolved .coin {
  animation: coin-land 0.55s ease both;
}

.cpu-panel.is-thinking {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  animation: soft-pulse 1.8s ease-in-out infinite;
}

.cpu-panel[data-enabled='true'] #cpu-toggle {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

@keyframes coin-flip {
  from {
    transform: rotateY(0deg) translateY(0);
  }
  50% {
    transform: rotateY(180deg) translateY(-0.35rem);
  }
  to {
    transform: rotateY(360deg) translateY(0);
  }
}

@keyframes coin-land {
  from {
    transform: rotateY(720deg) scale(1.08);
  }
  to {
    transform: rotateY(var(--coin-end, 0deg)) scale(1);
  }
}

.coin[data-face='heads'] {
  --coin-end: 0deg;
}

.coin[data-face='tails'] {
  --coin-end: 180deg;
}

.help-card ul {
  margin: 0.85rem 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

.site-footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem 2.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.site-footer strong {
  color: var(--text);
  font-family: "Syne", sans-serif;
}

.site-footer a,
.help-card a {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.site-footer a:hover,
.help-card a:hover {
  color: var(--text);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes piece-settle {
  from {
    opacity: 0.35;
    transform: translateY(-6px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes square-splash-fill {
  from {
    opacity: 0.85;
    transform: scale(0.35);
  }
  to {
    opacity: 0;
    transform: scale(1.2);
  }
}

@keyframes square-splash-ring {
  from {
    opacity: 0.95;
    transform: scale(0.45);
  }
  to {
    opacity: 0;
    transform: scale(1.55);
  }
}

@keyframes capture-burst-fill {
  0% {
    opacity: 0.95;
    transform: scale(0.2);
  }
  40% {
    opacity: 0.8;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.45);
  }
}

@keyframes capture-burst-ring {
  0% {
    opacity: 1;
    transform: scale(0.35) rotate(0deg);
  }
  55% {
    opacity: 0.75;
    transform: scale(1.05) rotate(8deg);
  }
  100% {
    opacity: 0;
    transform: scale(1.4) rotate(14deg);
  }
}

@keyframes check-square-pulse {
  0%,
  100% {
    box-shadow:
      inset 0 0 0 2px color-mix(in srgb, #f0b429 55%, #fff),
      inset 0 0 14px color-mix(in srgb, #f0b429 28%, transparent);
  }
  50% {
    box-shadow:
      inset 0 0 0 4px color-mix(in srgb, #f0b429 95%, #fff),
      inset 0 0 28px color-mix(in srgb, #f0b429 55%, transparent);
  }
}

@keyframes checkmate-square-pulse {
  0%,
  100% {
    box-shadow:
      inset 0 0 0 2px color-mix(in srgb, #ff6b6b 60%, #fff),
      inset 0 0 16px color-mix(in srgb, #ff6b6b 30%, transparent);
  }
  40% {
    box-shadow:
      inset 0 0 0 4px color-mix(in srgb, #ff6b6b 95%, #fff),
      inset 0 0 34px color-mix(in srgb, #ff6b6b 60%, transparent);
  }
}

@keyframes checkmate-ring {
  from {
    opacity: 0.95;
    transform: scale(0.55);
  }
  to {
    opacity: 0;
    transform: scale(1.7);
  }
}

@keyframes checkmate-glow {
  from {
    opacity: 0.9;
    transform: scale(0.4);
  }
  to {
    opacity: 0;
    transform: scale(1.35);
  }
}

@keyframes board-mate-flash {
  0% {
    filter: brightness(1);
  }
  18% {
    filter: brightness(1.12);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes soft-pulse {
  0%,
  100% {
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
  }
  50% {
    box-shadow: 0 12px 34px color-mix(in srgb, var(--accent) 35%, transparent);
  }
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: minmax(0, 1.15fr) minmax(250px, 0.85fr);
    grid-template-areas:
      "board notation"
      "meta notation"
      "settings settings";
  }
}

@media (max-width: 800px) {
  .app-shell {
    grid-template-columns: 1fr;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding-bottom: 0.35rem;
  }

  .play-stage {
    display: flex;
    flex-direction: column;
    gap: 0;
    order: 1;
  }

  /* One mobile play card: board on top, moves input immediately under it. */
  .panel-board {
    order: 1;
    flex: 0 0 auto;
    gap: 0.5rem;
    padding: 0.7rem 0.7rem 0.45rem;
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
    box-shadow: none;
  }

  .panel-notation {
    order: 2;
    position: static;
    flex: 0 0 auto;
    gap: 0.55rem;
    margin: 0;
    padding: 0.45rem 0.7rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    max-height: none;
    overflow: visible;
    box-shadow: var(--shadow);
  }

  /* Moves field first; CPU / new-match below the input. */
  .panel-notation .controls-stack {
    order: 1;
  }

  .panel-notation .cpu-panel {
    order: 2;
  }

  .notation-dock-handle {
    display: none;
  }

  .panel-board-meta {
    order: 3;
    gap: 0.55rem;
    padding: 0.7rem;
    margin-top: 0.55rem;
  }

  .panel-settings {
    order: 2;
    margin-top: 0.35rem;
  }

  .tagline {
    display: none;
  }

  .site-header {
    padding-top: 0.55rem;
    padding-bottom: 0.15rem;
  }

  .brand {
    font-size: 1.35rem;
  }

  .panel-notation > .panel-heading {
    display: none;
  }

  .panel-board .board-toolbar {
    gap: 0.45rem;
  }

  .panel-board .status-card {
    padding: 0.55rem 0.7rem;
    font-size: 0.92rem;
  }

  .clock-controls,
  .clock-hint {
    display: none;
  }

  .clock-faces {
    gap: 0.45rem;
  }

  .clock-face {
    padding: 0.45rem 0.55rem;
  }

  .clock-time {
    font-size: 1.15rem;
  }

  .board-layout {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
  }

  /* Captures above the board so input sits directly under the squares. */
  .captures-black {
    order: 1;
  }

  .captures-white {
    order: 2;
  }

  .board-layout .board {
    order: 3;
  }

  .captures {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
  }

  .captures-row {
    flex: 1;
  }

  .board {
    width: min(100%, 72vw);
    max-width: 22rem;
    margin-inline: auto;
  }

  .board-extras {
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    padding: 0.35rem 0.7rem;
  }

  .board-extras > summary {
    display: block;
    padding: 0.35rem 0;
  }

  .board-extras[open] {
    padding-bottom: 0.65rem;
  }

  .cpu-panel {
    padding: 0.55rem 0.7rem;
    gap: 0.45rem;
  }

  .cpu-title {
    font-size: 0.92rem;
  }

  .coin-stage {
    padding-top: 0.1rem;
  }

  .controls-stack {
    gap: 0.55rem;
  }

  textarea {
    min-height: 4.4rem;
    max-height: 9rem;
    font-size: 1rem;
    padding: 0.65rem 0.75rem;
  }

  .panel-notation .actions {
    gap: 0.4rem;
  }

  .panel-notation .feedback {
    padding: 0.55rem 0.7rem;
    font-size: 0.88rem;
  }

  /* While typing: keep board + input paired; hide the rest. */
  body.is-editing-moves .site-header,
  body.is-editing-moves .site-footer,
  body.is-editing-moves .panel-settings,
  body.is-editing-moves .panel-board-meta,
  body.is-editing-moves .board-actions,
  body.is-editing-moves .board-extras,
  body.is-editing-moves .replay-panel,
  body.is-editing-moves .cpu-panel,
  body.is-editing-moves .cpu-controls,
  body.is-editing-moves .coin-stage {
    display: none;
  }

  body.is-editing-moves .play-stage {
    gap: 0;
  }

  body.is-editing-moves .panel-board {
    padding: 0.55rem 0.55rem 0.35rem;
    gap: 0.35rem;
  }

  body.is-editing-moves .board {
    width: min(100%, 56vw);
    max-width: 18rem;
  }

  body.is-editing-moves .panel-notation {
    padding-top: 0.35rem;
  }

  body.is-editing-moves textarea {
    min-height: 5.5rem;
    max-height: 12rem;
  }
}

@media (max-width: 720px) {
  .site-header,
  .app-shell,
  .site-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .panel,
  .stage {
    padding: 0.85rem;
  }

  .panel-board {
    padding: 0.7rem 0.7rem 0.4rem;
  }

  .panel-notation {
    padding-left: 0.7rem;
    padding-right: 0.7rem;
  }

  .board {
    grid-template-columns: auto repeat(8, minmax(1.7rem, 1fr));
  }

  .board-actions {
    width: 100%;
  }

  .board-actions .button {
    flex: 1 1 auto;
  }

  .replay-panel {
    align-items: stretch;
  }

  .replay-controls {
    width: 100%;
  }

  .replay-controls .button {
    flex: 1 1 auto;
  }

  .replay-position {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
