:root {
  --parch: #e8dcc0;
  --parch-dark: #c9b98f;
  --ink: #241a10;
  --ember: #d98842;
  --ghost: #6fd8c4;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0a0705;
  font-family: 'IM Fell English', Georgia, serif;
  color: var(--parch);
  -webkit-tap-highlight-color: transparent;
}

#scene-container { position: fixed; inset: 0; }
#scene-container canvas { display: block; transition: filter 0.3s ease; }

/* ---------- vignette + flicker overlays ---------- */
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(ellipse at center,
    rgba(0,0,0,0) 35%, rgba(0,0,0,0.55) 82%, rgba(0,0,0,0.85) 100%);
  mix-blend-mode: multiply;
}
#flicker {
  position: fixed; inset: 0; pointer-events: none; z-index: 6;
  background: rgba(120,60,20,0.04);
  animation: flick 7s infinite steps(1);
  opacity: 0;
}
@keyframes flick {
  0%, 96%, 100% { opacity: 0; }
  96.5% { opacity: 0.25; }
  97% { opacity: 0; }
  97.5% { opacity: 0.4; }
  98% { opacity: 0; }
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 8; pointer-events: none;
  font-family: 'Special Elite', monospace;
  font-size: 13px; letter-spacing: 1px;
  color: rgba(232,220,192,0.65);
  text-shadow: 0 0 8px rgba(0,0,0,0.9);
  transition: opacity 2s ease;
  text-align: center;
  padding: 6px 14px;
  background: rgba(10,7,5,0.35);
  border: 1px solid rgba(217,136,66,0.2);
  border-radius: 2px;
}
#hud.faded { opacity: 0.15; }
#hud .key {
  color: var(--ember);
  letter-spacing: 2px;
}

/* ---------- mute button ---------- */
#mute-btn {
  position: fixed; top: 16px; right: 16px; z-index: 9;
  background: rgba(10,7,5,0.6);
  border: 1px solid rgba(217,136,66,0.35);
  color: rgba(232,220,192,0.75);
  font-family: 'Special Elite', monospace;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.2s;
}
#mute-btn:hover { border-color: var(--ember); color: var(--ember); }
#mute-btn.active { color: var(--ghost); border-color: var(--ghost); box-shadow: 0 0 12px rgba(111,216,196,0.3); }

/* ---------- mobile pad ---------- */
#mobile-pad {
  position: fixed; bottom: 20px; left: 20px; z-index: 8;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  touch-action: none;
}
#mobile-pad.hidden { display: none; }
#mobile-pad .pad-row { display: flex; gap: 6px; }
#mobile-pad button {
  width: 52px; height: 52px;
  background: rgba(10,7,5,0.55);
  border: 1px solid rgba(217,136,66,0.4);
  color: rgba(232,220,192,0.8);
  font-size: 18px;
  border-radius: 4px;
  cursor: pointer;
}
#mobile-pad button:active { background: rgba(217,136,66,0.35); }

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #0a0705;
  transition: opacity 0.8s ease;
}
#loader.gone { opacity: 0; pointer-events: none; }
#loader .lantern {
  font-size: 60px;
  filter: drop-shadow(0 0 30px rgba(217,136,66,0.8));
  animation: sway 3s ease-in-out infinite;
}
@keyframes sway { 0%,100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
#loader .loader-text {
  margin-top: 20px;
  font-family: 'Special Elite', monospace;
  color: rgba(232,220,192,0.6);
  letter-spacing: 2px;
}
.dots::after {
  content: '';
  animation: dots 1.4s steps(4) infinite;
}
@keyframes dots {
  0% { content: ''; } 25% { content: '.'; }
  50% { content: '..'; } 75% { content: '...'; }
}

/* ---------- inspect overlay ---------- */
#inspect-overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4,3,2,0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
#inspect-overlay.hidden { display: none; }
#inspect-overlay.show { opacity: 1; }

#inspect-panel {
  position: relative;
  max-width: 460px; width: calc(100% - 48px);
  padding: 34px 34px 40px;
  color: var(--ink);
  background:
    radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(80,55,20,0.25) 100%),
    linear-gradient(160deg, #eadfc2 0%, #d8c8a0 100%);
  border: 1px solid #a8925f;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), inset 0 0 60px rgba(120,90,40,0.25);
  border-radius: 3px;
  transform: translateY(12px) rotate(-0.4deg);
  transition: transform 0.35s cubic-bezier(.2,.9,.3,1);
}
#inspect-overlay.show #inspect-panel { transform: translateY(0) rotate(-0.4deg); }

#inspect-panel::before {
  content: '';
  position: absolute; inset: 8px;
  border: 1px solid rgba(120,90,40,0.35);
  pointer-events: none;
}

#inspect-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none;
  font-size: 28px; line-height: 1;
  color: #8a6f42; cursor: pointer;
  font-family: Georgia, serif;
}
#inspect-close:hover { color: #5a3a1a; }

#inspect-title {
  font-family: 'IM Fell English', Georgia, serif;
  font-style: italic;
  font-size: 30px;
  font-weight: 400;
  margin-bottom: 18px;
  color: #3a2810;
  border-bottom: 1px solid rgba(120,90,40,0.3);
  padding-bottom: 10px;
}

#inspect-body .hint {
  font-size: 15px;
  color: #6a5230;
  font-style: italic;
  margin-bottom: 18px;
  line-height: 1.5;
}
#inspect-body .msg {
  font-family: 'Special Elite', monospace;
  font-size: 17px;
  line-height: 1.7;
  color: #2a1c0c;
  min-height: 1.7em;
}
#inspect-body .loading { color: #8a6f42; font-style: italic; }

/* ---------- whisper (easter egg) ---------- */
.whisper {
  position: fixed; top: 42%; left: 50%; transform: translate(-50%, -50%);
  z-index: 40; pointer-events: none;
  font-family: 'IM Fell English', serif; font-style: italic;
  font-size: clamp(24px, 6vw, 48px);
  color: rgba(111,216,196,0.9);
  text-shadow: 0 0 30px rgba(111,216,196,0.6);
  letter-spacing: 2px;
  animation: whisperFade 3s ease forwards;
}
@keyframes whisperFade {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.9); letter-spacing: 8px; }
  20% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.05); }
}

/* ---------- footer ---------- */
#foot {
  position: fixed; bottom: 4px; right: 10px; z-index: 8;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
}
#foot a {
  color: rgba(217,136,66,0.4);
  text-decoration: none;
  transition: color 0.2s;
}
#foot a:hover { color: var(--ember); }

@media (max-width: 640px) {
  #hud { font-size: 10px; bottom: 90px; }
  #inspect-title { font-size: 24px; }
  #inspect-body .msg { font-size: 15px; }
}