:root {
  --bg: #12151a; --panel: #1a1f26; --panel2: #222932; --line: #2e3742;
  --text: #e7ebf0; --dim: #93a0ae; --accent: #6fd3a8;
  --best: #3ecf8e; --played: #ef5b5b; --alt: #5aa9f5; --opp: #c9d1da; --last: #f2c14e;
  --blunder: #ef5b5b; --mistake: #f29a4a; --inaccuracy: #e8cf5a;
  --sq-light: #e3e8dc; --sq-dark: #74917f;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, "Segoe UI", sans-serif; }
button { font: inherit; color: inherit; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #0d1a14; border-color: var(--accent); font-weight: 600; }
a { color: var(--accent); }

header { display: flex; align-items: center; gap: 24px; padding: 12px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.who { color: var(--dim); }
.stats { display: flex; gap: 20px; margin-left: auto; flex-wrap: wrap; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--dim); }

main { display: grid; grid-template-columns: 320px minmax(360px, 1fr) 400px; gap: 16px; padding: 16px 20px; align-items: start; }
@media (max-width: 1180px) { main { grid-template-columns: 280px 1fr; } #detail { grid-column: 1 / -1; } }
@media (max-width: 760px) { main { grid-template-columns: 1fr; padding: 12px 16px; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }

#side-body { padding: 10px; max-height: calc(100vh - 150px); overflow: auto; }
.item { display: block; width: 100%; text-align: left; margin-bottom: 8px; padding: 10px 12px; background: var(--panel2); }
.item.on { border-color: var(--accent); }
.item .t { font-weight: 600; }
.item .s { color: var(--dim); font-size: 12.5px; }
.item .n { display: inline-block; width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 50%; background: var(--line); margin-right: 8px; font-size: 12px; }
.item.done .n { background: var(--best); color: #0d1a14; }
.intro { color: var(--dim); padding: 2px 4px 10px; }
.sub { margin: 0 0 8px 14px; }
.sub button { display: block; width: 100%; text-align: left; padding: 4px 8px; margin-bottom: 4px; font-size: 13px; }
.finding { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.finding:last-child { border: 0; }
.finding h4 { margin: 0 0 4px; display: flex; justify-content: space-between; gap: 8px; }
.finding h4 span { color: var(--accent); white-space: nowrap; }
.finding p { margin: 0; color: var(--dim); }
.headline { padding: 6px 12px 12px; font-weight: 600; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.blunder { background: var(--blunder); } .mistake { background: var(--mistake); } .inaccuracy { background: var(--inaccuracy); }
.res { font-weight: 700; margin-right: 6px; } .res.win { color: var(--best); } .res.loss { color: var(--played); } .res.draw { color: var(--dim); }

#center { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.boardrow { display: flex; gap: 10px; width: 100%; max-width: min(640px, max(300px, calc(100vh - 290px))); }
#evalbar { width: 16px; border-radius: 4px; background: #2b2f36; position: relative; overflow: hidden; border: 1px solid var(--line); }
#evalfill { position: absolute; left: 0; right: 0; bottom: 0; background: #f1f1ec; transition: height .25s; }
#boardwrap { flex: 1; position: relative; aspect-ratio: 1; container-type: inline-size; border-radius: 6px; overflow: hidden; user-select: none; }
#board { position: absolute; inset: 0; display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr); }
.sq { position: relative; display: flex; align-items: center; justify-content: center; font-size: 10.2cqw; line-height: 1;
  font-family: "DejaVu Sans", "Noto Sans Symbols2", "Segoe UI Symbol", "Arial Unicode MS", sans-serif; }
.sq.l { background: var(--sq-light); } .sq.d { background: var(--sq-dark); }
.sq.hl::after { content: ""; position: absolute; inset: 0; background: rgba(242, 193, 78, .42); }
.sq.sel::after { content: ""; position: absolute; inset: 0; background: rgba(90, 169, 245, .5); }
.sq .pc { position: relative; z-index: 1; }
.sq .pc.w { color: #fdfdf8; text-shadow: 0 0 .6cqw #000, .25cqw .25cqw 0 #1b1b1b, -.25cqw .25cqw 0 #1b1b1b, .25cqw -.25cqw 0 #1b1b1b, -.25cqw -.25cqw 0 #1b1b1b; }
.sq .pc.b { color: #15181c; text-shadow: 0 0 .5cqw rgba(255,255,255,.55); }
.sq .co { position: absolute; font: 600 1.9cqw system-ui, sans-serif; opacity: .65; color: #26302a; }
.sq .co.f { right: 3%; bottom: 2%; } .sq .co.r { left: 3%; top: 2%; }
#arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
#controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
#posinfo { color: var(--dim); min-width: 210px; text-align: center; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; color: var(--dim); font-size: 12.5px; flex-wrap: wrap; justify-content: center; }
.legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
#graph { width: 100%; max-width: 640px; height: 70px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }

#detail { padding: 14px 16px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; color: #1a1205; text-transform: uppercase; letter-spacing: .4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--panel2); border: 1px solid var(--line); color: var(--dim); }
h2 { margin: 6px 0 2px; font-size: 18px; }
.meta { color: var(--dim); font-size: 13px; }
.prompt { margin: 12px 0; padding: 12px; background: var(--panel2); border-left: 3px solid var(--accent); border-radius: 6px; }
.feedback { margin: 8px 0; font-weight: 600; min-height: 21px; }
.feedback.ok { color: var(--best); } .feedback.no { color: var(--mistake); }
.swing { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-variant-numeric: tabular-nums; }
.swing .bar { flex: 1; height: 8px; border-radius: 4px; background: var(--line); position: relative; overflow: hidden; }
.swing .bar i { position: absolute; top: 0; bottom: 0; }
.line { margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line); border-left-width: 4px; border-radius: 6px; cursor: pointer; }
.line.on { background: var(--panel2); }
.line .lh { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--dim); margin-bottom: 4px; }
.line .lh b { color: var(--text); }
.mv { display: inline-block; padding: 1px 5px; border-radius: 4px; cursor: pointer; font-variant-numeric: tabular-nums; }
.mv:hover { background: var(--line); }
.mv.cur { background: var(--accent); color: #0d1a14; font-weight: 600; }
.mvno { color: var(--dim); margin-left: 4px; }
.line { overflow-wrap: anywhere; }
.note { margin: 12px 0 6px; }
.takeaway { padding: 10px 12px; background: rgba(111, 211, 168, .1); border: 1px solid rgba(111, 211, 168, .35); border-radius: 6px; }
.takeaway b { color: var(--accent); }
.movelist { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 2px 6px; max-height: 420px; overflow: auto; margin-top: 10px; }
.movelist .no { color: var(--dim); text-align: right; }
.movelist .m { padding: 1px 6px; border-radius: 4px; cursor: pointer; }
.movelist .m:hover { background: var(--line); }
.movelist .m.cur { background: var(--accent); color: #0d1a14; }
.foot { color: var(--dim); font-size: 12px; padding: 0 20px 20px; max-width: 900px; }
#caption { width: 100%; max-width: 640px; padding: 12px 16px; border-left: 4px solid var(--accent); }
#caption:empty { display: none; }
.cap-top { display: flex; justify-content: space-between; gap: 12px; color: var(--dim); font-size: 12.5px; margin-bottom: 4px; }
.cap-text { font-size: 16.5px; line-height: 1.45; min-height: 72px; }
.cap-text.rule { color: var(--accent); font-weight: 600; }
.cap-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.cap-row .hint { color: var(--dim); font-size: 13px; flex: 1; }
.cap-row .hint.no { color: var(--mistake); font-weight: 600; }
.cap-row .hint.ok { color: var(--best); font-weight: 600; }
.pips { display: flex; gap: 4px; }
.pips i { width: 18px; height: 4px; border-radius: 2px; background: var(--line); }
.pips i.on { background: var(--accent); } .pips i.q { outline: 1px solid var(--last); }
.sq.mk-danger::before, .sq.mk-safe::before, .sq.mk-focus::before { content: ""; position: absolute; inset: 0; }
.sq.mk-danger::before { background: rgba(239, 91, 91, .55); }
.sq.mk-safe::before { background: rgba(62, 207, 142, .6); }
.sq.mk-focus::before { box-shadow: inset 0 0 0 .7cqw #f2c14e; }
.script { margin: 12px 0 0; padding: 0; list-style: none; counter-reset: s; }
.script li { counter-increment: s; padding: 6px 8px 6px 34px; position: relative; border-radius: 6px; color: var(--dim); cursor: pointer; }
.script li::before { content: counter(s); position: absolute; left: 8px; top: 7px; width: 18px; height: 18px; line-height: 18px; text-align: center; font-size: 11px; border-radius: 50%; background: var(--line); color: var(--text); }
.script li.cur { background: var(--panel2); color: var(--text); }
.script li.todo { opacity: .35; cursor: default; }
button:disabled { opacity: .4; cursor: default; }
#nav { display: flex; gap: 4px; }
#nav button { background: none; border-color: transparent; color: var(--dim); }
#nav button.on { color: var(--text); background: var(--panel2); border-color: var(--line); }
#strip { display: flex; align-items: center; gap: 8px; padding: 10px 20px 0; flex-wrap: wrap; max-width: 1240px; margin: 0 auto; }
#strip .lt { color: var(--dim); margin-right: 6px; }
#strip .pos { padding: 4px 6px; border-radius: 20px; display: flex; align-items: center; gap: 6px; }
#strip .pos b { width: 22px; height: 22px; line-height: 22px; border-radius: 50%; background: var(--line); font-size: 12px; text-align: center; }
#strip .pos.done b { background: var(--best); color: #0d1a14; }
#strip .pos.on { border-color: var(--accent); padding-right: 12px; }
#profile { padding: 20px; grid-column: 1 / -1; max-width: 1000px; margin: 0 auto; }
#profile .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-top: 14px; }
#profile .finding { border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }

body.focus :is(#side, #caption, #controls, #graph, #profile, .stats, .who) { display: none; }
body[data-view="games"] :is(#strip, #profile) { display: none; }
body[data-view="profile"] :is(#strip, #side, #center, #detail) { display: none; }
body[data-view="profile"] main { display: block; }
body.focus main { grid-template-columns: minmax(300px, 1.25fr) minmax(280px, 1fr); max-width: 1240px; margin: 0 auto; }
body.focus #detail { grid-column: auto; display: flex; flex-direction: column; gap: 10px; }
body.focus .boardrow { max-width: min(100%, max(300px, calc(100vh - 170px))); }
@media (max-width: 640px) { body.focus main { grid-template-columns: 1fr; } body.focus .boardrow { max-width: min(100%, 52vh); } }

.lhead b { font-size: 17px; margin-left: 6px; }
.lhead .meta { margin-top: 4px; }
.feed { display: flex; flex-direction: column; gap: 8px; overflow: auto; max-height: max(130px, calc(100vh - 560px)); min-height: 110px; padding-right: 4px; scroll-behavior: smooth; }
.bub { padding: 9px 12px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); }
.bub.old { color: var(--dim); font-size: 13px; cursor: pointer; background: none; }
.bub.old:hover { color: var(--text); }
.bub.cur { font-size: 16.5px; line-height: 1.45; border-color: var(--accent); animation: bubin .25s ease-out; }
.bub.q { border-color: var(--last); }
.bub.rule { border-color: rgba(111, 211, 168, .5); background: rgba(111, 211, 168, .1); color: var(--text); }
.bub.rule b { color: var(--accent); }
@keyframes bubin { from { opacity: 0; transform: translateY(6px); } }
.prog { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--accent); animation: prog linear forwards; }
@keyframes prog { from { width: 0; } to { width: 100%; } }
.turn { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.turn span { flex: 1; color: var(--dim); }
.turn span.ok { color: var(--best); font-weight: 600; } .turn span.no { color: var(--mistake); font-weight: 600; }
.turn.you { padding: 8px 12px; border-radius: 8px; background: rgba(242, 193, 78, .12); border: 1px solid rgba(242, 193, 78, .5); }
.turn.you b { color: var(--last); text-transform: uppercase; letter-spacing: .5px; font-size: 12.5px; white-space: nowrap; }
.ctl { display: flex; gap: 8px; align-items: center; }
.ctl .grow { flex: 1; }
.nota { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.nr label { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--dim); margin-bottom: 2px; }
.nr label small { text-transform: none; letter-spacing: 0; margin-left: 8px; color: var(--last); font-size: 12px; }
.nr > div { line-height: 1.9; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.np { white-space: nowrap; display: inline-block; }
main > * { min-width: 0; }
#detail { overflow: hidden; }
.bub, .turn span, .lhead { overflow-wrap: anywhere; min-width: 0; }
.turn, .ctl { flex-wrap: wrap; }
.nn { color: var(--dim); margin: 0 2px 0 6px; font-size: 13px; }
.nm { padding: 2px 6px; border-radius: 4px; cursor: pointer; font-weight: 600; }
.nm:hover { background: var(--line); }
.nm.dim { color: var(--dim); font-weight: 400; }
.nm.bad { color: var(--played); }
.nm.good { color: var(--best); }
.nm.cur { background: var(--accent); color: #0d1a14; }
.nm.bad.cur { background: var(--played); color: #fff; }
.nhint { color: var(--dim); font-size: 12px; }
body[data-view="practice"] #evalbar { display: none; }
body[data-view="practice"] .legend { display: none; }
#strip .pos.clean b { background: var(--best); color: #0d1a14; }
#strip .pos.retry b { background: var(--mistake); color: #1a1205; }
.turn.look { padding: 8px 12px; border-radius: 8px; background: rgba(90, 169, 245, .12); border: 1px solid rgba(90, 169, 245, .5); }
.turn.look b { color: var(--alt); text-transform: uppercase; letter-spacing: .5px; font-size: 12.5px; white-space: nowrap; }
.acct { display: flex; gap: 14px; }
.who b { color: var(--text); }
.lhead .pattern { margin-top: 6px; padding: 6px 9px; border-left: 3px solid var(--mistake); background: var(--panel2); border-radius: 4px; font-size: 13px; }
#profile h3 { margin: 22px 0 0; font-size: 15px; }
#profile .ex { margin-top: 6px; }
#profile button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
#profile .tabs { display: flex; gap: 6px; }
#profile .tabs button.on { border-color: var(--accent); color: var(--accent); }
#profile .tbl { width: 100%; border-collapse: collapse; margin-top: 10px; font-variant-numeric: tabular-nums; }
#profile .tbl th, #profile .tbl td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
#profile .tbl th { color: var(--dim); font-weight: 500; }
#strip .lfor { flex-basis: 100%; color: var(--dim); font-size: 13px; }
#strip .lfor b { color: var(--text); }
#strip .lfor a { margin-left: 8px; }
body[data-view="history"] :is(#strip, #side, #center, #detail) { display: none; }
body[data-view="history"] main { display: block; }
#profile .hrow { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; padding: 10px 14px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); text-decoration: none; }
#profile .hrow:hover, #profile .hrow.on { border-color: var(--accent); }
#profile .hrow span { color: var(--dim); }
#profile .hrow em { color: var(--accent); font-style: normal; font-weight: 400; }
#strip .lfor.old { color: #ffcf9a; }
#strip .lfor.old b { color: #ffcf9a; }
#strip .rw { color: var(--accent); }
