:root {
  --paper: #e8d5b0;
  --ink: #2a1c10;
  --gold: #e8c547;
  --treasure: #e03c3c;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Outfit", system-ui, sans-serif;
  background: #081420;
  color: #fff;
}

.hidden { display: none !important; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.layer { position: fixed; z-index: 10; }
.layer--intro { inset: 0; z-index: 100; }
.layer--hud { top: 0; left: 0; right: 0; z-index: 30; }
.layer--hotspots { inset: 0; z-index: 20; pointer-events: none; }
.layer--hint { bottom: calc(0.8rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 25; pointer-events: none; }

/* Intro */
.layer--intro {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  background: radial-gradient(ellipse 70% 50% at 50% 20%, rgba(26,74,92,0.6), transparent),
              linear-gradient(180deg, rgba(8,20,32,0.5), rgba(8,20,32,0.95));
}

.intro-card {
  position: relative;
  max-width: 22rem;
  text-align: center;
}

.intro-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle, rgba(232,197,71,0.15), transparent 65%);
  pointer-events: none;
}

.intro-tag {
  font-family: "Caveat", cursive;
  font-size: 1.5rem;
  color: var(--gold);
  margin-bottom: 0.25rem;
}

.intro-card h1 {
  font-family: "IM Fell English", serif;
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  font-weight: 400;
  margin-bottom: 0.75rem;
}

.intro-text {
  font-size: 0.92rem;
  line-height: 1.55;
  color: rgba(255,255,255,0.7);
  margin-bottom: 1.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  min-width: 3rem;
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.12s;
}
.btn:active { transform: scale(0.95); }

.btn--gold {
  background: linear-gradient(135deg, #f0d060, #c9a227);
  color: var(--ink);
  box-shadow: 0 8px 32px rgba(232,197,71,0.35);
}

.btn--ghost {
  background: rgba(255,255,255,0.08);
  color: var(--ink);
  border: 1.5px solid rgba(42,28,16,0.25);
  flex: 1;
}

.btn--icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: rgba(0,0,0,0.45);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  font-size: 1.1rem;
}

/* HUD */
.layer--hud {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: calc(0.7rem + env(safe-area-inset-top)) 1rem 0.5rem;
}

.hud-mark {
  font-family: "IM Fell English", serif;
  font-weight: bold;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  background: rgba(0,0,0,0.5);
  border-radius: 5px;
}

.hud-count {
  flex: 1;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
}

/* Pins — real HTML buttons, positioned by JS (fallback % in HTML) */
.pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  padding: 8px;
  min-width: 56px;
  min-height: 56px;
  z-index: 1;
}

.pin__beacon {
  display: block;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8c0, var(--gold) 50%, #a07000);
  border: 2.5px solid var(--ink);
  box-shadow: 0 0 20px rgba(232,197,71,0.7), 0 4px 12px rgba(0,0,0,0.4);
  pointer-events: none;
  transition: transform 0.2s var(--ease);
}

.pin__label {
  font-family: "Caveat", cursive;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.65);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.pin.is-next .pin__beacon { animation: beacon-pulse 1.6s ease infinite; }
.pin.is-visited .pin__beacon { background: radial-gradient(circle at 35% 30%, #c0ffc0, #5a9e5a 50%, #2a602a); box-shadow: 0 0 16px rgba(90,158,90,0.6); }
.pin.is-active .pin__beacon { transform: scale(1.2); }

@keyframes beacon-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(232,197,71,0.7), 0 0 0 0 rgba(232,197,71,0.4); }
  50% { box-shadow: 0 0 28px rgba(232,197,71,0.9), 0 0 0 10px rgba(232,197,71,0); }
}

.pin--x .pin__x {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  font-family: "IM Fell English", serif;
  font-size: 2.2rem;
  font-weight: bold;
  color: var(--treasure);
  text-shadow: 0 0 20px rgba(224,60,60,0.8);
  pointer-events: none;
}

.pin--x.is-locked .pin__x { opacity: 0.25; }
.pin--x.is-ready .pin__x { animation: x-pulse 1.4s ease infinite; }

@keyframes x-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.layer--hint {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.45);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  white-space: nowrap;
}

/* Panel */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4,8,12,0.65);
  backdrop-filter: blur(3px);
}

.panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  max-height: 82dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  color: var(--ink);
  border-radius: 1.25rem 1.25rem 0 0;
  padding: 1rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 60px rgba(0,0,0,0.5);
  animation: up 0.35s var(--ease);
}

@keyframes up { from { transform: translateY(100%); } to { transform: none; } }

.panel__x {
  position: absolute;
  top: 0.7rem; right: 0.8rem;
  width: 2.25rem; height: 2.25rem;
  border: none; border-radius: 50%;
  background: rgba(42,28,16,0.1);
  font-size: 1.4rem; cursor: pointer;
  touch-action: manipulation;
  color: var(--ink);
}

.panel__tag { font-family: "Caveat", cursive; font-size: 1.15rem; color: #a07000; }
.panel__title { font-family: "IM Fell English", serif; font-size: 1.65rem; font-weight: 400; margin: 0.1rem 0 0.75rem; }
.panel__img { width: 100%; aspect-ratio: 4/5; object-fit: cover; border: 3px solid var(--ink); margin-bottom: 0.75rem; display: block; }
.panel__body { font-size: 0.92rem; line-height: 1.6; opacity: 0.85; margin-bottom: 0.4rem; }
.panel__cap { font-family: "Caveat", cursive; font-size: 1.1rem; margin-bottom: 1rem; }
.panel__row { display: flex; gap: 0.6rem; }
.panel__row .btn--gold { flex: 1; }
.panel--treasure .panel__img { aspect-ratio: 3/4; object-position: center 15%; }

.toast {
  position: fixed;
  top: calc(3.5rem + env(safe-area-inset-top));
  left: 1rem; right: 1rem;
  z-index: 80;
  padding: 0.85rem 1rem;
  background: rgba(4,8,12,0.92);
  border: 1px solid rgba(232,197,71,0.3);
  border-radius: 0.75rem;
  font-size: 0.85rem;
  color: var(--paper);
}

@media (min-width: 600px) {
  .panel {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, -50%);
    width: min(24rem, 90vw);
    max-height: 85vh;
    border-radius: 1rem;
    animation: pop 0.3s var(--ease);
  }
  @keyframes pop { from { opacity:0; transform:translate(-50%,-50%) scale(0.93); } to { opacity:1; transform:translate(-50%,-50%) scale(1); } }
}

@media (prefers-reduced-motion: reduce) {
  .pin.is-next .pin__beacon, .pin--x.is-ready .pin__x { animation: none; }
}
