:root {
  --bg: #0d1014;
  --panel: #151a21;
  --panel-2: #1b222c;
  --line: #28313d;
  --text: #e6edf3;
  --muted: #8d99a6;
  --accent: #7aa2f7;
  --good: #9ece6a;
  --warn: #e0af68;
  --bad: #f7768e;
  --book: #bb9af7;
  --sq-light: #e9d8bd;
  --sq-dark: #9a7b58;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 600px at 20% -10%, #18212c 0%, var(--bg) 55%) no-repeat, var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

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

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
}
button:hover { border-color: #3c4a5b; background: #212a36; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, #2f6fd0, #275cae); border-color: #3f7fd8; }
button.primary:hover { background: linear-gradient(180deg, #3a7de0, #2c66bd); }
button.ghost { background: transparent; }
button.small { padding: 4px 9px; font-size: 13px; border-radius: 8px; }
button.active { border-color: var(--accent); color: #cfe0ff; background: #1d2a3f; }

select, input[type=text], textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: rgba(13, 16, 20, .86);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(160deg, #2b3a52, #16202c); border: 1px solid #33425a;
  font-size: 17px; line-height: 1;
}
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; letter-spacing: .4px; text-transform: uppercase; }

nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
nav.tabs button { border: 1px solid transparent; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 9px; }
nav.tabs button:hover { color: var(--text); background: #161d26; }
nav.tabs button.active { color: var(--text); background: var(--panel-2); border-color: var(--line); }

.spacer { flex: 1; }
.pill { font-size: 12px; color: var(--muted); border: 1px solid var(--line); padding: 3px 9px; border-radius: 999px; }

main { max-width: 1240px; margin: 0 auto; padding: 22px; }
.view { display: none; }
.view.active { display: block; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 22px; align-items: start; }
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 15px; letter-spacing: .2px; }
.card h3 { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11.5px; letter-spacing: .8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.mt { margin-top: 12px; }
.hidden { display: none !important; }

/* board */
.board-wrap { position: relative; width: 100%; max-width: 620px; margin: 0 auto; }
.board {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0,0,0,.45), 0 0 0 1px #2a3340 inset;
  user-select: none;
  touch-action: manipulation;
}
.sq { position: relative; display: grid; place-items: center; cursor: pointer; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq .coord { position: absolute; font-size: 10px; font-weight: 700; opacity: .55; pointer-events: none; }
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: #6d5940; }
.sq.dark .coord { color: #f1e3cd; }

.piece {
  font-size: min(9.2vw, 62px);
  line-height: 1;
  pointer-events: none;
  transition: transform .12s ease;
  font-family: 'DejaVu Sans', 'Noto Sans Symbols 2', 'Segoe UI Symbol', sans-serif;
}
.piece.w { color: #fbf7ef; -webkit-text-stroke: 1.6px #23201c; text-shadow: 0 2px 3px rgba(0,0,0,.35); }
.piece.b { color: #22242a; -webkit-text-stroke: 1.2px #0b0c0e; text-shadow: 0 2px 3px rgba(0,0,0,.25); }
.piece.dragging { transform: scale(1.12); }

.sq.selected::after { content: ''; position: absolute; inset: 0; background: rgba(122,162,247,.42); }
.sq.last::after { content: ''; position: absolute; inset: 0; background: rgba(240,196,90,.32); }
.sq.check::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, rgba(247,118,142,.85), rgba(247,118,142,.15) 70%); }
.sq.hint::after {
  content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(20,26,34,.42); left: 35%; top: 35%;
}
.sq.hint.capture::after { width: 92%; height: 92%; left: 4%; top: 4%; background: transparent; border: 5px solid rgba(20,26,34,.34); border-radius: 50%; }
.sq .piece { position: relative; z-index: 2; }
.sq::after { z-index: 1; }

.arrows { position: absolute; inset: 0; pointer-events: none; z-index: 3; }

/* eval bar */
.evalbar { width: 10px; border-radius: 6px; overflow: hidden; background: #2a2f36; align-self: stretch; }
.evalbar .fill { background: #e9e2d6; height: 50%; transition: height .3s ease; }

/* horizontal eval bar: white share from the left */
.evalbar-h {
  position: relative; height: 12px; width: 100%; border-radius: 8px; overflow: hidden;
  background: #23262c; box-shadow: inset 0 0 0 1px var(--line);
}
.evalbar-h .fill {
  height: 100%; width: 50%; background: linear-gradient(180deg, #f6f1e7, #d6cec0);
  transition: width .25s ease;
}

/* move list */
.moves { display: flex; flex-direction: column; gap: 2px; max-height: 340px; overflow: auto; }
.mrow { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px; align-items: center; }
.mrow .num { color: var(--muted); font-size: 12px; text-align: right; }
.mv { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; cursor: pointer; font-variant-numeric: tabular-nums; }
.mv:hover { background: #1d2530; }
.mv.sel { background: #223049; }
.mv .glyph { font-size: 11px; font-weight: 700; }
.tone-great { color: var(--good); }
.tone-good { color: #a8d18d; }
.tone-ok { color: #c9d5e0; }
.tone-book { color: var(--book); }
.tone-warn { color: var(--warn); }
.tone-bad { color: #ff9f6e; }
.tone-worst { color: var(--bad); }

.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }

/* coach */
.coach { display: flex; flex-direction: column; gap: 10px; }
.coach-body { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 72px; white-space: pre-wrap; }
.coach-body.loading::after { content: ''; display: inline-block; width: 8px; height: 14px; background: var(--accent); animation: blink 1s steps(2) infinite; vertical-align: text-bottom; }
@keyframes blink { 50% { opacity: 0; } }

.stat { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed #222b36; }
.stat:last-child { border-bottom: 0; }
.stat b { font-variant-numeric: tabular-nums; }

.progress { height: 8px; background: #222b36; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, #4d7fd0, #7aa2f7); transition: width .2s; }

.list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow: auto; }
.item { display: flex; gap: 10px; align-items: center; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); cursor: pointer; }
.item:hover { border-color: #3a475a; }
.item.active { border-color: var(--accent); }
.item .tag { font-size: 11px; color: var(--muted); }

.fen { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }

kbd { background: #222b36; border: 1px solid #33404f; border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; font-size: 12px; }

footer { color: var(--muted); font-size: 12px; text-align: center; padding: 26px 20px 40px; }
footer a { color: #7c8b9c; }

.dialog { position: fixed; inset: 0; background: rgba(4,7,10,.7); display: grid; place-items: center; z-index: 50; }
.dialog .card { width: min(420px, 92vw); }
