:root {
  --bg: #12151a; --panel: #1b2028; --panel2: #252b35; --line: #313948; --text: #e9edf3; --muted: #9aa6b8;
  --accent: #7bc96f; --accent-ink: #0d1a0b; --accent2: #3a8fd6; --danger: #d9534f; --warn: #e0b030; --ok: #3aa655;
  --radius: 14px; --light: #eeeed2; --dark: #769656;
  color-scheme: dark;
}
[data-board=brown] { --light: #f0d9b5; --dark: #b58863; }
[data-board=blue] { --light: #dee3e6; --dark: #8ca2ad; }
[data-board=gray] { --light: #d8dce2; --dark: #6b7a90; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { min-height: 100dvh; padding-bottom: 76px; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.6rem; } h3 { font-size: 1.15rem; margin-top: 1.2rem; } h4 { font-size: 1rem; margin-top: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: .78rem; }
p { margin: .4rem 0 .8rem; }
small { font-size: .82rem; }
.muted { color: var(--muted); }
code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; }

/* shell */
header.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: rgba(18,21,26,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--dark); display: grid; place-items: center; font-size: 1.1rem; color: #fff; }
.topright { display: flex; align-items: center; gap: 10px; }
.chip { background: var(--panel2); border-radius: 99px; padding: 4px 12px; font-weight: 600; font-size: .9rem; }
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: rgba(27,32,40,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 2px 6px; color: var(--muted); font-size: .72rem; }
nav.tabs a .ni { font-size: 1.35rem; line-height: 1.2; }
nav.tabs a.on { color: var(--accent); font-weight: 600; }
main#app { max-width: 1120px; margin: 0 auto; padding: 14px 16px 24px; }
@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  nav.tabs { position: sticky; top: 53px; bottom: auto; justify-content: center; gap: 6px; border-top: 0; border-bottom: 1px solid var(--line); padding: 4px 8px; }
  nav.tabs a { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 8px 16px; border-radius: 10px; font-size: .95rem; }
  nav.tabs a.on { background: var(--panel2); }
}

/* generic */
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 14px; }
.card.accent { border-color: var(--accent); }
.card.warn { border-color: var(--warn); }
.card.center { text-align: center; }
.card.stat { text-align: center; padding: 12px 8px; }
.card.stat .big { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.card.stat small { display: block; color: var(--muted); }
.big { font-size: 2.4rem; font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.cards .card { margin: 0; }
.card.line { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; } .row.center { justify-content: center; }
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 12px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; display: inline-block; text-align: center; }
.btn:hover { border-color: #4a5568; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: #ff9a96; }
.btn.small { padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.btn.big { padding: 14px 24px; font-size: 1.05rem; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.pill { display: inline-block; background: var(--panel2); border-radius: 99px; padding: 2px 10px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.pill.ok { background: rgba(58,166,85,.2); color: #7fe39a; } .pill.warn { background: rgba(224,176,48,.2); color: var(--warn); } .pill.big { font-size: 1rem; padding: 8px 16px; }
.segs { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.seg { appearance: none; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 8px 16px; border-radius: 10px; font: inherit; cursor: pointer; }
.seg.on { border-color: var(--accent); background: rgba(123,201,111,.16); color: var(--accent); font-weight: 700; }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 6px 0 10px; }
.lvl { appearance: none; text-align: left; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 8px 12px; border-radius: 10px; font: inherit; cursor: pointer; display: flex; flex-direction: column; }
.lvl.on { border-color: var(--accent); background: rgba(123,201,111,.14); }
.lvl small { color: var(--muted); }
.toggle { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.toggle input { margin-top: 5px; width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.toggle span { display: flex; flex-direction: column; } .toggle small { color: var(--muted); }
.toggle.col { flex-direction: column; gap: 6px; }
select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; }
.listrow { display: flex; justify-content: space-between; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.listrow:last-child { border-bottom: 0; }
.res.win { color: #7fe39a; } .res.loss { color: #ff9a96; } .res.draw { color: var(--warn); }
.progress { height: 12px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
.progress.small { height: 8px; min-width: 100px; flex: 1; }
.progress .bar { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.progress.low .bar { background: var(--warn); }
.barrow { display: grid; grid-template-columns: minmax(110px, 1.2fr) 2fr auto; gap: 10px; align-items: center; margin: 8px 0; font-size: .92rem; }
.tip { background: rgba(58,143,214,.12); border: 1px solid rgba(58,143,214,.35); border-radius: 12px; padding: 10px 14px; margin: 12px 0; }
.tip p { display: inline; margin: 0; }
.tipcard p { margin: 4px 0 0; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--panel2); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.tile .ticon { font-size: 1.8rem; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.theme { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 12px; padding: 10px 12px; text-align: left; cursor: pointer; display: flex; flex-direction: column; font: inherit; }

/* today */
.hero { display: flex; justify-content: space-between; align-items: center; gap: 16px; background: linear-gradient(135deg, #1f3a1f 0%, #1b2028 70%); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-bottom: 14px; }
.hero h2 { margin-bottom: 0; } .hero p { margin: 2px 0 12px; }
.rings { display: flex; align-items: center; gap: 16px; }
.ring { --p: 0; width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--panel2) 0); position: relative; }
.ring::before { content: ""; position: absolute; inset: 9px; background: #1c2a1f; border-radius: 50%; }
.ring span { position: relative; font-weight: 700; }
.streak { text-align: center; display: flex; flex-direction: column; align-items: center; }
.streak .flame { font-size: 1.5rem; } .streak strong { font-size: 1.5rem; line-height: 1; }
.task { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-top: 1px solid var(--line); }
.task .check { width: 38px; height: 38px; border-radius: 50%; background: var(--panel2); display: grid; place-items: center; font-size: 1.1rem; flex: none; }
.task.done .check { background: var(--ok); color: #fff; font-weight: 700; }
.task.done .ttxt strong { text-decoration: line-through; color: var(--muted); }
.ttxt { display: flex; flex-direction: column; flex: 1; min-width: 0; } .ttxt small { color: var(--muted); }
.task .chev { color: var(--muted); font-size: 1.4rem; }
.heat { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; }
.heat .cell { aspect-ratio: 1; border-radius: 4px; background: var(--panel2); }
.heat .l1 { background: #2d5a33; } .heat .l2 { background: #3b7a43; } .heat .l3 { background: #4fa058; } .heat .l4 { background: #7bc96f; }
.spark, .evgraph { width: 100%; height: 90px; display: block; border-radius: 8px; }
.evgraph { height: 120px; }

/* board & play */
.play-grid { display: grid; grid-template-columns: minmax(0, 640px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 860px) { .play-grid { grid-template-columns: 1fr; } }
.boardrow { display: flex; gap: 8px; align-items: stretch; }
.board-holder { width: 100%; max-width: min(640px, calc(100dvh - 210px)); min-width: 260px; margin: 0 auto 8px; }
.board-holder.small { max-width: 360px; margin: 0 0 8px; }
@media (max-width: 860px) { .board-holder { max-width: min(640px, 100%); } }
.bd-wrap { display: grid; grid-template-columns: 18px 1fr; grid-template-rows: auto 18px; width: 100%; user-select: none; -webkit-user-select: none; }
.bd-wrap.nocoords { grid-template-columns: 1fr; grid-template-rows: auto; }
.bd-wrap.nocoords .bd-ranks, .bd-wrap.nocoords .bd-files, .bd-wrap.nocoords .bd-corner { display: none; }
.bd-ranks { display: flex; flex-direction: column; justify-content: space-around; align-items: center; font-size: .72rem; color: var(--muted); font-weight: 600; }
.bd-files { grid-column: 2; display: flex; justify-content: space-around; font-size: .72rem; color: var(--muted); font-weight: 600; padding-top: 2px; }
.bd-files span { width: 12.5%; text-align: center; }
.bd { position: relative; aspect-ratio: 1; width: 100%; border-radius: 6px; overflow: hidden; touch-action: none; cursor: pointer; box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.bd-sq { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.sq.light { background: var(--light); } .sq.dark { background: var(--dark); }
.bd-marks, .bd-pieces { position: absolute; inset: 0; pointer-events: none; }
.bd-pieces .pc { pointer-events: auto; }
.mk { position: absolute; width: 12.5%; height: 12.5%; }
.mk.last { background: rgba(255, 221, 60, .45); }
.mk.sel { background: rgba(70, 150, 255, .5); }
.mk.hint { background: rgba(60, 200, 110, .55); }
.mk.good { background: rgba(60, 200, 110, .6); }
.mk.bad { background: rgba(225, 60, 60, .6); }
.mk.check { background: radial-gradient(circle, rgba(255, 0, 0, .85) 0%, rgba(255, 0, 0, .55) 40%, transparent 72%); }
.mk.dot::after { content: ""; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 20, 20, .32); }
.mk.cap::after { content: ""; position: absolute; inset: 6%; border-radius: 50%; border: 5px solid rgba(20, 20, 20, .32); }
.pc { position: absolute; width: 12.5%; height: 12.5%; background-size: 100%; background-repeat: no-repeat; z-index: 2; will-change: transform; }
.pc.dragging { z-index: 6; transition: none !important; cursor: grabbing; filter: drop-shadow(0 6px 8px rgba(0,0,0,.5)); }
.bd-arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.bd-promo { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; gap: 8px; background: rgba(0,0,0,.6); }
.bd-promo[hidden] { display: none; }
.promo-btn.pc { position: relative; width: 19%; height: auto; aspect-ratio: 1; background-color: #eee; border: 0; border-radius: 12px; background-size: 92%; background-position: center; cursor: pointer; }
.evalbar { width: 22px; border-radius: 6px; background: #2a2d33; position: relative; overflow: hidden; flex: none; display: flex; flex-direction: column-reverse; min-height: 200px; }
.evalbar.flip { flex-direction: column; }
.evalbar .fill { background: #f2f2f2; width: 100%; height: 50%; transition: height .4s; }
.evalbar .evlabel { position: absolute; left: 0; right: 0; bottom: 2px; text-align: center; font-size: .62rem; color: #222; font-weight: 700; mix-blend-mode: normal; }
.evalbar.flip .evlabel { top: 2px; bottom: auto; }
.evalbar[hidden] { display: none; }
.status { font-weight: 600; margin: 6px 2px; min-height: 1.5em; }
.opening { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }
.coachbox { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; min-height: 80px; }
.coachbox p { margin: 6px 0; }
.verdict { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.vicon { min-width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 800; font-size: .85rem; color: #fff; flex: none; padding: 0 4px; }
.movelist { max-height: 220px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; margin-top: 10px; }
.moves { display: flex; flex-direction: column; }
.mrow { display: grid; grid-template-columns: 34px 1fr 1fr; align-items: center; }
.mnum { color: var(--muted); font-size: .85rem; }
.mv { appearance: none; background: transparent; border: 0; color: var(--text); text-align: left; padding: 3px 6px; font: inherit; border-radius: 6px; cursor: pointer; }
.mv.cur { background: var(--accent2); color: #fff; font-weight: 700; }
.movelist .moves { display: flex; flex-direction: row; flex-wrap: wrap; gap: 2px; }
.nav { justify-content: center; }
.crit-grid, .quiz-grid { display: grid; grid-template-columns: minmax(0, 360px) 1fr; gap: 14px; align-items: start; }
@media (max-width: 700px) { .crit-grid, .quiz-grid { grid-template-columns: 1fr; } }
.quiz { padding-bottom: 8px; }
.choices { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.btn.choice { text-align: left; }
.btn.choice.right { border-color: var(--ok); background: rgba(58,166,85,.2); }
.btn.choice.wrongc { border-color: var(--danger); background: rgba(217,83,79,.15); text-decoration: line-through; }
.feedback { margin: 6px 0; }
.lesson-body > p { font-size: 1.02rem; }
.diagram { margin: 14px 0; } .diagram figcaption { color: var(--muted); font-size: .9rem; max-width: 520px; }
.bigsq { font-size: 3.4rem; font-weight: 800; text-align: center; padding: 6px; cursor: pointer; letter-spacing: .04em; }
.catrow { display: flex; align-items: center; gap: 10px; margin: 6px 0; } .catrow strong { margin-left: auto; }
#toasts { position: fixed; left: 0; right: 0; bottom: 90px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: #2b3342; border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.out { opacity: 0; transition: opacity .35s; }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; max-width: 440px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
