:root {
  --bg-parchment: #f6efe0;
  --bg-card: #fcf8ef;
  --bg-inset: #efe4cc;
  --ink-primary: #1f2833;
  --ink-muted: #525b66;
  --brass: #a67423;
  --brass-bright: #d4a448;
  --ocean-deep: #153448;
  --ocean-teal: #1e5f74;
  --border-vintage: #d8c8a8;
  --good-bg: #ebf5ee;
  --good-border: #2d6a4f;
  --bad-bg: #fbeeee;
  --bad-border: #9e2a2b;
  --disc-bg: #eef4f8;
  --disc-border: #1e5f74;
  --tech-bg: #fbf2e1;
  --tech-border: #a67423;
  --shadow-soft: 0 8px 24px rgba(31, 40, 51, 0.12);
}

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

body {
  font-family: 'Noto Sans Gujarati', 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-parchment);
  color: var(--ink-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mono {
  font-family: 'IBM Plex Mono', monospace;
}

/* Header */
.topbar {
  background: linear-gradient(135deg, #132838 0%, #1d3c52 100%);
  color: #f8f2e4;
  padding: 0.6rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  border-bottom: 3px solid var(--brass-bright);
  z-index: 20;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-text {
  min-width: 0;
}

.compass-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(212, 164, 72, 0.16);
  border: 1.5px solid var(--brass-bright);
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.app-title {
  font-family: 'Playfair Display', 'Noto Sans Gujarati', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff9eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-subtitle {
  font-size: 0.76rem;
  color: #d6cbb5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

/* Segmented Mode Switch + Language Switch */
.mode-switch,
.lang-switch {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(212, 164, 72, 0.45);
  border-radius: 8px;
  padding: 2px;
}

.mode-btn,
.lang-btn {
  border: none;
  background: transparent;
  color: #d7ccb7;
  padding: 0.32rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s;
}

.mode-btn.active {
  background: #f5e6c8;
  color: #153448;
}

.lang-btn.active {
  background: var(--brass-bright);
  color: #16222f;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 0.36rem 0.7rem;
  border-radius: 8px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: rgba(212, 164, 72, 0.28);
}

/* Main Split Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1.32fr 1fr;
  min-height: 0;
}

/* Map Section */
.map-section {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #d8e4e8;
  border-right: 2px solid var(--border-vintage);
}

.map-canvas {
  flex: 1;
  width: 100%;
  min-height: 300px;
  z-index: 1;
}

.leaflet-container {
  font-family: 'Noto Sans Gujarati', 'Inter', sans-serif;
  background: #c7d9e2;
}

/* Floating HUD */
.map-hud {
  position: absolute;
  top: 12px;
  left: 52px;
  z-index: 500;
  background: rgba(252, 248, 239, 0.93);
  backdrop-filter: blur(6px);
  border: 1.5px solid var(--brass);
  border-radius: 10px;
  padding: 0.42rem 0.72rem;
  box-shadow: var(--shadow-soft);
  max-width: 245px;
  pointer-events: none;
}

.hud-stop-badge {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--brass);
}

.hud-date {
  font-family: 'Playfair Display', 'Noto Sans Gujarati', serif;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ocean-deep);
  margin-top: 1px;
}

.hud-location {
  font-size: 0.74rem;
  color: var(--ink-muted);
  margin-top: 1px;
}

.map-view-tools {
  position: absolute;
  top: 12px;
  right: 58px;
  z-index: 500;
  display: flex;
  gap: 0.4rem;
}

.map-tool-btn {
  background: rgba(252, 248, 239, 0.94);
  border: 1.5px solid var(--brass);
  color: var(--ocean-deep);
  padding: 0.36rem 0.65rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
  transition: background 0.15s, transform 0.15s;
}

.map-tool-btn:hover {
  background: #f5e6c8;
  transform: translateY(-1px);
}

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: 14px;
  left: 14px;
  z-index: 500;
  background: rgba(252, 248, 239, 0.92);
  border: 1px solid var(--border-vintage);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  font-size: 0.71rem;
}

.legend-title {
  font-weight: 700;
  color: var(--ocean-deep);
  margin-bottom: 4px;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
}

.legend-items span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-items em {
  font-style: normal;
  color: var(--ink-primary);
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.leg-atlantic { background: #1e5f74; }
.leg-sa { background: #2d6a4f; }
.leg-patagonia { background: #9c6644; }
.leg-andes { background: #b5651d; }
.leg-galapagos { background: #c1121f; }
.leg-pacific { background: #0077b6; }
.leg-home { background: #6d597a; }

/* Single-Line Top Voyage Milestone Ribbon */
.voyage-ribbon {
  background: #1a2d3d;
  color: #f8f2e4;
  padding: 0.42rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  border-bottom: 2px solid var(--brass);
  flex-shrink: 0;
  z-index: 18;
}

.playback-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.ctrl-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #f8f2e4;
  border: 1px solid rgba(212, 164, 72, 0.42);
  width: 30px;
  height: 30px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  display: grid;
  place-items: center;
  transition: all 0.15s;
}

.ctrl-btn:hover:not(:disabled) {
  background: rgba(212, 164, 72, 0.25);
}

.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.play-btn {
  background: var(--brass-bright);
  color: #16222f;
  font-weight: 700;
  width: 34px;
}

.play-btn:hover:not(:disabled) {
  background: #e5b75a;
}

.speed-btn {
  width: auto;
  padding: 0 0.5rem;
  font-size: 0.74rem;
  font-weight: 700;
}

.milestone-track-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
}

.milestone-segments {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(22, 1fr);
  gap: 3px;
  align-items: end;
  height: 28px;
}

.milestone-seg {
  position: relative;
  height: 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.38;
  transition: transform 0.15s, opacity 0.15s, height 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
}

.milestone-seg.visited {
  opacity: 0.86;
  height: 19px;
}

.milestone-seg.active {
  opacity: 1;
  height: 26px;
  box-shadow: 0 0 0 2px #fff9eb, 0 2px 8px rgba(0, 0, 0, 0.45);
  transform: translateY(-1px);
  z-index: 2;
}

.milestone-seg:hover {
  opacity: 1;
  height: 24px;
}

.sr-slider {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ribbon-readout {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(212, 164, 72, 0.4);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.74rem;
  color: #f8ebd0;
  white-space: nowrap;
  flex-shrink: 0;
}

.ribbon-step {
  font-weight: 700;
  color: var(--brass-bright);
}

.ribbon-sep {
  opacity: 0.55;
}

/* Custom Map Markers */
.beagle-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  display: grid;
  place-items: center;
  border: 2px solid #fffdf7;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.beagle-marker.active {
  transform: scale(1.28);
  box-shadow: 0 0 0 5px rgba(212, 164, 72, 0.55), 0 4px 10px rgba(0, 0, 0, 0.45);
  z-index: 900 !important;
}

.ship-icon {
  font-size: 28px;
  line-height: 1;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.45));
  display: inline-block;
  transform-origin: center center;
  will-change: transform;
}

/* Story Panel (Right) */
.story-panel {
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.story-header {
  padding: 0.9rem 1.2rem 0.7rem;
  background: linear-gradient(180deg, #efe4cc 0%, #fcf8ef 100%);
  border-bottom: 1px solid var(--border-vintage);
}

.story-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.74rem;
  color: var(--ink-muted);
  margin-bottom: 0.3rem;
}

.stop-order-pill {
  background: var(--ocean-deep);
  color: #f8e4b5;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.stop-date-banner {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--brass);
  margin-bottom: 0.2rem;
}

.stop-title {
  font-family: 'Playfair Display', 'Noto Sans Gujarati', serif;
  font-size: 1.24rem;
  line-height: 1.3;
  color: var(--ocean-deep);
}

.stop-region {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-top: 0.18rem;
}

/* Inline Mode Banner inside Story Header */
.panel-mode-bar {
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--border-vintage);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.mode-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 6px;
}

.mode-badge.simple {
  background: #e5f2ea;
  color: #1f5c3d;
}

.mode-badge.tech {
  background: #f8e8c8;
  color: #7c4d0f;
}

.inline-mode-link {
  border: none;
  background: transparent;
  color: var(--ocean-teal);
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.inline-mode-link:hover {
  color: var(--brass);
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem 1.15rem;
  background: #f5ebd6;
  border-bottom: 1px solid var(--border-vintage);
  overflow-x: auto;
  flex-shrink: 0;
}

.tab-btn {
  border: 1px solid var(--border-vintage);
  background: var(--bg-card);
  color: var(--ink-primary);
  padding: 0.32rem 0.68rem;
  border-radius: 999px;
  font-size: 0.77rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--ocean-deep);
  color: #fff6e0;
  border-color: var(--ocean-deep);
}

/* Scrollable Story Body */
.story-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.95rem 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.stop-summary {
  font-size: 0.93rem;
  line-height: 1.65;
  color: #242f3d;
}

/* Mode 2 Visibility Control */
body.mode-simple .tech-study-stack {
  display: none;
}

body.mode-tech .tech-study-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.tech-prose {
  font-size: 0.89rem;
  line-height: 1.68;
  color: #26313e;
}

.tech-prose p + p {
  margin-top: 0.72rem;
}

.sec-tech-narrative {
  background: #fdf6e7;
  border-color: rgba(166, 116, 35, 0.35);
  border-left: 4px solid var(--brass);
}

.sec-tech-metrics {
  background: #edf4f9;
  border-color: rgba(21, 52, 72, 0.25);
  border-left: 4px solid var(--ocean-deep);
}

.sec-tech-instruments {
  background: #f2f1f8;
  border-color: rgba(92, 75, 138, 0.28);
  border-left: 4px solid #5c4b8a;
}

.sec-tech-legacy {
  background: #eef7f2;
  border-color: rgba(45, 106, 79, 0.28);
  border-left: 4px solid #2d6a4f;
}

.darwin-quote {
  background: #f3ead4;
  border-left: 4px solid var(--brass);
  padding: 0.72rem 0.95rem;
  border-radius: 0 10px 10px 0;
  font-style: italic;
  font-size: 0.87rem;
  line-height: 1.55;
  color: #2c3540;
}

.darwin-quote footer {
  margin-top: 0.32rem;
  font-style: normal;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--brass);
}

.card-section {
  border-radius: 10px;
  padding: 0.82rem 0.95rem;
  border: 1px solid var(--border-vintage);
}

.card-section h3 {
  font-size: 0.88rem;
  margin-bottom: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card-section ul {
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  font-size: 0.86rem;
  line-height: 1.55;
}

.sec-discoveries {
  background: var(--disc-bg);
  border-color: rgba(30, 95, 116, 0.25);
  border-left: 4px solid var(--disc-border);
}

.sec-good {
  background: var(--good-bg);
  border-color: rgba(45, 106, 79, 0.25);
  border-left: 4px solid var(--good-border);
}

.sec-bad {
  background: var(--bad-bg);
  border-color: rgba(158, 42, 43, 0.25);
  border-left: 4px solid var(--bad-border);
}

.sec-photos {
  background: #f8f2e3;
}

/* Photo Grid */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.7rem;
  margin-top: 0.45rem;
}

.photo-card {
  background: #fff;
  border: 1px solid var(--border-vintage);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s;
  display: flex;
  flex-direction: column;
}

.photo-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.photo-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
  background: #e9e0cc;
}

.photo-fallback {
  height: 130px;
  display: grid;
  place-items: center;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.74rem;
  color: var(--ink-muted);
  background: #efe4cc;
}

.photo-card-cap {
  padding: 0.45rem 0.55rem;
  font-size: 0.74rem;
  line-height: 1.38;
  color: var(--ink-primary);
}

.photo-card-credit {
  padding: 0 0.55rem 0.45rem;
  font-size: 0.67rem;
  color: var(--ink-muted);
}

/* Story Footer */
.story-footer {
  padding: 0.6rem 1.2rem;
  background: #efe4cc;
  border-top: 1px solid var(--border-vintage);
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.nav-pill {
  flex: 1;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border-vintage);
  background: var(--bg-card);
  color: var(--ink-primary);
  font-weight: 600;
  font-size: 0.83rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.nav-pill:hover:not(:disabled) {
  background: #e8dac0;
}

.nav-pill.primary {
  background: var(--ocean-deep);
  color: #fff6e0;
  border-color: var(--ocean-deep);
}

.nav-pill.primary:hover:not(:disabled) {
  background: var(--ocean-teal);
}

.nav-pill:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 20, 29, 0.72);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  background: var(--bg-card);
  border: 2px solid var(--brass);
  border-radius: 14px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: var(--ocean-deep);
  color: #fff;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
}

.lightbox-card img {
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: 8px;
  background: #111821;
}

.lightbox-caption {
  margin-top: 0.75rem;
  font-size: 0.92rem;
  line-height: 1.5;
}

.lightbox-meta {
  margin-top: 0.45rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.lightbox-meta a {
  color: var(--ocean-teal);
  font-weight: 600;
}

.sources-card h2 {
  font-family: 'Playfair Display', 'Noto Sans Gujarati', serif;
  color: var(--ocean-deep);
  margin-bottom: 0.6rem;
  padding-right: 2rem;
}

.sources-card p {
  font-size: 0.9rem;
  line-height: 1.55;
  margin-bottom: 0.8rem;
}

.sources-list {
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.88rem;
}

.sources-list a {
  color: var(--ocean-teal);
  font-weight: 600;
}

.sources-note {
  margin-top: 1rem;
  padding: 0.7rem 0.9rem;
  background: #efe4cc;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.hidden-section {
  display: none !important;
}

/* Responsive Mobile & Tablet */
@media (max-width: 1024px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .voyage-ribbon {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
  }

  .milestone-track-wrap {
    order: 3;
    flex-basis: 100%;
  }

  .ribbon-readout {
    margin-left: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 54vh auto;
  }

  .map-section {
    border-right: none;
    border-bottom: 2px solid var(--border-vintage);
    height: 54vh;
  }

  .map-hud {
    left: 50px;
    top: 10px;
    padding: 0.45rem 0.7rem;
    max-width: 230px;
  }

  .map-legend {
    display: none;
  }

  .story-panel,
  .story-body {
    overflow: visible;
  }
}
