/* Fruit Fly Chess -------------------------------------------------------- */
/* Quiet, flat dark UI: one accent (Kenyon-cell cyan) for everything the fly
   does, neutral greys for the rest, color reserved for the brain and for
   meaning (won/lost, attractive/aversive). */
:root {
  color-scheme: dark;

  --bg: #0a0b0d;
  --surface: #111317;
  --surface-2: #171a1f;
  --surface-3: #1e2228;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #ececee;
  --muted: #9ba1ab;        /* 7:1 on --surface */
  --faint: #6b717c;        /* decorative / large text only */

  --accent: #22d3ee;
  --accent-ink: #04161b;
  --red: #f87171;
  --green: #34d399;
  --amber: #f5a524;

  /* neuron groups (brain map + legend) */
  --g-orn: #f5a524;
  --g-pn: #ff7a59;
  --g-ln: #e879f9;
  --g-kc: #22d3ee;
  --g-apl: #cbd5e1;
  --g-mbon_a: #34d399;
  --g-mbon_v: #f87171;
  --g-dan: #a78bfa;
  --g-lh: #facc15;
  --g-vis: #60a5fa;
  --g-cen: #a5b4c8;
  --g-out: #f8fafc;
  --g-sens: #d9f99d;

  --sq-light: #dee3e8;
  --sq-dark: #8796a5;
  --sq-last: rgba(56, 189, 248, 0.34);
  --sq-sel: rgba(34, 211, 238, 0.42);

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --ease-out: cubic-bezier(0.22, 0.8, 0.26, 1);
  --t-fast: 150ms;
  --t: 220ms;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* .btn gibi display kurallari hidden'i ezmesin */
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: clip;          /* never pan sideways on phones (clip keeps the sticky header working) */
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
svg { display: block; }
h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.1px; }
h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: 0.6px; text-transform: uppercase; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 28px;
  height: 60px; padding: 0 28px;
  background: rgba(10, 11, 13, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; flex: none; }
.logo { width: 30px; height: 30px; }
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: -0.2px; }

.modes { display: flex; align-items: stretch; gap: 4px; height: 100%; }
.seg {
  position: relative; padding: 0 12px; border: 0; background: none;
  color: var(--muted); font-size: 14px; font-weight: 500;
  transition: color var(--t-fast) ease;
}
.seg:hover { color: var(--text); }
.seg[aria-selected="true"] { color: var(--text); }
.seg[aria-selected="true"]::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px;
  border-radius: 2px; background: var(--accent);
}
.link-btn {
  margin-left: auto; border: 0; background: none; padding: 6px 2px;
  color: var(--muted); font-size: 14px; font-weight: 500;
  transition: color var(--t-fast) ease;
}
.link-btn:hover { color: var(--text); }

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 580px) minmax(400px, 1fr);
  gap: 32px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px 28px 8px;
  align-items: start;
}
.play, .insight { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.insight { gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
}
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 4px; }
.card-sub { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.card-sub b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.card-note { color: var(--muted); font-size: 12.5px; }
.sub-head { display: flex; align-items: baseline; gap: 10px; margin: 20px 0 8px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface-2); font-weight: 500; font-size: 13.5px;
  transition: background var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: rgba(255, 255, 255, 0.18); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--text); border-color: var(--text); color: #0a0b0d; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #ffffff; border-color: #ffffff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; color: var(--text); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 36px; padding: 0; }
.btn svg { width: 16px; height: 16px; }
.btn.danger { color: var(--red); border-color: rgba(248, 113, 113, 0.28); background: transparent; margin-top: 20px; }
.btn.danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.08); border-color: rgba(248, 113, 113, 0.5); }

.select {
  min-height: 32px; padding: 0 28px 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5' fill='none' stroke='%239ba1ab' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 8px center / 14px;
  color: var(--muted); font-size: 12.5px; appearance: none; cursor: pointer;
}
.select:hover { color: var(--text); border-color: var(--line-2); }

