/* Chess Walkthrough
   A study-room palette: deep slate, a blue-grey board, and one amber for "your move". */

@font-face { font-family: "Bricolage"; src: url("fonts/bricolage.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Plex"; src: url("fonts/plex-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex"; src: url("fonts/plex-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex"; src: url("fonts/plex-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --bg: #0c121c;
  --surface: #131c2a;
  --raised: #1a2538;
  --line: #263650;
  --line-soft: #1f2d44;
  --text: #e8edf6;
  --muted: #8a9ab3;
  --amber: #f3b94d;
  --amber-ink: #1d1503;
  --coral: #ef6b5b;
  --mint: #54c9a0;
  --sq-light: #d9e2ee;
  --sq-dark: #6d88ad;
  --r-card: 16px;
  --r-ctl: 10px;
  --display: "Bricolage", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Plex", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(109, 136, 173, 0.16), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 var(--body);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.hidden { display: none !important; }

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

/* ---------- Header ---------- */
.top { max-width: 1120px; margin: 0 auto; padding: 22px 16px 6px; }
.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 26px; height: 26px; border-radius: 6px; flex: none;
  background: conic-gradient(var(--sq-dark) 25%, var(--sq-light) 0 50%, var(--sq-dark) 0 75%, var(--sq-light) 0);
  box-shadow: 0 0 0 2px var(--amber);
}
h1 { font: 650 clamp(1.45rem, 4.2vw, 2rem)/1.1 var(--display); letter-spacing: -0.02em; margin: 0; }
.sub { margin: 8px 0 0; color: var(--muted); max-width: 52ch; }

main { max-width: 1120px; margin: 0 auto; padding: 14px 12px 28px; }
footer { max-width: 1120px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: 13px; }

/* ---------- Cards, controls ---------- */
.card { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-card); padding: 14px; }
#analysis { margin-top: 14px; }

input, textarea {
  width: 100%; margin: 0 0 8px; padding: 12px 13px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  font: inherit;
}
input::placeholder, textarea::placeholder { color: #66758f; }
input:focus, textarea:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(243, 185, 77, 0.18); }
textarea { resize: vertical; font-size: 13px; }

button {
  background: var(--raised); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  padding: 10px 14px; min-height: 44px;
  font: 500 14.5px/1.2 var(--body); cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
@media (hover: hover) { button:hover { border-color: #3b507a; background: #202d45; } }
button:active { transform: translateY(1px); }
button.primary { background: var(--amber); color: var(--amber-ink); border-color: var(--amber); font-weight: 600; }
@media (hover: hover) { button.primary:hover { background: #f7c76a; border-color: #f7c76a; } }
button.link { background: none; border: none; color: var(--amber); padding: 6px 2px; min-height: 0; text-decoration: underline; text-underline-offset: 3px; }

.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row > button { flex: 1; }
.hint { color: var(--muted); font-size: 13.5px; margin: 0 0 8px; }

/* ---------- Importer ---------- */
#importer > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font: 600 1.05rem/1.2 var(--display); letter-spacing: -0.01em; padding: 2px;
}
#importer > summary::-webkit-details-marker { display: none; }
.chev { width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform 0.2s; margin-right: 4px; }
#importer:not([open]) .chev { transform: rotate(-45deg); }
.importer-body { margin-top: 12px; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; margin-bottom: 12px; background: var(--bg); border-radius: 12px; }
.tab { min-height: 38px; padding: 8px 4px; font-size: 14px; background: transparent; border-color: transparent; color: var(--muted); }
.tab.active { background: var(--raised); color: var(--text); border-color: var(--line); }
.quick { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 8px; }

.game-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.game-list li { display: flex; gap: 6px; }
.game-list li > button:first-child { flex: 1; text-align: left; display: flex; justify-content: space-between; gap: 10px; background: var(--bg); }
.game-list .meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.game-list .del { flex: none; min-width: 44px; color: var(--coral); background: var(--bg); }
.auth { margin-bottom: 12px; }

/* ---------- Toast (status) ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translateX(-50%); max-width: min(92vw, 520px);
  padding: 11px 16px; border-radius: 12px; font-size: 14px;
  background: #223149; border: 1px solid #36507a; color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.toast:empty { display: none; }
.toast.err { border-color: var(--coral); background: #3a1f24; }

/* ---------- Workspace layout ---------- */
#workspace { margin-top: 14px; }
.gameinfo { display: flex; justify-content: space-between; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-bottom: 10px; }
#players { font: 600 1.1rem/1.25 var(--display); letter-spacing: -0.01em; }
#players span { color: var(--muted); font-weight: 400; font-family: var(--body); font-size: 0.9rem; }
.side-toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13.5px; }
.chip { padding: 6px 12px; min-height: 34px; border-radius: 999px; font-size: 13.5px; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.chip.save { margin-left: 4px; border-color: var(--amber); color: var(--amber); background: transparent; }

@media (min-width: 980px) {
  #workspace { display: grid; grid-template-columns: minmax(0, 580px) minmax(0, 1fr); gap: 20px; align-items: start; }
  .stage { position: sticky; top: 14px; }
  #analysis { margin-top: 0; }
}

/* ---------- Board ---------- */
.board-wrap { position: relative; width: 100%; max-width: 580px; margin: 0 auto; aspect-ratio: 1; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; height: 100%; border-radius: 10px; overflow: hidden; user-select: none; -webkit-user-select: none; box-shadow: 0 0 0 1px var(--line); }
.sq { position: relative; }
.sq.l { background: var(--sq-light); }
.sq.d { background: var(--sq-dark); }
.sq.hl::after { content: ""; position: absolute; inset: 0; background: rgba(243, 185, 77, 0.5); }
.sq.pick::after { content: ""; position: absolute; inset: 0; background: rgba(243, 185, 77, 0.75); }
.sq.dot::before { content: ""; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%; border-radius: 50%; background: rgba(12, 18, 28, 0.32); z-index: 2; }
.sq.live-click { cursor: pointer; }
.pc { position: absolute; inset: 3%; z-index: 1; background-size: contain; background-repeat: no-repeat; background-position: center; pointer-events: none; }
.coord { position: absolute; font: 600 10px/1 var(--body); z-index: 3; pointer-events: none; }
.coord.f { right: 4px; bottom: 3px; }
.coord.r { left: 4px; top: 3px; }
.sq.l .coord { color: #5b7399; }
.sq.d .coord { color: #e3ebf6; }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }

.controls { display: flex; gap: 6px; margin: 12px auto 0; max-width: 580px; }
.controls button { flex: none; min-width: 46px; padding: 8px; display: inline-flex; align-items: center; justify-content: center; }
.controls .primary { flex: 1; padding-inline: 12px; }
.controls svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.live { display: flex; gap: 6px; max-width: 580px; margin: 10px auto 0; }
.live input { margin: 0; flex: 1; }

.movelist { max-width: 580px; margin: 12px auto 0; max-height: 132px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 3px; padding: 8px; background: var(--surface); border: 1px solid var(--line-soft); border-radius: 12px; }
.mv { padding: 3px 8px; border-radius: 7px; font-size: 13.5px; cursor: pointer; border: 1px solid transparent; font-variant-numeric: tabular-nums; }
.mv .n { color: var(--muted); margin-right: 4px; }
.mv.opp { color: var(--text); font-weight: 600; }
.mv.me { color: var(--muted); }
.mv.cur { background: rgba(243, 185, 77, 0.16); border-color: var(--amber); color: var(--text); }
@media (hover: hover) { .mv:hover { background: var(--raised); } }

/* ---------- Analysis ---------- */
#analysis-head h2 { font: 650 1.25rem/1.2 var(--display); letter-spacing: -0.015em; margin: 2px 0 4px; }
#analysis-head p { margin: 0 0 10px; color: var(--muted); font-size: 14px; max-width: 60ch; }
#reset-board { margin: -2px 0 8px; }

.evalbar { height: 10px; border-radius: 999px; background: #05080e; overflow: hidden; margin: 10px 0 8px; border: 1px solid var(--line); }
.evalbar > div { height: 100%; background: linear-gradient(90deg, #cfd9e8, #f5f8fc); transition: width 0.3s; }
.note { padding: 11px 13px; border-radius: 12px; background: var(--raised); font-size: 14px; margin-bottom: 10px; color: #c7d2e4; }
.note b { color: var(--text); font-weight: 600; }
.spinner { color: var(--muted); font-size: 14px; padding: 8px 2px; }
.spinner::before { content: ""; display: inline-block; width: 12px; height: 12px; border: 2px solid var(--muted); border-right-color: transparent; border-radius: 50%; margin-right: 9px; vertical-align: -2px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul ul, .node > ul { margin: 6px 0 0 10px; padding-left: 12px; border-left: 2px solid var(--line); }
.node { margin: 8px 0; }
.node-row { background: var(--raised); border: 1px solid var(--line-soft); border-left: 4px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; transition: border-color 0.15s, background-color 0.15s; }
.node-row[data-rank="1"] { border-left-color: var(--amber); }
@media (hover: hover) { .node-row:hover { background: #202d45; } }
.node-row.sel { border-color: var(--amber); background: #22304a; }
.node-row.played { box-shadow: inset 0 0 0 1px #7f8ff0; }
.node-top { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.rank { width: 22px; height: 22px; border-radius: 50%; background: var(--line); color: var(--text); font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.node-row[data-rank="1"] .rank { background: var(--amber); color: var(--amber-ink); }
.who { font-size: 12.5px; color: var(--muted); }
.san { font: 650 1.1rem/1.1 var(--display); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.eval { padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--line); font-variant-numeric: tabular-nums; }
.eval.good { background: rgba(84, 201, 160, 0.18); color: #7ae0bd; }
.eval.bad { background: rgba(239, 107, 91, 0.2); color: #ff9a8c; }
.eval.mid { background: rgba(243, 185, 77, 0.16); color: #f6cf85; }
.verdict { color: var(--muted); font-size: 13px; }
.gauge { position: relative; height: 4px; margin-top: 9px; border-radius: 2px; background: var(--line-soft); }
.gauge::after { content: ""; position: absolute; left: 50%; top: -2px; width: 1px; height: 8px; background: #4a5f84; }
.gauge span { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.gauge .pos { background: var(--mint); }
.gauge .neg { background: var(--coral); }
.tags { margin-top: 8px; display: flex; gap: 5px; flex-wrap: wrap; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pvline { margin-top: 8px; color: #a9b7cf; font-size: 13.5px; font-variant-numeric: tabular-nums; word-break: break-word; }
.expand { margin-top: 7px; font-size: 13px; color: var(--amber); }
.played-badge { font-size: 12px; color: #aab4ff; border: 1px solid #7f8ff0; padding: 0 8px; border-radius: 999px; }

@media (max-width: 480px) {
  .controls { flex-wrap: wrap; }
  .controls button:not(.primary) { flex: 1; }
  .controls .primary { order: 10; flex: 1 1 100%; }
}
@media (max-width: 420px) {
  .tab { font-size: 13px; }
  .side-toggle > span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
