:root {
  --ink: #1a231f;
  --muted: #64706a;
  --paper: #f6f3ec;
  --card: #fffdf8;
  --forest: #153b32;
  --forest-2: #235c4b;
  --coral: #d86e54;
  --gold: #d7a849;
  --sky: #b9d9da;
  --line: rgba(26, 35, 31, .12);
  --shadow: 0 18px 50px rgba(25, 36, 31, .12);
  --radius: 24px;
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(185, 217, 218, .35), transparent 34rem),
    var(--paper);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(216,110,84,.35); outline-offset: 2px; }

.app-shell { min-height: 100vh; }
.screen { max-width: 720px; margin: 0 auto; min-height: 100vh; padding: 22px 18px calc(96px + var(--safe-bottom)); }
.screen.no-nav { padding-bottom: 32px; }

.eyebrow { margin: 0 0 8px; font-size: 12px; letter-spacing: .16em; text-transform: uppercase; font-weight: 800; color: var(--coral); }
h1, h2, h3, p { margin-top: 0; }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: clamp(34px, 9vw, 58px); line-height: .98; letter-spacing: -.035em; }
h2 { font-family: Georgia, "Times New Roman", serif; font-size: 30px; line-height: 1.05; letter-spacing: -.025em; }
h3 { font-size: 18px; }
.lede { color: var(--muted); font-size: 17px; line-height: 1.55; }
.small { color: var(--muted); font-size: 13px; line-height: 1.45; }

