/* NBCheckmate — ink and gold.
   The signature: the two corners where mate can happen glow gold, all the time.
   The design teaches the lesson before a word is read. */

:root {
  --bg: #0b1020;
  --bg2: #10172b;
  --panel: rgba(22, 27, 43, 0.72);
  --line: #232a40;
  --ink: #e8ebf3;
  --muted: #8d95ab;
  --gold: #fbbf24;
  --gold-soft: rgba(251, 191, 36, 0.22);
  --mint: #5eead4;
  --warn: #fb923c;
  --red: #f87171;
  --radius: 16px;
  --display: 'Sora', system-ui, sans-serif;
  --body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 70% at 50% -10%, #17203d 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button svg:not(.star) { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.view { display: none; }
body[data-view="home"] #home, body[data-view="drill"] #drill { display: block; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); display: grid; place-items: center; flex: none;
}
.chip { font: 600 13px var(--display); padding: 6px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }
.chip.xp { color: var(--gold); }

/* ---------------- home ---------------- */
#home { max-width: 640px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px 40px; }
.home-bar { display: flex; align-items: center; gap: 12px; }
.brand { position: relative; flex: none; }
.brand-logo { height: 52px; width: auto; display: block; background: #faf9f6; border-radius: 12px; padding: 5px; }
.belt-stripe { position: absolute; left: 6px; right: 6px; bottom: -7px; height: 5px; border-radius: 3px; background: var(--belt, transparent); box-shadow: 0 0 0 1px rgba(255,255,255,.15); }
.belt-stripe[style*="transparent"] { box-shadow: none; }
.brand-text { flex: 1; min-width: 0; }
.brand-text h1 { font: 700 22px/1 var(--display); margin: 0; letter-spacing: -0.02em; }
.brand-text h1 span { color: var(--gold); }
.brand-text p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
@media (min-width: 700px) { .brand-logo { height: 72px; } .brand-text h1 { font-size: 30px; } }

.daily {
  margin: 22px 0 6px; width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 14px 16px; border-radius: var(--radius); border: 1px solid rgba(251,191,36,.35);
  background: linear-gradient(135deg, rgba(251,191,36,.16), rgba(251,191,36,.03));
}
.daily.done { border-color: rgba(94,234,212,.35); background: linear-gradient(135deg, rgba(94,234,212,.12), rgba(94,234,212,.02)); }
.daily-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: rgba(251,191,36,.18); color: var(--gold); flex: none; }
.daily.done .daily-mark { color: var(--mint); background: rgba(94,234,212,.14); }
.daily-body { flex: 1; display: flex; flex-direction: column; }
.daily-title { font: 600 17px var(--display); }
.daily-sub { color: var(--muted); font-size: 13px; }
.chev { color: var(--muted); }

.section { font: 600 12px var(--display); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin: 26px 0 10px; }
.chapters { display: flex; flex-direction: column; gap: 10px; }
.chapter {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  padding: 14px 14px 14px 12px; border-radius: var(--radius); background: var(--panel);
  border: 1px solid var(--line); position: relative; overflow: hidden;
}
.chapter::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--belt); opacity: .9; }
.chapter.locked { opacity: .45; }
.ch-num { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font: 700 15px var(--display); background: rgba(255,255,255,.05); flex: none; }
.chapter.passed .ch-num { background: var(--belt); color: #0b1020; }
.ch-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ch-title { font: 600 16px var(--display); }
.ch-tag { color: var(--muted); font-size: 13px; }
.ch-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.rooms { display: flex; gap: 4px; }
.rooms i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.14); }
.rooms i.on { background: var(--mint); }
.stars { display: flex; gap: 1px; }
.star { width: 14px; height: 14px; fill: rgba(255,255,255,.12); stroke: none; }
.star.on { fill: var(--gold); }
.caption .star { width: 18px; height: 18px; vertical-align: -3px; }

.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tiers button { padding: 14px 8px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); font: 600 15px var(--display); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tiers small { font: 400 12px var(--body); color: var(--muted); }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 28px; }

/* ---------------- drill ---------------- */
#drill { padding: max(8px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); min-height: 100dvh; }
.drill-bar { display: flex; align-items: center; gap: 10px; max-width: 1100px; margin: 0 auto; }
.drill-head { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
#drill-title { font: 600 16px var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.rooms-tabs { display: flex; gap: 4px; }
.rooms-tabs:empty { display: none; }
.rooms-tabs a { font: 600 11px var(--display); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-decoration: none; padding: 3px 9px; border-radius: 999px; border: 1px solid transparent; }
.rooms-tabs a.on::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--mint); margin-right: 5px; vertical-align: 1px; }
.rooms-tabs a.cur { color: var(--ink); border-color: var(--line); background: var(--panel); }

