/* ============================================================ tokens */
:root {
  --bg: #0c0e13;
  --bg-2: #05060a;
  --panel: rgba(20, 24, 32, 0.66);
  --panel-2: rgba(33, 39, 50, 0.58);
  --line: rgba(186, 150, 78, 0.2);
  --text: #e7e2d6;
  --muted: #8e8879;
  --accent: #b6933f;
  --accent-soft: rgba(182, 147, 63, 0.14);

  --sq-light-1: #d9d1bf;
  --sq-light-2: #c3b9a4;
  --sq-dark-1: #2c3441;
  --sq-dark-2: #1c222c;

  --bezel-1: #322c22;
  --bezel-2: #12151b;

  --w-fill: #f2ecdd;
  --w-line: #2b3444;
  --w-eye: #2b3444;
  --b-fill: #242a34;
  --b-line: #0a0c10;
  --b-eye: #b0a894;

  /* Two opposing factions: White reads cool, Black reads ember-red.
     Kept as raw channels so rgb(var(--x) / a) can tint at any strength. */
  --faction-w-rgb: 110 166 255;
  --faction-b-rgb: 224 82 75;
  --accent-rgb: 182 147 63;

  --shadow-lg: 0 32px 64px -24px rgba(0, 0, 0, 0.85);
  --radius: 14px;
  /* Accelerate out of the origin, decelerate into the destination. */
  --ease: cubic-bezier(0.36, 0.02, 0.18, 1);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;
}

:root[data-theme="light"] {
  --bg: #d8d5cd;
  --bg-2: #b9b7b1;
  --panel: rgba(255, 253, 248, 0.78);
  --panel-2: rgba(240, 236, 227, 0.7);
  --line: rgba(139, 108, 46, 0.26);
  --text: #23282f;
  --muted: #6d6759;
  --accent: #8d6c1c;
  --accent-soft: rgba(141, 108, 28, 0.13);

  --sq-light-1: #f0ead9;
  --sq-light-2: #ddd4c0;
  --sq-dark-1: #58657a;
  --sq-dark-2: #414c5e;

  --bezel-1: #8b8375;
  --bezel-2: #4b4f58;

  --faction-w-rgb: 47 111 208;
  --faction-b-rgb: 185 58 51;
  --accent-rgb: 141 108 28;

  --w-fill: #fbf7ee;
  --w-line: #39445a;
  --w-eye: #39445a;
  --b-fill: #2f3642;
  --b-line: #12161c;
  --b-eye: #c3bba7;

  --shadow-lg: 0 26px 50px -26px rgba(30, 34, 42, 0.5);
}

/* ============================================================ base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 780px at 50% 32%, rgba(150, 160, 185, 0.09), transparent 62%),
    linear-gradient(170deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;

  /* Android Chrome fires its long-press text-selection gesture on the board,
     painting a native blue highlight and a copy/share callout over the app's
     own piece selection. Nothing here is copyable text, so kill selection,
     the callout and image dragging for the whole UI. */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Inherited: kills Chrome's grey/blue tap-flash overlay across the whole UI. */
  -webkit-tap-highlight-color: transparent;
}

/* user-drag doesn't inherit: the piece SVGs need it themselves, or a
   long-press-drag becomes an image drag instead of a move. */
svg {
  -webkit-user-drag: none;
}

/* Buttons: no double-tap-zoom delay or gesture ambiguity. The board keeps
   touch-action: none — it needs raw touchmove for drag-to-move. */
button {
  touch-action: manipulation;
}

