/* ---------------------------------------------------------------
   Countdown to Christmas: all styles.
   Colours live in the variables just below; dark mode follows the
   phone's setting.
   --------------------------------------------------------------- */

:root {
  --bg: #fbf3e6;
  --bg-2: #f3e2c9;
  --surface: #fffaf2;
  --text: #3a2318;
  --muted: #6e5141;
  --accent: #a8242c;        /* cranberry: buttons */
  --accent-text: #ffffff;
  --pine: #2f6b45;
  --gold: #e3a92f;
  --glow: 255, 205, 90;      /* today's glow, as r, g, b */
  --focus: #1f5fd1;
  --paper: #fbf5e8;
  --ink: #2b2118;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(70, 35, 15, .18);
  --hand: 'Patrick Hand', 'Caveat', 'Segoe Print', 'Bradley Hand', 'Comic Sans MS', cursive;
  --serif: 'Georgia', 'Iowan Old Style', 'Palatino Linotype', 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1311;
    --bg-2: #2a1b16;
    --surface: #2c1f1a;
    --text: #f7ebdc;
    --muted: #d3bba6;
    --accent: #c9343d;
    --accent-text: #ffffff;
    --pine: #6fbf8a;
    --gold: #f2c14e;
    --focus: #8ab4ff;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg-2); }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(var(--glow), .18), transparent 60%),
    linear-gradient(var(--bg), var(--bg-2));
  background-repeat: no-repeat;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

[hidden] { display: none !important; }

.noscript { text-align: center; padding: 1rem; }

/* ----- buttons ----- */

.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: .6rem 1.2rem;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font: 600 1rem/1.2 var(--sans);
  text-decoration: none; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .18);
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease;
}
.button:active { transform: translateY(2px); }
.button.small { min-height: 40px; padding: .4rem .9rem; font-size: .95rem; }
.button.ghost {
  background: transparent; color: var(--text);
  box-shadow: inset 0 0 0 2px currentColor;
}
.button.ghost.on-paper { color: var(--ink); }