.stage { max-width: 1100px; margin: 6px auto 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.board-col { width: 100%; display: flex; flex-direction: column; align-items: center; }
.meta { width: min(100%, var(--board-w)); display: flex; justify-content: space-between; align-items: center; min-height: 24px; font-size: 13px; color: var(--muted); padding: 0 4px; }
.dots { display: inline-flex; gap: 5px; vertical-align: middle; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.14); }
.dots i.cur { background: transparent; box-shadow: inset 0 0 0 2px var(--gold); }
.dots i.won { background: var(--mint); }
.dots i.lost { background: var(--red); }
.att { margin-left: 10px; }

:root { --board-w: min(100vw - 24px, 100dvh - 290px, 680px); }
.board-slot { width: var(--board-w); }
.nb-board.pb-root { --pb-size: 100%; --pb-gutter: 1rem; --pb-frame: #1b2238; --pb-label: #6b7590; }
.nb-board .pb-surface {
  box-shadow: 0 30px 60px -18px rgba(0,0,0,.7), 0 0 50px rgba(251,191,36,.06), inset 0 1px 1px rgba(255,255,255,.2);
  touch-action: none;
}
.nb-board .pb-sq { position: relative; }
.nb-corner { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 3px rgba(251,191,36,.75), inset 0 0 26px rgba(251,191,36,.55); background: rgba(251,191,36,.16); z-index: 1; }
.pb-sq[data-shade="dark"] .nb-corner { background: rgba(251,191,36,.42); box-shadow: inset 0 0 0 3px rgba(251,191,36,.9), inset 0 0 22px rgba(255,214,102,.6); }
.nb-last { position: absolute; inset: 0; background: rgba(94,234,212,.20); pointer-events: none; }
.nb-sel { position: absolute; inset: 0; background: rgba(94,234,212,.38); pointer-events: none; }
.nb-dot { position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; transform: translate(-50%, -50%); border-radius: 50%; background: rgba(11,16,32,.35); pointer-events: none; z-index: 5; }
.nb-glow { position: absolute; inset: 0; pointer-events: none; background: rgba(94,234,212,.35); animation: glow 1.6s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: .25; } to { opacity: .9; } }
.nb-flash { position: absolute; inset: 0; pointer-events: none; animation: flash .9s ease-out forwards; z-index: 6; }
.nb-flash-bad { background: rgba(248,113,113,.6); }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.nb-ghost { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 50; filter: drop-shadow(0 10px 10px rgba(0,0,0,.55)); }

