:root {
  --bg: #07060b;
  --ink: #ece6f5;
  --muted: #8d84a1;
  --ember: #ff3b2f;
  --ember-soft: rgba(255, 59, 47, .35);
  --violet: #7a5ae0;
  --silhouette: #040306;
  --silhouette-2: #0e0b15;
  --card-top: rgba(22, 17, 31, .94);
  --card-bottom: rgba(11, 9, 16, .93);
  --font-display: "Cinzel Decorative", "Cinzel", Georgia, serif;
  --font-caps: "Cinzel", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }
html { overflow-x: clip; }

body {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ================= Scene ================= */
.scene { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }

.sky-glow {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 55% 45% at 50% 32%, rgba(92, 52, 170, .22), transparent 70%),
    radial-gradient(ellipse 90% 40% at 50% 105%, rgba(150, 18, 30, .22), transparent 70%),
    linear-gradient(180deg, #040309 0%, #0b0814 55%, #130a15 100%);
}

#sky { position: absolute; inset: 0; width: 100%; height: 100%; }

.moon {
  position: absolute;
  top: clamp(64px, 11vh, 130px);
  right: clamp(18px, 12vw, 240px);
  width: clamp(64px, 10vw, 170px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 34%, #fbf7ee 0%, #e4ddce 45%, #b4ab9b 100%);
  box-shadow:
    0 0 40px 6px rgba(236, 228, 255, .2),
    0 0 160px 60px rgba(140, 120, 220, .12);
  animation: moonPulse 9s ease-in-out infinite;
}
.crater { position: absolute; border-radius: 50%; background: rgba(120, 110, 96, .35); box-shadow: inset 2px 2px 4px rgba(0,0,0,.18); }
.crater.c1 { width: 22%; height: 22%; top: 24%; left: 52%; }
.crater.c2 { width: 13%; height: 13%; top: 58%; left: 30%; }
.crater.c3 { width: 9%;  height: 9%;  top: 64%; left: 64%; }

@keyframes moonPulse { 50% { box-shadow: 0 0 52px 10px rgba(236, 228, 255, .26), 0 0 190px 70px rgba(140, 120, 220, .15); } }

.cloud {
  position: absolute;
  width: clamp(240px, 42vw, 640px);
  height: clamp(40px, 7vw, 110px);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(34, 27, 50, .92) 0%, rgba(34, 27, 50, .55) 45%, transparent 72%);
  will-change: transform;
  animation: cloudDrift 90s linear infinite;
}
.cloud-1 { top: clamp(80px, 13vh, 150px); animation-delay: -20s; }
.cloud-2 { top: clamp(40px, 7vh, 90px); animation-duration: 130s; animation-delay: -95s; opacity: .7; }
@keyframes cloudDrift {
  from { transform: translateX(-50vw); }
  to   { transform: translateX(110vw); }
}

/* Bats: flight path via `translate`, wing flap via `scale` */
.bat {
  position: absolute; left: -70px; top: 20vh;
  width: clamp(22px, 2.6vw, 38px);
  fill: #050407;
  animation: batFly 30s linear infinite, batFlap .18s ease-in-out infinite alternate;
}
.bat-1 { animation-delay: -4s, 0s; }
.bat-2 { top: 26vh; width: clamp(16px, 1.8vw, 26px); animation-delay: -5.2s, -.1s; animation-duration: 30s, .15s; }
.bat-3 { top: 12vh; animation-duration: 44s, .2s; animation-delay: -30s, -.05s; }
@keyframes batFly {
  0%   { translate: 0 0; }
  10%  { translate: 25vw -5vh; }
  20%  { translate: 50vw 3vh; }
  30%  { translate: 78vw -7vh; }
  40%, 100% { translate: calc(100vw + 140px) -2vh; }
}
@keyframes batFlap { from { scale: 1 1; } to { scale: 1 .35; } }

.tree {
  position: absolute;
  bottom: 5vh;
  height: min(64vh, 600px);
  aspect-ratio: 300 / 500;
}
.tree-left { left: max(-30px, -2vw); }
.tree .trunk { fill: var(--silhouette); }
.tree .branches path { stroke: var(--silhouette); }
.lantern line { stroke: var(--silhouette); }
.lantern rect { fill: #0c0910; stroke: #1c1525; stroke-width: 1; }
.lantern-light { fill: #ff9a4a; filter: drop-shadow(0 0 6px #ff6a2a) drop-shadow(0 0 16px #ff3b1f); animation: flicker 3.2s steps(1) infinite; }
.lantern { transform-box: fill-box; transform-origin: 50% 0; animation: sway 6s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }

.graveyard {
  position: absolute; left: 0; bottom: 0;
  width: 100%;
  height: clamp(150px, 27vh, 300px);
}
.graveyard .hill-back { fill: var(--silhouette-2); }
.graveyard .hill-front { fill: var(--silhouette); }
.candles circle { fill: #ffb26b; filter: drop-shadow(0 0 4px #ff7a2a) drop-shadow(0 0 10px #ff3b1f); animation: flicker 2.6s steps(1) infinite; }
.candles circle:nth-child(2) { animation-delay: -.9s; }
.candles circle:nth-child(3) { animation-delay: -1.7s; }
@keyframes flicker {
  0%, 100% { opacity: 1; } 12% { opacity: .7; } 18% { opacity: .95; } 46% { opacity: .55; } 52% { opacity: 1; } 78% { opacity: .8; }
}

.fog {
  position: absolute; left: 0; bottom: -4vh;
  width: 200%; height: 46vh;
  background-image:
    radial-gradient(ellipse 30% 45% at 18% 72%, rgba(170, 160, 205, .12), transparent 70%),
    radial-gradient(ellipse 22% 35% at 52% 82%, rgba(170, 160, 205, .09), transparent 70%),
    radial-gradient(ellipse 34% 50% at 84% 76%, rgba(170, 160, 205, .11), transparent 70%);
  background-size: 50% 100%;
  background-repeat: repeat-x;
  will-change: transform;
  animation: fogDrift 70s linear infinite;
}
.fog-front { bottom: -12vh; height: 36vh; opacity: .9; animation-duration: 45s; animation-direction: reverse; }
@keyframes fogDrift { from { transform: translateX(0); } to { transform: translateX(-50%); } }

.vignette { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(0, 0, 0, .75) 100%); }

.grain {
  position: absolute; inset: -50%;
  opacity: .07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  will-change: transform;
  animation: grain 1s steps(4) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 25% { transform: translate(-3%, 2%); } 50% { transform: translate(2%, -3%); } 75% { transform: translate(-1%, 3%); } 100% { transform: translate(0, 0); }
}

.flash {
  position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse 80% 70% at 80% 10%, rgba(225, 215, 255, .9), rgba(150, 130, 230, .35) 50%, transparent 80%);
  mix-blend-mode: screen;
}
.lightning .flash { animation: flash 1s ease-out; }
.lightning .reaper { animation: litUp 1s ease-out; }
@keyframes flash { 0% { opacity: 0; } 4% { opacity: .7; } 9% { opacity: .08; } 15% { opacity: .5; } 40% { opacity: 0; } }
@keyframes litUp { 0%, 40%, 100% { filter: none; } 4%, 15% { filter: brightness(2.2) contrast(1.1); } }

/* ================= Chrome ================= */
.topbar, .footer { position: relative; z-index: 3; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: max(16px, env(safe-area-inset-top)) clamp(16px, 4vw, 40px) 0;
  font-family: var(--font-caps);
  font-size: .72rem;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--muted);
}
.brand { color: #c8bedb; font-weight: 700; }
.clock { font-variant-numeric: tabular-nums; letter-spacing: .18em; }
.clock-moon { color: #d9cfa8; }

.topbar-right { display: flex; align-items: center; gap: clamp(10px, 2.5vw, 18px); }
.sound-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px 6px 9px;
  border: 1px solid rgba(255, 90, 80, .25);
  border-radius: 999px;
  background: rgba(10, 8, 14, .5);
  color: var(--muted);
  font: inherit; letter-spacing: .2em; text-transform: inherit;
  cursor: pointer;
  transition: color .2s, border-color .2s, box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
}
.sound-toggle svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle .spk { fill: currentColor; stroke: none; }
.sound-toggle[aria-pressed="false"] .wave,
.sound-toggle[aria-pressed="true"] .mute { display: none; }
.sound-toggle[aria-pressed="true"] { color: var(--ink); border-color: rgba(255, 106, 92, .6); box-shadow: 0 0 18px -6px var(--ember); }
.sound-toggle:hover { color: var(--ink); border-color: #ff6a5c; }
.sound-toggle:focus-visible { outline: 2px solid #ff6a5c; outline-offset: 3px; }
.sound-toggle.hint { animation: soundHint 2.4s ease-in-out infinite; }
@keyframes soundHint { 50% { box-shadow: 0 0 0 4px rgba(255, 59, 47, .15), 0 0 22px -4px var(--ember); color: var(--ink); } }

.footer {
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  text-align: center;
  font-family: var(--font-caps);
  font-size: .66rem;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: rgba(141, 132, 161, .7);
}

/* ================= Stage ================= */
.wrap {
  position: relative; z-index: 2;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow-x: clip; /* the aura and scythe may extend past narrow screens */
  padding: 8px 16px 16px;
}

/* --k scales the reaper (and its hands) to the height left above the card; set by scene.js */
.stage {
  --k: 1;
  position: relative;
  width: min(420px, 100%);
}

/* Login page fills exactly one screen on phones and desktops — no scrolling */
@media (orientation: portrait), (min-height: 500px) {
  body.login {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }
}

.aura {
  position: absolute;
  left: 50%; top: 0;
  width: 150%; aspect-ratio: 1;
  translate: -50% -12%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 40, 30, .13) 0%, rgba(110, 60, 200, .1) 35%, transparent 65%);
  will-change: opacity, scale;
  animation: auraPulse 6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes auraPulse { 50% { opacity: .65; scale: 1.05; } }

/* reaper: 118% of card width, lower body tucked behind the card */
.reaper {
  position: relative; z-index: 1;
  width: calc(118% * var(--k));
  margin-left: calc(50% - 59% * var(--k));
  margin-bottom: calc(-29.4% * var(--k));
  transform-origin: 50% 85%;
  transition: transform 1s cubic-bezier(.2, .8, .2, 1);
  pointer-events: none;
}
.reaper-tilt { transform-origin: 50% 90%; will-change: transform; } /* rotated by scene.js */
.reaper-float {
  position: relative;
  animation: float 7s ease-in-out infinite;
  will-change: transform;
  /* fade the robe out behind the card */
  -webkit-mask-image: linear-gradient(#000 74%, transparent 96%);
  mask-image: linear-gradient(#000 74%, transparent 96%);
}
.reaper-svg { display: block; width: 100%; height: auto; overflow: visible; }
/* face + eyes: small layers placed over the hood opening (percentages of the 400x460 viewBox) */
.reaper-layer { position: absolute; overflow: visible; will-change: transform; }
.reaper-face { left: 40%; top: 42.391%; width: 20%; height: 23.913%; }
.reaper-eyes { left: 37.5%; top: 45.652%; width: 25%; height: 13.043%; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.blade-glint { stroke-dasharray: 12 200; stroke-dashoffset: 12; animation: glint 8s ease-in-out infinite; }
@keyframes glint { 0%, 72% { stroke-dashoffset: 12; } 92%, 100% { stroke-dashoffset: -100; } }

.eyes { transform-box: fill-box; transform-origin: center; transition: transform .09s ease-in; }
.blink .eyes { transform: scaleY(.06); }
.eye-halo { opacity: .45; }

.lean .reaper { transform: translateY(16px) scale(1.045); }
.lean .eyes { transform: scale(1.18); }

.denied .reaper-tilt { animation: shake .8s ease-in-out; }
.denied .eye-halo { animation: rage .8s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: rotate(0); } 15% { transform: rotate(-3.5deg); } 35% { transform: rotate(3deg); }
  55% { transform: rotate(-2deg); } 75% { transform: rotate(1.2deg); }
}
@keyframes rage { 50% { filter: brightness(1.8) saturate(1.4); } }

/* ================= Card ================= */
.card {
  position: relative; z-index: 2;
  border-radius: 22px;
  background: linear-gradient(180deg, var(--card-top), var(--card-bottom));
  border: 1px solid rgba(255, 80, 70, .14);
  box-shadow:
    0 40px 90px -24px rgba(0, 0, 0, .95),
    inset 0 1px 0 rgba(255, 255, 255, .05);
}
.card::before {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 50px -8px var(--ember-soft);
  opacity: .35;
  animation: cardPulse 5s ease-in-out infinite;
}
.card::after {
  content: ""; position: absolute; left: 12%; right: 12%; top: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 120, 100, .55), transparent);
}
@keyframes cardPulse { 50% { opacity: .9; } }

.hands {
  position: absolute; top: 0;
  left: calc(50% - 50% * var(--k));
  width: calc(100% * var(--k)); height: auto;
  transform: translateY(-71.43%); /* aligns svg y=100 with the card's top edge */
  z-index: 3;
  overflow: visible;
  pointer-events: none;
}
.hand { transition: transform .5s ease; }
.finger { transform-box: fill-box; transform-origin: 50% 0; transition: transform .3s; }
.hand-right .finger { animation: drum 5.5s ease-in-out infinite; }
.hand-right .f1 { animation-delay: 1.2s; }
.hand-right .f2 { animation-delay: 1.32s; }
.hand-right .f3 { animation-delay: 1.44s; }
.hand-right .f4 { animation-delay: 1.56s; }
@keyframes drum { 0%, 6%, 100% { transform: none; } 3% { transform: scaleY(.55); } }
.lean .hand { transform: translateY(1.5px); }
.lean .finger { animation: none; transform: scaleY(1.1); }

.card-body {
  position: relative;
  padding: clamp(40px, 11%, 50px) clamp(20px, 7%, 36px) 26px;
  text-align: center;
}

.title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.75rem, 1.1rem + 2.6vw, 2.5rem);
  line-height: 1.1;
  letter-spacing: .05em;
  background: linear-gradient(180deg, #f6f1ff 10%, #a596c4 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 50, 40, .22));
}

.tagline {
  margin: 10px 0 0;
  min-height: 1.5em;
  color: var(--muted);
  font-size: clamp(.8rem, 3.6vw, .95rem);
  white-space: nowrap;
  transition: opacity .6s ease;
}
.tagline.swap { opacity: 0; }

.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 22px; color: var(--ember); font-size: .8rem; }
.divider span { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, rgba(255, 90, 80, .45), transparent); }
.divider i { font-style: normal; text-shadow: 0 0 10px var(--ember); }

