:root {
  color-scheme: dark;
  --ink: #f7f3e8;
  --muted: #aebad1;
  --night: #0b1223;
  --panel: #121e37;
  --panel-2: #172744;
  --line: #304265;
  --gold: #f4a62a;
  --gold-2: #ffcb59;
  --mint: #58d7ae;
  --blue: #5fb8ff;
  --danger: #ff7c7c;
  --shadow: 0 24px 70px rgba(0,0,0,.32);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--night); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 5%, rgba(95,184,255,.16), transparent 34rem),
    radial-gradient(circle at 90% 90%, rgba(244,166,42,.13), transparent 34rem),
    var(--night);
  font-family: ui-rounded, "Avenir Next", Avenir, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.hidden { display: none !important; }

.strings {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .12;
  background: repeating-linear-gradient(to bottom, transparent 0 58px, #8fb6d7 59px, transparent 60px 64px);
  mask-image: linear-gradient(to right, transparent, black 20%, black 80%, transparent);
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1.2rem;
  min-height: 76px;
  padding: .75rem max(1rem, calc((100vw - 1120px)/2));
  background: rgba(11,18,35,.86);
  border-bottom: 1px solid rgba(120,154,203,.25);
  backdrop-filter: blur(18px);
}

.brand, .icon-button, .back-button, .text-button {
  border: 0;
  background: none;
  cursor: pointer;
}
.brand { display: inline-flex; align-items: center; gap: .8rem; justify-self: start; font-size: 1rem; font-weight: 800; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px;
  color: #15120b; background: linear-gradient(145deg, var(--gold-2), var(--gold)); box-shadow: 0 8px 24px rgba(244,166,42,.22);
}
.top-stats { display: flex; gap: .65rem; font-size: .9rem; color: var(--muted); }
.top-stats span { padding: .45rem .72rem; border: 1px solid var(--line); border-radius: 999px; background: rgba(23,39,68,.72); }
.top-stats b { color: var(--ink); }
.icon-button { padding: .65rem .9rem; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-weight: 800; }

main { position: relative; width: min(1120px, calc(100% - 2rem)); margin: 0 auto; padding: 2.5rem 0 5rem; }
.view { animation: arrive .35s ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(10px); } }

