:root {
  --cream: #F6EDE0;
  --cream-2: #EADCC8;
  --paper: #FFF8EE;
  --ink: #16100A;
  --ink-soft: #2A2218;
  --muted: #4A3F33;
  --green: #0C3D30;
  --green-2: #155C48;
  --green-text: #F4F7F2;
  --terra: #8C3B24;
  --terra-2: #A24B2F;
  --gold: #6B4508;
  --gold-bg: #F0D7A2;
  --ok-bg: #D4EBDD;
  --ok-ink: #0C3D30;
  --bad-bg: #F6D4CE;
  --bad-ink: #6F1414;
  --line: #D7C8B2;
  --shadow: 0 12px 40px rgba(22, 16, 10, 0.16);
  --radius: 22px;
  --font-d: "Fraunces", "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  --font-b: "Nunito", "Segoe UI", "Helvetica Neue", Roboto, "Noto Sans", sans-serif;
  --hud: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-b);
  background: var(--cream);
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.45;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--font-d); line-height: 1.15; margin: 0 0 10px; letter-spacing: -0.03em; color: var(--ink); }
h1 { font-size: 34px; }
h2 { font-size: 28px; }
h3 { font-size: 22px; }

.hud {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  min-height: var(--hud);
  padding: 8px 14px;
  background: rgba(12, 61, 48, 0.94);
  color: var(--green-text);
  backdrop-filter: blur(12px);
}
.hud strong { font-size: 16px; letter-spacing: 0.04em; text-transform: uppercase; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud .grow { flex: 1; min-width: 0; }
.path { display: flex; gap: 5px; align-items: center; }
.path i {
  width: 11px; height: 11px; border-radius: 50%;
  background: #3E6B5C; display: block;
  box-shadow: 0 0 0 2px rgba(244, 247, 242, 0.15);
}
.path i.on { background: #F0D7A2; }
.path i.now { background: #FFF8EE; box-shadow: 0 0 0 3px rgba(240, 215, 162, 0.7); }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 14px;
  background: rgba(255,248,238,0.14); color: var(--green-text);
  cursor: pointer; display: grid; place-items: center; flex: 0 0 44px;
}
.icon-btn:active { transform: scale(0.96); }
.bar { height: 6px; background: #0A2E24; }
.bar > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #E8C36A, #F6EBD0); transition: width 0.4s ease; }

.stage { width: min(720px, 100%); margin: 0 auto; padding: 0 0 120px; min-height: calc(100dvh - var(--hud) - 6px); }

.hero {
  position: relative; min-height: 52dvh;
  background: #2A2218 center/cover no-repeat;
  display: flex; align-items: flex-end;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(22,16,10,0.05) 20%, rgba(22,16,10,0.82) 100%);
}
.hero-copy { position: relative; z-index: 1; color: #FFF8EE; padding: 24px 20px 20px; }
.hero-copy h1, .hero-copy p { color: #FFF8EE; text-shadow: 0 2px 14px rgba(22,16,10,0.88); }
.hero-copy .kicker { color: var(--gold); }
.kicker {
  display: inline-block; font-size: 16px; font-weight: 800;
  letter-spacing: 0.1em; text-transform: uppercase;
  background: #F0D7A2; color: var(--gold); border-radius: 999px;
  padding: 6px 12px; margin-bottom: 10px;
}
.hero .kicker { background: #F0D7A2; color: var(--gold); }

.panel { background: var(--paper); padding: 20px 18px 8px; }
.speech {
  display: grid; grid-template-columns: 76px 1fr; gap: 12px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin: 0 0 14px;
  box-shadow: var(--shadow);
}
.speech img { width: 76px; height: 76px; object-fit: cover; border-radius: 18px; }
.speech .who, .bubble .who { font-size: 16px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--terra); margin: 0 0 4px; }
.speech p { margin: 0; color: var(--ink-soft); }

.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 0 16px 16px;
  animation: rise 0.4s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.btn, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 54px; width: 100%; padding: 12px 16px; margin-top: 10px;
  border-radius: 16px; border: 0; cursor: pointer; font-weight: 800;
  transition: transform 0.12s ease, filter 0.12s;
}
.btn { background: var(--green); color: var(--green-text); }
.btn:hover { filter: brightness(1.08); }
.btn:active, .btn-ghost:active, .choice:active { transform: scale(0.98); }
.btn[disabled], .choice[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; color: var(--ink); border: 2px solid var(--ink); }
.row { display: flex; gap: 10px; }
.row .btn, .row .btn-ghost { flex: 1; }

.list { margin: 8px 0 0; padding-left: 1.15em; }
.list li { margin: 0 0 8px; color: var(--ink-soft); }
.aside {
  background: var(--gold-bg); color: var(--gold);
  border-radius: 16px; padding: 12px 14px; margin: 12px 0; font-weight: 700;
}

/* Mind map */
.mmap-center {
  text-align: center; background: var(--green); color: var(--green-text);
  border-radius: 20px; padding: 16px; margin: 0 0 12px;
}
.mmap-center h3, .mmap-center p { color: var(--green-text); margin: 0; }
.mmap-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mnode {
  text-align: left; background: #FFF; border: 2px solid var(--line);
  border-radius: 16px; padding: 12px; cursor: pointer; min-height: 74px; font-weight: 800;
  color: var(--ink);
}
.mnode.open { border-color: var(--green); background: var(--ok-bg); }
.mnode small { display: block; font-weight: 650; color: var(--ink-soft); margin-top: 6px; }

/* Hangman */
.gallows { text-align: center; padding: 8px 0 4px; }
.word { font-family: var(--font-d); font-size: clamp(18px, 5.4vw, 28px); letter-spacing: 0; font-weight: 700; margin: 8px 0 12px; text-align: center; display: flex; justify-content: center; gap: 2px; flex-wrap: nowrap; }
.word span { min-width: 0.9em; }
.lives { text-align: center; color: var(--terra); font-weight: 800; margin-bottom: 10px; }
.keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.key {
  min-height: 44px; border-radius: 10px; border: 2px solid var(--line);
  background: #FFF; font-weight: 800; cursor: pointer; color: var(--ink);
}
.key.used { background: var(--cream-2); color: var(--muted); }
.key.hit { background: var(--ok-bg); border-color: var(--ok-ink); color: var(--ok-ink); }
.key.miss { background: var(--bad-bg); border-color: var(--bad-ink); color: var(--bad-ink); }

/* Match */
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip {
  min-height: 64px; border-radius: 16px; border: 2px solid var(--line);
  background: #FFF; padding: 10px; text-align: left; font-weight: 800; cursor: pointer; color: var(--ink);
}
.chip.sel { border-color: var(--green); box-shadow: 0 0 0 3px rgba(12,61,48,0.18); }
.chip.done { background: var(--ok-bg); border-color: var(--ok-ink); color: var(--ok-ink); }

/* Sort */
.sort-list { display: grid; gap: 8px; }
.sort-item {
  background: #FFF; border: 2px solid var(--line); border-radius: 16px;
  padding: 12px 12px 12px 14px; font-weight: 800; cursor: grab;
  display: flex; gap: 10px; align-items: center; touch-action: none;
  user-select: none;
}
.sort-item.hold { cursor: grabbing; box-shadow: var(--shadow); transform: scale(1.02); background: #FFF8EE; }
.sort-item .n {
  flex: 0 0 30px; height: 30px; border-radius: 8px; background: var(--green);
  color: var(--green-text); display: grid; place-items: center; font-size: 16px;
}
.sort-item .sort-text { flex: 1; min-width: 0; }
.sort-item .nudges { display: grid; gap: 4px; flex: 0 0 44px; }
.nudge {
  width: 44px; height: 36px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--cream); color: var(--ink); font-size: 16px; font-weight: 800; cursor: pointer; padding: 0;
}
.nudge:disabled { opacity: 0.35; cursor: default; }

/* Dialogue */
.talk { display: grid; gap: 12px; }
.bubble {
  background: #FFF; border: 1px solid var(--line); border-radius: 20px 20px 20px 6px;
  padding: 14px; display: grid; grid-template-columns: 64px 1fr; gap: 10px;
}
.bubble img { width: 64px; height: 64px; object-fit: cover; border-radius: 50%; }
.trust { display: flex; gap: 6px; align-items: center; margin: 0 0 10px; font-size: 16px; font-weight: 800; color: var(--ink-soft); }
.trust i { width: 12px; height: 12px; border-radius: 50%; background: var(--cream-2); display: block; }
.trust i.on { background: var(--green); }
.choices { display: grid; gap: 8px; }
.choice {
  text-align: left; width: 100%; background: #FFF; color: var(--ink);
  border: 2px solid var(--line); border-radius: 16px; padding: 14px; cursor: pointer; font-weight: 750; min-height: 56px;
}
.choice.correct { background: var(--ok-bg); border-color: var(--ok-ink); color: var(--ok-ink); }
.choice.wrong { background: var(--bad-bg); border-color: var(--bad-ink); color: var(--bad-ink); }

.feedback { margin-top: 12px; padding: 12px 14px; border-radius: 16px; font-weight: 700; }
.feedback.ok { background: var(--ok-bg); color: var(--ok-ink); }
.feedback.bad { background: var(--bad-bg); color: var(--bad-ink); }

/* Word search */
.ws-wrap { overflow: auto; }
.grid {
  display: grid; gap: 3px; margin: 8px auto; width: min(100%, 360px);
  user-select: none; touch-action: none;
}
.cell {
  aspect-ratio: 1; display: grid; place-items: center;
  background: #FFF; border-radius: 8px; font-weight: 800; font-size: 17px;
  color: var(--ink); border: 1px solid var(--line);
}
.cell.hot { background: var(--gold-bg); }
.cell.found { background: var(--ok-bg); color: var(--ok-ink); }
.words { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.words span { background: var(--cream-2); color: var(--ink); border-radius: 999px; padding: 6px 10px; font-weight: 800; font-size: 16px; }
.words span.got { background: var(--ok-bg); color: var(--ok-ink); text-decoration: line-through; }

/* Medal / complete */
.celebrate { text-align: center; padding: 8px 0 4px; }
.celebrate img { width: min(260px, 70%); margin: 0 auto 8px; }
.medal {
  display: inline-block; background: var(--gold-bg); color: var(--gold);
  border-radius: 999px; padding: 8px 14px; font-weight: 800; margin: 6px 0 12px;
}
.score { font-family: var(--font-d); font-size: 48px; color: var(--green); font-weight: 700; }

.cert {
  background:
    linear-gradient(#FFF8EE, #FFF8EE) padding-box,
    linear-gradient(135deg, #6B4508, #E8C36A, #6B4508) border-box;
  border: 6px solid transparent;
  border-radius: 18px; padding: 22px 16px; text-align: center; margin: 0 16px 16px;
}
.cert small { display: block; color: var(--muted); margin-top: 8px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-weight: 800; margin: 12px 0; }
.check-row input { width: 22px; height: 22px; margin-top: 3px; accent-color: var(--green); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; }

.pad { padding: 0 16px; }
.hidden { display: none !important; }
.mini { font-size: 16px; color: var(--muted); font-weight: 700; }

.scene { margin: 0 16px 14px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.scene img { width: 100%; height: 168px; object-fit: cover; }

@media (max-width: 420px) {
  h1 { font-size: 30px; }
  h2 { font-size: 26px; }
  .mmap-grid { grid-template-columns: 1fr; }
  .chip { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.cta-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  width: min(720px, 100%); margin: 0 auto;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(246,237,224,0), var(--cream) 34%);
  pointer-events: none;
}
.cta-dock[hidden] { display: none; }
.cta-dock .btn, .cta-dock .btn-ghost { pointer-events: auto; margin-top: 8px; }