/* Google button — dark theme per Google branding guidelines */
.google-btn {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; height: 50px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid #8e918f;
  background: #131314;
  color: #e3e3e3;
  font: 500 15px/1 var(--font-body);
  letter-spacing: .01em;
  cursor: pointer;
  transition: border-color .25s, box-shadow .25s, transform .15s, background .25s;
  -webkit-tap-highlight-color: transparent;
}
.google-btn:hover { border-color: #ff6a5c; box-shadow: 0 0 0 4px rgba(255, 59, 47, .12), 0 0 30px -4px rgba(255, 59, 47, .5); background: #18171a; }
.google-btn:active { transform: scale(.985); }
.google-btn:focus-visible { outline: 2px solid #ff6a5c; outline-offset: 3px; }
.google-btn[disabled] { cursor: progress; }
.g-logo { display: grid; place-items: center; width: 20px; height: 20px; }
.g-logo svg { width: 20px; height: 20px; display: block; }
.g-spinner {
  display: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .15);
  border-top-color: var(--ember);
  animation: spin .8s linear infinite;
}
.google-btn.busy .g-logo { display: none; }
.google-btn.busy .g-spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.status { margin: 14px 0 0; min-height: 2.7em; font-size: .85rem; line-height: 1.35; color: var(--muted); }
.status.error { color: #ff8a7e; }
.status.ok { color: #d8c9ff; }

.fine {
  margin: 14px 0 0;
  font-family: var(--font-caps);
  font-size: .64rem;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: rgba(141, 132, 161, .75);
}

/* ================= Sign-in transition ================= */
.curtain {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 38%, rgba(140, 0, 0, .35), #000 62%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.1s ease .35s;
}
.curtain p {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 1rem + 2vw, 2.2rem);
  letter-spacing: .08em;
  color: #e9dfff;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .8s ease 1.1s, transform .8s ease 1.1s;
}
.reaped .curtain { opacity: 1; pointer-events: all; }
.reaped .curtain p { opacity: 1; transform: none; }
.reaped .reaper { transform: translateY(34px) scale(1.14); transition-duration: 1.4s; }
.reaped .eyes { transform: scale(1.7); }

/* ================= Responsive ================= */
@media (max-width: 720px) {
  .tree { height: min(46vh, 380px); opacity: .9; }
  .tree-left { left: -18vw; }
  .bat-3 { display: none; }
  .topbar { font-size: .64rem; letter-spacing: .24em; }
}

@media (max-width: 420px) {
  .sound-label { display: none; }
  .sound-toggle { padding: 7px; }
}

@media (max-height: 700px) {
  .card-body { padding-top: 34px; padding-bottom: 18px; }
  .divider { margin: 14px 0; }
  .status { margin-top: 10px; }
  .fine { margin-top: 8px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .wrap { place-items: start center; }
  .tree, .moon, .cloud { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    transition-delay: 0s !important;
  }
}

@media (max-width: 420px) {
  .fine { letter-spacing: .16em; font-size: .6rem; }
}