.btn { border: 0; border-radius: 999px; padding: 15px 20px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .15s ease, opacity .15s ease, background .15s ease; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: var(--forest); color: white; box-shadow: 0 10px 24px rgba(21,59,50,.2); }
.btn.secondary { background: rgba(21,59,50,.08); color: var(--forest); }
.btn.ghost { background: transparent; color: var(--forest); border: 1px solid var(--line); }
.btn.coral { background: var(--coral); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.card { background: rgba(255,253,248,.94); border: 1px solid rgba(255,255,255,.6); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.stack { display: grid; gap: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }

/* onboarding */
.onboarding { background: var(--forest); color: white; overflow: hidden; position: relative; }
.onboarding::before { content: ""; position: fixed; inset: -20% -30% auto; height: 65vh; background: radial-gradient(circle, rgba(215,168,73,.35), transparent 60%); pointer-events: none; }
.onboarding .screen { display: flex; flex-direction: column; position: relative; }
.onboarding h1 { margin-top: 8vh; max-width: 590px; }
.onboarding .lede { color: rgba(255,255,255,.76); max-width: 540px; }
.postcard-map { margin: 24px 0; min-height: 260px; border-radius: 32px; position: relative; overflow: hidden; background: linear-gradient(145deg, #1c4f42, #0b2721); border: 1px solid rgba(255,255,255,.13); }
.route-line { position: absolute; inset: 18% 14%; border: 2px dashed rgba(255,255,255,.25); border-radius: 50%; transform: rotate(-8deg); }
.map-stop { position: absolute; width: 14px; height: 14px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 8px rgba(215,168,73,.14); }
.map-stop::after { content: attr(data-label); position: absolute; white-space: nowrap; top: 20px; left: 50%; transform: translateX(-50%); color: white; font-size: 11px; font-weight: 800; }
.map-stop.locked { background: rgba(255,255,255,.3); box-shadow: 0 0 0 8px rgba(255,255,255,.06); }
.dots { display: flex; gap: 7px; margin-top: auto; padding-top: 18px; }
.dot { width: 8px; height: 8px; border-radius: 99px; background: rgba(255,255,255,.25); }
.dot.active { width: 28px; background: var(--gold); }
.onboarding-actions { display: grid; gap: 10px; margin-top: 16px; }

/* header/home */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.brand { font-family: Georgia, serif; font-weight: 800; font-size: 20px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--forest); color: white; font-weight: 900; }
.hero { color: white; border-radius: 32px; overflow: hidden; position: relative; min-height: 330px; padding: 26px; display: flex; flex-direction: column; justify-content: flex-end; background: linear-gradient(180deg, rgba(8,25,22,.05), rgba(8,25,22,.88)), linear-gradient(135deg, #d88a61, #385f6b 52%, #173b32); box-shadow: var(--shadow); }
.hero::before { content: ""; position: absolute; width: 190px; height: 250px; right: -22px; top: 18px; border-radius: 90px 90px 20px 20px; border: 12px solid rgba(255,255,255,.14); transform: rotate(8deg); }
.hero-content { position: relative; z-index: 1; }
.hero h1 { font-size: 46px; margin-bottom: 12px; }
.hero-meta { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 16px; }
.pill { border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 800; background: rgba(255,255,255,.14); backdrop-filter: blur(10px); }
.progress-bar { height: 7px; background: rgba(255,255,255,.17); border-radius: 99px; overflow: hidden; margin: 12px 0; }
.progress-bar > span { display: block; height: 100%; background: var(--gold); border-radius: inherit; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.metric { padding: 16px 12px; background: var(--card); border-radius: 20px; text-align: center; border: 1px solid var(--line); }
.metric strong { display: block; font-size: 22px; }
.metric span { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.section-title { display: flex; align-items: end; justify-content: space-between; margin: 26px 2px 12px; }
.section-title h2 { font-size: 25px; margin: 0; }
.episode-card { padding: 18px; background: var(--card); border: 1px solid var(--line); border-radius: 22px; display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; }
.episode-index { width: 48px; height: 48px; border-radius: 16px; background: rgba(21,59,50,.09); color: var(--forest); display: grid; place-items: center; font-family: Georgia, serif; font-size: 20px; font-weight: 900; }
.episode-card.locked { opacity: .55; }
.episode-card h3 { margin-bottom: 4px; }
.episode-card p { margin: 0; color: var(--muted); font-size: 13px; }
.status-icon { font-size: 20px; }

/* journey */
.journey-head { margin-bottom: 16px; }
.journey-head .back { border: 0; background: transparent; color: var(--forest); font-weight: 800; padding: 0 0 14px; }
.scene-progress { display: flex; gap: 6px; margin-bottom: 18px; }
.scene-progress span { height: 6px; flex: 1; border-radius: 99px; background: var(--line); }
.scene-progress span.done { background: var(--forest-2); }
.scene-progress span.current { background: var(--gold); }
.plot-card { background: var(--forest); color: white; border-radius: 28px; padding: 22px; margin-bottom: 16px; }
.plot-card p:last-child { color: rgba(255,255,255,.74); margin-bottom: 0; }
.dialogue-card { padding: 22px; border-radius: 28px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.character { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.character-face { width: 50px; height: 50px; border-radius: 18px; display: grid; place-items: center; background: linear-gradient(145deg, var(--sky), #e6c2aa); font-size: 24px; }
.character-name { font-weight: 900; }
.character-role { color: var(--muted); font-size: 12px; }
.speech { font-family: Georgia, serif; font-size: 24px; line-height: 1.35; margin: 12px 0 18px; }
.gloss { display: inline; border-bottom: 1px dashed var(--coral); cursor: help; }
.help-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { border: 1px solid var(--line); background: transparent; color: var(--forest); border-radius: 999px; padding: 9px 12px; font-size: 12px; font-weight: 800; }
.support-box { background: #f0eee7; border-radius: 16px; padding: 13px 14px; margin-bottom: 14px; color: #49544e; font-size: 14px; line-height: 1.45; }
.response-input { width: 100%; border: 1.5px solid var(--line); background: #fff; min-height: 112px; resize: vertical; border-radius: 18px; padding: 15px; color: var(--ink); }
.response-input.short { min-height: 58px; resize: none; }
.answer-feedback { border-radius: 18px; padding: 14px; margin: 14px 0; font-size: 14px; line-height: 1.5; }
.answer-feedback.good { background: rgba(35,92,75,.10); color: #174a3c; }
.answer-feedback.retry { background: rgba(216,110,84,.11); color: #7d392b; }
.model-answer { font-family: Georgia, serif; font-size: 18px; color: var(--forest); margin-top: 7px; }
.xp-float { display: inline-flex; border-radius: 999px; padding: 6px 9px; font-weight: 900; color: #725515; background: rgba(215,168,73,.2); }

/* results/class/progress */
.result-orb { width: 132px; height: 132px; margin: 28px auto; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, #f4d78d, var(--gold)); color: #4e3a0d; box-shadow: 0 20px 50px rgba(215,168,73,.34); text-align: center; }
.result-orb strong { display: block; font-size: 35px; }
.culture-card { border-left: 5px solid var(--coral); }
.leader-row { display: grid; grid-template-columns: 34px 44px 1fr auto; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.leader-row:last-child { border-bottom: 0; }
.rank { font-weight: 900; color: var(--muted); }
.leader-avatar { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; background: rgba(21,59,50,.1); font-weight: 900; }
.leader-name { font-weight: 800; }
.leader-xp { font-weight: 900; color: var(--forest); }
.weak-card { display: flex; justify-content: space-between; align-items: center; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.weak-card small { color: var(--muted); }

.bottom-nav { position: fixed; z-index: 20; left: 50%; transform: translateX(-50%); bottom: 12px; width: min(calc(100% - 24px), 690px); background: rgba(255,253,248,.92); backdrop-filter: blur(18px); border: 1px solid rgba(255,255,255,.8); border-radius: 24px; padding: 8px; display: grid; grid-template-columns: repeat(4, 1fr); box-shadow: 0 18px 50px rgba(26,35,31,.18); }
.nav-item { border: 0; background: transparent; padding: 9px 5px; border-radius: 17px; color: var(--muted); font-size: 11px; font-weight: 800; display: grid; gap: 3px; place-items: center; }
.nav-item span:first-child { font-size: 19px; }
.nav-item.active { color: var(--forest); background: rgba(21,59,50,.08); }

.toast { position: fixed; z-index: 50; left: 50%; bottom: 104px; transform: translate(-50%, 20px); background: #17211d; color: white; border-radius: 999px; padding: 11px 16px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .screen { padding-top: 34px; }
  .hero { min-height: 380px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
