:root {
  --night: #0c1626;
  --night-2: #16253d;
  --snow: #f7f4ee;
  --paper: #fbf6ec;
  --ink: #2a2118;
  --ink-soft: #6b5d4f;
  --red: #c8323b;
  --red-dark: #8e1f27;
  --green: #2c7a57;
  --green-dark: #1c5139;
  --gold: #f2c14e;
  --gold-dark: #b98a1c;
  --blue: #2b4c7e;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--snow);
  background: var(--night) radial-gradient(ellipse at 50% -10%, #2a4470 0%, var(--night-2) 40%, var(--night) 80%) fixed;
  line-height: 1.5;
}
button, input, textarea { font: inherit; }
[hidden] { display: none !important; }

.snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.page { position: relative; z-index: 1; max-width: 980px; margin: 0 auto; padding: 32px 16px 48px; }

/* ---------- Header ---------- */
.hero { text-align: center; margin-bottom: 28px; }
.eyebrow { margin: 0; font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.hero h1 { font-family: var(--serif); font-size: clamp(2rem, 6vw, 3.3rem); line-height: 1.1; margin: 8px 0 10px; text-wrap: balance; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5); }
.tagline { margin: 0 auto; max-width: 34em; color: #d5dcea; }
.stats { display: flex; justify-content: center; gap: 10px; margin: 18px 0 6px; flex-wrap: wrap; }
.stat { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 999px; padding: 4px 14px; font-size: 0.95rem; }
.stat b { color: var(--gold); font-variant-numeric: tabular-nums; }
.status { min-height: 1.5em; margin: 12px 0; color: #e8edf6; }
.status .count { font-family: var(--serif); font-size: 1.6rem; color: var(--gold); font-weight: 700; }
.actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--red); color: #fff; font-weight: 600;
  padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 2px 0 var(--red-dark);
  transition: transform 0.1s, filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--red-dark); }
.btn:disabled { cursor: default; filter: saturate(0.6); opacity: 0.85; }
.btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 1.5px currentColor; }
.btn.small { padding: 6px 14px; font-size: 0.9rem; }
.btn.icon { padding: 10px 14px; font-family: var(--emoji); }
.link { background: none; border: 0; padding: 0; color: var(--gold); text-decoration: underline; cursor: pointer; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------- Doors ---------- */
.doors {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-flow: dense;
  gap: 14px;
}
.door {
  position: relative;
  aspect-ratio: 1;
  border: 0; padding: 0; margin: 0;
  border-radius: var(--radius);
  background: #07101d;
  box-shadow: inset 0 4px 14px rgba(0, 0, 0, 0.8);
  perspective: 900px;
  cursor: pointer;
  color: var(--ink);
}
.door.wide { grid-column: span 2; aspect-ratio: auto; }
.door.big { grid-column: span 2; grid-row: span 2; aspect-ratio: auto; }
.door.big .num { font-size: clamp(1.6rem, 5vw, 2.4rem); }
.door.big .peek { font-size: clamp(3rem, 9vw, 4.5rem); }

.behind {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 2px;
  padding: 8px; text-align: center;
  border-radius: var(--radius);
  background: radial-gradient(circle at 50% 40%, #fff9ec, #eadcc2);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.35);
}
.peek { font-family: var(--emoji); font-size: clamp(1.8rem, 5vw, 2.6rem); line-height: 1; }
.peek-title { font-family: var(--serif); font-weight: 700; font-size: clamp(0.7rem, 1.8vw, 0.9rem); line-height: 1.15; }
.peek-stars { color: var(--gold-dark); font-size: 0.8rem; letter-spacing: 1px; }

.front {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  transform-origin: left center;
  transition: transform 0.85s cubic-bezier(0.3, 1.25, 0.45, 1), box-shadow 0.85s;
  backface-visibility: hidden;
  display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45), inset 0 0 0 2px rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.door.open .front { transform: rotateY(-78deg); box-shadow: -10px 6px 18px rgba(0, 0, 0, 0.5); }
.door.open { z-index: 1; }
.num {
  display: grid; place-items: center;
  width: 2.3em; height: 2.3em;
  border-radius: 50%;
  background: var(--paper);
  color: var(--red-dark);
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(1.1rem, 3.4vw, 1.6rem);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35), inset 0 0 0 3px var(--gold);
}
.today-tag {
  position: absolute; top: 8px; right: -26px;
  transform: rotate(35deg);
  background: var(--gold); color: var(--ink);
  font-size: 0.65rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 2px 30px;
}

/* Wrapping paper */
.p0 .front { background: radial-gradient(circle, var(--gold) 2.5px, transparent 3px) 0 0 / 18px 18px, var(--red); }
.p1 .front { background: repeating-linear-gradient(45deg, var(--green) 0 12px, var(--green-dark) 12px 24px); }
.p2 .front { background: repeating-linear-gradient(-45deg, var(--paper) 0 9px, var(--red) 9px 18px); }
.p3 .front { background: radial-gradient(circle, rgba(255, 255, 255, 0.85) 1.5px, transparent 2px) 0 0 / 14px 14px, radial-gradient(circle, rgba(255, 255, 255, 0.5) 1px, transparent 1.5px) 7px 7px / 14px 14px, var(--blue); }
.p4 .front {
  background:
    repeating-linear-gradient(0deg, rgba(200, 50, 59, 0.55) 0 6px, transparent 6px 22px),
    repeating-linear-gradient(90deg, rgba(200, 50, 59, 0.55) 0 6px, transparent 6px 22px),
    var(--gold);
}
.p5 .front {
  background:
    linear-gradient(90deg, transparent 42%, var(--gold) 42% 58%, transparent 58%),
    linear-gradient(0deg, transparent 42%, var(--gold) 42% 58%, transparent 58%),
    var(--green);
}

.door.today .front { animation: glow 2.2s ease-in-out infinite; }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 3px var(--gold), 0 0 14px 2px rgba(242, 193, 78, 0.55); }
  50% { box-shadow: 0 0 0 3px var(--gold), 0 0 32px 10px rgba(242, 193, 78, 0.85); }
}
.door.locked { cursor: not-allowed; }
.door:not(.open):not(.locked):hover .front { transform: rotateY(-12deg); }
.door.wiggle .front { animation: wiggle 0.45s; }
@keyframes wiggle { 20% { transform: rotate(-4deg); } 40% { transform: rotate(4deg); } 60% { transform: rotate(-3deg); } 80% { transform: rotate(2deg); } }