.fuel { width: min(100%, var(--board-w)); display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.fuel[hidden] { display: none; }
.fuel-track { grid-column: 1 / -1; height: 10px; border-radius: 999px; background: rgba(255,255,255,.07); overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.5); }
.fuel-fill { height: 100%; width: var(--pct, 100%); border-radius: inherit; background: linear-gradient(90deg, #2dd4bf, var(--mint)); transition: width .4s ease, background .4s; box-shadow: 0 0 12px rgba(94,234,212,.45); }
.fuel[data-level="amber"] .fuel-fill { background: linear-gradient(90deg, #f59e0b, var(--gold)); box-shadow: 0 0 12px rgba(251,191,36,.5); }
.fuel[data-level="red"] .fuel-fill { background: linear-gradient(90deg, #dc2626, var(--red)); box-shadow: 0 0 14px rgba(248,113,113,.6); animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .7; } to { opacity: 1; } }
.fuel-name { margin-top: 4px; font: 600 11px var(--display); text-transform: uppercase; letter-spacing: .1em; }
#fuel-label { margin-top: 4px; text-align: right; }

.talk-col { width: min(100%, var(--board-w)); display: flex; flex-direction: column; gap: 10px; }
.caption { margin: 0; min-height: 3.1em; font-size: 16px; line-height: 1.4; padding: 10px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.caption.good { border-color: rgba(94,234,212,.4); }
.caption.warn { border-color: rgba(251,146,60,.5); }
.caption b { color: var(--gold); font-weight: 600; }
.controls { display: flex; gap: 8px; }
.ctl { flex: 1; min-height: 52px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; justify-content: center; gap: 6px; font: 600 14px var(--display); padding: 0 8px; }
.ctl.primary { background: var(--gold); color: #1a1405; border-color: transparent; flex: 1.6; }
.ctl:disabled { opacity: .35; }
.ctl span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Wide screens: board left, words right. */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  :root { --board-w: min(100dvh - 130px, 760px); }
  .stage { flex-direction: row; align-items: flex-start; justify-content: center; gap: 28px; }
  .board-col { width: auto; }
  .talk-col { width: 340px; margin-top: 30px; flex: none; }
}

/* ---------------- menu, toast, sticker ---------------- */
.menu { position: fixed; inset: 0; background: rgba(5,8,16,.6); backdrop-filter: blur(6px); z-index: 100; display: flex; justify-content: flex-end; }
.menu[hidden] { display: none; }
.menu-sheet { width: min(320px, 86vw); height: 100%; background: #121829; border-left: 1px solid var(--line); padding: max(18px, env(safe-area-inset-top)) 12px 18px; display: flex; flex-direction: column; gap: 4px; }
.menu-sheet button { text-align: left; padding: 14px 12px; border-radius: 12px; border: 0; background: transparent; font: 500 16px var(--display); display: flex; justify-content: space-between; }
.menu-sheet button:hover { background: rgba(255,255,255,.05); }
.menu-sheet .val { color: var(--gold); }
.menu-sheet hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 8px 0; }

.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1b2238; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 120; font-size: 14px; }
.toast[hidden] { display: none; }

.sticker { position: fixed; inset: 0; z-index: 110; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(5,8,16,.55); }
.sticker[hidden] { display: none; }
.sticker img { width: 150px; background: #faf9f6; border-radius: 22px; padding: 10px; box-shadow: 0 0 0 4px var(--gold), 0 20px 50px rgba(0,0,0,.6); }
.sticker p { font: 700 24px var(--display); margin: 0; text-align: center; padding: 0 20px; }
.sticker.pop img { animation: pop .7s cubic-bezier(.2,1.6,.4,1) both; }
.sticker.pop p { animation: rise .6s .15s ease-out both; }
@keyframes pop { from { transform: scale(.3) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); color: var(--muted); z-index: 200; font: 500 15px var(--display); }

/* Settings drawer: the home-screen icon picker */
.icon-pick { padding: 8px 4px; }
.ip-title { font-weight: 600; margin-bottom: 8px; }
.ip-row { display: flex; gap: 8px; }
.ip { padding: 0; border: 2px solid transparent; border-radius: 14px; background: none; }
.ip.on { border-color: var(--gold); }
.ip img { width: 56px; height: 56px; border-radius: 12px; display: block; }
.ip-note { font-size: 12px; opacity: .7; margin-top: 6px; }

/* ---------------- teacher view & lecture mode ---------------- */
body.teacher #xp, body.teacher .belt-stripe, body.teacher .stars { display: none; }

/* Lecture mode: for a dim projector. Big board, big words, no game chrome, silent. */
body.lecture { --board-w: min(100vw - 24px, 100dvh - 250px); }
body.lecture #xp, body.lecture .belt-stripe, body.lecture .stars, body.lecture #score, body.lecture .rooms-tabs { display: none; }
body.lecture .caption { font-size: 48px; line-height: 1.15; padding: 18px 22px; }
body.lecture .caption .star { display: none; }
body.lecture #drill-title { font-size: 26px; }
body.lecture .ctl { min-height: 76px; font-size: 22px; border-radius: 18px; }
body.lecture .ctl svg { width: 30px; height: 30px; }
body.lecture .fuel { font-size: 18px; }
body.lecture .fuel-track { height: 16px; }
body.lecture .fuel-name { font-size: 16px; }
body.lecture .meta { font-size: 22px; color: var(--ink); }
body.lecture .nb-board.pb-root { --pb-gutter: 1.6rem; --pb-label: #c7cfe0; }
body.lecture .nb-board .pb-files, body.lecture .nb-board .pb-ranks { font-size: 1.3rem; font-weight: 600; }
body.lecture .nb-corner { box-shadow: inset 0 0 0 5px var(--gold), inset 0 0 30px rgba(251,191,36,.7); }
@media (min-aspect-ratio: 5/4) {
  body.lecture { --board-w: min(100dvh - 175px, 60vw); }
  body.lecture .stage { flex-direction: row; align-items: flex-start; justify-content: center; gap: 28px; }
  body.lecture .board-col { width: auto; }
  body.lecture .talk-col { width: min(34vw, 600px); margin-top: 30px; flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
