:root {
  --ink: #0d0b12;
  --cream: #fff6e6;
  --gold: #f3c76b;
  --rose: #ff6b8b;
  --glass: rgba(12, 9, 20, .62);
  --line: rgba(255, 246, 230, .18);
  --serif: 'Playfair Display', Georgia, serif;
  --script: 'Great Vibes', cursive;
  --sans: Inter, system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* Author display rules (e.g. #title { display: grid }) would otherwise
   override the hidden attribute and leave invisible layers eating clicks. */
[hidden] { display: none !important; }
html, body {
  height: 100%; overflow: hidden; background: var(--ink); color: var(--cream);
  font-family: var(--sans); -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- stage ---------------------------------------------------------- */
#viewport { position: fixed; inset: 0; overflow: hidden; }
#viewport svg { display: block; width: 100%; height: 100%; }
#viewport.frozen { filter: grayscale(.75) brightness(.75) contrast(1.1); transition: filter .25s; }
#viewport.vhs { filter: contrast(1.35) saturate(1.9) hue-rotate(-12deg) blur(.4px); }
.hot { cursor: pointer; }
.hot:focus { outline: none; }
.hot:focus-visible { outline: 3px solid var(--gold); }
.halo { fill: none; stroke: #ffd77a; stroke-width: 7; opacity: 0; pointer-events: none; }
.halo.on { animation: halo 1.8s ease-in-out infinite; }
.halo.strong { animation-duration: .9s; stroke-width: 11; }
@keyframes halo { 0%, 100% { opacity: .12; } 50% { opacity: .85; } }
.twinkle { animation: twinkle 2.6s ease-in-out infinite; }
@keyframes twinkle { 0%, 70%, 100% { opacity: 0; } 82% { opacity: 1; } }
.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: .2; } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 15; }
#flash { position: fixed; inset: 0; background: #000; opacity: 1; pointer-events: none; z-index: 50; }

/* ---- VHS -------------------------------------------------------------- */
#vhs {
  position: fixed; inset: 0; z-index: 45; pointer-events: none; font-family: 'VT323', monospace; color: #fff;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.28) 0 2px, transparent 2px 4px);
  text-shadow: 2px 0 #ff2a6d, -2px 0 #05d9e8;
}
#vhs .vhs-label { position: absolute; top: max(70px, calc(env(safe-area-inset-top) + 60px)); left: 22px; font-size: clamp(30px, 6vw, 52px); }
#vhs .vhs-time { position: absolute; bottom: 24px; right: 22px; font-size: clamp(24px, 4.5vw, 40px); }
#vhs::after {
  content: ''; position: absolute; left: 0; right: 0; height: 18%; top: 60%;
  background: linear-gradient(transparent, rgba(255,255,255,.12), transparent); animation: tracking .7s linear infinite;
}
@keyframes tracking { from { transform: translateY(-80vh); } to { transform: translateY(40vh); } }

/* ---- HUD -------------------------------------------------------------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  opacity: 0; transition: opacity .6s;
}
body.playing #hud { opacity: 1; }
#hud > *, .hud-right > * { pointer-events: auto; }
.hud-right { display: flex; gap: 8px; margin-left: auto; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.icon {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass);
  font-weight: 700; font-size: 14px; cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.icon[aria-pressed="false"] { opacity: .5; text-decoration: line-through; }
.pill {
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass);
  font-weight: 600; font-size: 14px; cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.pill.solid { background: var(--cream); color: var(--ink); border-color: var(--cream); }
#choco {
  background: var(--glass); padding: 9px 14px; border-radius: 999px; font-weight: 700; font-size: 15px;
  border: 1px solid var(--line); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#choco.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.3); } }

/* ---- captions --------------------------------------------------------- */
#caption {
  position: fixed; left: 50%; bottom: max(4.5vh, calc(env(safe-area-inset-bottom) + 14px));
  width: min(calc(100vw - 32px), 680px); padding: 14px 20px 16px; z-index: 20; pointer-events: none;
  background: var(--glass); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  opacity: 0; transform: translateX(-50%) translateY(12px); transition: opacity .35s, transform .35s;
}
#caption.show { opacity: 1; transform: translateX(-50%); }
#caption p {
  font-family: var(--serif); font-style: italic; font-size: clamp(17px, 2.3vw, 23px); line-height: 1.42;
  text-align: center; text-wrap: pretty; min-height: 1.42em;
}

#toast {
  position: fixed; top: max(66px, calc(env(safe-area-inset-top) + 58px)); left: 50%; z-index: 31; pointer-events: none;
  transform: translate(-50%, -10px); opacity: 0; transition: opacity .3s, transform .3s;
  background: var(--cream); color: var(--ink); font-weight: 700; font-size: 15px; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35); white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- popup ------------------------------------------------------------ */
#popup { position: fixed; inset: 0; z-index: 42; display: grid; place-items: center; background: rgba(0,0,0,.45); padding: 16px; }
#popup[hidden] { display: none; }
#popup .card {
  width: min(100%, 360px); background: #f7f1e3; color: #2a2118; border-radius: 6px; padding: 24px 24px 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); text-align: center; transform: rotate(-1.5deg);
}
#popup h3 { font-family: var(--serif); font-size: 22px; margin-bottom: 12px; }
#popup ul { list-style: none; text-align: left; margin: 0 auto 14px; font-size: 15px; line-height: 1.9; }
#popup li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dotted #b8a98f; }
#popup .small { font-size: 13px; font-style: italic; opacity: .75; margin-bottom: 14px; }
#popup .pill.solid { background: #2a2118; color: #f7f1e3; border-color: #2a2118; }

