* { box-sizing: border-box; }
body {
  margin: 0;
  background: #091329;
  color: #fff1d6;
  font: 1rem system-ui, -apple-system, sans-serif;
}
main {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}
button {
  cursor: pointer;
  color: inherit;
  font: inherit;
}
button:focus-visible, a:focus-visible, select:focus-visible {
  outline: 2px solid #fff2c2;
  outline-offset: 3px;
}
[hidden] { display: none !important; }

/* Prompts & Status */
#prompt, #toast {
  position: absolute;
  left: 50%;
  bottom: max(7vh, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  text-align: center;
}
#prompt {
  pointer-events: none;
  white-space: nowrap;
}
#enter, #toast {
  background: rgba(8, 18, 36, 0.86);
  border: 1px solid #d3b78380;
  border-radius: 2rem;
  padding: 0.65rem 1.25rem;
  box-shadow: 0 3px 18px #08122766;
  backdrop-filter: blur(8px);
}
#enter {
  pointer-events: auto;
  font: italic clamp(1.25rem, 2.2vw, 1.65rem) Georgia, serif;
  padding: 0.78em 1.65em;
  min-height: 54px;
  transition: background 0.2s ease, transform 0.2s ease;
}
#enter.intro-reveal {
  animation: enter-rise 1.2s cubic-bezier(0.22, 1, 0.36, 1) 1.25s both;
}
#skipReveal {
  pointer-events: auto;
  background: rgba(8, 18, 36, 0.68);
  border: 1px solid #d3b78355;
  border-radius: 2rem;
  padding: 0.45rem 1.05rem;
  font: 500 0.85rem system-ui, sans-serif;
  color: rgba(255, 241, 214, 0.85);
  backdrop-filter: blur(6px);
  animation: ink-in 0.5s ease-out 1.2s both;
}
#skipReveal:hover {
  background: rgba(16, 32, 58, 0.9);
  border-color: #ebd097;
  color: #fff4da;
}
#enter:hover:not(:disabled) {
  background: rgba(16, 32, 58, 0.94);
  transform: translateY(-1px);
}
@keyframes enter-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* Atmospheric Loading Curtain */
#loader {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 38%, #132748 0%, #09152b 58%, #050c1a 100%);
  transition: opacity 1.15s cubic-bezier(0.22, 1, 0.36, 1), visibility 1.15s linear;
}
#loader.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loader-snow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    radial-gradient(2px 2px at 18% 24%, #fff6e0, transparent),
    radial-gradient(1.5px 1.5px at 42% 62%, #dbe9ff, transparent),
    radial-gradient(2px 2px at 74% 31%, #fff6e0, transparent),
    radial-gradient(1.5px 1.5px at 86% 74%, #dbe9ff, transparent),
    radial-gradient(2px 2px at 30% 82%, #fff6e0, transparent),
    radial-gradient(1.5px 1.5px at 62% 16%, #dbe9ff, transparent);
  background-size: 420px 420px;
  animation: snow-drift 18s linear infinite;
}
@keyframes snow-drift {
  from { background-position: 0 0; }
  to { background-position: 80px 420px; }
}
.loader-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.15rem;
  padding: 1.5rem;
  text-align: center;
  animation: ink-in 0.8s ease-out both;
}
.loader-inner img {
  width: clamp(7.5rem, 16vw, 11rem);
  filter: drop-shadow(0 0 18px rgba(245, 214, 150, 0.28));
}
.loader-track {
  width: 180px;
  height: 2px;
  border-radius: 999px;
  background: rgba(235, 206, 148, 0.18);
  overflow: hidden;
}
#loaderBar {
  height: 100%;
  width: 6%;
  background: linear-gradient(90deg, #cfa55b, #ffebc2);
  border-radius: 999px;
  transition: width 0.25s ease-out;
}
#status {
  margin: 0;
  max-width: min(88vw, 420px);
  font: italic 0.98rem Georgia, serif;
  color: rgba(255, 241, 214, 0.82);
  letter-spacing: 0.02em;
}
#loader.error .loader-track { display: none; }
#loader.error #status {
  font-style: normal;
  font-family: system-ui, -apple-system, sans-serif;
  color: #ffd5b0;
}
#toast {
  bottom: max(3vh, env(safe-area-inset-bottom));
  font: 0.9rem system-ui, sans-serif;
  color: #ffe8ba;
  z-index: 6;
  max-width: 90vw;
  animation: ink-in 0.25s ease-out;
}