/* Vignette: the board sits in a lit pocket, the edges fall away to black. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(120% 95% at 50% 38%, transparent 35%, rgba(0, 0, 0, 0.62) 100%);
}

/* Two soft blobs drifting past each other read as fog without a texture file. */
body::after {
  content: "";
  position: fixed;
  inset: -25%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background:
    radial-gradient(38% 30% at 28% 34%, rgba(126, 146, 190, 0.11), transparent 70%),
    radial-gradient(34% 26% at 74% 66%, rgba(190, 150, 90, 0.075), transparent 70%);
  animation: drift 48s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(-2.5%, 1.5%, 0) scale(1); }
  to { transform: translate3d(3%, -2%, 0) scale(1.09); }
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* Every layout rule below sets `display`, which would otherwise beat [hidden]. */
[hidden] {
  display: none !important;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================ chrome */
.app {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(14px, 2.4vw, 28px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: clamp(14px, 2vw, 22px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand .mark {
  width: 38px;
  height: 38px;
  fill: var(--accent);
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.4));
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-text strong {
  font-size: 1.06rem;
  letter-spacing: 0.16em;
}
.brand-text span {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  transition: background 0.16s, border-color 0.16s, transform 0.12s;
}
.icon-btn:hover {
  background: var(--panel-2);
  border-color: var(--accent);
}
.icon-btn:active {
  transform: translateY(1px);
}
.icon-btn svg {
  width: 19px;
  height: 19px;
  grid-area: 1 / 1;
  fill: currentColor;
  stroke: none;
}
.icon-btn svg .wave,
.icon-btn svg .rays {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}
.icon-btn .ic-sound-off,
.icon-btn .ic-amb-off,
.icon-btn.off .ic-sound-on,
.icon-btn.off .ic-amb-on,
.ic-sun,
:root[data-theme="light"] .ic-moon {
  display: none;
}
.icon-btn.off .ic-sound-off,
.icon-btn.off .ic-amb-off,
:root[data-theme="light"] .ic-sun {
  display: block;
}

/* ============================================================ layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  gap: clamp(16px, 2.4vw, 30px);
  align-items: start;
}

.board-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: min(100%, 74vh);
  margin: 0 auto;
}
#strip-top {
  order: 1;
}
.board-frame {
  order: 2;
}
#strip-bottom {
  order: 3;
}
.board-area.flipped #strip-top {
  order: 3;
}
.board-area.flipped #strip-bottom {
  order: 1;
}

/* ============================================================ player strips */
.player-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 0 4px;
}
.player-strip .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid var(--line);
  flex: none;
}
#strip-bottom .dot {
  background: var(--w-fill);
}
#strip-top .dot {
  background: var(--b-fill);
}
.player-strip .pname {
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.player-strip .tray {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  min-width: 0;
  flex: 1;
}
.taken {
  width: 19px;
  height: 19px;
  margin-right: -6px;
  opacity: 0.72;
}
.taken:last-child {
  margin-right: 0;
}
.taken svg {
  width: 100%;
  height: 100%;
  display: block;
  stroke-width: 1.2;
}
.taken.w svg {
  fill: var(--w-fill);
  stroke: var(--w-line);
}
.taken.b svg {
  fill: var(--b-fill);
  stroke: var(--b-line);
}
.player-strip .material {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
/* The clock sits at the far end of its own player's strip, so it reads as
   belonging to that side of the board rather than to the panel. */
.player-strip .clock {
  flex: none;
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.player-strip .clock.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.player-strip .clock.low {
  color: #e0524b;
  border-color: rgb(224 82 75 / 0.5);
}
.player-strip .clock.active.low {
  background: rgb(224 82 75 / 0.12);
  animation: clock-low 1s ease-in-out infinite;
}
@keyframes clock-low {
  50% { opacity: 0.45; }
}

.thinking-tag {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.thinking-tag i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.1s infinite;
}
.thinking-tag i:nth-child(2) {
  animation-delay: 0.16s;
}
.thinking-tag i:nth-child(3) {
  animation-delay: 0.32s;
}
@keyframes blink {
  0%, 60%, 100% { opacity: 0.2; }
  30% { opacity: 1; }
}

/* ============================================================ board */
.board-frame {
  position: relative;
  padding: clamp(15px, 2.6vw, 26px);
  border-radius: var(--radius);
  background: linear-gradient(155deg, var(--bezel-1), var(--bezel-2) 62%, #0a0c10);
  box-shadow: var(--shadow-lg), 0 0 90px -30px rgba(150, 170, 210, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px rgba(0, 0, 0, 0.45);
}
.board-frame::before {
  content: "";
  position: absolute;
  inset: clamp(9px, 1.7vw, 17px);
  border-radius: 8px;
  border: 1px solid rgba(186, 150, 78, 0.34);
  pointer-events: none;
}

/* The brass hairline breathes while the computer is searching. */
body.thinking .board-frame::before {
  animation: thinkGlow 1.7s ease-in-out infinite;
}
@keyframes thinkGlow {
  0%, 100% { border-color: rgba(186, 150, 78, 0.34); }
  50% { border-color: rgba(214, 178, 96, 0.8); }
}

.board {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  touch-action: none;
  cursor: pointer;
}
.board.locked {
  cursor: default;
}

.squares {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45), inset 0 3px 20px rgba(0, 0, 0, 0.3);
}
/* Layered gradients fake aged stone / obsidian without shipping a texture. */
.sq {
  position: relative;
}
.sq.light {
  background:
    repeating-linear-gradient(112deg, rgba(255, 255, 255, 0.045) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(24deg, rgba(60, 55, 45, 0.045) 0 1px, transparent 1px 11px),
    linear-gradient(158deg, var(--sq-light-1), var(--sq-light-2));
}
.sq.dark {
  background:
    repeating-linear-gradient(112deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(24deg, rgba(0, 0, 0, 0.09) 0 1px, transparent 1px 11px),
    linear-gradient(158deg, var(--sq-dark-1), var(--sq-dark-2));
}

.markers,
.pieces,
.coords {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.coord {
  position: absolute;
  font-size: clamp(0.55rem, 1.1vw, 0.68rem);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(196, 162, 92, 0.72);
}
:root[data-theme="light"] .coord {
  color: rgba(255, 246, 226, 0.88);
}
.coord.file {
  left: calc(var(--c) * 12.5%);
  width: 12.5%;
  bottom: -1.35em;
  text-align: center;
}
.coord.rank {
  top: calc(var(--r) * 12.5%);
  height: 12.5%;
  left: -1.5em;
  width: 1.2em;
  display: grid;
  place-items: center;
}

/* ------------------------------------------------ markers */
.marker {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
}
/* Markers carry the colour of the piece they belong to, so both sides read
   as opposing factions rather than "the highlight colour". */
.marker {
  --f: var(--accent-rgb);
}
.marker.w {
  --f: var(--faction-w-rgb);
}
.marker.b {
  --f: var(--faction-b-rgb);
}

.marker.last {
  background: linear-gradient(160deg, rgb(var(--f) / 0.26), rgb(var(--f) / 0.11));
  box-shadow: inset 0 0 0 1px rgb(var(--f) / 0.34);
}
.marker.selected {
  background: rgb(var(--f) / 0.2);
  box-shadow: inset 0 0 0 2px rgb(var(--f) / 0.6), inset 0 0 18px rgb(var(--f) / 0.3);
}

/* Soft glowing ring instead of a flat dot, breathing gently. */
.marker.target::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgb(var(--f) / 0.72) 0 38%,
    rgb(var(--f) / 0.26) 62%,
    transparent 76%
  );
  box-shadow: 0 0 14px rgb(var(--f) / 0.45);
  animation: pop 0.18s ease-out, breathe 2.4s ease-in-out 0.18s infinite;
}
/* The capture ring is the marker itself, and `transform` already positions it,
   so it breathes on opacity only. */
.marker.target-capture {
  border-radius: 50%;
  box-shadow: inset 0 0 0 max(3px, 0.85vmin) rgb(var(--f) / 0.62),
    inset 0 0 22px rgb(var(--f) / 0.34), 0 0 12px rgb(var(--f) / 0.28);
  animation: fade 0.18s ease-out, breatheFade 2.4s ease-in-out 0.18s infinite;
}
@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
}
@keyframes fade {
  from { opacity: 0; }
}
@keyframes breathe {
  0%, 100% { opacity: 0.72; transform: scale(0.94); }
  50% { opacity: 1; transform: scale(1.06); }
}
@keyframes breatheFade {
  0%, 100% { opacity: 0.74; }
  50% { opacity: 1; }
}

/* Urgent: warmer, brighter and roughly twice the tempo of a move ring. */
.marker.check::after {
  content: "";
  position: absolute;
  inset: -6%;
  background: radial-gradient(
    circle,
    rgba(255, 138, 60, 0.92) 6%,
    rgba(228, 74, 38, 0.55) 44%,
    transparent 74%
  );
  filter: blur(1px);
  animation: checkPulse 0.85s ease-in-out infinite;
}
@keyframes checkPulse {
  0%, 100% { opacity: 0.5; transform: scale(0.86); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* ------------------------------------------------ pieces */
.piece {
  position: absolute;
  top: 0;
  left: 0;
  width: 12.5%;
  height: 12.5%;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
  /* --dur is set per move in board.js: longer slides take (a little) longer. */
  transition: transform var(--dur, 240ms) var(--ease);
  will-change: transform;
}
.piece.no-anim {
  transition: none;
}
.piece svg {
  width: 100%;
  height: 100%;
  display: block;
  padding: 5%;
  stroke-width: 1.15;
  transition: transform 0.18s var(--ease), opacity 0.22s ease, filter 0.18s ease;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}
.piece.w svg {
  fill: var(--w-fill);
  stroke: var(--w-line);
}
.piece.b svg {
  fill: var(--b-fill);
  stroke: var(--b-line);
}
.piece svg .detail {
  fill: none;
  stroke-width: 1.25;
}
.piece.w .eye {
  fill: var(--w-eye);
  stroke: none;
}
.piece.b .eye {
  fill: var(--b-eye);
  stroke: none;
}

/* Picked up (click or drag start): the piece lifts off the board. */
.piece.lifted {
  z-index: 10;
}
.piece.lifted svg {
  transform: scale(1.07);
  filter: drop-shadow(0 7px 9px rgba(0, 0, 0, 0.55));
}
.piece.dragging {
  transition: none;
  transform: translate(var(--dx), var(--dy));
  z-index: 20;
}
.piece.dragging svg {
  transform: scale(1.14);
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.5));
}
/* Landing squash-and-settle, so a move ends with weight instead of stopping. */
.piece.land svg {
  animation: settle 110ms ease-out;
}
@keyframes settle {
  0% { transform: scale(1.05, 0.95); }
  55% { transform: scale(0.96, 1.04); }
  100% { transform: scale(1); }
}
.piece.appear svg {
  opacity: 0;
  transform: scale(0.55);
}
/* A captured piece keeps dissolving while the capturer is still sliding in. */
.piece.gone {
  z-index: 0;
}
.piece.gone svg {
  opacity: 0;
  transform: scale(0.55) rotate(-8deg);
}

/* ------------------------------------------------ overlays on the board */
.overlay,
.promo {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(6, 8, 12, 0.68);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 30;
}
.overlay.show,
.promo.show {
  opacity: 1;
}

.result-card,
.promo-card {
  text-align: center;
  padding: 26px 32px;
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  border: 1px solid var(--line);
  box-shadow: 0 24px 48px -18px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transform: translateY(14px) scale(0.96);
  transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.25, 1.1);
}
.overlay.show .result-card,
.promo.show .promo-card {
  transform: none;
}
.result-icon {
  font-size: 2.6rem;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 6px;
}
.result-card h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
.result-card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.promo-card p {
  margin: 0 0 12px;
  font-size: 0.8rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.promo-choices {
  display: flex;
  gap: 8px;
}
.promo-btn {
  width: clamp(48px, 9vw, 62px);
  height: clamp(48px, 9vw, 62px);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.promo-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
}
.promo-btn svg {
  width: 100%;
  height: 100%;
  stroke-width: 1.15;
}
.promo-btn.w svg {
  fill: var(--w-fill);
  stroke: var(--w-line);
}
.promo-btn.b svg {
  fill: var(--b-fill);
  stroke: var(--b-line);
}

/* ============================================================ panel */
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 0.92rem;
  font-weight: 600;
  transition: border-color 0.2s, color 0.2s;
}
.status.check {
  border-color: rgba(255, 122, 60, 0.55);
  color: #ff9a63;
  box-shadow: 0 0 22px -6px rgba(255, 122, 60, 0.5);
}
.status.over {
  border-color: var(--accent);
  color: var(--accent);
}
/* The turn indicator glows in the faction colour of the side to move. */
.turn-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: none;
  border: 1px solid rgb(var(--f) / 0.7);
  box-shadow: 0 0 0 3px rgb(var(--f) / 0.16), 0 0 12px rgb(var(--f) / 0.5);
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.turn-dot[data-turn="w"] {
  --f: var(--faction-w-rgb);
  background: var(--w-fill);
}
.turn-dot[data-turn="b"] {
  --f: var(--faction-b-rgb);
  background: var(--b-fill);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
/* A small glowing bronze tick anchors each section header. */
.label::before {
  content: "";
  width: 3px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px rgb(var(--accent-rgb) / 0.8);
  flex: none;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.segmented button {
  padding: 8px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.16s, color 0.16s;
}
.segmented.small button {
  font-size: 0.74rem;
  padding: 7px 2px;
}
.segmented button:hover {
  color: var(--text);
}
.segmented button.on {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgb(var(--accent-rgb) / 0.38), 0 0 14px -4px rgb(var(--accent-rgb) / 0.55);
}

.moves {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
}
.moves-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.eval {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.movelist {
  list-style: none;
  margin: 0;
  padding: 6px;
  height: clamp(140px, 26vh, 260px);
  overflow-y: auto;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.82rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.movelist::-webkit-scrollbar {
  width: 8px;
}
.movelist::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
}
.movelist li {
  display: grid;
  grid-template-columns: 2.1em 1fr 1fr;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 6px;
}
.movelist li:nth-child(odd) {
  background: rgba(255, 255, 255, 0.022);
}
.movelist .num {
  color: var(--muted);
  font-size: 0.74rem;
}
.movelist .san {
  padding: 2px 5px;
  border-radius: 5px;
}
.movelist .san.current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn {
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.16s, border-color 0.16s, transform 0.12s, opacity 0.16s;
}
.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
.btn.primary {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, #c8a251, #8f7028);
  border-color: transparent;
  color: #16110a;
  box-shadow: 0 0 20px -6px rgb(var(--accent-rgb) / 0.7);
}
.btn.primary:hover:not(:disabled) {
  filter: brightness(1.1);
  background: linear-gradient(180deg, #c8a251, #8f7028);
}
.result-card .btn.primary {
  padding: 11px 26px;
}

/* ============================================================ online */
/* Three modes share the width two used to, so the labels tighten up. */
#mode button {
  font-size: 0.76rem;
  padding: 8px 2px;
}

.online-lobby,
.online-room {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
}
.code-input {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.code-input::placeholder {
  color: var(--muted);
  letter-spacing: 0.22em;
}
.code-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* The code is the one thing on screen a player has to read out loud. */
.room-code {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border-radius: 11px;
  border: 1px dashed rgb(var(--accent-rgb) / 0.5);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 1.32rem;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-indent: 0.26em; /* letter-spacing pads the right edge; recentre it */
  user-select: text;
}
.room-code:hover {
  border-style: solid;
}
.copy-hint {
  font-family: var(--font);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-indent: 0;
  text-transform: uppercase;
  color: var(--muted);
}

.tc-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
}
.tc-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.online-you,
.online-note,
.online-conn {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}
.online-note.error {
  color: #e0524b;
}
/* An opponent who vanished is the one thing here worth interrupting for. */
.online-conn {
  color: #e0524b;
  font-weight: 600;
  animation: waiting 1.5s ease-in-out infinite;
}
/* Waiting on the second player: the same pulse the thinking tag uses. */
.online-room.waiting .online-you {
  color: var(--accent);
  animation: waiting 1.5s ease-in-out infinite;
}
@keyframes waiting {
  50% { opacity: 0.42; }
}

/* ============================================================ boot */
.boot {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.9rem;
  z-index: 100;
}
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================ responsive */
@media (max-width: 940px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .board-area {
    max-width: min(100%, 66vh);
  }
  .movelist {
    height: 130px;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 10px;
  }
  .board-area {
    max-width: 100%;
  }
  .brand-text span {
    display: none;
  }
  .board-frame {
    padding: 13px 15px 20px;
  }
  .coord.rank {
    left: -1.25em;
  }
  .panel {
    padding: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
