/* Direction: a calm analysis desk. Cool blue-grey surfaces, one indigo accent, a muted
   slate board. The only saturated colors belong to move quality (brilliant to blunder),
   so a mistake is the first thing the eye finds. */
:root {
  --bg: #edf0f4; --panel: #ffffff; --raise: #f5f7fa; --fg: #151d28; --muted: #5d6877; --line: #d9dfe7;
  --accent: #3454d1; --accent-fg: #ffffff; --accent-soft: #e4e9fb;
  --win: #2f9a62; --draw: #98a2b0; --loss: #d4483e;
  --sq-l: #e6ecf1; --sq-d: #7f9bb3; --hl: rgba(236, 201, 62, .5);
  --brill: #17a99e; --best: #3d9f68; --good: #86b556; --inacc: #d9ac2f; --mist: #ec8a3a; --blun: #d4483e;
  --evalw: #f4f6f8; --evalb: #1d2632;
  --head: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141c; --panel: #161e29; --raise: #1c2634; --fg: #e6ebf2; --muted: #93a0b2; --line: #28344a;
    --accent: #7fa0ff; --accent-fg: #0a1020; --accent-soft: #1f2d52;
    --win: #4fc58a; --draw: #7d8898; --loss: #f0766b;
    --sq-l: #d9e1e8; --sq-d: #627f98;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141c; --panel: #161e29; --raise: #1c2634; --fg: #e6ebf2; --muted: #93a0b2; --line: #28344a;
  --accent: #7fa0ff; --accent-fg: #0a1020; --accent-soft: #1f2d52;
  --win: #4fc58a; --draw: #7d8898; --loss: #f0766b;
  --sq-l: #d9e1e8; --sq-d: #627f98;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--body); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1 { font: 700 clamp(1.5rem, 3.2vw, 2.2rem)/1.15 var(--head); margin: 0 0 .8rem; text-wrap: balance; }
h2 { font: 600 1rem/1.3 var(--head); margin: 0 0 .8rem; }
.muted { color: var(--muted); font: 400 .85rem var(--body); margin-left: .4rem; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .85rem; cursor: pointer; transition: border-color .15s, background .15s; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .65rem; }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.2rem; padding: .8rem max(16px, 3vw); background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font: 700 1.25rem var(--head); letter-spacing: -.01em; }
.load { display: flex; flex-wrap: wrap; gap: .5rem; }
.status { color: var(--muted); font-size: .9rem; flex: 1; min-width: 12rem; }
.tabs { display: flex; gap: .4rem; padding: .9rem max(16px, 3vw) 0; max-width: 1500px; margin: 0 auto; }
.tabs button, .sideTabs button { background: transparent; border-color: transparent; color: var(--muted); font-weight: 600; }
.tabs button.on, .sideTabs button.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
main { padding: 1rem max(16px, 3vw) 2rem; max-width: 1500px; margin: 0 auto; }
.empty { max-width: 58ch; padding: 4rem 0; color: var(--muted); font-size: 1.05rem; }
.empty h1 { color: var(--fg); }
.foot { padding: 1.5rem max(16px, 3vw) 2.5rem; color: var(--muted); font-size: .8rem; max-width: 1500px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem; margin-bottom: 1rem; min-width: 0; }
.hint { color: var(--muted); font-size: .8rem; margin: 0 .2rem; }

/* stats */
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; }
.tile b { display: block; font: 700 1.7rem/1.2 var(--head); }
.tile span { color: var(--muted); font-size: .85rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem 1rem; margin-bottom: 1rem; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: .3rem .75rem; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-fg); }
canvas { width: 100%; display: block; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .65rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; cursor: pointer; user-select: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--raise); }
td.name { white-space: normal; min-width: 14rem; }
.wdl { display: flex; height: 10px; width: 140px; border-radius: 5px; overflow: hidden; background: var(--line); }
.wdl i:nth-child(1) { background: var(--win); } .wdl i:nth-child(2) { background: var(--draw); } .wdl i:nth-child(3) { background: var(--loss); }
.row { margin-bottom: .85rem; }
.row .wdl { width: 100%; height: 12px; margin-top: .25rem; }
.row .lab { display: flex; justify-content: space-between; gap: .5rem; }
.row .lab span:first-child { overflow-wrap: anywhere; }
.rowLink { cursor: pointer; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: .6rem; }
.wd { text-align: center; font-size: .85rem; }
.wd .col { height: 90px; display: flex; flex-direction: column-reverse; border-radius: 6px; overflow: hidden; background: var(--line); margin-bottom: .3rem; }
.wd .col i:nth-child(1) { background: var(--win); } .wd .col i:nth-child(2) { background: var(--draw); } .wd .col i:nth-child(3) { background: var(--loss); }