/* Ornament hotspots on the tree */
#spots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ornament {
  position: absolute;
  pointer-events: auto;
  transform: translate(-50%, -50%);
  border: 0;
  background: transparent;
  border-radius: 50%;
  padding: 0;
  transition: box-shadow 0.2s ease, background 0.2s ease;
}
.ornament:hover, .ornament:focus-visible {
  box-shadow: 0 0 14px 4px #ffd67ab8;
  background: #fff2b422;
  z-index: 2;
}
.ornament.locked {
  cursor: pointer;
}
.ornament.locked:hover, .ornament.locked:focus-visible {
  box-shadow: 0 0 12px 3px #c6def580;
  background: #d0e5fa1c;
}
.ornament span {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: rgba(13, 24, 44, 0.94);
  border: 1px solid #d3b78355;
  color: #fff0cd;
  font-size: 0.82rem;
  border-radius: 0.45rem;
  padding: 0.3rem 0.6rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.ornament:hover span, .ornament:focus-visible span {
  display: block;
}

/* Masthead (title + countdown) */
#mast {
  position: absolute;
  top: 7%;
  left: 3%;
  width: 32%;
  text-align: center;
  color: #fff1d4;
  pointer-events: none;
  text-shadow: 0 2px 14px #05152b, 0 1px 3px #0a1830;
  animation: ink-in 0.7s both;
}
#mast img {
  display: block;
  margin: 0 auto 0.7em;
  width: clamp(5rem, 9vw, 10rem);
  filter: drop-shadow(0 1px 4px #14263d);
}
#mast h1 {
  font: normal clamp(2.8rem, 5.3vw, 6.6rem)/0.89 Georgia, serif;
  letter-spacing: -0.055em;
  margin: 0;
}
#mast em {
  display: block;
  font-weight: normal;
}
.countdown {
  display: inline-grid;
  gap: 0.25rem;
  margin-top: clamp(0.8rem, 2.5vh, 2rem);
  padding: 0.65em 1.4em;
  border-block: 1px solid #e9cb897a;
  background: linear-gradient(90deg, transparent, #091a33a8 25% 75%, transparent);
}
.countdown span {
  font: 600 0.67rem system-ui, sans-serif;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #ffe2a6;
}
#revealClock {
  font: normal clamp(1.3rem, 2.3vw, 2rem)/1 Georgia, serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}
.mast-actions {
  margin-top: clamp(0.95rem, 2.4vh, 1.75rem);
}
#todayBtn {
  pointer-events: auto;
  font: italic clamp(1.12rem, 1.9vw, 1.48rem)/1.15 Georgia, serif;
  letter-spacing: 0.01em;
  color: #fff8e6;
  padding: 0.72em 1.55em;
  min-height: 52px;
  border-radius: 999px;
  border: 1px solid rgba(255, 224, 150, 0.58);
  background: linear-gradient(
    180deg,
    rgba(255, 226, 152, 0.34) 0%,
    rgba(218, 165, 76, 0.24) 55%,
    rgba(176, 122, 42, 0.30) 100%
  );
  backdrop-filter: blur(12px) saturate(1.35);
  -webkit-backdrop-filter: blur(12px) saturate(1.35);
  text-shadow: 0 1px 8px rgba(32, 18, 4, 0.65);
  box-shadow:
    inset 0 1px 1px rgba(255, 248, 224, 0.55),
    inset 0 -1px 6px rgba(212, 152, 54, 0.25),
    0 6px 24px rgba(5, 14, 28, 0.5),
    0 0 22px rgba(245, 200, 108, 0.22);
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
#todayBtn:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 236, 182, 0.85);
  background: linear-gradient(
    180deg,
    rgba(255, 232, 168, 0.46) 0%,
    rgba(228, 176, 86, 0.34) 55%,
    rgba(188, 134, 48, 0.38) 100%
  );
  box-shadow:
    inset 0 1px 2px rgba(255, 250, 232, 0.7),
    inset 0 -1px 8px rgba(226, 168, 66, 0.32),
    0 8px 28px rgba(5, 14, 28, 0.58),
    0 0 30px rgba(255, 214, 122, 0.38);
}

