:root {
  color-scheme: dark;
  --ink: #f5fbff;
  --muted: #9fb8c8;
  --cyan: #62f0e6;
  --gold: #ffd97c;
  --violet: #bd91ff;
  --danger: #ff6f91;
  --panel: rgba(7, 18, 29, .78);
  --line: rgba(164, 230, 238, .22);
  --shadow: 0 24px 80px rgba(0, 0, 0, .46);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #050b12; color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button { color: var(--ink); border: 1px solid var(--line); background: linear-gradient(180deg, rgba(34,66,83,.86), rgba(10,26,40,.92)); border-radius: 12px; padding: .8rem 1.1rem; cursor: pointer; letter-spacing: .02em; transition: transform .16s ease, border-color .16s ease, filter .16s ease; }
button:hover, button:focus-visible { transform: translateY(-2px); border-color: rgba(98,240,230,.72); filter: brightness(1.12); outline: none; }
button:disabled { opacity: .38; cursor: not-allowed; transform: none; }
button.primary { background: linear-gradient(135deg, #1e756e, #315f8c 62%, #664a91); border-color: rgba(138,255,238,.7); box-shadow: 0 10px 38px rgba(41,171,169,.22); }
.hidden { display: none !important; }
#app, #game { width: 100%; height: 100%; display: block; }
#game { background: radial-gradient(circle at 50% 40%, #102638 0, #07111c 48%, #03070c 100%); }
.screen { position: fixed; inset: 0; display: none; place-items: center; z-index: 20; padding: 4vw; background: radial-gradient(circle at 50% 40%, rgba(9,28,42,.35), rgba(2,5,9,.82)); backdrop-filter: blur(8px); }
.screen.active { display: grid; }
.glass { background: linear-gradient(150deg, rgba(13,35,49,.9), rgba(5,13,23,.86)); border: 1px solid rgba(155,226,234,.2); box-shadow: var(--shadow), inset 0 1px rgba(255,255,255,.05); backdrop-filter: blur(18px); }
.title-panel { width: min(620px, 92vw); padding: clamp(1.4rem, 4vw, 3rem); border-radius: 28px; text-align: center; position: relative; overflow: hidden; }
.title-panel::before, .level-panel::before, .modal::before, .story-panel::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(110deg, transparent 10%, rgba(110,255,239,.05) 38%, transparent 58%); }
.logo { display: block; width: min(470px, 86%); margin: 0 auto 1rem; filter: drop-shadow(0 12px 35px rgba(46,224,210,.15)); }
.title-art { position: fixed; inset: 0; background: url('./assets/key-art.svg') center/cover no-repeat; opacity: .6; mix-blend-mode: screen; }
.eyebrow { color: var(--cyan); font-size: .7rem; letter-spacing: .23em; font-weight: 750; text-transform: uppercase; margin: 0 0 .55rem; }
.intro { color: #c8d9e3; line-height: 1.7; max-width: 52ch; margin: 1rem auto 1.5rem; }
.menu-actions { display: grid; gap: .75rem; }
.controls-summary { font-size: .76rem; color: #7f9aaa; margin: 1.4rem 0 0; line-height: 1.5; }
footer { position: fixed; bottom: 1.2rem; font-size: .7rem; color: #6e8595; }
.level-panel { position: relative; width: min(1050px, 96vw); max-height: 90vh; overflow: auto; padding: clamp(1rem, 3vw, 2.2rem); border-radius: 24px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.panel-head h2 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.7rem); }
.icon-button { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 1.5rem; }
.tabs { display: flex; gap: .6rem; margin: 1.3rem 0; overflow-x: auto; padding-bottom: .3rem; }
.tabs button.active { border-color: var(--cyan); color: var(--cyan); }
.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: .8rem; }
.level-card { min-height: 142px; text-align: left; position: relative; overflow: hidden; }
.level-card strong { display: block; font-size: 1.08rem; margin: .25rem 0 .55rem; }
.level-card span { color: var(--muted); font-size: .8rem; line-height: 1.45; }
.level-card .badge { position: absolute; top: .8rem; right: .8rem; color: var(--gold); }
.story-screen { background: radial-gradient(circle at 50% 42%, rgba(89,42,103,.3), rgba(2,5,9,.92)); }
.story-panel { position: relative; width: min(680px, 92vw); padding: clamp(1.6rem, 5vw, 3.4rem); border-radius: 30px; overflow: hidden; text-align: center; background: linear-gradient(145deg, rgba(51,25,63,.94), rgba(7,16,29,.95) 62%, rgba(19,42,48,.92)); border-color: rgba(192,108,255,.4); }
.story-sigil { width: 92px; height: 92px; display: grid; place-items: center; margin: 0 auto 1rem; border-radius: 50%; border: 1px solid rgba(192,108,255,.55); color: #d9a7ff; font-size: 3rem; background: radial-gradient(circle, rgba(192,108,255,.18), transparent 68%); box-shadow: 0 0 54px rgba(192,108,255,.16); }
.story-panel h2 { margin: .2rem 0 .65rem; font-size: clamp(2rem, 5vw, 3.3rem); }
.story-speaker { color: #d9a7ff; letter-spacing: .18em; font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.story-body { margin: .5rem auto 1.4rem; color: #d6e3ea; max-width: 56ch; line-height: 1.75; }
.story-panel button { width: 100%; margin-top: .55rem; }
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; padding: 1rem; display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; }
.hud.hidden, .touch.hidden { display: none; }
.hud .glass { pointer-events: auto; border-radius: 16px; }
.compact { padding: .8rem 1rem; }
.hud-left { max-width: min(460px, 44vw); }
.hud-left h1 { font-size: 1.05rem; margin: 0 0 .2rem; }
.hud-left p:last-child, .hud-left #level-brief { color: var(--muted); font-size: .72rem; margin: 0; }
.mastery-rule, .fracture-rule, .causal-rule { display: inline-flex; margin-top: .55rem !important; padding: .28rem .5rem; border-radius: 999px; font-weight: 700; letter-spacing: .04em; }
.mastery-rule { border: 1px solid rgba(255,217,124,.38); color: var(--gold) !important; background: rgba(255,217,124,.06); }
.fracture-rule { border: 1px solid rgba(192,108,255,.46); color: #d9a7ff !important; background: rgba(192,108,255,.08); }
.causal-rule { border: 1px solid rgba(113,216,255,.48); color: #a9e9ff !important; background: rgba(113,216,255,.08); }
.hud-center { display: flex; gap: 1rem; }
.hud-center div { min-width: 86px; text-align: center; }
.hud-center span, .result-stats span { display: block; color: var(--muted); font-size: .65rem; text-transform: uppercase; letter-spacing: .1em; }
.hud-center strong { color: var(--gold); }
.hud-right { display: flex; gap: .5rem; }
.hud-right button { padding: .58rem .75rem; font-size: .72rem; }
.modal { position: relative; width: min(440px, 92vw); padding: 2rem; border-radius: 24px; display: grid; gap: .75rem; text-align: center; }
.modal h2 { margin: 0 0 .8rem; font-size: 2rem; }
.settings { text-align: left; }
.settings label { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--line); padding: 1rem 0; }
.settings input[type=range] { width: 48%; }
.grade { width: 100px; height: 100px; margin: .3rem auto; border-radius: 50%; display: grid; place-items: center; font-size: 3.2rem; font-weight: 900; color: var(--gold); border: 2px solid rgba(255,217,124,.62); background: radial-gradient(circle, rgba(255,217,124,.18), transparent 70%); box-shadow: 0 0 45px rgba(255,217,124,.18); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: .5rem 0; }
.result-stats div { background: rgba(255,255,255,.035); padding: .8rem; border-radius: 12px; }
.transmission { margin: .2rem 0 .5rem; padding: .85rem 1rem; border-left: 2px solid var(--gold); background: rgba(255,217,124,.055); color: #d8e7ef; font-size: .82rem; line-height: 1.55; text-align: left; font-style: normal; border-radius: 0 10px 10px 0; }
.codex-panel { width: min(1120px, 96vw); }
.codex-progress { color: var(--muted); margin: .5rem 0 1.2rem; }
.codex-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .85rem; }
.codex-card { min-height: 180px; padding: 1rem; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(150deg, rgba(23,49,64,.64), rgba(7,15,27,.9)); position: relative; }
.codex-card .codex-glyph { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid rgba(98,240,230,.38); border-radius: 50%; color: var(--cyan); font-size: 1.4rem; margin-bottom: .7rem; }
.codex-card h3 { margin: 0 0 .45rem; font-size: 1rem; }
.codex-card p { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.55; }
.codex-card small { display: block; color: var(--gold); font-size: .58rem; letter-spacing: .14em; text-transform: uppercase; margin-bottom: .3rem; }
.codex-card.locked { opacity: .48; filter: grayscale(.65); }
.codex-card.locked .codex-glyph { color: #6c8290; border-color: rgba(145,168,180,.25); }
#toast { position: fixed; left: 50%; bottom: 10%; z-index: 40; transform: translate(-50%, 25px); opacity: 0; pointer-events: none; background: rgba(4,12,20,.94); border: 1px solid var(--line); border-radius: 18px; padding: .7rem 1.1rem; color: var(--cyan); transition: .25s ease; max-width: min(620px, 88vw); text-align: center; line-height: 1.4; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }
.touch { position: fixed; z-index: 12; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%); grid-template-columns: repeat(5, 52px); gap: .35rem; pointer-events: auto; }
.touch button { width: 52px; height: 48px; padding: 0; background: rgba(7,22,34,.86); }
.touch button.wide { width: auto; grid-column: span 2; font-size: .65rem; }
@media (pointer: coarse), (max-width: 760px) {
  .touch:not(.hidden) { display: grid; }
  .hud { padding: .5rem; }
  .hud-left { max-width: 48vw; }
  .hud-left #level-brief { display: none; }
  .mastery-rule, .fracture-rule, .causal-rule { display: none !important; }
  .hud-center { position: fixed; top: .5rem; right: .5rem; gap: .35rem; }
  .hud-center div { min-width: 62px; }
  .hud-right { position: fixed; right: .5rem; top: 4.6rem; }
  .hud-right #sound-btn { display: none; }
  .title-panel { margin-bottom: 5rem; }
  .codex-grid { grid-template-columns: 1fr; }
  .codex-card { min-height: 0; }
  .story-panel { padding: 1.5rem; }
  .story-sigil { width: 70px; height: 70px; font-size: 2.3rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; } }
.high-contrast { --cyan: #7ffff4; --gold: #ffe28a; --line: rgba(255,255,255,.44); }