.icon-button {
  display: inline-grid; place-items: center;
  width: 48px; height: 48px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  font-size: 1.2rem; cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.icon-button svg { width: 24px; height: 24px; }
.icon-button.sound .sound-on { display: none; }
.icon-button.sound.on .sound-on { display: block; }
.icon-button.sound.on .sound-off { display: none; }

/* ----- toast ----- */

.toast {
  position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom));
  z-index: 100; max-width: min(92vw, 28rem);
  padding: .75rem 1.1rem; border-radius: 999px;
  background: #2b1a14; color: #fff; text-align: center;
  font-weight: 600; box-shadow: var(--shadow);
  opacity: 0; transform: translate(-50%, 12px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =============================================================
   Landing page
   ============================================================= */

.landing-main {
  max-width: 64rem; margin: 0 auto;
  padding: calc(2rem + env(safe-area-inset-top)) 1.25rem calc(2rem + env(safe-area-inset-bottom));
  text-align: center;
}

.hero-kicker { margin: 0; color: var(--gold); letter-spacing: .2em; font-size: .85rem; font-weight: 700; }
.hero h1 {
  margin: .25rem 0 .5rem;
  font: 700 clamp(2.1rem, 8vw, 3.6rem)/1.05 var(--serif);
  color: var(--accent);
}
@media (prefers-color-scheme: dark) { .hero h1 { color: #ff8d84; } }
.hero-intro { margin: 0 auto; max-width: 32rem; font-size: 1.15rem; color: var(--muted); }

.status {
  display: inline-block; margin: 1rem auto 0; padding: .5rem 1rem;
  border-radius: 999px; background: var(--surface); box-shadow: var(--shadow);
  font-weight: 600;
}

.chooser-heading { margin: 2rem 0 1rem; font: 600 1.3rem var(--serif); }

.chooser {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
}

.choice {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: .9rem .9rem 1.1rem;
  border-radius: 22px; background: var(--surface);
  box-shadow: var(--shadow); text-decoration: none;
  transition: transform .18s ease;
  -webkit-tap-highlight-color: transparent;
}
.choice:hover { transform: translateY(-3px); }
.choice:active { transform: scale(.98); }
.choice.current { box-shadow: var(--shadow), 0 0 0 3px var(--gold); }
.choice-thumb {
  display: block; width: 100%; aspect-ratio: 3 / 4;
  border-radius: 14px; overflow: hidden; background: var(--bg-2);
}
.choice-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.choice-label { font: 700 1.25rem var(--serif); }
.choice-badge {
  position: absolute; top: 1.2rem; right: 1.2rem;
  padding: .2rem .6rem; border-radius: 999px;
  background: var(--gold); color: #3a2318; font-size: .85rem; font-weight: 700;
}

/* On phones, show the three calendars as large rows. */
@media (max-width: 560px) {
  .choice { flex-direction: row; text-align: left; padding: .75rem; }
  .choice-thumb { width: 38%; flex: none; }
  .choice-label { font-size: 1.3rem; }
  .choice-badge { top: auto; bottom: .9rem; right: .9rem; }
}

.loading-text, .landing-foot { color: var(--muted); }
.landing-foot { margin-top: 2rem; font-size: .95rem; }

/* =============================================================
   Calendar page
   ============================================================= */

.calendar-page { overflow: hidden; }

.page {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .75rem;
}
.topbar-title {
  flex: 1; margin: 0; text-align: center;
  font: 700 clamp(1.1rem, 4.5vw, 1.5rem)/1.2 var(--serif);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.banner, .message {
  margin: 0 .75rem .4rem; padding: .5rem .9rem;
  border-radius: 12px; background: var(--surface); box-shadow: var(--shadow);
  text-align: center; font-weight: 600;
}
.message { background: #fff1cf; color: #4a2c00; }

.stage {
  position: relative; flex: 1; min-height: 0;
  display: grid; place-items: center;
  padding: .25rem .5rem;
  overflow: hidden;
}

.frame {
  position: relative;
  transform-origin: 0 0;
  border-radius: 10px;
  touch-action: manipulation;
}
.frame.zooming { will-change: transform; }

.calendar-image {
  display: block; width: 100%; height: 100%;
  border-radius: 10px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  box-shadow: var(--shadow);
}

/* loading spinner */
.loader { display: none; }
.stage.loading .loader { display: block; }
.loader span {
  display: block; width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid rgba(var(--glow), .35); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .5rem;
  padding: .5rem .75rem .75rem;
}
.toolbar .button { min-height: 44px; padding: .4rem .9rem; font-size: .95rem; }
.switch-link { padding: .6rem .5rem; font-weight: 600; font-size: .95rem; }

/* ----- hotspots -----
   Never draw numbers: they are printed on the calendar itself. */

.hotspots { position: absolute; inset: 0; }

.hotspot {
  position: absolute; padding: 0; margin: 0;
  border: 0; border-radius: 8px;
  background: transparent; color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* Bigger invisible tap area for small drawers (at least 44 x 44 px). */
.hotspot::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: max(100%, 44px); height: max(100%, 44px);
  transform: translate(-50%, -50%);
}
.hotspot:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* today: gentle pulsing glow (only opacity animates) */
.hotspot.today::before {
  content: ''; position: absolute; inset: -3px; border-radius: 10px;
  box-shadow: 0 0 0 3px rgba(var(--glow), .95), 0 0 18px 8px rgba(var(--glow), .75);
  animation: pulse 1.8s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* earlier day, not opened yet: faint highlight */
.hotspot.past {
  background: rgba(var(--glow), .16);
  box-shadow: inset 0 0 0 2px rgba(var(--glow), .6);
}

/* future: dimmed with a small lock */
.hotspot.future { background: rgba(25, 12, 6, .42); }

.badge {
  position: absolute; top: 4%; right: 4%;
  width: clamp(12px, 24%, 22px); aspect-ratio: 1;
  display: grid; place-items: center;
  border-radius: 50%; pointer-events: none;
}
.badge svg { width: 70%; height: 70%; }
.badge.lock { background: rgba(0, 0, 0, .55); color: #fff; }
.badge.star { background: var(--gold); color: #6a2a00; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }

.hotspot.shake { animation: shake .45s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* =============================================================
   Opening a drawer
   ============================================================= */

.drawer-fx { position: absolute; inset: 0; pointer-events: none; }
.drawer-cavity {
  position: absolute; border-radius: 6px;
  background: #140906;
  box-shadow: inset 0 6px 10px rgba(0, 0, 0, .9), inset 0 -2px 4px rgba(255, 255, 255, .06);
}
.drawer-sprite {
  position: absolute; border-radius: 6px;
  background-repeat: no-repeat;
  will-change: transform;
}
.drawer-shadow {
  position: absolute; inset: 0; border-radius: inherit; z-index: -1;
  box-shadow: 0 10px 18px rgba(0, 0, 0, .55);
  opacity: 0;
}

.drawer-layer {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 1rem;
}
.drawer-backdrop { position: absolute; inset: 0; background: #120805; opacity: 0; }

.paper-zone {
  position: fixed; z-index: 1;
  perspective: 1100px;
  transform: rotate(-1.2deg);
  pointer-events: none;
}

/* ----- the CSS origami ----- */
.o-mover { position: absolute; left: 0; top: 0; transform-origin: 0 0; transform-style: preserve-3d; will-change: transform, opacity; }
.o-spin { width: 100%; height: 100%; transform-origin: 25% 25%; transform-style: preserve-3d; }
.o-sheet { position: relative; transform-style: preserve-3d; }
.o-half { position: absolute; left: 0; width: 100%; height: 50%; transform-style: preserve-3d; }
.o-top { top: 0; }
.o-bottom { top: 50%; transform-origin: 50% 0; transform: rotateX(180deg) translateZ(-3px); }
.o-q {
  position: absolute; top: 0; width: 50%; height: 100%;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(80, 50, 20, .12);
  backface-visibility: visible;
}
.o-tl, .o-bl { left: 0; }
.o-tr, .o-br { left: 50%; transform-origin: 0 50%; transform: rotateY(-180deg) translateZ(-1px); }
/* fold-line shading: darker near the crease while folded */
.o-shade { position: absolute; inset: 0; pointer-events: none; opacity: .55; }
.o-tr > .o-shade, .o-br > .o-shade { background: linear-gradient(90deg, rgba(60, 35, 10, .55), rgba(60, 35, 10, 0) 70%); }
.o-bottom > .o-shade { background: linear-gradient(180deg, rgba(60, 35, 10, .5), rgba(60, 35, 10, 0) 70%); }
.o-tl { background: linear-gradient(-90deg, rgba(60, 35, 10, .1), transparent 25%) var(--paper); }
.o-bl { background: linear-gradient(0deg, transparent 75%, rgba(60, 35, 10, .1)) var(--paper); }

.o-video { position: absolute; inset: 0; background: var(--paper); border-radius: 6px; overflow: hidden; }
.o-video video { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ----- the paper card ----- */
.card {
  position: relative; z-index: 2;
  width: min(92vw, 30rem);
  max-height: calc(100dvh - 2rem);
  display: flex; flex-direction: column; gap: .9rem;
  visibility: hidden;
}
.card-paper {
  position: relative; overflow: auto;
  padding: 1.6rem 1.5rem 1.8rem;
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--hand);
  font-size: clamp(1.35rem, 5.4vw, 1.6rem);
  line-height: 1.35;
  background-color: var(--paper);
  /* paper grain + faint crease lines from the folds */
  background-image:
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(90, 60, 30, .07) 50%, transparent calc(50% + 1px)),
    linear-gradient(0deg, transparent calc(50% - 1px), rgba(90, 60, 30, .07) 50%, transparent calc(50% + 1px)),
    radial-gradient(120% 90% at 50% 40%, transparent 60%, rgba(120, 80, 40, .12)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .12 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45), 0 2px 0 rgba(0, 0, 0, .05);
  transform: rotate(-1.2deg);
}
.card-paper p { margin: 0 0 .55em; }
.card-day { font-size: .85em; color: #7a5a40; letter-spacing: .02em; }
.card-title { margin: 0 0 .5em; font: inherit; font-size: 1.35em; line-height: 1.15; color: #8e1d24; }
.card-text p:last-child { margin-bottom: 0; }
.card-finale {
  font-size: 1.7em; line-height: 1.1; text-align: center; color: #8e1d24;
  margin-bottom: .2em !important;
}
.card-closing { margin-top: .9em !important; padding-top: .6em; border-top: 2px dashed rgba(90, 60, 30, .25); }
.card-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; }
.card-actions .button.ghost.on-paper { background: var(--paper); box-shadow: none; }

/* Day 24 confetti and snow */
.confetti { position: fixed; left: 50%; top: 42%; z-index: 3; pointer-events: none; }
.confetti i { position: absolute; left: 0; top: 0; display: block; will-change: transform, opacity; }
.confetti .bit { width: 9px; height: 14px; border-radius: 2px; }
.confetti .flake { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 6px rgba(255, 255, 255, .8); }

/* =============================================================
   Dialogs (list, reminders, help)
   ============================================================= */

dialog.sheet {
  width: min(94vw, 34rem); max-height: 86dvh;
  padding: 1.1rem 1.25rem 1.4rem;
  border: 0; border-radius: 22px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
dialog.sheet::backdrop { background: rgba(18, 8, 5, .55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.sheet-head h2 { margin: 0; font: 700 1.35rem var(--serif); }
.sheet-head .icon-button { box-shadow: none; background: var(--bg-2); }
.caption { color: var(--muted); font-size: .95rem; }
.help-list { padding-left: 1.2rem; }
.help-list li { margin-bottom: .6rem; }

.prompt-list { display: grid; gap: .8rem; }
.list-item { padding: .9rem 1rem; border-radius: 14px; background: var(--bg); }
.list-item h3 { margin: 0 0 .3rem; font: 700 1.05rem var(--serif); }
.list-item p { margin: 0 0 .6rem; }
.list-item.opened h3::after { content: ' ★'; color: var(--gold); }

/* =============================================================
   Hotspot editor (?edit=1)
   ============================================================= */

body.editing .hotspots { display: none; }
.editor-layer { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }
.editor-ref, .editor-box {
  position: absolute; display: grid; place-items: center;
  font: 700 14px var(--sans); pointer-events: none;
}
.editor-ref { border: 2px dashed rgba(255, 255, 255, .7); color: rgba(255, 255, 255, .8); text-shadow: 0 0 3px #000; }
.editor-box { border: 2px solid #19c37d; background: rgba(25, 195, 125, .25); color: #fff; text-shadow: 0 0 3px #000; }
.editor-box.drawing { border-color: #ffcc00; background: rgba(255, 204, 0, .25); }
.editor-bar {
  position: fixed; left: 50%; top: calc(.5rem + env(safe-area-inset-top)); z-index: 60;
  transform: translateX(-50%);
  width: min(96vw, 40rem);
  padding: .6rem .8rem; border-radius: 14px;
  background: rgba(20, 12, 8, .92); color: #fff; text-align: center;
  box-shadow: var(--shadow);
}
.editor-bar p { margin: 0 0 .3rem; }
.editor-count { font-weight: 700; font-size: 1.1rem; }
.editor-hint { font-size: .85rem; opacity: .8; }
.editor-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; }
.editor-bar .button.ghost { color: #fff; }
.editor-output { width: 100%; margin-top: .5rem; font: 12px/1.3 ui-monospace, Consolas, monospace; }

/* =============================================================
   Reduce motion
   ============================================================= */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
  .hotspot.today::before { animation: none; opacity: 1; }
  .hotspot.shake { animation: none; }
  .loader span { animation-duration: 3s; }
}
