:root {
  --stage: #1b2129;
  --panel: #232b35;
  --panel-2: #2c3641;
  --line: #3a4654;
  --bone: #ebe6dc;
  --muted: #9aa6b2;
  --film: #8cc7c1;
  --film-ink: #10302c;
  --hl: #ff9e1f;
  --paper: #f1eadc;
  --ink: #2a2420;
  --ink-soft: #6b5f55;
  --good: #8fd19b;
  --good-bg: #1f3a2a;
  --bad: #f0a58a;
  --bad-bg: #43281f;
  --sans: Inter, "Segoe UI", Roboto, "Noto Sans", system-ui, -apple-system, sans-serif;
  --serif: Charter, "Iowan Old Style", Cambria, Georgia, "DejaVu Serif", serif;
  --r: 10px;
  --vvh: 100dvh;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--stage); color: var(--bone); font: 16px/1.45 var(--sans); overflow: hidden; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--film); outline-offset: 2px; }
[hidden] { display: none !important; }
a { color: var(--film); }

/* ---------- layout ---------- */
.app {
  height: var(--vvh);
  display: grid;
  grid-template-rows: minmax(0, 44fr) minmax(0, 56fr);
  grid-template-columns: 100%;
}
.app[data-screen="home"] { grid-template-rows: 112px minmax(0, 1fr); }
.kb-open .app { grid-template-rows: minmax(0, 34fr) minmax(0, 66fr); }

.viewer { position: relative; overflow: hidden; background: radial-gradient(120% 90% at 50% 40%, #232c37 0%, var(--stage) 70%); border-bottom: 1px solid var(--line); }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.scene-host { position: absolute; inset: 0; }
.panel { overflow-y: auto; overscroll-behavior: contain; background: var(--panel); padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
.screen { max-width: 560px; margin: 0 auto; }

/* landscape phone: 3D on the left, quiz on the right */
@media (orientation: landscape) and (max-height: 560px) {
  .app, .app[data-screen="home"], .kb-open .app { grid-template-rows: 100%; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .viewer { border-bottom: 0; border-right: 1px solid var(--line); }
  .panel { padding-top: 8px; }
}
/* laptop */
@media (min-width: 900px) and (min-height: 561px) {
  .app, .app[data-screen="home"] { grid-template-rows: 100%; grid-template-columns: minmax(0, 1fr) 460px; }
  .viewer { border-bottom: 0; border-right: 1px solid var(--line); }
  .panel { padding: 20px 24px; }
}

.view-brand { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 12px; }
.view-brand h1 { margin: 0; font: 600 26px/1.15 var(--serif); letter-spacing: 0.01em; }
.view-brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.view-loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(20, 26, 33, 0.85); padding: 8px 14px; border-radius: var(--r); color: var(--muted); font-size: 14px; }
.text-card { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 18px; }
.text-card p { margin: 0; max-width: 34em; background: var(--paper); color: var(--ink); font: 17px/1.5 var(--serif); padding: 16px 18px; border-radius: var(--r); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }

.view-tools { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; }
.view-tools button { min-height: 40px; padding: 0 12px; border-radius: 20px; border: 1px solid var(--line); background: rgba(27, 33, 41, 0.82); font-size: 13px; color: var(--bone); }
.view-tools button[aria-pressed="true"] { background: var(--film); color: var(--film-ink); border-color: var(--film); }
.orient { position: absolute; left: 0; right: 0; top: 8px; display: flex; justify-content: space-between; padding: 0 10px; pointer-events: none; color: var(--muted); font: 600 13px var(--sans); }
.orient span { background: rgba(27, 33, 41, 0.7); border-radius: 6px; padding: 2px 7px; }

/* ---------- controls ---------- */
.primary, .secondary, .opt, .chip { border-radius: var(--r); border: 1px solid transparent; min-height: 48px; padding: 0 16px; }
.primary { background: var(--film); color: var(--film-ink); font-weight: 600; }
.primary:disabled { opacity: 0.5; }
.secondary { background: var(--panel-2); border-color: var(--line); }
.secondary:disabled { opacity: 0.45; }
.big { width: 100%; min-height: 52px; font-size: 17px; }
.chip { min-height: 40px; background: var(--panel-2); border-color: var(--line); font-size: 14px; }
.link-btn { background: none; border: 0; color: var(--film); padding: 10px 4px; min-height: 44px; }
.link-btn.danger { color: var(--bad); }
.note { color: var(--muted); font-size: 14px; }

/* ---------- home ---------- */
.home-head { display: flex; align-items: center; justify-content: space-between; }
.home-head h2 { margin: 0; font-size: 19px; }
.home-actions { display: flex; gap: 8px; margin: 6px 0 10px; }
.section-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.sec-row { display: flex; gap: 12px; align-items: center; padding: 10px 12px; min-height: 56px; border-radius: var(--r); background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; }
.sec-row input { width: 22px; height: 22px; accent-color: var(--film); flex: none; }
.sec-main { flex: 1; display: grid; gap: 3px; min-width: 0; }
.sec-name { font-weight: 600; }
.sec-meta { color: var(--muted); font-size: 13px; }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--good); }
.home-start { display: grid; gap: 8px; margin-top: 14px; position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--panel) 14px); }
#done .home-start { position: static; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.count { font-weight: 400; opacity: 0.8; }

