:root {
  --bg1: #150826;
  --bg2: #07030d;
  --orange: #ff8a1f;
  --orange-hot: #ffb347;
  --purple: #8b5cf6;
  --text: #f5ecff;
  --muted: #a794c4;
  --panel: rgba(36, 18, 60, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 0%, var(--bg1) 0%, var(--bg2) 70%) fixed;
  overflow-x: hidden;
  min-height: 100vh;
  transition: background 0.8s ease;
}

body {
  --pk-a: #ffa53a; --pk-b: #d9570a; --pk-side: #c24a08; --pk-mid: #ff8a1f;
  --pk-stem: #4d7a2a; --pk-glow: #ffd36b; --pk-shadow: rgba(255, 120, 20, 0.4);
}
body[data-mode="short"] {
  --orange: #a78bfa; --orange-hot: #c4b5fd;
  --pk-a: #c4b5fd; --pk-b: #6d3fd6; --pk-side: #5b34b0; --pk-mid: #a78bfa;
  --pk-stem: #4d7a2a; --pk-glow: #f5f3ff; --pk-shadow: rgba(160, 120, 255, 0.4);
}
body[data-mode="long"] {
  --orange: #4ade80; --orange-hot: #86efac;
  --pk-a: #86efac; --pk-b: #15803d; --pk-side: #166534; --pk-mid: #4ade80;
  --pk-stem: #d9f99d; --pk-glow: #ecfccb; --pk-shadow: rgba(80, 220, 130, 0.4);
}

/* Pumpkin colors follow the mode through CSS variables */
.pk-a { stop-color: var(--pk-a); transition: stop-color 0.6s; }
.pk-b { stop-color: var(--pk-b); transition: stop-color 0.6s; }
.pk-side { fill: var(--pk-side); }
.pk-mid { fill: var(--pk-mid); }
.pk-stem { stroke: var(--pk-stem); stroke-linecap: round; }
.pumpkin .glow path { fill: var(--pk-glow); }

/* Backdrop */
.moon {
  position: fixed; top: 6vh; right: 8vw;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff4d6, #f2c46b 70%);
  box-shadow: 0 0 60px 20px rgba(255, 190, 90, 0.25);
  animation: moonpulse 6s ease-in-out infinite;
}
.stars {
  position: fixed; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 70%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 15%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 75% 55%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 80%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 20% 90%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 65% 35%, #fff 50%, transparent 51%);
  animation: twinkle 4s ease-in-out infinite alternate;
}

.ghost { position: fixed; width: 70px; opacity: 0.85; filter: drop-shadow(0 0 14px rgba(200, 170, 255, 0.5)); pointer-events: none; }
.ghost-a { left: 6vw; top: 22vh; animation: float 6s ease-in-out infinite; }
.ghost-b { right: 7vw; bottom: 20vh; width: 56px; opacity: 0.6; animation: float 7.5s ease-in-out -2s infinite; }

.bat { position: fixed; width: 46px; pointer-events: none; top: 12vh; left: -60px; filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.6)); animation: fly 18s linear infinite, flap 0.35s ease-in-out infinite alternate; }

/* Drifting fog */
.fog { position: fixed; left: -50%; width: 200%; height: 220px; bottom: 0; pointer-events: none; opacity: 0.5;
  background: radial-gradient(ellipse at 20% 100%, rgba(139,92,246,0.28), transparent 60%),
              radial-gradient(ellipse at 70% 100%, rgba(255,138,31,0.12), transparent 55%); }
.fog-a { animation: drift 40s linear infinite alternate; }
.fog-b { bottom: 20px; opacity: 0.35; animation: drift 60s linear -20s infinite alternate-reverse; }
.bat-b { top: 30vh; width: 34px; animation-duration: 25s; animation-delay: -9s; }

.ground { position: fixed; bottom: 0; left: 0; right: 0; height: 120px; pointer-events: none; z-index: 1; }
.ground svg { width: 100%; height: 100%; display: block; }

/* App layout */
.app {
  position: relative; z-index: 2;
  max-width: 460px; margin: 0 auto;
  padding: 28px 20px 110px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  animation: rise 0.8s ease both;
}

.title {
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: clamp(1.8rem, 6vw, 2.5rem);
  letter-spacing: 1px;
  text-shadow: 0 0 18px rgba(255, 138, 31, 0.35);
}
.title span { color: var(--orange); transition: color 0.6s; }