/* review layout */
.reviewLayout { display: grid; grid-template-columns: 250px minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
@media (max-width: 1150px) { .reviewLayout { grid-template-columns: 220px minmax(0, 1fr); } .side { grid-column: 1 / -1; } }
@media (max-width: 780px) { .reviewLayout { grid-template-columns: 1fr; } }
.gameList { max-height: calc(100vh - 7rem); overflow-y: auto; position: sticky; top: .5rem; margin: 0; }
@media (max-width: 780px) { .gameList { position: static; max-height: 36vh; } }
.g { display: block; width: 100%; text-align: left; margin-bottom: .4rem; padding: .5rem .65rem; border-radius: 10px; }
.g.on { border-color: var(--accent); background: var(--accent-soft); }
.g .r { font-weight: 700; display: inline-block; width: 1.3rem; }
.g .r.W { color: var(--win); } .g .r.L { color: var(--loss); } .g .r.D { color: var(--draw); }
.g small { display: block; color: var(--muted); font-size: .8rem; }
.boardCol { min-width: 0; max-width: 700px; width: 100%; }
.gameMeta { display: flex; flex-wrap: wrap; gap: .2rem 1rem; align-items: baseline; margin-bottom: .6rem; }
.gameMeta b { font: 600 1.1rem var(--head); }
.gameMeta a { color: var(--accent); }
.playerBar { display: flex; align-items: center; gap: .7rem; padding: .35rem .2rem; min-height: 2.6rem; }
.playerBar .nm { font-weight: 600; }
.playerBar .rt { color: var(--muted); }
.playerBar .cap { color: var(--muted); font-size: .95rem; letter-spacing: .02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playerBar .cap b { font-weight: 600; font-size: .85rem; margin-left: .3rem; }
.playerBar .acc { font-size: .85rem; color: var(--accent); font-weight: 600; }
.clock { font: 600 1.05rem var(--head); background: var(--raise); border: 1px solid var(--line); border-radius: 8px; padding: .15rem .6rem; min-width: 4.6rem; text-align: center; }
.boardWrap { display: flex; gap: .5rem; align-items: stretch; }
.boardBox { position: relative; flex: 1; min-width: 0; aspect-ratio: 1; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; height: 100%; border-radius: 6px; overflow: hidden; }
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.l { background: var(--sq-l); } .sq.d { background: var(--sq-d); }
.sq.hl::before { content: ""; position: absolute; inset: 0; background: var(--hl); }
.sq img { position: relative; width: 94%; height: 94%; z-index: 1; user-select: none; -webkit-user-drag: none; }
.sq .co { position: absolute; font-size: .62rem; font-weight: 600; opacity: .75; z-index: 0; }
.sq.l .co { color: var(--sq-d); } .sq.d .co { color: var(--sq-l); }
.sq .co.f { right: 3px; bottom: 1px; } .sq .co.r { left: 3px; top: 1px; }
.sq .mk { position: absolute; top: -6%; right: -6%; z-index: 3; width: 36%; aspect-ratio: 1; border-radius: 50%; color: #fff; font: 700 clamp(9px, 1.7vw, 14px)/1 var(--head); display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.evalBar { width: 22px; background: var(--evalb); border-radius: 6px; overflow: hidden; position: relative; }
#evalFill { position: absolute; left: 0; right: 0; background: var(--evalw); height: 50%; transition: height .25s ease; }
#evalNum { position: absolute; left: 0; right: 0; font-size: .6rem; font-weight: 700; text-align: center; padding: 2px 0; }
.controls { display: flex; flex-wrap: wrap; gap: .4rem; margin: .7rem 0; align-items: center; }
.controls .spacer { flex: 1; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: .4rem; }
#progressBar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.coach { min-height: 2.8rem; margin: .3rem 0 1rem; display: flex; flex-wrap: wrap; gap: .3rem .6rem; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .05rem .55rem; border-radius: 999px; color: #fff; font-size: .8rem; font-weight: 600; }
.k-brill { background: var(--brill); } .k-best { background: var(--best); } .k-good { background: var(--good); }
.k-inacc { background: var(--inacc); color: #2a2100; } .k-mist { background: var(--mist); } .k-blun { background: var(--blun); }
.graphPanel { margin: 0; }
.graphPanel canvas { cursor: pointer; touch-action: none; }

/* side panel */
.sideTabs { display: flex; gap: .3rem; margin-bottom: .8rem; }
.moves { display: grid; grid-template-columns: 2.2rem 1fr 1fr; gap: 2px .3rem; max-height: 440px; overflow-y: auto; align-content: start; }
.moves .n { color: var(--muted); padding: .35rem 0; }
.mv { display: flex; align-items: center; justify-content: space-between; gap: .3rem; text-align: left; border: 0; background: transparent; padding: .3rem .45rem; border-radius: 6px; font-weight: 600; }
.mv:hover { background: var(--raise); }
.mv.on { background: var(--accent); color: var(--accent-fg); }
.mv small { font-weight: 400; opacity: .75; font-size: .75rem; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: .25rem; }
.sumGrid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-bottom: 1rem; }
.sumGrid .big { background: var(--raise); border-radius: 10px; padding: .7rem .9rem; }
.sumGrid .big b { display: block; font: 700 1.8rem/1.1 var(--head); }
.sumGrid .big span { color: var(--muted); font-size: .85rem; }
.qt { font-size: .9rem; }
.qt td, .qt th { padding: .3rem .4rem; cursor: default; }
.qt th { color: var(--muted); font-weight: 600; }
.qt td:not(:first-child), .qt th:not(:first-child) { text-align: center; }
.facts { font-size: .9rem; color: var(--muted); margin-top: .8rem; }
.facts p { margin: .2rem 0; }
.moment { display: block; width: 100%; text-align: left; margin-bottom: .45rem; padding: .55rem .7rem; border-radius: 10px; }
.moment small { display: block; color: var(--muted); }
.pending { color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