/* Talk Reveal Card */
#prompt:has(#day:not([hidden])) {
  left: 51%;
  right: 5%;
  bottom: 50%;
  width: auto;
  transform: translateY(50%);
  padding: 0;
  text-align: left;
  background: none;
  white-space: normal;
}
#day {
  --avatar-size: clamp(3.4rem, 6.8vh, 4.7rem);
  --speaker-width: clamp(5rem, 8.5vw, 6.25rem);
  pointer-events: auto;
  width: 100%;
  margin: 0;
  color: #fff1d8;
  text-shadow: 0 2px 12px #071420;
  animation: ink-in 0.6s both;
  overflow: visible;
  padding-inline: 0.15em;
}
#date {
  margin: 0;
  font: 600 0.74rem/1.3 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: #f5d696;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
#date::after {
  content: "";
  width: 4rem;
  height: 1px;
  background: linear-gradient(to right, #dbb978, transparent);
}
#title {
  font: italic 400 clamp(2.1rem, min(4.3vw, 7vh), 4.9rem)/1.02 Georgia, serif;
  letter-spacing: -0.04em;
  margin: 0.24em 0;
  text-wrap: balance;
  overflow-wrap: break-word;
}
#edition {
  margin: 0 0 0.75rem;
  font: 0.88rem system-ui, sans-serif;
  color: #d4cec5;
}
#sponsor:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 0.65em;
  margin: 0.2em 0 0.75em;
  color: #e1dacb;
  font: italic clamp(1.2rem, 1.8vw, 1.75rem)/1.15 Georgia, serif;
}
#sponsor img {
  display: block;
  height: 1.55em;
  max-width: 40%;
  object-fit: contain;
}
#sealedBox:not([hidden]) {
  margin: 0.5rem 0 0.4rem;
}
.sealed-clock {
  margin-top: 0.35rem;
  padding: 0.7em 1.5em;
}
#ornamentClock {
  font: normal clamp(1.5rem, 2.8vw, 2.4rem)/1.05 Georgia, serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: #fff3d8;
}
.sealed-when {
  margin: 0.8rem 0 0;
  font: italic clamp(0.95rem, 1.35vw, 1.15rem)/1.45 Georgia, serif;
  color: #dfd6c3;
}
#story {
  font: 400 clamp(0.96rem, 1.3vw, 1.2rem)/1.44 Georgia, serif;
  max-width: 34em;
  color: #e1dacb;
  margin: 0 0 0.85rem;
}
#presenter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.9rem;
  align-items: flex-start;
  font-size: 0.84rem;
  line-height: 1.35;
  color: #d4cec5;
}
.speaker {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: var(--speaker-width);
  gap: 0.3rem;
  overflow-wrap: anywhere;
}
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  flex: none;
  width: var(--avatar-size);
  height: var(--avatar-size);
  background: #49463d;
  color: #fff1d8;
  box-shadow: 0 0 0 1px #d7bc8766;
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.1rem;
  margin-top: 1.05rem;
}
#watch {
  display: inline-block;
  border-radius: 100px;
  padding: 0.65em 1.35em;
  color: #2c2217;
  text-decoration: none;
  text-shadow: none;
  font-weight: 650;
  font-size: 0.92rem;
  background: linear-gradient(#ffebc2, #e5c284);
  transition: filter 0.15s ease, transform 0.15s ease;
}
#watch:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}
.day-nav {
  display: inline-flex;
  gap: 0.5rem;
}
.day-nav button {
  background: rgba(16, 31, 50, 0.72);
  border: 1px solid #d3b78355;
  border-radius: 100px;
  padding: 0.5em 0.95em;
  font-size: 0.82rem;
  color: #f3e2c0;
}
.day-nav button:hover {
  background: rgba(28, 48, 74, 0.9);
  border-color: #ebd097;
}

/* Back button */
#back {
  position: absolute;
  z-index: 3;
  left: max(0.6rem, env(safe-area-inset-left));
  bottom: max(0.6rem, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff0d4;
}
#back svg {
  opacity: 0.76;
  filter: drop-shadow(0 1px 2px #162238);
}
#back:hover, #back:focus-visible {
  background: #101f32a6;
}
#back:hover svg, #back:focus-visible svg {
  opacity: 1;
}

/* Subtle Sound Toggle Button (bottom-right) */
#soundBtn {
  position: absolute;
  z-index: 4;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid #d3b78344;
  border-radius: 50%;
  background: rgba(8, 18, 36, 0.56);
  color: #fff0d4;
  backdrop-filter: blur(6px);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
