:root {
  --bg: #302e2b;
  --bg2: #262522;
  --panel: #262421;
  --raise: #3c3a37;
  --raise2: #4b4847;
  --line: #3e3b38;
  --text: #ffffff;
  --muted: #bab9b8;
  --dim: #8b8987;
  --green: #81b64c;
  --green-d: #45753c;
  --light: #ebecd0;
  --dark: #739552;
  --light-coord: #739552;
  --dark-coord: #ebecd0;
  --board: min(calc(100vh - 150px), calc(100vw - 590px), 820px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
b { font-weight: 700; }

/* ---------- top bar ---------- */
.top { height: 52px; display: flex; align-items: center; gap: 16px; padding: 0 20px; background: var(--bg2); border-bottom: 1px solid #1f1e1c; }
.brand { display: flex; align-items: center; gap: 9px; background: none; border: 0; padding: 0; font-weight: 800; font-size: 19px; letter-spacing: -.2px; }
.tag { color: var(--dim); font-size: 13px; }
.top .btn { margin-left: auto; }
body[data-view="home"] #newReview { display: none; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 6px; padding: 9px 16px; background: var(--raise); color: #fff; font-weight: 700; box-shadow: 0 3px 0 #1f1e1c; transition: filter .12s, transform .05s; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1f1e1c; }
.btn.green { background: var(--green); box-shadow: 0 4px 0 var(--green-d); text-shadow: 0 1px 0 rgba(0,0,0,.2); }
.btn.green:active { box-shadow: 0 2px 0 var(--green-d); }
.btn.big { font-size: 19px; padding: 13px 26px; border-radius: 8px; }
.btn.small { padding: 6px 12px; font-size: 13px; box-shadow: 0 2px 0 #1f1e1c; }
.btn.ghost { background: transparent; box-shadow: none; border: 1px solid var(--raise2); color: var(--muted); }

/* ---------- home ---------- */
.home { display: none; max-width: 1040px; margin: 0 auto; padding: 44px 24px 30px; }
body[data-view="home"] .home { display: block; }
.hero { display: grid; grid-template-columns: 360px 1fr; gap: 40px; align-items: center; }
.hero-board { aspect-ratio: 1; border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
  background: conic-gradient(var(--dark) 90deg, var(--light) 90deg 180deg, var(--dark) 180deg 270deg, var(--light) 270deg) 0 0 / 25% 25%;
  position: relative; overflow: hidden; }
.hero-board::after { content: ""; position: absolute; inset: 0; background:
  url(/pieces/wN.svg) 37.5% 62.5% / 12.5% no-repeat, url(/pieces/bK.svg) 75% 12.5% / 12.5% no-repeat,
  url(/pieces/wQ.svg) 62.5% 37.5% / 12.5% no-repeat, url(/pieces/bP.svg) 87.5% 25% / 12.5% no-repeat,
  url(/pieces/wK.svg) 12.5% 100% / 12.5% no-repeat, url(/pieces/bR.svg) 25% 0 / 12.5% no-repeat,
  conic-gradient(var(--light) 90deg, var(--dark) 90deg 180deg, var(--light) 180deg 270deg, var(--dark) 270deg) 0 0 / 25% 25%; }
.hero-card h1 { font-size: 40px; margin: 0 0 6px; letter-spacing: -.5px; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 16px; }
textarea { width: 100%; resize: vertical; min-height: 64px; background: var(--bg2); border: 2px solid var(--raise); border-radius: 8px; color: #fff; padding: 12px 14px; font: 15px/1.4 ui-monospace, Menlo, monospace; outline: none; }
textarea:focus { border-color: var(--green); }
.row { display: flex; gap: 14px; align-items: center; margin-top: 14px; }
.row .btn { margin-left: auto; min-width: 170px; }
.seg { display: inline-flex; background: var(--bg2); border-radius: 8px; padding: 3px; }
.seg button { background: none; border: 0; padding: 8px 14px; border-radius: 6px; color: var(--muted); font-weight: 700; }
.seg button i { font-style: normal; font-weight: 400; font-size: 12px; color: var(--dim); margin-left: 3px; }
.seg button.on { background: var(--raise2); color: #fff; }
.err { color: #fa7a6a; min-height: 1.3em; margin: 10px 0 0; font-weight: 600; }
.how { list-style: none; padding: 0; margin: 14px 0 0; display: flex; gap: 22px; color: var(--dim); font-size: 13px; flex-wrap: wrap; }
.how b { color: var(--muted); margin-right: 4px; }
.foot { color: var(--dim); font-size: 12px; text-align: center; margin-top: 40px; }

.games { margin-top: 30px; }
.games-head { color: var(--muted); margin: 0 0 10px; }
.loading { color: var(--muted); padding: 16px; background: var(--panel); border-radius: 8px; }
.loading.err { color: #fa7a6a; }
.grow { width: 100%; display: grid; grid-template-columns: 74px 1fr 66px 80px 64px 72px; gap: 12px; align-items: center; text-align: left; background: var(--panel); border: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; }
.grow:first-of-type { border-radius: 8px 8px 0 0; }
.grow:last-child { border-radius: 0 0 8px 8px; border-bottom: 0; }
.grow:hover { background: #2f2d2a; }
.grow .tc { font-size: 12px; font-weight: 700; text-transform: capitalize; color: var(--muted); }
.grow .pl { line-height: 1.6; }
.grow .pl i { color: var(--dim); font-style: normal; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 7px; vertical-align: -1px; }
.dot.w { background: #fff; } .dot.b { background: #1b1a18; border: 1px solid #5a5856; }
.res { font-weight: 800; font-size: 13px; text-align: center; border-radius: 4px; padding: 2px 0; }
.res.win { color: #fff; background: var(--green); } .res.loss { color: #fff; background: #c0392b; } .res.draw { color: #fff; background: #777; }
.grow .mv, .grow .dt { color: var(--dim); font-size: 13px; }
.grow .rv { color: var(--green); font-weight: 700; text-align: right; }

/* ---------- review layout ---------- */
.review { display: none; justify-content: center; gap: 14px; padding: 18px 20px; height: calc(100vh - 52px); }
body[data-view="review"] .review { display: flex; }
.evalbar { width: 28px; height: var(--board); margin-top: 38px; background: #403d39; border-radius: 3px; position: relative; overflow: hidden; display: flex; flex-direction: column-reverse; }
.evalbar .fill { background: #fff; height: 50%; transition: height .45s ease; }
.evalbar.flip { flex-direction: column; }
.evalbar .lab { position: absolute; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 800; }
.evalbar .lab.w { bottom: 4px; color: #403d39; } .evalbar .lab.b { top: 4px; color: #fff; }
.evalbar.flip .lab.w { bottom: auto; top: 4px; } .evalbar.flip .lab.b { top: auto; bottom: 4px; }
.boardcol { display: flex; flex-direction: column; width: var(--board); }
.strip { height: 38px; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.strip .av, .sp .av { width: 28px; height: 28px; border-radius: 4px; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.av.w { background: #f0efe9; color: #403d39; } .av.b { background: #57534f; color: #fff; }
.strip .nm { font-weight: 700; }
.strip .elo { color: var(--dim); }
.strip .caps { display: flex; align-items: center; margin-left: 4px; }
.strip .caps img { width: 18px; height: 18px; margin-right: -6px; }
.strip .caps b { margin-left: 10px; color: var(--dim); font-size: 12px; }
.clock { margin-left: auto; font: 700 18px/1 ui-monospace, Menlo, monospace; padding: 6px 10px; border-radius: 4px; min-width: 92px; text-align: right; background: #2b2926; color: #8b8987; }
.clock.run.w { background: #fff; color: #262421; } .clock.run.b { background: #262421; color: #fff; outline: 1px solid #57534f; }

/* ---------- board ---------- */
.board { position: relative; width: var(--board); height: var(--board); border-radius: 3px; overflow: hidden; user-select: none; touch-action: none; }
.board .squares { position: absolute; inset: 0; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); }
.sq { position: relative; }
.sq.l { background: var(--light); } .sq.d { background: var(--dark); }
.sq span { position: absolute; font-weight: 700; font-size: calc(var(--board) / 52); }
.sq .rank { top: 3%; left: 5%; } .sq .file { bottom: 2%; right: 6%; }
.sq.l span { color: var(--light-coord); } .sq.d span { color: var(--dark-coord); }
.marks, .pieces, .badges { position: absolute; inset: 0; pointer-events: none; }
.mk { position: absolute; width: 12.5%; height: 12.5%; }
.mk.last { background: rgba(255, 255, 51, .5); }
.mk.sel { background: rgba(20, 85, 30, .5); }
.mk.dot::after { content: ""; position: absolute; inset: 37%; border-radius: 50%; background: rgba(0,0,0,.16); }
.mk.cap { box-shadow: inset 0 0 0 calc(var(--board) / 110) rgba(0,0,0,.16); border-radius: 50%; }
.piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; transition: transform .18s ease; will-change: transform; }
.piece.dragging { transition: none !important; z-index: 5; filter: drop-shadow(0 4px 6px rgba(0,0,0,.35)); }
.board.live { cursor: pointer; }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.badge { position: absolute; z-index: 6; filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); animation: pop .22s ease-out; }
.badge .badge-ico { width: calc(var(--board) / 24); height: calc(var(--board) / 24); display: block; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- side panel ---------- */
.panel { width: 440px; height: calc(var(--board) + 76px); background: var(--panel); border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; }
.ph { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 14px; font-weight: 800; font-size: 18px; background: #21201d; }
.pbody { flex: 1; overflow-y: auto; padding: 14px 16px; }
.pbody.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; }
.pfoot { padding: 12px 16px 16px; background: #21201d; display: flex; flex-direction: column; gap: 10px; }
.pfoot .btn.big { width: 100%; }
.big { font-size: 20px; font-weight: 800; margin: 0 0 8px; }
.muted { color: var(--dim); } .small { font-size: 12px; }
.prog { width: 80%; height: 10px; background: var(--raise); border-radius: 6px; overflow: hidden; margin: 6px 0; }
.prog div { height: 100%; background: var(--green); transition: width .25s; }
.spin { width: 36px; height: 36px; border: 4px solid var(--raise); border-top-color: var(--green); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pbody.center .btn { margin-top: 14px; }

.coach { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.coach .pencil { flex: none; }
.bubble { flex: 1; background: #fff; color: #312e2b; border-radius: 8px; padding: 10px 12px; position: relative; min-height: 40px; font-size: 14.5px; }
.bubble::before { content: ""; position: absolute; left: -7px; top: 13px; border: 7px solid transparent; border-left: 0; border-right-color: #fff; }
.bubble .ctop { display: flex; align-items: center; gap: 8px; font-size: 16px; margin-bottom: 4px; }
.bubble .ctop b { flex: 1; }
.bubble .ev { font: 800 13px ui-monospace, Menlo, monospace; background: #f0efe9; color: #312e2b; padding: 2px 6px; border-radius: 4px; }
.bubble .ev.neg { background: #403d39; color: #fff; }
.bubble .ct { margin: 0; }
.bubble .muted { color: #777; margin: 4px 0 0; }
.bubble .btn.small { margin-top: 8px; background: #e7e6e1; color: #312e2b; box-shadow: 0 2px 0 #c9c7c0; }
.bubble .btn.green { margin-top: 10px; color: #fff; }

.graph { width: 100%; height: 76px; display: block; border-radius: 4px; cursor: pointer; margin-bottom: 14px; }

.sumplayers { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; margin: 6px 0 12px; }
.sp { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.sp .spn { font-weight: 700; font-size: 13px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc { font-weight: 800; font-size: 22px; padding: 6px 0; width: 96px; text-align: center; border-radius: 6px; }
.acc.w { background: #fff; color: #312e2b; } .acc.b { background: #403d39; color: #fff; }
.splab { color: var(--muted); font-weight: 700; padding-bottom: 12px; }
.counts { width: 100%; border-collapse: collapse; }
.counts td { padding: 4px 0; font-weight: 800; }
.counts .cw, .counts .cb { width: 96px; text-align: center; }
.counts .lab { display: flex; align-items: center; gap: 10px; font-weight: 700; padding-left: 20%; }
.counts tr td:first-child, .counts tr td:last-child { color: var(--muted); }
.counts td.brilliant:not(:empty) { color: #26c2a3; }
.ratings { display: grid; grid-template-columns: 96px 1fr 96px; align-items: center; margin: 12px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.ratings .rt { text-align: center; font-weight: 800; font-size: 18px; background: var(--raise); border-radius: 6px; padding: 5px 0; }
.ratings .rl { text-align: center; font-weight: 700; color: var(--muted); }
.ratings i { font-style: normal; font-size: 11px; color: var(--dim); font-weight: 400; }
.opening { font-size: 13.5px; padding: 10px 0; border-top: 1px solid var(--line); }
.km { border-top: 1px solid var(--line); padding-top: 10px; }
.kmh { font-weight: 800; margin-bottom: 6px; }
.kmr { display: grid; grid-template-columns: 22px auto 1fr; gap: 8px; align-items: start; width: 100%; text-align: left; background: none; border: 0; padding: 7px 6px; border-radius: 6px; font-size: 13px; }
.kmr:hover { background: var(--raise); }
.kmr b { white-space: nowrap; }
.kmr span { color: var(--muted); }

.moves-body { display: flex; flex-direction: column; }
.mlist { flex: 1; overflow-y: auto; background: #21201d; border-radius: 6px; padding: 4px 0; min-height: 120px; }
.mrow { display: grid; grid-template-columns: 44px 1fr 1fr; align-items: center; }
.mrow:nth-child(even) { background: #2a2825; }
.mrow .no { color: var(--dim); text-align: right; padding-right: 10px; font-size: 13px; }
.mv { display: flex; align-items: center; gap: 5px; background: none; border: 0; padding: 5px 8px; text-align: left; font-weight: 700; border-radius: 4px; margin: 1px 4px; }
.mv:hover { background: var(--raise); }
.mv.cur { background: #4b4847; box-shadow: inset 0 -2px 0 #6f6d6a; }
.nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.nb { background: var(--raise); border: 0; border-radius: 6px; height: 40px; display: grid; place-items: center; box-shadow: 0 3px 0 #1f1e1c; }
.nb:hover { background: var(--raise2); }
.nb svg { width: 22px; height: 22px; fill: #d3d2d0; }
.acts { display: flex; gap: 8px; }
.acts .btn { flex: 1; padding: 9px 6px; }

.rprog { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.rp { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; padding: 4px 8px; border-radius: 5px; background: var(--raise); color: var(--muted); font-weight: 700; }
.rp.done { opacity: .5; } .rp.now { background: var(--raise2); color: #fff; outline: 1px solid var(--green); }