/* ---------------------------------------------------------------- players */
.player { display: flex; align-items: center; gap: 12px; padding: 2px 2px; }
.avatar { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.avatar.fly { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.avatar.fly svg { width: 30px; height: 30px; }
.avatar.you-av { background: var(--surface-2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.avatar.you-av svg { width: 18px; height: 18px; }
.player-meta { min-width: 0; flex: 1; }
.player-name { font-weight: 600; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.player-sub { font-size: 12.5px; color: var(--muted); }
.mode-tag { font-size: 11px; font-weight: 500; padding: 0 7px; line-height: 18px; border-radius: 5px; background: var(--surface-3); color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.pill[data-state="thinking"] { color: var(--accent); }
.pill[data-state="thinking"] .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.pill[data-state="pondering"] { color: #8fd3df; }
.pill[data-state="pondering"] .dot { background: #67c6d6; animation: pulse 1.8s ease-in-out infinite; }
.pill[data-state="turn"] { color: var(--text); }
.pill[data-state="turn"] .dot { background: var(--green); }
.pill[data-state="won"] { color: var(--green); }
.pill[data-state="won"] .dot { background: var(--green); }
.pill[data-state="lost"] { color: var(--red); }
.pill[data-state="lost"] .dot { background: var(--red); }
.pill .t { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: 2px; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.8); } }

/* ---------------------------------------------------------------- board */
.board-shell {
  position: relative; border-radius: var(--r);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 20px 40px rgba(0, 0, 0, 0.35);
  transition: box-shadow var(--t) ease;
}
/* Touch: the page scrolls when you swipe across the board; scrolling is switched off
   only where a touch can start a move (your movable pieces, the selected piece, the
   squares it can go to) so dragging still works. */
.board {
  position: relative; width: 100%; aspect-ratio: 1;
  border-radius: var(--r); overflow: hidden; user-select: none; touch-action: manipulation;
}
.board.can-move .sq.can, .board .sq.sel, .board .sq.target, .board.dragging .sq { touch-action: none; }
.squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.sq {
  position: relative; border: 0; padding: 0; margin: 0; border-radius: 0;
  cursor: default; outline-offset: -3px;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq::before, .sq::after { content: ""; position: absolute; pointer-events: none; }
.sq.last::before { inset: 0; background: var(--sq-last); }
.sq.sel::before { inset: 0; background: var(--sq-sel); }
.sq.from-preview::before { inset: 0; background: rgba(34, 211, 238, 0.16); }
.sq.check::before { inset: 0; background: radial-gradient(circle, rgba(239, 68, 68, 0.95) 0 28%, rgba(239, 68, 68, 0.35) 52%, transparent 74%); }
.sq.target::after {
  width: 30%; height: 30%; left: 35%; top: 35%; border-radius: 50%;
  background: rgba(10, 20, 26, 0.32);
  transition: transform var(--t-fast) var(--ease-out), opacity var(--t-fast) ease;
}
.sq.target.occupied::after {
  inset: 4%; width: auto; height: auto; left: 4%; top: 4%; border-radius: 50%;
  background: none; box-shadow: inset 0 0 0 5px rgba(10, 20, 26, 0.32);
}
.sq.target { cursor: pointer; }
.sq.target:hover::after, .sq.target.hover::after { transform: scale(1.18); }
.sq.target.occupied:hover::after, .sq.target.occupied.hover::after { transform: none; box-shadow: inset 0 0 0 5px rgba(34, 211, 238, 0.75); }
.sq.preview::after { opacity: 0.5; }
.sq.hover:not(.target)::after { inset: 0; width: auto; height: auto; left: 0; top: 0; border-radius: 0; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.7); background: none; }
.sq .coord { position: absolute; font: 600 10.5px var(--font); opacity: 0.9; pointer-events: none; }
.sq .coord.file { right: 4px; bottom: 2px; }
.sq .coord.rank { left: 4px; top: 2px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.pieces { position: absolute; inset: 0; pointer-events: none; }
.pc {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%;
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
  transition: transform var(--t) var(--ease-out), opacity 160ms ease;
  will-change: transform;
}
.pc img {
  display: block; width: 100%; height: 100%; pointer-events: none; user-select: none;
  filter: drop-shadow(0 1.5px 1px rgba(0, 0, 0, 0.22));
  transition: transform var(--t-fast) var(--ease-out), filter var(--t-fast) ease;
}
.pieces.no-anim .pc { transition: none !important; }
.pc.dragging { transition: none; z-index: 10; }
.pc.dragging img { transform: scale(1.12); filter: drop-shadow(0 10px 8px rgba(0, 0, 0, 0.4)); }
.pc.captured { opacity: 0; transition: opacity 180ms ease; }
.pc.appear { animation: appear 200ms var(--ease-out); }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
.board.can-move .sq.can { cursor: grab; }
.board.dragging, .board.dragging .sq { cursor: grabbing; }
.board.busy .sq { cursor: progress; }

/* experimental 3D view */
.view-toggle {
  align-self: flex-end; display: inline-flex; gap: 2px; padding: 2px; margin-bottom: -4px;
  border-radius: 8px; background: var(--surface); border: 1px solid var(--line);
}
.view-toggle button {
  border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 500;
  padding: 3px 10px; border-radius: 6px; display: inline-flex; align-items: center; gap: 5px;
}
.view-toggle button:hover { color: var(--text); }
.view-toggle button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.view-toggle .beta { font-size: 9.5px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase; color: var(--accent); }
.board3d {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: var(--r); overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1a2028, #0b0d10 75%); touch-action: manipulation;
}
.board3d canvas { display: block; width: 100%; height: 100%; touch-action: none; }   /* pieces can be dragged by touch */
.board3d-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; pointer-events: none; }
.board3d-msg:empty { display: none; }
.board-shell.view-3d .board, .board-shell.view-3d .kbadges { display: none; }

/* board themes */
.board[data-theme="walnut"] { --sq-light: #ebdcc0; --sq-dark: #ad8460; --sq-last: rgba(245, 190, 60, 0.42); }
.board[data-theme="sage"] { --sq-light: #eceed4; --sq-dark: #7a9a5c; --sq-last: rgba(246, 246, 105, 0.5); }
.board[data-theme="ocean"] { --sq-light: #dfe7ec; --sq-dark: #7f9db0; --sq-last: rgba(120, 200, 255, 0.4); }

/* review */
.board-shell.reviewing { box-shadow: 0 0 0 2px var(--amber), 0 20px 40px rgba(0, 0, 0, 0.35); }
.review-tag {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%); z-index: 3;
  font: 600 10.5px/1 var(--font); letter-spacing: 0.6px; text-transform: uppercase;
  padding: 5px 9px; border-radius: 999px; background: var(--amber); color: #2a1800;
  opacity: 0; pointer-events: none; transition: opacity var(--t) ease;
}
.board-shell.reviewing .review-tag { opacity: 1; }

.nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-btns { display: flex; gap: 2px; }
.nav-btns .btn { min-height: 32px; width: 34px; }
.nav-btns svg { width: 17px; height: 17px; }
.nav-pos { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.board-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.board-tools .btn.icon { width: 32px; min-height: 32px; }
#fast[aria-pressed="true"] { color: var(--accent); background: rgba(34, 211, 238, 0.1); }
.cands tr.fresh td { background: rgba(34, 211, 238, 0.06); animation: fresh-row 420ms var(--ease-out); }
@keyframes fresh-row { from { background: rgba(34, 211, 238, 0.22); } }

.status { min-height: 22px; font-size: 14px; color: var(--muted); padding: 4px 2px 0; }
.status b { color: var(--text); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.moves-card { margin-top: 8px; }
.moves-card .card-head { margin-bottom: 10px; }
.moves {
  margin: 0; padding: 0; list-style: none;
  display: grid; grid-template-columns: 34px 1fr 1fr; gap: 0 10px;
  font: 13px/1.95 var(--mono); max-height: 200px; overflow-y: auto;
}
.moves li { display: contents; }
.moves .n { color: var(--faint); align-self: center; }
.mv-btn {
  justify-self: start; border: 0; background: none; padding: 0 6px; margin-left: -6px;
  font: inherit; color: var(--text); border-radius: 5px; line-height: 1.95;
  transition: background var(--t-fast) ease;
}
.mv-btn:hover { background: var(--surface-3); }
.mv-btn.fly { color: var(--accent); }
.mv-btn.cur { background: rgba(34, 211, 238, 0.14); }
.mv-btn.cheat { text-decoration: underline wavy var(--amber); text-underline-offset: 4px; }
.result { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 5px; background: var(--surface-3); color: var(--muted); }
.result.win { color: var(--green); background: rgba(52, 211, 153, 0.1); }
.result.loss { color: var(--red); background: rgba(248, 113, 113, 0.1); }
.agree { margin-left: auto; }

/* ---------------------------------------------------------------- game over */
/* king badges: crown on the winner, # on the mated king, ½ on both for a draw */
.kbadges { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.kbadge {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%;
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
}
.kbadge i {
  position: absolute; right: 3%; top: 3%; width: 34%; height: 34%; min-width: 17px; min-height: 17px;
  display: grid; place-items: center; border-radius: 50%;
  font: 700 12px/1 var(--font); font-style: normal; color: #fff;
  box-shadow: 0 0 0 2px rgba(10, 11, 13, 0.85), 0 4px 10px rgba(0, 0, 0, 0.35);
  animation: badge-pop 460ms cubic-bezier(0.34, 1.56, 0.64, 1) 250ms both;
}
.kbadge i svg { width: 64%; height: 64%; }
.kbadge.win i { background: var(--green); color: #04261a; }
.kbadge.lose i { background: #ef4444; animation-delay: 380ms; }
.kbadge.draw i { background: #6b717c; }
@keyframes badge-pop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.pc.fallen img {
  transform: rotate(-16deg) translate(-3%, 5%);
  filter: drop-shadow(0 1.5px 1px rgba(0, 0, 0, 0.22)) saturate(0.7) brightness(0.92);
  transition: transform 700ms cubic-bezier(0.3, 1.4, 0.5, 1) 200ms, filter 700ms ease 200ms;
}

/* fixed to the viewport so it never widens the page (it used to overflow the board and let phones pan sideways) */
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }

.result-overlay {
  --tone: var(--muted);
  position: absolute; inset: 0; z-index: 8; border-radius: var(--r);
  display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(8, 10, 13, 0.5), rgba(8, 10, 13, 0.8));
  backdrop-filter: blur(2.5px) saturate(0.8);
  animation: fade-in 380ms ease both;
}
.result-overlay[data-outcome="win"] { --tone: var(--green); }
.result-overlay[data-outcome="loss"] { --tone: #f87171; }
.result-overlay[data-outcome="draw"] { --tone: #a1a7b0; }
.result-overlay.closing { animation: fade-out 200ms ease both; }
.result-overlay.closing .result-card { animation: card-out 200ms ease both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }

.result-card {
  position: relative; width: min(340px, 100%); padding: 26px 22px 16px; text-align: center;
  background: linear-gradient(180deg, color-mix(in srgb, var(--tone) 7%, #121418), #111317 45%);
  border: 1px solid var(--line-2); border-radius: 16px; outline: none;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  animation: card-in 560ms cubic-bezier(0.2, 0.9, 0.25, 1.12) 60ms both;
}
.result-card::before {
  content: ""; position: absolute; left: 22px; right: 22px; top: -1px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--tone), transparent);
}
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes card-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
.result-card > * { animation: rise 460ms var(--ease-out) both; }
.result-card > :nth-child(2) { animation-delay: 160ms; }
.result-card > :nth-child(3) { animation-delay: 200ms; }
.result-card > :nth-child(4) { animation-delay: 240ms; }
.result-card > :nth-child(5) { animation-delay: 290ms; }
.result-card > :nth-child(6) { animation-delay: 330ms; }
.result-card > :nth-child(n+7) { animation-delay: 370ms; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.result-emblem {
  position: relative; width: 64px; height: 64px; margin: 0 auto 14px;
  display: grid; place-items: center; border-radius: 18px; color: var(--tone);
  background: color-mix(in srgb, var(--tone) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 38%, transparent);
  animation: emblem-in 640ms cubic-bezier(0.34, 1.56, 0.64, 1) 120ms both !important;
}
.result-emblem svg { width: 34px; height: 34px; }
.result-emblem svg.fly { width: 46px; height: 46px; }
.result-emblem .half { font: 700 30px/1 var(--font); }
.result-emblem::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--tone) 45%, transparent);
  animation: emblem-ring 1.8s ease-out 700ms 2;
}
@keyframes emblem-in { from { opacity: 0; transform: scale(0.5) rotate(-8deg); } to { opacity: 1; transform: none; } }
@keyframes emblem-ring { to { box-shadow: 0 0 0 16px transparent; } }

.result-score { font: 500 12px var(--mono); color: var(--muted); letter-spacing: 1px; }
.result-title { margin: 4px 0 4px; font-size: 25px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.15; }
.result-sub { margin: 0; color: var(--muted); font-size: 13.5px; }
.result-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 18px 0 0;
  background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.result-stats div { background: #111317; padding: 9px 4px 8px; min-width: 0; }
.result-stats dt { font-size: 10px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.6px; white-space: nowrap; }
.result-stats dd { margin: 3px 0 0; font: 600 15px/1.2 var(--font); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-note { margin: 12px 2px 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.result-note:empty { display: none; }
.result-note b { color: var(--text); font-weight: 600; }
.result-actions { display: flex; gap: 8px; margin-top: 18px; }
.result-actions .btn { flex: 1; }
.result-review { display: block; margin: 10px auto 0; font-size: 13px; }

#result.clickable { cursor: pointer; }
#result.clickable:hover { filter: brightness(1.2); }

/* ---------------------------------------------------------------- brain */
.live-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 10.5px/1 var(--font); letter-spacing: 0.7px; text-transform: uppercase;
  padding: 4px 8px; border-radius: 5px; background: var(--surface-3); color: var(--muted);
}
.live-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.live-badge[data-state="live"] { color: #ff8a8a; background: rgba(248, 113, 113, 0.1); }
.live-badge[data-state="live"] .dot { background: #ff5a5a; animation: ring 1.4s ease-out infinite; }
.live-badge[data-state="replay"] { color: #8fd3df; background: rgba(34, 211, 238, 0.08); }
.live-badge[data-state="replay"] .dot { background: #67c6d6; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.55); } 100% { box-shadow: 0 0 0 6px rgba(255, 90, 90, 0); } }
.stage-stat { margin-left: auto; font: 12px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }

.stage { position: relative; border-radius: var(--r); overflow: hidden; background: #05070a; }
.stage-labels { position: absolute; inset: 0; pointer-events: none; }
.rlabel {
  position: absolute; transform: translate(-50%, -50%);
  font: 600 9.5px/1 var(--font); letter-spacing: 1px; text-transform: uppercase; white-space: nowrap;
  color: rgba(214, 226, 238, 0.62); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 8px rgba(0, 0, 0, 0.8);
}
.stage.no-labels .stage-labels { display: none; }
.stage-orient { position: absolute; right: 12px; bottom: 9px; font: 10.5px var(--mono); color: rgba(160, 176, 194, 0.5); pointer-events: none; }
#brain-labels[aria-pressed="false"] { color: var(--faint); }
#brain { display: block; width: 100%; height: auto; }
.stage-caption {
  position: absolute; left: 10px; bottom: 8px; max-width: calc(100% - 200px);
  font: 500 12px/1.4 var(--mono); color: #c4ced8;
  background: rgba(5, 7, 10, 0.78); padding: 4px 8px; border-radius: 5px;
  pointer-events: none;
}
.stage-caption:empty { display: none; }
.stage-controls { display: flex; align-items: center; gap: 4px; margin: 10px 0 0 -6px; flex-wrap: wrap; }
.legend {
  list-style: none; margin: 12px 0 0; padding: 14px 0 0; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 22px;
  font-size: 12px; color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.legend .sw { width: 7px; height: 7px; border-radius: 50%; flex: none; box-shadow: 0 0 6px currentColor; }
.legend .n { margin-left: auto; font: 11.5px var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- candidates */
.table-wrap { overflow-x: auto; margin: 0 -6px; }
.cands { width: 100%; border-collapse: collapse; font-size: 13px; }
.cands th { text-align: left; font-weight: 500; color: var(--faint); font-size: 11.5px; padding: 0 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.cands td { padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.cands tr:last-child td { border-bottom: 0; }
.cands .num { text-align: right; font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--muted); }
.cands th.num { font-family: var(--font); font-size: 11.5px; color: var(--faint); }
.cands .range { font: 400 11px var(--mono); color: var(--faint); margin-left: 6px; }
.cands tr.chosen td { background: rgba(34, 211, 238, 0.06); }
.cands tr.chosen td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.mv { font: 500 13px var(--mono); white-space: nowrap; }
.badge { font: 500 10.5px var(--font); padding: 1px 6px; border-radius: 4px; margin-left: 7px; vertical-align: 1px; }
.badge.pick { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.badge.engine { background: var(--surface-3); color: var(--muted); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 11px; padding: 0 7px; line-height: 19px; border-radius: 4px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.cap { color: var(--amber); background: rgba(245, 165, 36, 0.08); }
.chip.chk { color: #ff9b7e; background: rgba(255, 122, 89, 0.08); }
.chip.dng { color: var(--red); background: rgba(248, 113, 113, 0.08); }
.cands td.more { color: var(--faint); font-size: 12px; text-align: center; padding: 10px 6px 2px; }
.valdot { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.valdot .track { position: relative; flex: 1; height: 14px; }
.valdot .track::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; transform: translateY(-50%); background: var(--line-2); }
.valdot .dot { position: absolute; top: 50%; width: 8px; height: 8px; border-radius: 50%; transform: translate(-50%, -50%); background: var(--muted); transition: left var(--t) var(--ease-out); }
.cands tr.chosen .valdot .dot { width: 10px; height: 10px; background: var(--accent); box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.18); }
.valdot .v { font: 12px var(--mono); width: 42px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.cands tr.chosen .valdot .v { color: var(--text); }
.empty { color: var(--muted); font-size: 13px; padding: 14px 6px 4px; }

/* ---------------------------------------------------------------- tastes */
.tastes { display: grid; grid-template-columns: 110px 1fr 56px; gap: 8px 14px; align-items: center; font-size: 13px; }
.tastes .name small { color: var(--faint); font: 10px var(--mono); margin-left: 5px; }
.taste-axis { position: relative; height: 20px; }
.taste-axis::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line-2); }
.taste-axis .b { position: absolute; height: 7px; border-radius: 2px; transition: left var(--t) var(--ease-out), width var(--t) var(--ease-out); }
.taste-axis .b.innate { top: 2px; background: #3a414c; }
.taste-axis .b.now { top: 11px; }
.taste-axis .b.solo { top: 6.5px; }
.taste-axis .b.pos { background: var(--green); }
.taste-axis .b.neg { background: var(--red); }
.tastes .d { font: 12px var(--mono); text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.tastes .d.up { color: var(--green); }
.tastes .d.down { color: var(--red); }
.taste-key { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.taste-key i { display: inline-block; width: 12px; height: 6px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.loading { color: var(--muted); font-size: 13px; grid-column: 1 / -1; }

.syn { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); line-height: 1.6; }
.syn b { color: var(--text); font: 500 12.5px var(--mono); }
.history { display: flex; flex-wrap: wrap; gap: 4px; min-height: 22px; }
.hg { width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center; font: 600 10.5px var(--font); color: #071012; }
.hg.W { background: var(--green); }
.hg.L { background: var(--red); }
.hg.D { background: #4a515c; color: var(--text); }

.train { margin-top: 4px; }
.train-row { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.train-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.train-row select, .train-row input {
  min-height: 38px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; color: var(--text);
}
.train-row input { width: 76px; }
.progress { height: 4px; background: var(--surface-3); border-radius: 4px; overflow: hidden; margin-top: 14px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width 400ms var(--ease-out); }
#train-status { margin-top: 8px; }

/* ---------------------------------------------------------------- toast, dialog */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 50; max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px; border-radius: 10px; font-size: 13.5px;
  background: var(--surface-2); border: 1px solid var(--line-2); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: toast-in 240ms var(--ease-out);
}
.toast.reward b { color: var(--green); }
.toast.punishment b { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

dialog {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  padding: 0; border: 1px solid var(--line-2); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(3, 5, 8, 0.72); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 16px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted);
  transition: color var(--t-fast) ease, background var(--t-fast) ease;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }
.dialog-body { padding: 4px 22px 24px; overflow-y: auto; max-height: calc(100vh - 140px); }
.dialog-body h3 { margin: 20px 0 6px; color: var(--text); font-size: 12px; }
.dialog-body p { margin: 0; color: #c9ced6; font-size: 14px; line-height: 1.65; }
.dialog-body .refs { margin-top: 20px; color: var(--muted); font-size: 12.5px; }

.foot {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px;
  max-width: 1480px; margin: 28px auto 0; padding: 18px 28px 32px;
  border-top: 1px solid var(--line); color: var(--faint); font-size: 12px;
}
.foot a { color: var(--muted); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1120px) {
  /* one column: the brain goes above the board, the analysis cards below the game */
  .layout { display: flex; flex-direction: column; align-items: stretch; gap: 12px; max-width: 640px; padding: 16px 16px 8px; }
  .play, .insight { display: contents; }
  .brain-card { order: -1; }
}
@media (max-width: 720px) {
  /* phone: fit the brain strip, both players and the board on one screen */
  .topbar { gap: 10px; padding: 0 12px; height: 48px; }
  .logo { width: 26px; height: 26px; }
  .seg, .link-btn { font-size: 13.5px; }
  .layout { padding: 8px 12px 8px; gap: 8px; }
  .stage { height: clamp(96px, 15svh, 150px); }
  #brain { width: 100%; height: 100%; object-fit: contain; }
  .stage-labels, .stage-controls { display: none; }
  .player { gap: 10px; }
  .avatar { width: 30px; height: 30px; border-radius: 8px; }
  .avatar.fly svg { width: 25px; height: 25px; }
  .avatar.you-av svg { width: 16px; height: 16px; }
  .player-name { font-size: 13.5px; }
  .player-sub { font-size: 11.5px; line-height: 1.3; }
  .brand-name { display: none; }
  .seg { padding: 0 9px; }
  .seg[aria-selected="true"]::after { left: 9px; right: 9px; }
  .tastes { grid-template-columns: 84px 1fr 50px; }
  .valdot { min-width: 110px; }
  .card { padding: 16px; }
  /* compact brain above the board: the map itself, its live count and controls */
  .brain-card { padding: 12px 12px 10px; }
  .brain-card .card-sub, .brain-card .legend, .stage-orient { display: none; }
  .brain-card .card-head { margin-bottom: 8px; }
  .stage-caption { max-width: calc(100% - 20px); font-size: 11px; }
  .rlabel { font-size: 7px; letter-spacing: 0.5px; }
  .stage-controls { margin-top: 6px; }
  .result-overlay { padding: 10px; }
  .result-card { padding: 18px 14px 12px; }
  .result-emblem { width: 48px; height: 48px; margin-bottom: 8px; border-radius: 14px; }
  .result-emblem svg { width: 26px; height: 26px; }
  .result-emblem svg.fly { width: 36px; height: 36px; }
  .result-title { font-size: 20px; }
  .result-stats { margin-top: 12px; }
  .result-stats dd { font-size: 13.5px; }
  .result-note { display: none; }
  .result-note.reveal { display: block; margin-top: 8px; font-size: 12px; }
  .result-actions { margin-top: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