.mission-board {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 230px;
  padding: clamp(1.7rem, 5vw, 4rem);
  border: 1px solid #3f5478;
  border-radius: 30px 30px 90px 30px;
  background:
    linear-gradient(115deg, rgba(27,53,91,.96), rgba(16,29,53,.96)),
    var(--panel);
  box-shadow: var(--shadow);
}
.mission-board::after {
  content: ""; position: absolute; right: -90px; top: -130px; width: 360px; height: 360px; border: 48px solid rgba(95,184,255,.11); border-radius: 50%;
}
.eyebrow { margin: 0 0 .35rem; color: var(--gold-2); font-size: .78rem; font-weight: 900; letter-spacing: .16em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .6rem; font-size: clamp(2rem, 6vw, 4.6rem); line-height: .98; letter-spacing: -.045em; }
h2 { margin-bottom: .5rem; font-size: clamp(1.4rem, 3vw, 2.1rem); line-height: 1.1; }
.lead { max-width: 42rem; margin-bottom: 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.25rem); }
.level-dial { position: relative; z-index: 1; display: grid; place-items: center; flex: 0 0 116px; height: 116px; border: 9px solid #29466f; border-top-color: var(--gold); border-radius: 50%; background: #0d1830; transform: rotate(7deg); }
.level-dial span { color: var(--muted); font-size: .66rem; font-weight: 900; letter-spacing: .15em; }
.level-dial strong { margin-top: -.5rem; font-size: 2.5rem; color: var(--gold-2); }

.score-strip { display: grid; grid-template-columns: repeat(4,1fr); gap: 1px; margin: 1rem 0 2rem; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--line); }
.score-strip div { padding: 1rem 1.2rem; background: var(--panel); }
.score-strip span { display: block; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.score-strip strong { display: block; margin-top: .15rem; font-size: 1.2rem; }

.mode-panel, .badges-panel { margin-top: 1.25rem; padding: clamp(1.2rem, 3vw, 2rem); border: 1px solid var(--line); border-radius: 24px; background: rgba(18,30,55,.88); box-shadow: 0 16px 50px rgba(0,0,0,.16); }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.panel-heading.compact { align-items: center; margin-bottom: .8rem; }
.panel-heading h2 { margin-bottom: 0; }
.save-note { color: var(--muted); font-size: .88rem; }
.mode-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: .9rem; }
.mode-card { position: relative; display: grid; gap: .35rem; min-height: 150px; padding: 1.2rem; text-align: left; border: 1px solid #405677; border-radius: 18px; background: #101c34; cursor: pointer; transition: transform .18s, border-color .18s, background .18s; }
.mode-card:hover { transform: translateY(-4px); border-color: var(--blue); background: #172744; }
.mode-card.featured { border-color: #8c6727; background: linear-gradient(145deg, rgba(244,166,42,.13), #101c34 56%); }
.mode-time { width: max-content; padding: .22rem .58rem; color: #1b160b; border-radius: 999px; background: var(--gold-2); font-size: .78rem; font-weight: 900; }
.mode-card strong { align-self: end; font-size: 1.22rem; }
.mode-card small { color: var(--muted); font-size: .84rem; }
.resume-button, .primary-button, .secondary-button { border-radius: 14px; cursor: pointer; font-weight: 900; }
.resume-button { width: 100%; margin-top: 1rem; padding: .9rem 1rem; border: 1px solid var(--mint); background: rgba(88,215,174,.1); color: var(--mint); }
.text-button { color: var(--blue); font-weight: 800; }
.badge-row { display: grid; grid-template-columns: repeat(4,1fr); gap: .7rem; }
.badge { display: flex; align-items: center; gap: .7rem; padding: .8rem; border: 1px dashed #425979; border-radius: 15px; color: #7f8ca5; background: rgba(9,18,35,.45); }
.badge.unlocked { color: var(--ink); border-style: solid; border-color: #79622f; background: rgba(244,166,42,.08); }
.badge-icon { display: grid; place-items: center; flex: 0 0 38px; height: 38px; border-radius: 12px; background: #21304b; filter: grayscale(1); }
.badge.unlocked .badge-icon { filter: none; background: #3c321c; }
.badge strong { display: block; font-size: .88rem; }
.badge small { color: var(--muted); font-size: .75rem; }

.session-head { display: flex; align-items: center; gap: 1.2rem; margin-bottom: 1rem; }
.back-button { padding: .6rem 0; color: var(--muted); font-weight: 800; }
.session-progress-wrap { flex: 1; }
.session-progress-label { display: flex; justify-content: space-between; margin-bottom: .45rem; font-size: .9rem; }
.session-progress-label span { color: var(--muted); }
.session-progress-label strong { color: var(--gold-2); }
.progress-track { overflow: hidden; height: 12px; border-radius: 999px; background: #263551; box-shadow: inset 0 2px 5px rgba(0,0,0,.28); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--gold),var(--gold-2),var(--mint)); transition: width .35s ease; }
.play-stage { min-height: 590px; padding: clamp(1.35rem, 4vw, 3rem); border: 1px solid #3c5379; border-radius: 28px; background: linear-gradient(150deg,rgba(23,39,68,.98),rgba(12,23,44,.98)); box-shadow: var(--shadow); }
.stage-kicker { display: flex; align-items: center; gap: .65rem; margin-bottom: 1rem; color: var(--gold-2); font-size: .8rem; font-weight: 900; letter-spacing: .12em; }
.stage-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; color: #20180b; background: var(--gold); }
.play-stage h1 { max-width: 820px; font-size: clamp(2rem,5vw,4rem); }
.stage-intro { max-width: 760px; color: var(--muted); font-size: 1.08rem; }
.request-display { display: grid; grid-template-columns: repeat(4,1fr); gap: .65rem; margin: 1.7rem 0; }
.request-chip { min-height: 100px; padding: 1rem; border: 1px solid #466087; border-radius: 16px; background: #0e1a32; }
.request-chip span { display: block; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
.request-chip strong { display: block; margin-top: .3rem; color: var(--mint); font-size: 1.08rem; }
.term-link { padding: 0; border: 0; color: var(--blue); background: none; text-decoration: underline; text-underline-offset: 3px; cursor: help; }
.task-list { display: grid; gap: .65rem; margin: 1.5rem 0; }
.task-check { display: grid; grid-template-columns: 28px 1fr; gap: .75rem; align-items: start; padding: .85rem 1rem; border: 1px solid #354a6e; border-radius: 14px; background: rgba(9,18,35,.48); cursor: pointer; }
.task-check:hover { border-color: #55739e; }
.task-check input { width: 22px; height: 22px; margin-top: .08rem; accent-color: var(--mint); }
.task-check span { font-size: 1rem; }
.video-button { display: inline-flex; align-items: center; gap: .45rem; padding: .72rem 1rem; border-radius: 12px; color: #17130b; background: var(--gold); font-weight: 900; text-decoration: none; }
.video-button::before { content: "▶"; }
.fact-card { margin-top: 1.3rem; padding: 1rem 1.1rem; border-left: 5px solid var(--mint); border-radius: 5px 14px 14px 5px; background: rgba(88,215,174,.08); }
.fact-card b { color: var(--mint); }
.stage-actions { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1rem; }
.primary-button, .secondary-button { min-height: 54px; padding: .8rem 1.2rem; }
.primary-button { border: 0; color: #21180a; background: linear-gradient(135deg,var(--gold-2),var(--gold)); box-shadow: 0 12px 30px rgba(244,166,42,.2); }
.primary-button span { margin-left: .4rem; padding: .18rem .42rem; border-radius: 999px; background: rgba(0,0,0,.14); font-size: .8rem; }
.secondary-button { border: 1px solid var(--line); background: var(--panel); }
.stage-message { min-height: 1.5rem; margin: .6rem 0 0; text-align: right; color: var(--danger); }

.quiz-grid { display: grid; gap: 1rem; margin-top: 1.5rem; }
.quiz-card { padding: 1.1rem; border: 1px solid #3b5275; border-radius: 16px; background: rgba(9,18,35,.5); }
.quiz-card p { margin-bottom: .8rem; font-weight: 800; }
.answer-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: .55rem; }
.answer-button { min-height: 48px; padding: .65rem .8rem; text-align: left; border: 1px solid #486186; border-radius: 11px; background: #14233e; cursor: pointer; }
.answer-button:hover { border-color: var(--blue); }
.answer-button.correct { color: #071b14; border-color: var(--mint); background: var(--mint); }
.answer-button.wrong { color: #321111; border-color: var(--danger); background: var(--danger); }
.answer-button:disabled { cursor: default; opacity: .92; }
.answer-note { margin: .55rem 0 0; color: var(--muted); font-size: .88rem; }
.answer-note.good { color: var(--mint); }

.wrap-score { display: grid; grid-template-columns: repeat(3,1fr); gap: .8rem; margin: 1.5rem 0; }
.wrap-score div { padding: 1.1rem; border: 1px solid #425a7e; border-radius: 16px; background: #101d35; }
.wrap-score span { color: var(--muted); font-size: .8rem; text-transform: uppercase; }
.wrap-score strong { display: block; margin-top: .2rem; color: var(--gold-2); font-size: 1.65rem; }

.history-head { display: flex; gap: 2rem; align-items: start; margin-bottom: 2rem; }
.history-head h1 { font-size: clamp(2rem,5vw,3.8rem); }
.history-list { display: grid; gap: .8rem; }
.history-day { display: grid; grid-template-columns: 1fr auto auto; gap: 1rem; align-items: center; padding: 1rem 1.2rem; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.history-day span { color: var(--muted); }
.empty-state { padding: 3rem; text-align: center; border: 1px dashed var(--line); border-radius: 20px; color: var(--muted); }

.glossary-dialog { width: min(760px,calc(100% - 1.5rem)); max-height: 86vh; padding: 0; color: var(--ink); border: 1px solid #496184; border-radius: 24px; background: #101c32; box-shadow: var(--shadow); }
.glossary-dialog::backdrop { background: rgba(3,8,18,.75); backdrop-filter: blur(7px); }
.dialog-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 1.35rem 1.4rem .8rem; background: #101c32; }
.dialog-head h2 { margin: 0; }
.close-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: #172744; cursor: pointer; font-size: 1.6rem; }
.search-label { display: grid; gap: .35rem; padding: 0 1.4rem 1rem; color: var(--muted); font-size: .85rem; font-weight: 800; }
.search-label input { width: 100%; padding: .82rem 1rem; color: var(--ink); border: 1px solid #486184; border-radius: 12px; background: #0b162a; font-size: 1rem; }
.glossary-list { display: grid; gap: .55rem; padding: 0 1.4rem 1.5rem; }
.glossary-entry { scroll-margin-top: 130px; padding: .85rem 1rem; border: 1px solid #354c70; border-radius: 13px; background: #13213b; }
.glossary-entry.highlight { animation: flash 1.1s ease; border-color: var(--gold); }
@keyframes flash { 50% { background: rgba(244,166,42,.2); } }
.glossary-entry dt { color: var(--gold-2); font-weight: 900; }
.glossary-entry dd { margin: .25rem 0 0; color: #d4dbea; }
.xp-pop { position: fixed; z-index: 20; right: 7vw; bottom: 8vh; padding: .8rem 1rem; border-radius: 14px; color: #17120a; background: var(--gold-2); font-size: 1.2rem; font-weight: 1000; opacity: 0; transform: translateY(15px) scale(.8); pointer-events: none; }
.xp-pop.show { animation: xp .9s ease both; }
@keyframes xp { 20%,70% { opacity: 1; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(-28px) scale(1.08); } }

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; min-height: 68px; }
  .top-stats { display: none; }
  main { width: min(100% - 1rem,1120px); padding-top: 1rem; }
  .mission-board { min-height: 190px; padding: 1.4rem; border-radius: 24px 24px 64px 24px; }
  .mission-board h1 { max-width: 70%; }
  .level-dial { flex-basis: 86px; height: 86px; border-width: 7px; }
  .level-dial strong { font-size: 1.8rem; }
  .score-strip { grid-template-columns: repeat(2,1fr); }
  .mode-grid, .badge-row { grid-template-columns: 1fr; }
  .mode-card { min-height: 115px; }
  .panel-heading { align-items: start; flex-direction: column; }
  .play-stage { min-height: 0; padding: 1.2rem; border-radius: 22px; }
  .request-display, .wrap-score { grid-template-columns: repeat(2,1fr); }
  .answer-grid { grid-template-columns: 1fr; }
  .stage-actions { position: sticky; bottom: .4rem; padding: .5rem; border-radius: 16px; background: rgba(11,18,35,.9); backdrop-filter: blur(12px); }
  .primary-button { flex: 1; }
  .history-day { grid-template-columns: 1fr auto; }
  .history-day span { grid-column: 1/-1; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
