:root {
  --bg: #0f1420;
  --panel: #161d2e;
  --panel-2: #1e2740;
  --line: #2a3550;
  --text: #e8ecf5;
  --muted: #93a0bd;
  --accent: #ff7a59;
  --accent-2: #6ea8ff;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

/* The [hidden] attribute must win over class rules like display:flex */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  text-transform: lowercase; /* whole app renders lowercase (see .cap for the exceptions) */
}

/* form controls don't inherit text-transform by default — make them lowercase too */
button, input, select, textarea {
  text-transform: inherit;
}

/* the only letters allowed to show uppercase — the hidden "Capitals" clues */
.cap {
  text-transform: uppercase;
}

.shell {
  display: flex;
  height: 100vh;
}

.app {
  flex: 1;
  min-width: 0; /* let the map column shrink beside the sidebar */
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* a grid column defaults to auto = max-content, so a long step dock sized this
     column to ~2400px and widened the whole page. minmax(0,1fr) caps it at the
     container so the dock scrolls instead. */
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
}

/* ---------- Inventory sidebar ---------- */
.sidebar {
  width: 88px;
  flex: 0 0 88px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px 10px;
}

.inv-title {
  font-size: 10px;
  text-transform: lowercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 14px;
}

.inv-empty {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  opacity: 0.6;
}

.inv-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.inv-item {
  width: 100%;
  display: flex;
  justify-content: center;
}

.inv-icon {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, border-color 0.12s ease;
  cursor: default;
}

.inv-item:hover .inv-icon {
  transform: translateY(-2px);
  border-color: var(--accent-2);
}

.inv-emoji {
  font-size: 28px;
  line-height: 1;
}

.inv-img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

/* draggable items are quiet easter eggs — no glow/highlight, just a grab cursor if you find them */
.inv-item[draggable="true"] .inv-icon {
  cursor: grab;
}

.inv-item[draggable="true"] .inv-icon:active {
  cursor: grabbing;
}

/* Draggable "place-me" pin dropped on the map */
.place-pin-marker {
  font-size: 30px;
  line-height: 1;
  text-align: center;
  cursor: grab;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.55));
}

.place-pin-marker:active {
  cursor: grabbing;
}

/* Finale panel — the proposal */
.detail.finale .detail-body {
  text-align: center;
  padding: 30px 26px 40px;
}

.detail.finale .detail-meta {
  justify-content: center;
}

.detail.finale .detail-desc {
  font-size: 25px;
  line-height: 1.5;
  font-weight: 600;
  color: #fff;
}

.inv-qty {
  position: absolute;
  right: -6px;
  bottom: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1000;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(180deg, var(--panel), rgba(22, 29, 46, 0.85));
  border-bottom: 1px solid var(--line);
  z-index: 500;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 122, 89, 0.2);
}

.brand h1 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.2px;
  margin: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.event-count {
  color: var(--muted);
  font-size: 13px;
}

.mode-toggle {
  display: flex;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--accent);
  color: #1a1000;
}

.mode-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Map ---------- */
.map-wrap {
  container-type: size; /* enables cqw/cqh units below */
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--bg);
  min-height: 0; /* let the grid row shrink so the map can fit */
}

/* Fixed 16:9 rectangle, scaled to fit whichever axis is tighter. */
#map {
  --ratio: calc(16 / 9);
  aspect-ratio: 16 / 9;
  height: min(100cqh, calc(100cqw / var(--ratio)));
  width: auto;
  max-width: 100%;
  background: #0b101a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden; /* clip tiles to the rounded rectangle */
  box-shadow: var(--shadow);
}

/* Custom pin markers */
.pin {
  width: 26px;
  height: 26px;
  border-radius: 50% 50% 50% 0;
  background: var(--accent);
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, background 0.15s ease;
}

.pin::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.pin-wrap:hover .pin {
  transform: rotate(-45deg) scale(1.15);
  background: var(--accent-2);
}

/* Auto-drop: a pin falls onto its spot when a stage unlocks. Uses the
   `translate` property so it composes with Leaflet's positioning transform. */
.pin-drop {
  animation: pinDrop 0.6s cubic-bezier(0.3, 1.5, 0.55, 1) both;
}

/* a newly unlocked pin is held invisible until the camera arrives */
.pin-pending {
  opacity: 0 !important;
}
@keyframes pinDrop {
  0% { translate: 0 -80px; opacity: 0; }
  15% { opacity: 1; }
  100% { translate: 0 0; opacity: 1; }
}

/* Frontier pin — unlocked but unsolved, the current "play me" target */
.pin.frontier {
  background: var(--accent-2);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 0 0 rgba(110, 168, 255, 0.5);
  }
  50% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 0 10px rgba(110, 168, 255, 0);
  }
}

/* Locked pin — visible but mysterious */
.pin.locked {
  background: #55617e;
  border-color: rgba(255, 255, 255, 0.55);
  opacity: 0.85;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cfd6e6;
  font-size: 12px;
  font-weight: 800;
}

.pin.locked::after {
  display: none;
}

/* the "?" glyph sits inside the rotated pin, so counter-rotate it */
.pin.locked {
  transform: rotate(-45deg);
}

.pin.locked > * {
  transform: rotate(45deg);
}

/* ---------- Popup card ---------- */
.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 0;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0;
  width: 320px !important;
}

.leaflet-popup-tip {
  background: var(--panel);
  border: 1px solid var(--line);
}

.leaflet-popup-close-button {
  color: var(--muted) !important;
  padding: 10px 10px 0 0 !important;
}