#soundBtn:hover, #soundBtn:focus-visible {
  background: rgba(16, 31, 50, 0.85);
  border-color: #ebd097;
}
#soundBtn[aria-pressed="true"] {
  border-color: #f0cf8b99;
  box-shadow: 0 0 14px rgba(240, 207, 139, 0.25);
  color: #ffe8b5;
}
#soundBtn .sound-on { display: none; }
#soundBtn[aria-pressed="true"] .sound-on { display: block; }
#soundBtn[aria-pressed="true"] .sound-off { display: none; }

/* Preview Simulator Banner (only shown when ?preview=... is in URL) */
#previewBanner {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(12, 24, 42, 0.9);
  border: 1px solid #e7c27c88;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  color: #ffe7b8;
  backdrop-filter: blur(8px);
}
#previewBanner select {
  background: #13253d;
  color: #fff2d8;
  border: 1px solid #526a82;
  border-radius: 999px;
  padding: 2px 8px;
  font: inherit;
}
#previewBanner a {
  color: #f5d28c;
  text-decoration: none;
  font-weight: 600;
}
#previewBanner a:hover { text-decoration: underline; }

@keyframes ink-in {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 800px) and (min-aspect-ratio: 105/100) {
  #mast {
    top: 5%;
    left: 6%;
    width: 38%;
  }
  #mast::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: -14% -8%;
    background: radial-gradient(ellipse at center, #061932b5, transparent 72%);
  }
}

@media (max-width: 799px), (max-aspect-ratio: 105/100) {
  #mast {
    top: max(1.15rem, env(safe-area-inset-top));
    width: max-content;
    left: 50%;
    translate: -50% 0;
    transform-origin: top center;
    scale: var(--mast-scale, 1);
  }
  #mast img {
    width: 7.4rem;
    margin-bottom: 0.5rem;
  }
  #mast h1 {
    font-size: 3.7rem;
    line-height: 0.88;
  }
  #mast em {
    display: block;
  }
  .countdown {
    display: inline-grid;
    gap: 0.28rem;
    margin-top: 1.05rem;
    padding: 0.6em 1.4em;
  }
  .countdown span {
    font-size: 0.72rem;
  }
  #revealClock {
    font-size: 1.7rem;
  }
  .mast-actions {
    margin-top: 1.05rem;
  }
  #todayBtn {
    font-size: 1.25rem;
    padding: 0.68em 1.5em;
    min-height: 52px;
  }
  #mast.mast-wide {
    width: max-content;
    left: 50%;
    translate: -50% 0;
  }
  #mast.mast-wide img {
    width: 6.4rem;
    margin-bottom: 0.28rem;
  }
  #mast.mast-wide h1 {
    font-size: 3.9rem;
    line-height: 0.94;
    white-space: nowrap;
  }
  #mast.mast-wide em {
    display: inline;
  }
  #mast.mast-wide .countdown {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.55rem;
    padding: 0.36rem 1.05rem;
  }
  #mast.mast-wide #revealClock {
    font-size: 1.25rem;
  }
  #mast.mast-wide .mast-actions {
    margin-top: 0.55rem;
  }
  #mast.mast-wide #todayBtn {
    font-size: 1.18rem;
    padding: 0.55em 1.45em;
    min-height: 46px;
  }
}

@media (max-width: 799px), (max-aspect-ratio: 112/100) {
  #prompt:has(#day:not([hidden])) {
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    text-align: center;
    padding: 1rem 5% max(2.5dvh, env(safe-area-inset-bottom));
    background: linear-gradient(transparent, #0c1825e8 30%, #0c1825);
  }
  #day { --avatar-size: 3.1rem; --speaker-width: 4.9rem; }
  #date { justify-content: center; font-size: 0.65rem; }
  #date::after { display: none; }
  #title { font-size: clamp(1.65rem, 4.4vh, 2.5rem); margin: 0.16em 0; }
  #story { font-size: 0.9rem; line-height: 1.3; margin: 0.35rem auto 0.55rem; }
  #sponsor { justify-content: center; }
  #presenter { justify-content: center; gap: 0.45rem 0.65rem; }
  .card-footer { justify-content: center; margin-top: 0.65rem; }
}

@media (prefers-reduced-motion: reduce) {
  #day, #mast, #toast, #enter.intro-reveal, .loader-snow, .loader-inner { animation: none; }
  #loader { transition: none; }
}