/* ---------- Panels ---------- */
.panel {
  margin-top: 36px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 20px;
}
.panel h2 { font-family: var(--serif); margin: 0 0 6px; font-size: 1.5rem; }
.muted { color: #b9c2d3; }
.how ul { margin: 0; padding-left: 1.2em; }
.how li { margin: 4px 0; }
.secret .answer-row { margin-top: 14px; }

.phrase { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; margin: 12px 0; }
.word { display: flex; gap: 4px; }
.tile {
  display: inline-grid; place-items: center;
  width: 1.9em; height: 2.3em;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-family: var(--serif); font-weight: 700; font-size: 1.05rem;
}
.tile.lit { background: var(--gold); color: var(--ink); border-color: var(--gold-dark); }
.tile.fresh { animation: pop 0.7s ease-out; }
.tile.mini { width: 1.6em; height: 1.9em; font-size: 0.9rem; margin: 0 2px; vertical-align: middle; }
@keyframes pop { 0% { transform: scale(0.3) rotate(-20deg); } 60% { transform: scale(1.25); } 100% { transform: none; } }

.foot { text-align: center; margin-top: 36px; color: #b9c2d3; }
.foot p { font-family: var(--serif); font-size: 1.15rem; color: var(--snow); }

/* ---------- Modal ---------- */
.modal {
  width: min(600px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  color-scheme: light;
}
.modal[open] { display: flex; flex-direction: column; animation: fade 0.25s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal::backdrop { background: rgba(5, 10, 20, 0.7); }
.m-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px 14px 20px;
  background: var(--red); color: #fff;
  border-bottom: 4px solid var(--gold);
}
.m-emoji { font-family: var(--emoji); font-size: 2.2rem; line-height: 1; }
.m-titles { flex: 1; min-width: 0; }
.m-head .eyebrow { color: #ffe3a3; }
.m-head h2 { margin: 0; font-family: var(--serif); font-size: 1.45rem; line-height: 1.2; }
.close { background: rgba(255, 255, 255, 0.15); color: #fff; border: 0; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; flex: none; }
.close:hover { background: rgba(255, 255, 255, 0.28); }
.m-body { padding: 18px 20px 22px; overflow-y: auto; }
.m-body .muted { color: var(--ink-soft); }
.intro { font-style: italic; color: var(--ink-soft); margin-top: 0; }
.prompt { font-family: var(--serif); font-size: 1.25rem; line-height: 1.4; margin: 0.4em 0 0.8em; }
.big-answer { font-family: var(--serif); font-size: 1.9rem; font-weight: 700; color: var(--red-dark); margin: 0.2em 0; text-transform: capitalize; }
.hint { color: var(--green-dark); }
.feedback { min-height: 1.5em; font-weight: 600; color: var(--ink); margin: 8px 0; }
.solved { text-align: center; padding: 8px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.letter-note { margin: 18px 0 0; padding-top: 12px; border-top: 1px dashed #d8c9ad; color: var(--ink-soft); font-size: 0.95rem; }
.summary { font-weight: 600; }
.signoff { font-family: var(--serif); font-size: 1.2rem; text-align: center; margin-top: 18px; }

.answer-row { display: flex; gap: 8px; }
.answer-row input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  border-radius: 999px;
  border: 2px solid #d8c9ad;
  background: #fff;
  color: var(--ink);
}
.secret .answer-row input { border-color: rgba(255, 255, 255, 0.3); background: rgba(255, 255, 255, 0.95); }
.answer-row input:focus { outline: none; border-color: var(--gold-dark); }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.options { display: grid; gap: 8px; }
.opt {
  text-align: left; padding: 11px 14px;
  border-radius: 10px; border: 2px solid #e2d5bd;
  background: #fff; color: var(--ink); cursor: pointer;
}
.opt:hover:not(:disabled) { border-color: var(--gold-dark); }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--green); background: #e3f3ea; }
.opt.wrong { border-color: var(--red); background: #fbe3e3; }

.joke { padding: 10px 0; border-bottom: 1px dashed #e2d5bd; }
.joke:last-child { border-bottom: 0; }
.setup { font-weight: 600; margin: 0 0 6px; }
.punch { font-family: var(--serif); font-size: 1.2rem; color: var(--red-dark); margin: 0; animation: pop 0.4s ease-out; }

.steps { padding-left: 1.3em; }
.steps li { margin: 6px 0; }
.note { display: grid; gap: 4px; font-weight: 600; margin: 10px 0; }
.note textarea { padding: 10px; border-radius: 10px; border: 2px solid #d8c9ad; background: #fff; color: var(--ink); font-weight: 400; resize: vertical; }

.verse { margin: 14px 0; padding: 12px 18px; border-left: 4px solid var(--gold); background: #fff6df; border-radius: 0 10px 10px 0; font-family: var(--serif); font-size: 1.08rem; }
.verse p { margin: 0 0 6px; }
.verse cite { display: block; text-align: right; font-style: normal; color: var(--ink-soft); font-family: var(--sans); font-size: 0.9rem; }

.tiles { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 10px; }

.bingo { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.bingo-cell {
  aspect-ratio: 1; padding: 4px;
  border-radius: 10px; border: 2px solid #e2d5bd;
  background: #fff; color: var(--ink);
  font-size: clamp(0.68rem, 2.6vw, 0.85rem); line-height: 1.15; font-weight: 600;
  cursor: pointer;
}
.bingo-cell.on { background: var(--green); border-color: var(--green-dark); color: #fff; }

/* Games */
.stage { position: relative; min-height: 300px; border-radius: 12px; overflow: hidden; background: linear-gradient(#1d3157, #3d5f8f); color: var(--snow); }
.overlay { display: grid; place-content: center; justify-items: center; text-align: center; gap: 4px; min-height: 300px; padding: 20px; }
.overlay .muted { color: #d5dcea; }
.overlay .big-answer { color: var(--gold); }
.hud { position: absolute; top: 8px; left: 12px; z-index: 2; font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); pointer-events: none; }
.game-canvas { display: block; width: 100%; touch-action: none; cursor: none; }

.whack { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 44px 16px 18px; }
.hole {
  aspect-ratio: 1.2;
  border: 0; border-radius: 50% 50% 12px 12px;
  background: radial-gradient(ellipse at 50% 85%, #fff 0 40%, #cfe0f2 70%);
  box-shadow: inset 0 -6px 0 #a9c1dc;
  font-family: var(--emoji); font-size: clamp(1.8rem, 8vw, 2.6rem);
  cursor: pointer; touch-action: manipulation;
}
.hole.up { animation: rise 0.15s ease-out; }
.hole.ouch { background: #ffd0d0; }
@keyframes rise { from { transform: translateY(10px) scale(0.85); } }

.spot { --n: 3; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 4px; padding: 40px 10px 12px; }
.spot-cell {
  aspect-ratio: 1; border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  font-family: var(--emoji); font-size: calc(min(560px, 90vw) / var(--n) * 0.48);
  line-height: 1; padding: 0; cursor: pointer; touch-action: manipulation;
}
.spot-cell:hover { background: rgba(255, 255, 255, 0.22); }

.memory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.card {
  position: relative; aspect-ratio: 1;
  border: 0; padding: 0; border-radius: 10px;
  background: transparent; cursor: pointer;
  perspective: 600px; touch-action: manipulation;
}
.card-back, .card-face {
  position: absolute; inset: 0; display: grid; place-items: center;
  border-radius: 10px; backface-visibility: hidden;
  transition: transform 0.4s;
  font-family: var(--emoji); font-size: clamp(1.5rem, 7vw, 2.3rem);
}
.card-back { background: repeating-linear-gradient(45deg, var(--red) 0 8px, var(--red-dark) 8px 16px); color: #fff; }
.card-face { background: #fff; border: 2px solid #e2d5bd; transform: rotateY(180deg); }
.card.up .card-back { transform: rotateY(-180deg); }
.card.up .card-face { transform: rotateY(0); }
.card.matched .card-face { border-color: var(--green); background: #e3f3ea; }

/* Toast + confetti */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: calc(100% - 32px); text-align: center;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

/* 22 small doors + two wide + one big = 30 cells, which fills 5 or 3 columns evenly */
@media (max-width: 720px) {
  .doors { gap: 10px; }
}
@media (max-width: 560px) {
  .page { padding-top: 24px; }
  .doors { grid-template-columns: repeat(3, 1fr); }
  .m-body { padding: 16px; }
  .answer-row { flex-wrap: wrap; }
  .answer-row .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}
