:root {
  --bg: #e8edf1; --surface: #ffffff; --ink: #1a2530; --muted: #5d6c7a; --line: #d3dbe2;
  --accent: #1d6c8a; --accent-ink: #ffffff; --accent-soft: #dcecf2;
  --sq-light: #dfe6ec; --sq-dark: #7f9bb0; --hl: rgba(255, 214, 51, .55); --arrow: #2e8b57;
  --best: #2e8b57; --good: #7aa35a; --inacc: #d19a12; --mistake: #de7a2a; --blunder: #c63a30;
  --win: #2e8b57; --draw: #8795a3; --loss: #c63a30;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181e; --surface: #1b242c; --ink: #e5ebf0; --muted: #98a6b3; --line: #2c3945;
    --accent: #55aacb; --accent-ink: #0c1318; --accent-soft: #1f3541;
    --sq-light: #b9c6d1; --sq-dark: #587388; --hl: rgba(255, 214, 51, .45);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
h1 { font-size: 1.15rem; margin: 0; letter-spacing: .01em; }
h2 { font-size: .95rem; margin: 0 0 .7rem; font-weight: 650; }
.num, td.n, .cards b { font-variant-numeric: tabular-nums; }

.top { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center; padding: .8rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.userform { display: flex; gap: .4rem; }
.actions { display: flex; gap: .5rem; align-items: center; margin-left: auto; flex-wrap: wrap; }
input[type=text], input[type=search], input[type=password], select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .4rem .6rem; min-width: 0;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn { font: inherit; cursor: pointer; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .4rem .8rem; list-style: none; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--blunder); }
.btn.small { padding: .15rem .6rem; }
summary::-webkit-details-marker { display: none; }
.settings { position: relative; }
.settings .panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 270px; display: grid; gap: .7rem; padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.settings label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }

.progress { padding: .6rem 1.25rem; background: var(--accent-soft); border-bottom: 1px solid var(--line); }
.progress-text { display: flex; justify-content: space-between; gap: 1rem; align-items: center; font-size: .9rem; margin-bottom: .4rem; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.notice { margin: .75rem 1.25rem 0; padding: .6rem .9rem; border-left: 4px solid var(--accent); background: var(--surface); border-radius: 4px; }
.notice.error { border-color: var(--blunder); }

.tabs { display: flex; gap: .25rem; padding: .6rem 1.25rem 0; border-bottom: 1px solid var(--line); }
.tabs a { padding: .5rem .9rem; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ink); border-color: var(--accent); font-weight: 600; }
main { padding: 1rem 1.25rem 3rem; max-width: 1280px; margin: 0 auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar label { display: flex; gap: .5rem; align-items: center; color: var(--muted); }
.check { color: var(--muted); }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.card, .box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .9rem 1rem; }
.card span { display: block; color: var(--muted); font-size: .82rem; }
.card b { display: block; font-size: 1.7rem; line-height: 1.2; }
.card small { color: var(--muted); }
.insights { display: grid; gap: .4rem; margin-bottom: 1rem; }
.insights p { margin: 0; padding: .5rem .8rem; background: var(--accent-soft); border-radius: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: .75rem; margin-bottom: .75rem; }
.chartwrap { position: relative; height: 260px; }
.chartwrap.short { height: 220px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .35rem .4rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.n, th.n { text-align: right; }
.wdl { display: flex; height: 8px; border-radius: 4px; overflow: hidden; min-width: 90px; background: var(--line); }
.wdl i { display: block; height: 100%; }
.wdl .w { background: var(--win); } .wdl .d { background: var(--draw); } .wdl .l { background: var(--loss); }

.gamelist { display: grid; gap: .35rem; margin-bottom: 1rem; }
.grow { display: grid; grid-template-columns: 1.4rem 1fr auto auto; gap: .2rem .9rem; align-items: center; padding: .55rem .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; color: inherit; text-decoration: none; }
.grow:hover { border-color: var(--accent); }
.grow .sub { grid-column: 2; color: var(--muted); font-size: .82rem; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.dot.w { background: #fff; } .dot.b { background: var(--ink); }
.badge { font-size: .8rem; font-weight: 600; padding: .1rem .55rem; border-radius: 10px; color: #fff; }
.badge.win { background: var(--win); } .badge.draw { background: var(--draw); } .badge.loss { background: var(--loss); }
.acc { min-width: 3.2rem; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Viewer */
.viewer { display: grid; grid-template-columns: minmax(300px, 640px) minmax(300px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .viewer { grid-template-columns: 1fr; } }
.boardrow { display: flex; gap: .5rem; }
.evalbar { width: 22px; border-radius: 4px; overflow: hidden; background: #26313b; display: flex; flex-direction: column-reverse; position: relative; flex: none; }
.evalbar.flip { flex-direction: column; }
.evalbar i { display: block; background: #f4f6f8; width: 100%; transition: height .25s; }
.evalbar em { position: absolute; left: 0; right: 0; font: 600 10px/1 var(--font); text-align: center; font-style: normal; color: #7a8896; }
.evalbar em.top { top: 3px; } .evalbar em.bot { bottom: 3px; }
.board { position: relative; flex: 1; aspect-ratio: 1; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); border-radius: 4px; overflow: hidden; user-select: none; }
.sq { position: relative; }
.sq.l { background: var(--sq-light); } .sq.d { background: var(--sq-dark); }
.sq.hl::after { content: ""; position: absolute; inset: 0; background: var(--hl); }
.sq svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.sq .co { position: absolute; font: 600 10px/1 var(--font); opacity: .75; pointer-events: none; }
.sq .co.r { top: 3px; left: 3px; } .sq .co.f { bottom: 3px; right: 3px; }
.sq.l .co { color: var(--sq-dark); } .sq.d .co { color: var(--sq-light); }
.arrow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.controls { display: flex; gap: .4rem; margin: .7rem 0 .4rem 30px; flex-wrap: wrap; }
.moveinfo { margin: .3rem 0 0 30px; min-height: 3.2rem; }
.moveinfo b { font-size: 1.05rem; }
.tag { display: inline-block; font-size: .78rem; font-weight: 600; padding: 0 .5rem; border-radius: 9px; color: #fff; margin-left: .4rem; vertical-align: 1px; }
.tag.best { background: var(--best); } .tag.good { background: var(--good); } .tag.inaccuracy { background: var(--inacc); }
.tag.mistake { background: var(--mistake); } .tag.blunder { background: var(--blunder); }
.side { display: grid; gap: .75rem; }
.summary { display: grid; grid-template-columns: 1fr auto auto; gap: .25rem .9rem; font-size: .9rem; align-items: baseline; }
.summary .h { color: var(--muted); font-size: .8rem; }
.movelist { display: grid; grid-template-columns: 2.4rem 1fr 1fr; gap: 1px; max-height: 340px; overflow-y: auto; font-size: .92rem; }
.movelist .no { color: var(--muted); padding: .25rem .2rem; text-align: right; }
.movelist button { font: inherit; color: inherit; background: none; border: 0; border-radius: 4px; text-align: left; padding: .25rem .5rem; cursor: pointer; }
.movelist button:hover { background: var(--accent-soft); }
.movelist button.cur { background: var(--accent); color: var(--accent-ink); }
.mk { font-weight: 700; margin-left: .15rem; }
.mk.inaccuracy { color: var(--inacc); } .mk.mistake { color: var(--mistake); } .mk.blunder { color: var(--blunder); }
.cur .mk { color: inherit; }
.vhead { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: baseline; margin-bottom: .8rem; }
.vhead h2 { margin: 0; font-size: 1.05rem; }
.vhead a { color: var(--accent); }

.overlay { position: fixed; inset: 0; background: rgba(10, 16, 22, .6); display: grid; place-items: center; z-index: 50; }
.loginbox { display: grid; gap: .8rem; width: min(340px, 90vw); padding: 1.5rem; background: var(--surface); border-radius: 10px; }
.loginbox h2 { margin: 0; font-size: 1.1rem; }
.err { color: var(--blunder); margin: 0; min-height: 1.2em; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.who { color: var(--muted); font-size: .9rem; }
.regextra { display: grid; gap: .8rem; }