/* ---- prompt ----------------------------------------------------------- */
#prompt {
  position: fixed; inset: 0; z-index: 40; display: grid; place-content: center; gap: 30px; text-align: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.15), rgba(0,0,0,.6)); pointer-events: none;
}
#prompt[hidden] { display: none; }
#prompt p { font-family: var(--serif); font-style: italic; font-size: clamp(26px, 5.4vw, 46px); text-shadow: 0 4px 24px rgba(0,0,0,.6); text-wrap: balance; }
.choices { display: flex; gap: 20px; justify-content: center; }
.choice {
  pointer-events: auto; min-width: 124px; padding: 15px 28px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--cream); background: rgba(12,9,20,.5); font-weight: 800; font-size: 20px; letter-spacing: .14em;
}
.choice:hover { background: var(--cream); color: var(--ink); }

/* ---- end card ----------------------------------------------------------- */
#endcard {
  position: fixed; top: max(70px, calc(env(safe-area-inset-top) + 62px)); left: 50%; transform: translateX(-50%); z-index: 35;
  width: min(calc(100vw - 32px), 520px); text-align: center; padding: 22px 22px 20px; border-radius: 20px;
  background: rgba(20, 12, 40, .66); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#endcard[hidden] { display: none; }
#endcard h2 { font-family: var(--script); font-weight: 400; font-size: clamp(48px, 11vw, 78px); line-height: 1.05; color: var(--gold); text-shadow: 0 0 24px rgba(243,199,107,.45); }
#endcard .heart { font-family: var(--sans); font-size: .55em; vertical-align: middle; display: inline-block; animation: beat 1.2s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.25); } 30% { transform: scale(1); } 45% { transform: scale(1.18); } }
#endcard .sub { font-family: var(--serif); font-style: italic; font-size: clamp(18px, 3.4vw, 22px); margin: 4px 0 10px; }
#endcard .choco-sum { font-size: 14px; opacity: .85; margin-bottom: 16px; }
.end-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#endcard.mini { width: auto; padding: 8px 18px; cursor: pointer; }
#endcard.mini h2 { font-size: 34px; }
#endcard.mini .sub, #endcard.mini .choco-sum, #endcard.mini .end-actions { display: none; }

/* ---- title ------------------------------------------------------------ */
#title {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; text-align: center; padding: 16px;
  background: radial-gradient(ellipse 60% 45% at 50% 0%, rgba(255,205,120,.22), transparent 70%), var(--ink);
}
#title .lamp {
  position: absolute; top: 0; left: 50%; width: 2px; height: 14vh; background: #444; transform: translateX(-50%);
}
#title .lamp::after {
  content: ''; position: absolute; bottom: -14px; left: 50%; width: 30px; height: 18px; transform: translateX(-50%);
  background: #ffd98a; border-radius: 15px 15px 4px 4px; box-shadow: 0 0 40px 18px rgba(255,205,120,.45);
}
.title-inner { display: grid; justify-items: center; gap: 10px; margin-top: 6vh; }
.neon {
  font-family: var(--sans); font-weight: 800; font-size: clamp(54px, 13vw, 96px); color: #ffd1dc; line-height: 1;
  text-shadow: 0 0 6px #fff, 0 0 18px var(--rose), 0 0 40px var(--rose), 0 0 70px #ff2a6d; animation: flicker 4s infinite;
}
@keyframes flicker { 0%, 18%, 22%, 62%, 64%, 100% { opacity: 1; } 20%, 63% { opacity: .35; } }
#title h1 { font-family: var(--script); font-weight: 400; font-size: clamp(64px, 17vw, 132px); color: var(--gold); line-height: 1; text-shadow: 0 0 30px rgba(243,199,107,.35); }
#title .tag { font-family: var(--serif); font-style: italic; font-size: clamp(17px, 3.6vw, 22px); opacity: .85; }
.start {
  margin-top: 22px; padding: 16px 34px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--cream); color: var(--ink); font-weight: 800; font-size: 18px; letter-spacing: .04em;
  box-shadow: 0 0 0 0 rgba(255,246,230,.5); animation: pulse 2s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 18px rgba(255,246,230,0); } 100% { box-shadow: 0 0 0 0 rgba(255,246,230,0); } }
#title .hint { font-size: 13px; opacity: .6; margin-top: 6px; }

/* ---- feedback ------------------------------------------------------------- */
.ripple {
  position: fixed; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; pointer-events: none; z-index: 70;
  border: 2px solid rgba(255,246,230,.85); animation: ripple .5s ease-out forwards;
}
@keyframes ripple { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
.float-heart { position: fixed; z-index: 25; pointer-events: none; color: #ff4d6d; font-size: 26px; margin: -13px 0 0 -13px; text-shadow: 0 2px 8px rgba(0,0,0,.25); }

/* Tall phones: the characters stand low in frame, so captions go up top
   (under the HUD) and toasts drop to the bottom. */
@media (orientation: portrait) and (max-aspect-ratio: 3/4) {
  #caption { bottom: auto; top: max(66px, calc(env(safe-area-inset-top) + 58px)); transform: translateX(-50%) translateY(-12px); }
  #caption.show { transform: translateX(-50%); }
  #toast { top: auto; bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px)); }
  #endcard { top: max(66px, calc(env(safe-area-inset-top) + 58px)); }
}

@media (prefers-reduced-motion: reduce) {
  .halo.on, .twinkle, .neon, .start, #vhs::after, #endcard .heart { animation: none; }
  .halo.on { opacity: .6; }
}
