:root {
  --bg: #070b14;
  --panel: #0b1220;
  --panel-2: #111827;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --orange: #f97316;
  --amber: #fbbf24;
  --green: #4ade80;
  --stroke: rgba(255,255,255,0.08);
  --font: Inter, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); background: var(--bg); color: var(--ink); }
#map { position: fixed; inset: 0; }

/* Splash */
.splash {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 30%, #1c1917 0%, #070b14 55%, #020617 100%);
  text-align: center;
  transition: opacity 0.7s ease, visibility 0.7s ease;
  overflow: hidden;
}
.splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-kicker {
  font-size: 0.75rem; letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--orange);
  font-weight: 700;
  margin-bottom: 0.75rem;
}
.splash h1 {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  margin: 0 0 0.75rem;
  background: linear-gradient(135deg, #fdba74, #f97316 40%, #fbbf24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.splash-lead {
  max-width: 32rem; margin: 0 auto 1rem;
  color: var(--muted); line-height: 1.55; font-size: 1rem;
}
.splash-stress {
  max-width: 34rem; margin: 0 auto 1.5rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(74,222,128,0.35);
  background: rgba(6,78,59,0.35);
  color: #d1fae5;
  font-size: 0.92rem;
  line-height: 1.5;
}
.splash-stress strong { color: var(--green); }
.splash-start {
  border: none; cursor: pointer;
  background: linear-gradient(135deg, #ea580c, #f97316);
  color: #1c0900;
  font-weight: 800; font-size: 1rem;
  padding: 0.85rem 1.6rem; border-radius: 999px;
  font-family: inherit;
  box-shadow: 0 12px 40px -12px rgba(249,115,22,0.7);
}
.splash-hint { margin-top: 1rem; font-size: 0.75rem; color: #64748b; }

/* Layout shell */
.shell {
  position: fixed; inset: 0; z-index: 10;
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  pointer-events: none;
  height: 100dvh;
  max-height: 100dvh;
}
.shell > * { pointer-events: auto; min-height: 0; }
.sidebar {
  background: linear-gradient(180deg, rgba(11,18,32,0.96), rgba(7,11,20,0.98));
  border-right: 1px solid var(--stroke);
  display: flex; flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  backdrop-filter: blur(12px);
  -webkit-overflow-scrolling: touch;
}
.sidebar-head { padding: 1rem 1.1rem 0.75rem; border-bottom: 1px solid var(--stroke); flex-shrink: 0; }
.sidebar-kicker {
  font-size: 0.65rem; letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orange); font-weight: 700;
}
.sidebar h1 {
  margin: 0.25rem 0 0.35rem;
  font-size: 1.35rem; font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fdba74, #f97316);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.sidebar-sub { margin: 0; font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--stroke);
  flex-shrink: 0;
}
.audio-btn, .layer-btn, .nav-btn {
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  font-family: inherit; font-weight: 600; font-size: 0.75rem;
  padding: 0.4rem 0.65rem; border-radius: 999px; cursor: pointer;
}
.audio-btn:hover { border-color: rgba(255,255,255,0.25); }
.audio-btn.on {
  border-color: rgba(251, 191, 36, 0.5);
  background: rgba(251,191,36,0.12);
  color: var(--amber);
}
.layer-btn.on {
  border-color: rgba(249, 115, 22, 0.5);
  background: rgba(249,115,22,0.12);
  color: var(--orange);
}
.toolbar-note { font-size: 0.68rem; color: #64748b; }

.progress-wrap { padding: 0.5rem 1rem 0.25rem; flex-shrink: 0; }
.progress-label { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.3rem; }
.progress-bar {
  height: 4px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden;
}
#progressFill {
  height: 100%; width: 16%;
  background: linear-gradient(90deg, #ea580c, #fbbf24);
  border-radius: 999px;
}

.story-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 1rem 0.85rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chapter-card {
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 1rem 1.05rem;
  margin-bottom: 0.7rem;
  cursor: pointer;
  transition: all 0.25s ease;
  background: rgba(255,255,255,0.04);
}
.chapter-card:hover {
  border-color: rgba(249,115,22,0.45);
  background: rgba(249,115,22,0.06);
  transform: translateX(3px);
}
.chapter-card.active {
  border-color: var(--orange);
  background: linear-gradient(135deg, rgba(249,115,22,0.2), rgba(15,23,42,0.95));
  box-shadow: 0 0 0 1px rgba(249,115,22,0.35), 0 12px 40px -16px rgba(249,115,22,0.45);
}
.chapter-card.christian-heavy.active {
  border-color: rgba(74,222,128,0.55);
  background: linear-gradient(135deg, rgba(74,222,128,0.12), rgba(249,115,22,0.06));
  box-shadow: 0 0 0 1px rgba(74,222,128,0.25), 0 12px 40px -20px rgba(74,222,128,0.25);
}
.chapter-card .era {
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
  font-weight: 700;
}
.chapter-card h3 {
  margin: 0.25rem 0 0.4rem;
  font-size: 1.12rem;
  font-weight: 800;
  color: #f8fafc;
  letter-spacing: -0.02em;
}
.chapter-card > p {
  margin: 0;
  font-size: 0.88rem;
  color: #e2e8f0;
  line-height: 1.55;
}

.plate {
  display: none;
  margin-top: 0.65rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  background: #0f172a;
}
.chapter-card.active .plate { display: block; animation: fadeIn 0.4s ease; }
.plate-visual {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 1.75rem;
  letter-spacing: 0.15em;
}
.chapter-card.active .plate-visual {
  animation: plateGlow 2.5s ease-in-out infinite alternate;
}
@keyframes plateGlow {
  from { filter: brightness(1); }
  to { filter: brightness(1.15); }
}
.plate-visual.samhain { background: linear-gradient(135deg, #431407, #7c2d12); }
.plate-visual.christian { background: linear-gradient(135deg, #052e16, #14532d); }
.plate-visual.blend { background: linear-gradient(135deg, #1c1917, #3f3f46); }
.plate-visual.modern { background: linear-gradient(135deg, #2e1065, #4c1d95); }
.plate-caption {
  padding: 0.5rem 0.7rem;
  font-size: 0.78rem;
  color: #e2e8f0;
  line-height: 1.4;
  border-top: 1px solid var(--stroke);
}

.story-expand {
  display: none;
  margin-top: 0.7rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 0.92rem;
  color: #f1f5f9;
  line-height: 1.7;
}
.story-expand p { margin: 0 0 0.75rem; }
.story-expand p:last-of-type { margin-bottom: 0.5rem; }
.story-expand strong { color: #fde68a; font-weight: 700; }
.chapter-card.active .story-expand { display: block; animation: fadeIn 0.45s ease; }
.story-expand .christian-callout {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(74, 222, 128, 0.4);
  background: linear-gradient(135deg, rgba(6, 78, 59, 0.55), rgba(15, 23, 42, 0.9));
  color: #ecfdf5;
  font-size: 0.88rem;
  line-height: 1.6;
  font-weight: 500;
}
.story-expand .christian-callout::before {
  content: "✝ Christian thread · ";
  color: #4ade80;
  font-weight: 800;
  letter-spacing: 0.02em;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.nav-row {
  display: flex; gap: 0.5rem; padding: 0.65rem 1rem 1rem;
  border-top: 1px solid var(--stroke);
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  padding: 0.55rem;
  font-size: 0.85rem;
}
.nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.nav-btn.primary {
  background: linear-gradient(135deg, #ea580c, #f97316);
  border-color: transparent;
  color: #1c0900;
  font-weight: 800;
}

.map-chrome {
  position: relative;
  pointer-events: none;
}
.map-chrome .hint {
  position: absolute; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,0.85);
  border: 1px solid var(--stroke);
  padding: 0.5rem 0.9rem; border-radius: 999px;
  font-size: 0.8rem; color: var(--muted);
  pointer-events: none;
}
.map-chrome .hint.hide { display: none; }

.popup-card { max-width: 260px; }
.popup-card h4 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.popup-card p { margin: 0 0 0.4rem; font-size: 0.8rem; color: #cbd5e1; line-height: 1.45; }
.popup-card .src { font-size: 0.68rem; color: #64748b; }

.maplibregl-popup-content {
  background: #0f172a !important;
  color: var(--ink) !important;
  border-radius: 12px !important;
  border: 1px solid var(--stroke);
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
  padding: 0.75rem 0.9rem !important;
}
.maplibregl-popup-tip { border-top-color: #0f172a !important; }

.marker-wrap { position: relative; width: 36px; height: 36px; }
.marker-inner {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: #111827; border: 2px solid rgba(249,115,22,0.7);
  font-size: 1rem;
  box-shadow: 0 0 16px rgba(249,115,22,0.35);
  cursor: pointer;
}
.marker-pulse {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid rgba(249,115,22,0.45);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(0.85); opacity: 0.8; }
  100% { transform: scale(1.45); opacity: 0; }
}

.leaf {
  position: fixed; z-index: 90; pointer-events: none;
  width: 12px; height: 12px; border-radius: 2px 10px;
  background: #ea580c; opacity: 0;
  animation: fall linear infinite;
}
@keyframes fall {
  0%   { transform: translateY(100vh) scale(0.4); opacity: 0; }
  10%  { opacity: 0.65; }
  90%  { opacity: 0.45; }
  100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}

/* ---- Responsive: story readable & not stuck at bottom ---- */

/* Tablets / iPad — story column on the LEFT */
@media (min-width: 768px) and (max-width: 1100px) {
  .shell {
    grid-template-columns: minmax(300px, 360px) 1fr;
    grid-template-rows: 1fr;
  }
  .sidebar {
    position: relative;
    height: 100dvh;
    max-height: 100dvh;
    border-right: 1px solid var(--stroke);
  }
}

/* Phones — pin story panel to TOP (not under the map) */
@media (max-width: 767px) {
  .shell {
    display: block;
    height: 100dvh;
    pointer-events: none;
  }
  .map-chrome {
    position: fixed;
    left: 0;
    right: 0;
    top: 52dvh;
    bottom: 0;
    pointer-events: none;
  }
  .sidebar {
    position: fixed !important;
    left: 0;
    right: 0;
    top: 0 !important;
    bottom: auto !important;
    height: 52dvh;
    max-height: 52dvh;
    z-index: 30;
    border-right: none;
    border-bottom: 1px solid rgba(249, 115, 22, 0.35);
    box-shadow: 0 12px 40px rgba(0,0,0,0.45);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    order: unset !important;
  }
  .story-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-head { padding: 0.55rem 0.85rem 0.4rem; }
  .sidebar h1 { font-size: 1.05rem; }
  .sidebar-sub { font-size: 0.72rem; }
  .toolbar { padding: 0.4rem 0.75rem; }
  .toolbar-note { display: none; }
  .nav-row { padding: 0.4rem 0.75rem 0.55rem; }
  .chapter-card { padding: 0.7rem 0.8rem; margin-bottom: 0.5rem; }
  .chapter-card h3 { font-size: 1rem; }
  .story-expand { font-size: 0.86rem; line-height: 1.65; }
  .map-chrome .hint { bottom: 0.6rem; font-size: 0.72rem; }
}

/* Landscape phones — story on LEFT */
@media (max-width: 900px) and (orientation: landscape) {
  .shell {
    display: grid !important;
    grid-template-columns: minmax(240px, 40vw) 1fr;
    grid-template-rows: 1fr;
    height: 100dvh;
  }
  .sidebar {
    position: relative !important;
    left: auto;
    right: auto;
    top: auto !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    width: auto;
    z-index: 30;
    border-bottom: none;
    border-right: 1px solid var(--stroke);
    box-shadow: none;
  }
  .map-chrome {
    position: relative !important;
    top: auto !important;
    left: auto;
    right: auto;
    bottom: auto;
    height: 100%;
  }
}
