:root {
  --ink: #e8eef5;
  --accent: #ffd27a;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--ink); font-family: var(--sans); overflow: hidden; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* --- buttons and persistent controls --- */
.btn {
  font: 600 1.05rem var(--sans); color: #111; background: var(--accent); border: 0; border-radius: 999px;
  padding: 0.8em 1.8em; cursor: pointer; letter-spacing: 0.02em; box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}
.btn:disabled { opacity: 0.5; cursor: default; }
#skip {
  position: fixed; right: max(16px, env(safe-area-inset-right)); top: max(14px, env(safe-area-inset-top)); z-index: 30;
  color: rgba(255,255,255,0.75); text-decoration: none; font: 500 0.95rem var(--sans); letter-spacing: 0.08em;
  padding: 6px 10px; border: 1px solid rgba(255,255,255,0.25); border-radius: 999px; backdrop-filter: blur(4px);
}
#skip:hover { color: #fff; border-color: rgba(255,255,255,0.6); }
#mute {
  position: fixed; left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.25); background: rgba(0,0,0,0.35);
  color: #fff; font-size: 1.1rem; cursor: pointer; backdrop-filter: blur(4px);
}

/* --- start overlay --- */
#start { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 60%, rgba(10,16,30,0.6), rgba(0,0,0,0.92)); }
.start-box { text-align: center; padding: 24px; max-width: 420px; }
.start-box h2 { font: 300 2rem var(--sans); letter-spacing: 0.25em; text-transform: uppercase; margin: 0 0 0.5em; }
.start-box p { color: rgba(255,255,255,0.7); line-height: 1.5; margin: 0 0 1.5em; }
.start-box .small { font-size: 0.85rem; margin-top: 1.5em; }
.start-box .small a { color: rgba(255,255,255,0.6); }
#start.out { transition: opacity 0.8s; opacity: 0; pointer-events: none; }

/* --- HUD (scene 2) --- */
#hud { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity 0.7s; }
#hud.on { opacity: 1; }
.hud-panel {
  font-family: var(--mono); color: #cfe6ff; width: min(680px, 92vw);
  border: 1px solid rgba(160,210,255,0.45); background: rgba(6,14,26,0.45); backdrop-filter: blur(3px);
  padding: 14px 18px 18px; box-shadow: 0 0 0 1px rgba(160,210,255,0.08), 0 0 40px rgba(80,140,255,0.12) inset;
}
.hud-head { display: flex; justify-content: space-between; font-size: 0.72rem; letter-spacing: 0.2em; opacity: 0.7; border-bottom: 1px solid rgba(160,210,255,0.3); padding-bottom: 8px; margin-bottom: 12px; }
#hud-text { margin: 0; font-size: clamp(0.8rem, 2.6vw, 1.15rem); line-height: 1.7; letter-spacing: 0.08em; white-space: pre-wrap; min-height: 6em; text-shadow: 0 0 8px rgba(120,190,255,0.5); }
#hud-text .dim { color: rgba(160,200,240,0.45); }
#hud-text .cur { display: inline-block; width: 0.6em; height: 1em; background: #cfe6ff; vertical-align: -0.15em; animation: blink 0.8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* --- overlays --- */
#flash { position: fixed; inset: 0; z-index: 25; background: #fff; opacity: 0; pointer-events: none; }
#fade { position: fixed; inset: 0; z-index: 24; background: #f6e8d2; opacity: 0; pointer-events: none; }
#entry { position: fixed; inset: 0; z-index: 23; opacity: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,120,30,0) 45%, rgba(255,110,20,0.55) 80%, rgba(255,60,0,0.9) 100%); }

/* --- scene 6 --- */
#card-scene { position: fixed; inset: 0; z-index: 15; background: #c7d6e6; overflow: hidden; }
#card-scene[hidden] { display: none; }
#house { position: absolute; inset: 0; width: 100%; height: 100%; }
.envelope {
  position: absolute; left: 50%; bottom: 7vh; width: min(560px, 88vw); aspect-ratio: 1.6;
  transform: translate(-50%, 160%); transition: transform 1.1s cubic-bezier(0.2, 0.8, 0.2, 1);
  perspective: 1200px; filter: drop-shadow(0 18px 30px rgba(0,0,0,0.35));
}
.envelope.in { transform: translate(-50%, 0); }
.env-back { position: absolute; inset: 0; background: #efe3cf; border-radius: 6px; }
.env-front { position: absolute; inset: 0; border-radius: 6px; background: #f6ecdb;
  clip-path: polygon(0 0, 50% 55%, 100% 0, 100% 100%, 0 100%); z-index: 3; }
.env-front::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0.08), rgba(0,0,0,0) 40%); clip-path: inherit; }
.env-flap { position: absolute; left: 0; right: 0; top: 0; height: 56%; background: #e7d9c0; border-radius: 6px 6px 0 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%); transform-origin: top; transform: rotateX(0deg);
  transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1); z-index: 4; }
.envelope.open .env-flap { transform: rotateX(-180deg); z-index: 1; }
.card {
  position: absolute; left: 5%; right: 5%; top: 6%; bottom: 6%; background: #fffdf8; border-radius: 4px; z-index: 2;
  padding: clamp(14px, 4vw, 36px); color: #2b2622; text-align: center; overflow: hidden;
  transition: top 1.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
.envelope.card-out .card { top: -85%; bottom: auto; min-height: 88%; max-height: 78vh; overflow: auto; z-index: 5; }
.card h1 { font: 600 clamp(1.3rem, 4.5vw, 2.1rem) var(--serif); color: #8a3a2a; margin: 0.2em 0 0.6em; }
.card p { font: 400 clamp(0.85rem, 2.4vw, 1.05rem)/1.55 var(--sans); margin: 0 0 0.8em; white-space: pre-line; }
.card .fine { opacity: 0; transition: opacity 1s; }
.envelope.card-out .card .fine, .envelope.card-out .card p { opacity: 1; }
#card-sign { font-style: italic; color: #6a5a50; }
#replay { position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6; opacity: 0; transition: opacity 0.8s; }
#replay.on { opacity: 1; }

@media (max-width: 700px) {
  .envelope { bottom: 10vh; }
  .envelope.card-out .card { top: -70%; }
}
@media (prefers-reduced-motion: reduce) {
  .envelope, .env-flap, .card { transition-duration: 0.01s; }
}