.card-photo {
  width: 100%;
  height: auto;
  max-height: 46vh; /* cap tall photos so the popup never runs off-screen */
  object-fit: contain; /* show the WHOLE photo, no cropping */
  display: block;
  background: #0b101a; /* clean letterbox for portrait shots */
}

.card-body {
  padding: 16px 18px 20px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.card-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
}

.card-title {
  font-size: 19px;
  font-weight: 650;
  margin: 0 0 8px;
}

.card-desc {
  font-size: 14px;
  line-height: 1.55;
  color: #c7d0e4;
  margin: 0;
}

.card-pad {
  padding: 16px 18px 18px;
}

.play-btn {
  margin-top: 14px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  background: var(--accent);
  color: #1a1000;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.play-btn:hover {
  filter: brightness(1.06);
}

/* ---------- Prompt dialog (welcome / clue) ---------- */
.prompt-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 9, 16, 0.66);
  opacity: 0;
  transition: opacity 0.26s ease;
}

.prompt-overlay.open {
  opacity: 1;
}

.prompt-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 30px 28px 28px;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}

.prompt-overlay.open .prompt-card {
  transform: translateY(0) scale(1);
}

.prompt-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 19px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.prompt-close:hover {
  color: var(--text);
}

.prompt-eyebrow {
  text-transform: lowercase;
  letter-spacing: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.prompt-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 14px;
}

.prompt-text {
  font-size: 15px;
  line-height: 1.6;
  color: #dbe2f0;
  margin: 0 0 14px;
}

.prompt-img {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
  margin-top: 6px;
}

/* ---------- Slide-in detail panel ---------- */
.detail {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(440px, 92vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 44px rgba(0, 0, 0, 0.45);
  transform: translateX(100%);
  transition: transform 0.34s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.detail.open {
  transform: translateX(0);
}

.detail-scroll {
  height: 100%;
  overflow-y: auto;
}

.detail-photo {
  width: 100%;
  height: auto;
  display: block;
  background: #0b101a; /* clean backdrop while loading / for any bars */
  transition: opacity 0.25s ease;
}

.detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 20, 32, 0.72);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}

.detail-close:hover {
  background: rgba(15, 20, 32, 0.95);
}

.detail-body {
  padding: 22px 24px 32px;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 12px;
}

.detail-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
}

.detail-desc {
  font-size: 16px;
  line-height: 1.65;
  color: #dbe2f0;
  margin: 0;
}

.detail-actions:not(:empty) {
  margin-top: 18px;
}

.replay-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.replay-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent);
}

/* ---------- Dock (timeline / journey) ---------- */
.dock {
  min-width: 0;
  background: linear-gradient(0deg, var(--panel), rgba(22, 29, 46, 0.85));
  border-top: 1px solid var(--line);
  z-index: 500;
}

.timeline {
  padding: 14px 22px 18px;
}

/* ---------- Journey panel ---------- */
.journey-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 22px;
  min-width: 0;
}

.journey-panel .restart-btn {
  flex: 0 0 auto; /* never let the button be squeezed by a long step track */
}

.journey-info {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0; /* without this the step track grows the page instead of scrolling */
}

.progress {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  max-width: 520px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-radius: 999px;
  transition: width 0.5s ease;
}

.progress-text {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- Step dock (numbered puzzle buttons) ---------- */
.step-track {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
  flex: 1;
  /* a flex item defaults to min-width:auto, which refuses to shrink below its
     content — so overflow-x never engages and the whole page widens instead */
  min-width: 0;
  scroll-behavior: smooth;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.step-track::-webkit-scrollbar {
  height: 8px;
}
.step-track::-webkit-scrollbar-track {
  background: transparent;
}
.step-track::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}
.step-track::-webkit-scrollbar-thumb:hover {
  background: var(--accent-2);
}

.step-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.step-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent-2);
}

.step-btn.current {
  border-color: var(--accent);
  padding: 0 16px;
  animation: pulse-step 1.8s ease-in-out infinite;
}

.step-btn .step-num {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
}

.step-btn.done img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.step-btn .step-loc {
  font-size: 13px;
  font-weight: 600;
  padding-right: 6px;
  white-space: nowrap;
}

@keyframes pulse-step {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(255, 122, 89, 0.5);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(255, 122, 89, 0);
  }
}

.restart-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.restart-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.timeline-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.timeline-label {
  font-size: 12px;
  text-transform: lowercase;
  letter-spacing: 1.5px;
  color: var(--muted);
}

.timeline-track {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.year-chip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 66px;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: all 0.15s ease;
}

.year-chip .count {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.year-chip:hover {
  border-color: var(--accent-2);
  color: var(--text);
}

.year-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1000;
}

.year-chip.active .count {
  color: rgba(26, 16, 0, 0.7);
}

.year-chip.all {
  min-width: auto;
  flex-direction: row;
  padding: 9px 16px;
}

/* ---------- Restart confirmation ---------- */
/* Reuses .prompt-overlay/.prompt-card for the frame; only the actions differ. */
.confirm-card {
  max-width: 400px;
  text-align: center;
  padding: 30px 28px 24px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
}

.confirm-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 10px;
  cursor: pointer;
}

.confirm-btn:hover {
  border-color: var(--accent-2);
  color: var(--text);
}

/* the destructive one — coloured so it can't be hit by muscle memory */
.confirm-btn.danger {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1000;
}

.confirm-btn.danger:hover {
  filter: brightness(1.08);
  color: #1a1000;
}