/* Mode tabs */
.modes {
  display: flex; gap: 4px; padding: 5px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px; backdrop-filter: blur(6px);
}
.modes button {
  background: none; border: 0; color: var(--muted);
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 0.9rem;
  transition: background 0.3s, color 0.3s, transform 0.2s;
}
.modes button:hover { color: var(--text); }
.modes button.active { background: var(--orange); color: #1a0b2e; font-weight: 700; box-shadow: 0 0 16px -2px var(--orange); }
.modes button:focus-visible, .btn:focus-visible, .link:focus-visible { outline: 2px solid var(--orange-hot); outline-offset: 2px; }

/* Dial */
.dial { position: relative; width: min(320px, 80vw); aspect-ratio: 1; display: grid; place-items: center; }
.ring { overflow: visible; position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring-bg { stroke: rgba(255,255,255,0.07); }
.ring-fg {
  stroke: var(--orange); stroke-linecap: round;
  stroke-dasharray: 942.48; stroke-dashoffset: 0;
  filter: drop-shadow(0 0 8px var(--orange));
  transition: stroke-dashoffset 0.4s linear, stroke 0.6s;
}

.pumpkin { width: 62%; filter: drop-shadow(0 8px 24px var(--pk-shadow)); animation: bob 4s ease-in-out infinite; }
.pumpkin .glow { opacity: 0.35; transition: opacity 0.6s; }
.running .pumpkin .glow { opacity: 1; filter: drop-shadow(0 0 8px #ffb347); animation: flicker 2.2s ease-in-out infinite; }
.running .ring-fg { animation: ringglow 2.4s ease-in-out infinite; }
.running .pumpkin { animation: bob 2.5s ease-in-out infinite; }
.pumpkin.done { animation: shake 0.6s ease 3; }
.title { animation: titleglow 4s ease-in-out infinite alternate; }

/* Time */
.time-wrap { text-align: center; }
.time {
  font-family: "Courier New", monospace; font-weight: 700;
  font-size: clamp(3.2rem, 14vw, 4.6rem);
  font-variant-numeric: tabular-nums; letter-spacing: 2px;
  color: var(--orange-hot);
  text-shadow: 0 0 22px var(--orange);
  transition: color 0.6s;
}
.label { color: var(--muted); margin-top: 4px; min-height: 1.4em; transition: opacity 0.3s; }

/* Buttons */
.controls { display: flex; gap: 14px; }
.btn {
  font: inherit; font-weight: 700; font-size: 1.05rem;
  padding: 13px 34px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--orange); transition: transform 0.15s, box-shadow 0.3s, background 0.3s, color 0.3s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px) scale(0.97); }
.btn.primary { background: var(--orange); color: #1a0b2e; box-shadow: 0 0 22px -4px var(--orange); min-width: 130px; }
.btn.primary:hover { box-shadow: 0 0 30px 0 var(--orange); }
.btn.ghost-btn { background: transparent; color: var(--orange-hot); }
.btn.ghost-btn:hover { background: rgba(255,255,255,0.06); }

.auto { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; cursor: pointer; }
.auto input { accent-color: var(--orange); width: 16px; height: 16px; cursor: pointer; }

/* Stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; }
.stat {
  background: var(--panel); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px; padding: 14px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  backdrop-filter: blur(6px);
}
.stat-title { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1.5px; }
.stat-sub { font-size: 0.85rem; }
.big { font-size: 2.2rem; font-weight: 700; color: var(--orange-hot); line-height: 1; }
.big.bump { animation: bump 0.6s ease; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 0.75rem; cursor: pointer; text-decoration: underline; }
.link:hover { color: var(--text); }

.dots { display: flex; gap: 10px; height: 28px; align-items: center; }
.dot {
  width: 20px; height: 20px; border-radius: 50% 50% 46% 46%;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15);
  transition: background 0.4s, transform 0.4s, box-shadow 0.4s;
}
.dot.done { background: var(--orange); box-shadow: 0 0 10px var(--orange); transform: scale(1.1); }
.dot.current { border-color: var(--orange-hot); animation: pulse 1.6s ease-in-out infinite; }

/* Animations */
@keyframes float { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-22px) rotate(3deg); } }
@keyframes bob { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-6px) scale(1.02); } }
@keyframes ringglow { 0%,100% { filter: drop-shadow(0 0 6px var(--orange)); } 50% { filter: drop-shadow(0 0 16px var(--orange)); } }
@keyframes titleglow { from { text-shadow: 0 0 12px rgba(255,138,31,0.25); } to { text-shadow: 0 0 26px rgba(255,138,31,0.6); } }
@keyframes flicker { 0%,100% { opacity: 1; } 40% { opacity: 0.75; } 55% { opacity: 1; } 75% { opacity: 0.85; } }
@keyframes fly { 0% { transform: translate(0, 0); } 25% { transform: translate(30vw, 40px); } 50% { transform: translate(60vw, -20px); } 75% { transform: translate(90vw, 50px); } 100% { transform: translate(120vw, 0); } }
@keyframes flap { from { scale: 1 1; } to { scale: 1 0.55; } }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(22%); } }
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }
@keyframes moonpulse { 0%,100% { box-shadow: 0 0 60px 20px rgba(255,190,90,0.25); } 50% { box-shadow: 0 0 80px 28px rgba(255,190,90,0.35); } }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.5); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }

@media (max-width: 600px) {
  .app { padding: 14px 16px 120px; gap: 10px; }
  .title { font-size: 1.6rem; margin-top: 4px; }
  .modes button { padding: 8px 12px; font-size: 0.82rem; }
  .dial { width: min(230px, 62vw); }
  .time { font-size: 3.2rem; }
  .ghost-a { top: auto; bottom: 12px; left: 3vw; width: 40px; opacity: 0.7; }
  .ghost-b { display: none; }
  .moon { width: 40px; height: 40px; top: 6px; right: 8px; box-shadow: 0 0 30px 10px rgba(255,190,90,0.25); animation: none; }
  .btn { padding: 12px 28px; }
  .stat { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}