/* ---------- quiz ---------- */
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.quiz-progress { color: var(--muted); font-size: 14px; text-align: right; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 2px 0 10px; }
.steps li { flex: 1; text-align: center; font-size: 13px; padding: 5px 0; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.steps li.on { background: var(--film); color: var(--film-ink); font-weight: 600; }
.steps li.done { color: var(--bone); }
.prompt { margin: 0 0 6px; font-size: 19px; line-height: 1.3; }
.kicker { margin: 0 0 4px; color: var(--hl); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.hint { margin: 0 0 8px; color: var(--hl); font-size: 15px; }
.hint:empty { display: none; }
.name-form { display: flex; gap: 8px; }
.name-form input { flex: 1; min-width: 0; min-height: 52px; padding: 0 14px; border-radius: var(--r); background: var(--stage); border: 1px solid var(--line); font-size: 18px; }
.name-form input:focus { border-color: var(--film); outline: none; }
.name-form input:disabled { opacity: 0.7; }
.opts { display: grid; gap: 8px; }
.opt { background: var(--panel-2); border-color: var(--line); text-align: left; padding: 10px 14px; line-height: 1.3; }
.opt:disabled { cursor: default; opacity: 0.75; }
.opt.right { background: var(--good-bg); border-color: var(--good); opacity: 1; }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); opacity: 1; }
.sys-grid { grid-template-columns: 1fr 1fr; }
.sys-grid .opt { min-height: 48px; font-size: 15px; padding: 8px 10px; }
@media (max-width: 340px) { .sys-grid { grid-template-columns: 1fr; } }

.feedback { margin-top: 12px; padding: 12px; border-radius: var(--r); border: 1px solid var(--line); display: grid; gap: 8px; }
.feedback.good { background: var(--good-bg); border-color: var(--good); }
.feedback.bad { background: var(--bad-bg); border-color: var(--bad); }
.verdict { margin: 0; font-weight: 700; font-size: 18px; }
.feedback.good .verdict { color: var(--good); }
.feedback.bad .verdict { color: var(--bad); }
.fb-detail { margin: 0; }
.tag { background: var(--paper); color: var(--ink); border-radius: var(--r); padding: 10px 14px; }
.tag-name { margin: 0; font: 600 20px/1.25 var(--serif); }
.tag-name:empty { display: none; }
.tag-info { margin: 4px 0 0; color: var(--ink-soft); font-size: 15px; }
.tag-info:empty { display: none; }
.tag-sys { margin: 2px 0 0; color: var(--ink-soft); font-size: 14px; font-weight: 600; }

/* ---------- done / explore ---------- */
.missed { padding-left: 20px; }
.missed li { padding: 3px 0; }
.big-tag { margin: 8px 0 12px; }
.ex-mcq { margin: 8px 0 0; padding-left: 18px; color: var(--ink); font-size: 14px; }
.ex-mcq .q { color: var(--ink-soft); }
.ex-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#exSection { min-height: 44px; max-width: 70%; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); padding: 0 8px; }

/* ---------- about ---------- */
.about { max-width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--bone); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.about::backdrop { background: rgba(0, 0, 0, 0.55); }
.about h2 { margin-top: 0; }
.about h3 { margin-bottom: 4px; font-size: 16px; }
.credits { padding-left: 18px; font-size: 14px; }
.credits li { margin: 4px 0; }
.dialog-close { display: flex; justify-content: flex-end; margin-top: 10px; }

.text-card.as-hint { inset: auto 8px 56px 8px; z-index: 2; pointer-events: none; }
.text-card.as-hint p { font-size: 15px; padding: 10px 12px; }
.quiz-head .link-btn { white-space: nowrap; flex: none; }
.quiz-head .quiz-progress { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
