/* KCNA Quest. One dark theme, mobile first. */

:root {
  --bg: #0d1117;
  --bg-2: #141b24;
  --bg-3: #1c2531;
  --line: #2b3746;
  --text: #e6edf3;
  --dim: #9fb0c3;
  --accent: #5b9dff;
  --ok: #3fd08a;
  --warn: #f2b84b;
  --bad: #ff6b6b;
  --gold: #ffd166;
  --world: var(--accent);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.2; text-wrap: balance; }
h2 { font-size: 1.2rem; line-height: 1.25; }
a { color: var(--accent); }
code, kbd, pre { font-family: var(--mono); }
code { background: var(--bg-3); padding: 0.1em 0.35em; border-radius: 5px; font-size: 0.9em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--bg-3); padding: 8px 12px; z-index: 10; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.boot, .fine { color: var(--dim); font-size: 0.9rem; }
.boot { padding: 48px 16px; text-align: center; }
.error { color: var(--bad); }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(13, 17, 23, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.brand-mark { color: var(--accent); font-size: 1.3rem; line-height: 1; }
.hud { display: flex; gap: 14px; align-items: center; justify-content: flex-end; min-width: 0; }
.hud-rank { display: flex; gap: 8px; align-items: center; min-width: 0; font-size: 0.85rem; }
.rank-name { font-weight: 600; white-space: nowrap; }
.xpbar { width: 90px; height: 8px; background: var(--bg-3); border-radius: 99px; overflow: hidden; flex: none; }
.xpbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #8fd3ff); border-radius: 99px; transition: width 0.6s ease; }
.xp-num { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud-streak { font-variant-numeric: tabular-nums; color: var(--dim); white-space: nowrap; filter: grayscale(1); }
.hud-streak.lit { color: var(--warn); filter: none; }
.tabs { grid-column: 1 / -1; display: flex; gap: 4px; }
.tab { flex: 1; text-align: center; padding: 7px 4px; border-radius: 9px; color: var(--dim); text-decoration: none; font-size: 0.92rem; font-weight: 600; }
.tab.on { background: var(--bg-3); color: var(--text); }
.tab:hover { color: var(--text); }

.main { max-width: 980px; margin: 0 auto; padding: 20px 16px 80px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
.btn:hover:not(:disabled) { border-color: var(--dim); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; }
.btn.primary.glow:not(:disabled) { box-shadow: 0 0 0 4px rgba(91, 157, 255, 0.25); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 0.85rem; }

/* ---------- map ---------- */
.next-card {
  display: grid; gap: 2px; padding: 16px 18px; border-radius: var(--radius); text-decoration: none; color: var(--text);
  background: linear-gradient(120deg, rgba(91, 157, 255, 0.22), rgba(91, 157, 255, 0.05)); border: 1px solid rgba(91, 157, 255, 0.5);
}
.next-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }
.next-card strong { font-size: 1.15rem; }
.next-why { color: var(--dim); font-size: 0.88rem; }

.world { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; border-top: 3px solid var(--world); }
.world-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.world-tag { color: var(--world); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.world-meta { text-align: right; display: grid; font-size: 0.82rem; color: var(--dim); white-space: nowrap; }
.world-meta .pct { font-size: 1.1rem; color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.path { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.stop {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border-radius: 10px; background: var(--bg-3); border: 1px solid transparent; color: var(--text); text-decoration: none;
}
a.stop:hover { border-color: var(--world); }
.stop.rec { border-color: var(--world); box-shadow: 0 0 0 3px color-mix(in srgb, var(--world) 22%, transparent); }
.stop.soon { opacity: 0.45; }
.stop-num { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--bg); border: 2px solid var(--line); color: var(--dim); }
.stop.played .stop-num { border-color: var(--world); color: var(--world); }
.stop.mastered .stop-num { background: var(--gold); border-color: var(--gold); color: #3a2a00; font-size: 1.2rem; }
.stop-text { display: grid; min-width: 0; }
.stop-blurb { color: var(--dim); font-size: 0.86rem; }
.stop-sub { color: var(--dim); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
.stars { white-space: nowrap; letter-spacing: 2px; }
.star { color: var(--line); }
.star.on { color: var(--gold); }

/* ---------- level frame ---------- */
.level-head { display: grid; gap: 6px; }
.back { color: var(--dim); text-decoration: none; font-size: 0.9rem; }
.back:hover { color: var(--text); }
.lesson { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 14px; scroll-margin-top: 110px; }
.beat-head { display: grid; gap: 10px; }
.beat-dots { list-style: none; display: flex; gap: 6px; margin: 0; padding: 0; }
.dot { flex: 1; height: 6px; border-radius: 99px; background: var(--bg-3); }
.dot.done { background: var(--ok); }
.dot.now { background: var(--accent); }
.dot.prove.now { background: var(--warn); }
.beat-heading { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.beat-kind { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--bg-3); color: var(--accent); }
.beat-kind.try { color: var(--ok); }
.beat-kind.prove { color: var(--warn); }
.beat-body { display: grid; gap: 12px; min-height: 120px; }
.beat-say { color: var(--ok); min-height: 1.5em; }
.beat-foot { display: flex; justify-content: flex-end; }
.lead { color: var(--dim); max-width: 65ch; }
.lead.prompt { color: var(--text); font-weight: 600; font-size: 1.05rem; }

/* ---------- stage (svg) ---------- */
.stage-wrap { display: grid; gap: 8px; min-width: 0; }
.stage-scroll { overflow-x: auto; min-width: 0; -webkit-overflow-scrolling: touch; }
/* min-width keeps diagram text readable on a phone; only the drawing scrolls sideways */
.stage { display: block; width: 100%; min-width: 680px; height: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; max-height: 62vh; }
/* reserved height, so the step button does not jump under the finger between captions */
.stage-caption { min-height: 6em; color: var(--text); max-width: 70ch; }
@media (min-width: 700px) { .stage-caption { min-height: 4.5em; } }

/* narrow screens: the drawing always fits the width, a camera (the viewBox) zooms to the action */
.stage-wrap { position: relative; }
@media (max-width: 699.98px) {
  .stage { min-width: 0; }
  .stage-scroll { overflow-x: hidden; }
}
.stage-wrap.is-narrow .stage { min-width: 0; }
.stage-wrap.is-narrow .stage-scroll { overflow-x: hidden; }

/* control bar: shown only on narrow screens, and in fullscreen (for Close) */
.stage-bar { display: none; justify-content: flex-end; gap: 8px; }
.stage-wrap.is-narrow .stage-bar, .stage-wrap.is-full .stage-bar { display: flex; }
.stage-wrap:not(.is-narrow) .stage-follow { display: none; }
.stage-wrap.is-full .stage-fs { display: none; }
.stage-close { display: none; }
.stage-wrap.is-full .stage-close { display: inline-flex; }
.stage-btn { min-height: 44px; min-width: 44px; padding: 8px 14px; align-items: center; justify-content: center; }
.stage-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.stage-wrap.is-full .stage-bar { position: absolute; top: 6px; right: 6px; z-index: 2; }

/* fullscreen: CSS only, because iPhone Safari has no element Fullscreen API and no orientation lock */
.beat-body.stage-full, .stage-wrap.stage-full {
  position: fixed; inset: 0; z-index: 40; margin: 0; min-height: 0;
  background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 8px; overflow: auto; overscroll-behavior: contain;
}
.beat-body.stage-full > .lead { display: none; }
.stage-full .stage-wrap, .stage-wrap.stage-full { flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.stage-full .stage-scroll { min-height: 0; }
.stage-full .stage { height: 100%; max-height: none; min-width: 0; }
.stage-full .stage-caption { min-height: 0; max-height: 5.5em; overflow: auto; font-size: 0.9rem; }
.stage-full .w-stepper { flex: none; }
/* portrait phone: turn the whole container a quarter turn so the diagram is landscape */
@media (orientation: portrait) {
  .beat-body.stage-full, .stage-wrap.stage-full {
    inset: auto; top: 0; left: 0;
    width: 100vh; width: 100dvh; height: 100vw; height: 100dvw;
    transform-origin: top left; transform: rotate(90deg) translateY(-100%);
    /* the container is turned 90deg clockwise: its left edge is the screen top, its top edge the screen right */
    padding: max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-top));
  }
}
.stage .node-body { fill: var(--bg-3); stroke: var(--line); stroke-width: 2; transition: fill 0.25s, stroke 0.25s; }
.stage .node-label { fill: var(--text); font: 600 14px var(--sans); }
.stage .node-sub { fill: var(--dim); font: 11px var(--sans); }
.stage .node.clickable { cursor: pointer; }
.stage .node.clickable:hover .node-body { stroke: var(--accent); }
.stage .node.clickable:focus-visible { outline: none; }
.stage .node.clickable:focus-visible .node-body { stroke: var(--accent); stroke-width: 4; }
.stage .tone-active .node-body { stroke: var(--accent); fill: #1b2c47; }
.stage .tone-ok .node-body { stroke: var(--ok); fill: #153326; }
.stage .tone-warn .node-body { stroke: var(--warn); fill: #3a2e12; }
.stage .tone-bad .node-body { stroke: var(--bad); fill: #3d1b1e; }
.stage .tone-accent .node-body { stroke: #c58cff; fill: #2a1f3d; }
.stage .tone-ghost .node-body { stroke-dasharray: 5 5; fill: transparent; }
.stage .tone-ghost .node-label { fill: var(--dim); }
.stage .link { stroke: var(--line); stroke-width: 2; fill: none; }
.stage .link.dashed { stroke-dasharray: 6 6; }
.stage .link.tone-active { stroke: var(--accent); }
.stage .link.tone-ok { stroke: var(--ok); }
.stage .link.tone-bad { stroke: var(--bad); }
.stage .link-label, .stage .note { fill: var(--dim); font: 11px var(--sans); }
.stage .zone rect { fill: rgba(255, 255, 255, 0.02); stroke: var(--line); stroke-dasharray: 4 6; }
.stage .zone text { fill: var(--dim); font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: 0.08em; }
.stage .packet circle { fill: var(--accent); filter: drop-shadow(0 0 6px var(--accent)); }
.stage .packet.tone-ok circle { fill: var(--ok); filter: drop-shadow(0 0 6px var(--ok)); }
.stage .packet.tone-bad circle { fill: var(--bad); filter: drop-shadow(0 0 6px var(--bad)); }
.stage .packet.tone-warn circle { fill: var(--warn); filter: drop-shadow(0 0 6px var(--warn)); }
.stage .packet-label { fill: var(--text); font: 600 11px var(--sans); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }

/* ---------- widgets ---------- */
.w-q { font-weight: 600; font-size: 1.05rem; max-width: 65ch; }
.w-count { color: var(--dim); font-size: 0.8rem; }
.w-why { min-height: 1.5em; color: var(--dim); max-width: 65ch; }
.w-done { color: var(--ok); font-weight: 600; }
.w-quiz, .w-order, .w-match, .w-bucketgame { display: grid; gap: 10px; }
.w-options { display: grid; gap: 8px; }
.opt {
  appearance: none; text-align: left; font: inherit; color: var(--text); background: var(--bg-3); border: 1px solid var(--line);
  padding: 12px 14px; border-radius: 10px; cursor: pointer; min-height: 44px;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.good { border-color: var(--ok); background: #153326; }
.opt.bad { border-color: var(--bad); background: #3d1b1e; }
.opt:disabled { cursor: default; }
.w-lane { list-style: none; margin: 0; padding: 8px; display: grid; gap: 6px; min-height: 52px; border: 1px dashed var(--line); border-radius: 10px; counter-reset: lane; }
.w-lane li { counter-increment: lane; }
.w-lane li::before { content: counter(lane) ". "; color: var(--dim); }
.w-pool { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; font: inherit; color: var(--text); background: var(--bg-3); border: 1px solid var(--line);
  padding: 9px 12px; border-radius: 10px; cursor: pointer; text-align: left; min-height: 42px;
}
button.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip.placed { border-color: var(--ok); background: #153326; cursor: default; }
.chip.picked { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91, 157, 255, 0.25); }
.chip.alt { border-style: dashed; }
.w-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.w-col { display: grid; gap: 8px; align-content: start; }
.w-card { padding: 18px; border-radius: 12px; background: var(--bg-3); border: 1px solid var(--line); font-weight: 600; font-size: 1.05rem; text-align: center; min-height: 64px; display: grid; place-items: center; }
.w-card.done { color: var(--ok); }
.w-buckets { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.bucket { appearance: none; font: inherit; font-weight: 600; color: var(--text); background: var(--bg); border: 2px dashed var(--line); padding: 14px 10px; border-radius: 12px; cursor: pointer; min-height: 56px; }
.bucket:hover:not(:disabled) { border-color: var(--accent); }
.bucket.good { border-color: var(--ok); background: #153326; border-style: solid; }
.w-stepper { display: flex; gap: 8px; flex-wrap: wrap; }
.shake { animation: shake 0.32s linear; border-color: var(--bad) !important; }
@keyframes shake { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* generic lesson bits levels may use */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.panel { background: var(--bg-3); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 0.9rem; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; font-family: var(--mono); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 0.78rem; font-weight: 600; background: var(--bg); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.slider { display: grid; gap: 4px; font-size: 0.9rem; }
.slider input { width: 100%; accent-color: var(--accent); }
.yaml { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 13px/1.5 var(--mono); overflow-x: auto; white-space: pre; margin: 0; }
.yaml .hl { background: rgba(242, 184, 75, 0.2); border-radius: 3px; }

/* ---------- result ---------- */
.result { text-align: center; display: grid; gap: 12px; justify-items: center; padding: 32px 16px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); }
.result-stars .stars { font-size: 3rem; letter-spacing: 8px; }
.result-stars .star.on { animation: pop 0.5s ease backwards; }
.result-stars .star.on:nth-child(2) { animation-delay: 0.15s; }
.result-stars .star.on:nth-child(3) { animation-delay: 0.3s; }
@keyframes pop { from { transform: scale(0) rotate(-30deg); opacity: 0; } 70% { transform: scale(1.3); } }
.result-stars .star { display: inline-block; }
.result-xp { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.result-lines { list-style: none; margin: 0; padding: 0; color: var(--dim); display: grid; gap: 4px; max-width: 55ch; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------- stats ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 2px; color: var(--dim); font-size: 0.85rem; }
.tile-n { font-size: 1.5rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.grid { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.grid th, .grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.grid th { color: var(--dim); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 20; width: min(92vw, 420px); }
.toast { background: var(--bg-3); border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; animation: rise 0.25s ease; transition: opacity 0.3s; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); }
.toast.good { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }
.toast.out { opacity: 0; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* ---------- terminal dojo ---------- */
.dojo { display: grid; gap: 14px; grid-template-columns: 1fr; }
.mission-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mission-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 12px 14px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
a.mission-row:hover { border-color: var(--accent); }
.mission-row .m-meta { color: var(--dim); font-size: 0.82rem; grid-column: 1; }
.tier-head { margin-top: 10px; color: var(--dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.brief { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.brief p { max-width: 70ch; }
.goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.goals li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; color: var(--dim); }
.goals li::before { content: "○"; color: var(--line); }
.goals li.met { color: var(--text); }
.goals li.met::before { content: "●"; color: var(--ok); }
.brief-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.timer { font: 600 0.95rem var(--mono); font-variant-numeric: tabular-nums; color: var(--dim); margin-left: auto; }
.timer.over { color: var(--warn); }
.hint { border-left: 3px solid var(--warn); padding: 6px 10px; background: var(--bg-3); border-radius: 0 8px 8px 0; font-size: 0.92rem; }
.work { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.work > div { min-width: 0; }
@media (min-width: 900px) { .work { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; } }

.term { background: #05080c; border: 1px solid var(--line); border-radius: 10px; font: 13px/1.45 var(--mono); display: grid; grid-template-rows: 1fr auto; height: min(60vh, 520px); overflow: hidden; }
.term-out { overflow-y: auto; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; overscroll-behavior: contain; }
.term-out .ln-cmd { color: var(--text); }
.term-out .ln-cmd .ps { color: var(--ok); }
.term-out .ln-out { color: #c9d4e0; white-space: pre; overflow-x: auto; }
.term-out .ln-err { color: #ff9a9a; white-space: pre-wrap; }
.term-out .ln-sys { color: var(--warn); }
.term-in { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); background: #0a0f15; }
.term-in .ps { color: var(--ok); white-space: nowrap; }
.term-in input { flex: 1; min-width: 0; background: transparent; border: 0; color: var(--text); font: inherit; outline: none; padding: 6px 0; font-size: 16px; }
@media (min-width: 700px) { .term-in input { font-size: 13px; } }
.term-keys { display: flex; gap: 6px; padding: 6px 12px 8px; background: #0a0f15; overflow-x: auto; }
.term-keys button { appearance: none; font: 12px var(--mono); color: var(--dim); background: var(--bg-3); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; white-space: nowrap; cursor: pointer; }

.editor { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); display: grid; place-items: center; z-index: 30; padding: 12px; }
.editor-box { width: min(900px, 100%); height: min(86vh, 760px); background: #05080c; border: 1px solid var(--line); border-radius: 12px; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.editor-head, .editor-foot { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: #0a0f15; font: 12px var(--mono); color: var(--dim); }
.editor-foot { justify-content: flex-end; }
.editor-head .err { color: var(--bad); margin-left: auto; }
.editor-head .pos { color: var(--dim); font-variant-numeric: tabular-nums; }
.editor textarea { width: 100%; height: 100%; resize: none; border: 0; outline: none; background: transparent; color: var(--text); font: 14px/1.5 var(--mono); padding: 12px; tab-size: 2; white-space: pre; }

.cview { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 10px; }
.cview h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.cv-nodes { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.cv-node { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--bg); min-height: 86px; display: grid; gap: 6px; align-content: start; }
.cv-node.cordoned { border-style: dashed; opacity: 0.7; }
.cv-node-name { font: 600 12px var(--mono); color: var(--dim); display: flex; justify-content: space-between; gap: 6px; }
.cv-pods { display: flex; flex-wrap: wrap; gap: 5px; }
.cv-pod { width: 22px; height: 22px; border-radius: 6px; background: var(--line); position: relative; animation: podin 0.35s ease backwards; cursor: default; }
.cv-pod[data-s="Running"] { background: var(--ok); }
.cv-pod[data-s="Running"][data-ready="0"] { background: repeating-linear-gradient(45deg, var(--ok), var(--ok) 4px, #1d5a40 4px, #1d5a40 8px); }
.cv-pod[data-s="ContainerCreating"], .cv-pod[data-s="Pending"] { background: var(--warn); animation: podin 0.35s ease backwards, blink 1s ease infinite; }
.cv-pod[data-s="Completed"] { background: #4a6b8a; }
.cv-pod[data-s="Terminating"] { background: var(--dim); opacity: 0.5; }
.cv-pod.bad { background: var(--bad); }
.cv-pod.sys { opacity: 0.35; width: 12px; height: 12px; border-radius: 3px; align-self: center; }
@keyframes podin { from { transform: scale(0); } }
@keyframes blink { 50% { opacity: 0.45; } }
.cv-pending { border: 1px dashed var(--warn); border-radius: 10px; padding: 8px; }
.cv-list { display: grid; gap: 4px; font: 12px var(--mono); }
.cv-list .cv-item { display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; background: var(--bg); border-radius: 6px; border: 1px solid var(--line); }
.cv-item .to { color: var(--dim); }
.cv-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.72rem; color: var(--dim); }
.cv-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- boss ---------- */
.boss-pick { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.boss-card { display: grid; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--bg-2); border: 1px solid var(--line); border-top: 3px solid var(--world); color: var(--text); text-decoration: none; }
.boss-card:hover { border-color: var(--world); }
.boss-card .fine { font-size: 0.82rem; }
.arena { display: grid; gap: 14px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.arena-top { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.hp { height: 14px; border-radius: 99px; background: var(--bg-3); overflow: hidden; }
.hp > span { display: block; height: 100%; background: linear-gradient(90deg, var(--bad), #ff9f6b); transition: width 0.4s ease; }
.hearts { font-size: 1.2rem; letter-spacing: 3px; white-space: nowrap; color: var(--bad); }
.boss-face { font-size: 3.4rem; text-align: center; line-height: 1; transition: transform 0.2s; }
.boss-face.hit { animation: bosshit 0.4s ease; }
@keyframes bosshit { 30% { transform: translateX(10px) rotate(8deg) scale(0.9); filter: brightness(2); } }
.boss-name { text-align: center; color: var(--dim); font-size: 0.85rem; }
.tbar { height: 5px; border-radius: 99px; background: var(--bg-3); overflow: hidden; }
.tbar > span { display: block; height: 100%; background: var(--accent); width: 100%; }
.combo { color: var(--warn); font-weight: 700; min-height: 1.4em; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---- narrow phones ---- */
@media (max-width: 480px) {
  .xp-num { display: none; }
  .xpbar { width: 64px; }
  .top { gap: 6px 10px; padding-left: 12px; padding-right: 12px; }
  .main { padding-left: 12px; padding-right: 12px; }
  .lesson, .world, .brief, .arena { padding: 12px; }
  .term-keys button { padding: 10px 12px; font-size: 13px; }
  .w-cols { grid-template-columns: 1fr; }
}
.beat-body, .lesson { min-width: 0; }
.main > * { min-width: 0; }

/* ---- result: what was missed ---- */
.missed { text-align: left; display: grid; gap: 8px; width: 100%; max-width: 62ch; }
.missed h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--warn); }
.missed li { list-style: none; background: var(--bg-3); border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: 0 8px 8px 0; padding: 8px 10px; }
.missed ul { margin: 0; padding: 0; display: grid; gap: 6px; }
.missed .q { font-weight: 600; }
.missed .why { color: var(--dim); font-size: 0.92rem; }

/* ---- today card and focus chips ---- */
.today { display: grid; gap: 8px; padding: 14px 16px; border-radius: var(--radius); background: var(--bg-2); border: 1px solid var(--line); }
.today h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.today ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.today ul a { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg-3); color: var(--text); text-decoration: none; border: 1px solid transparent; }
.today ul a:hover { border-color: var(--accent); }
.today .tag { color: var(--dim); font-size: 0.82rem; white-space: nowrap; }
.today li.done a { opacity: 0.55; }
.today li.done .tag { color: var(--ok); }
.focus-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.on { border-color: var(--accent); background: #1b2c47; }
.mode-pick { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- predict, typed answers, checklists ---- */
.w-predict { display: grid; gap: 8px; border-style: dashed; }
.w-type { display: grid; gap: 8px; }
.w-input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font: 16px var(--sans); padding: 10px 12px; min-height: 44px; }
.w-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.w-input.good { border-color: var(--ok); }
.w-checklist { display: grid; gap: 4px; }

/* ---- readiness: first-try accuracy against the pass mark ---- */
.hud-ready { display: grid; justify-items: end; line-height: 1.05; text-decoration: none; color: var(--dim); }
.hud-ready .ready-n { font-weight: 700; font-size: 1.05rem; color: var(--text); font-variant-numeric: tabular-nums; }
.hud-ready .ready-l { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; }
.hud-ready.ok .ready-n { color: var(--ok); }
.hud-ready.low .ready-n { color: var(--warn); }
.hud-days { font-size: 0.8rem; color: var(--dim); white-space: nowrap; }
.ready-big { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ready-big.ok { color: var(--ok); }
.ready-big.low { color: var(--warn); }
.ready-bars { display: grid; gap: 8px; }
.ready-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(80px, 2fr) auto; gap: 10px; align-items: center; font-size: 0.9rem; }
.ready-name { min-width: 0; }
.ready-bar { position: relative; height: 12px; border-radius: 99px; background: var(--bg-3); overflow: hidden; }
.ready-bar .fill { position: absolute; inset: 0 auto 0 0; background: var(--warn); border-radius: 99px; }
.ready-bar .fill.ok { background: var(--ok); }
.ready-bar .line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: 0.8; }
.ready-val { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
@media (max-width: 480px) { .ready-row { grid-template-columns: 1fr auto; } .ready-bar { grid-column: 1 / -1; order: 3; } }
.today.done { border-color: var(--ok); }
.done-line { color: var(--ok); font-weight: 600; }
.ride-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ride-list li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 6px 10px; background: var(--bg-3); border-radius: 8px; color: var(--dim); }
.ride-list li.now { color: var(--text); border: 1px solid var(--accent); }
.ride-list li.pass { color: var(--ok); }
.ride-list li.fail { color: var(--bad); }
