:root {
  --night: #0b0614;
  --plum: #2a1240;
  --ember: #ff5e1a;
  --gold: #ffd166;
  --ink: #f4ecff;
  --muted: rgba(244, 236, 255, 0.72);
  --glass: rgba(14, 8, 26, 0.62);
  --glass-edge: rgba(255, 209, 102, 0.28);
  --glow-color: #a9d6ff;
  --glow-strength: 0;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: "IM Fell English", Georgia, serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* ---------- backdrop ---------- */

#camera,
#sky,
#scene,
#glow {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#camera {
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.8s ease;
}

body.has-camera #camera {
  opacity: 1;
}

#sky {
  background:
    radial-gradient(1px 1px at 20% 30%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 20%, #fff9 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40% 70%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 60%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 10% 85%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 60% 45%, #fff6 50%, transparent 51%),
    radial-gradient(circle at 78% 18%, #fff3d6 0 6%, #ffd16633 7%, transparent 14%),
    radial-gradient(ellipse at 50% 120%, var(--plum), var(--night) 70%);
  animation: twinkle 6s ease-in-out infinite alternate;
}

body.has-camera #sky {
  display: none;
}

@keyframes twinkle {
  from {
    filter: brightness(0.85);
  }
  to {
    filter: brightness(1.15);
  }
}

#scene {
  touch-action: none;
}

/* Edge glow that heats up as you get closer */
#glow {
  pointer-events: none;
  box-shadow: inset 0 0 calc(40px + 120px * var(--glow-strength)) calc(10px * var(--glow-strength))
    var(--glow-color);
  opacity: var(--glow-strength);
  transition:
    opacity 0.8s ease,
    box-shadow 0.8s ease;
}

body.hot #glow {
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: calc(var(--glow-strength) * 0.45);
  }
}

/* ---------- intro ---------- */

#intro {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background: var(--night);
}

.intro-card {
  width: min(360px, 100%);
  text-align: center;
}

h1 {
  margin-bottom: 12px;
  font-size: 2.4rem;
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink);
}

.lede {
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1.45;
}

#begin {
  width: 100%;
  margin-top: 28px;
  padding: 15px 20px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: var(--night);
  font-size: 1.15rem;
}

#begin:disabled {
  opacity: 0.5;
  cursor: wait;
}

.fine {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

.error {
  margin-top: 14px;
  color: #ffb4a2;
}

/* ---------- hunting HUD ---------- */

#hud {
  position: fixed;
  z-index: 10;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}

.reading {
  width: min(420px, 100%);
  padding: 12px 16px;
  text-align: center;
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  border-radius: 18px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

#temp {
  font-size: 2rem;
  line-height: 1.1;
  color: var(--glow-color);
  text-shadow: 0 0 14px color-mix(in srgb, var(--glow-color) 60%, transparent);
  transition: color 0.6s ease;
}

#distance {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

#hint {
  color: var(--muted);
  font-style: italic;
}

#compass {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(14, 8, 26, 0.55) 58%, rgba(255, 209, 102, 0.12) 60%, transparent 71%);
  border: 1px solid var(--glass-edge);
}

#needle {
  position: absolute;
  inset: 10px;
  will-change: transform;
  filter: drop-shadow(0 0 10px rgba(255, 94, 26, 0.65));
}

#needle svg {
  width: 100%;
  height: 100%;
}

/* Without a compass the needle shows the bearing from north, so mark north */
.north {
  display: none;
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--gold);
  font-size: 0.8rem;
}

body.no-compass .north {
  display: block;
}

body.revealed #compass {
  display: none;
}

/* ---------- small bits ---------- */

#test-badge {
  position: fixed;
  z-index: 20;
  left: 14px;
  bottom: max(18px, env(safe-area-inset-bottom));
  padding: 4px 10px;
  border-radius: 6px;
  background: #ff3864;
  color: #fff;
  font: 700 0.75rem system-ui, sans-serif;
  letter-spacing: 0.08em;
}

#toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 70px));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(20, 10, 34, 0.92);
  border: 1px solid var(--glass-edge);
  text-align: center;
  font-size: 1rem;
  animation: fade-in 0.3s ease;
}

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