/* ── Theme variables ──────────────────────────────────────────────────────── */
:root { --slot-empty: #2d2d2d; }

/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0e0e1a;
  color: #e8e8f0;
  overflow: hidden;
  height: 100vh;
}

/* ── Map ──────────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* ── Left control panel ───────────────────────────────────────────────────── */
#control-panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 280px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  background: rgba(14, 14, 30, 0.92);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 18px 20px;
  z-index: 1000;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

#control-panel h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 2px;
}

#control-panel .subtitle {
  font-size: 0.75rem;
  color: #7878a0;
  margin-bottom: 16px;
}

.control-group {
  margin-bottom: 14px;
}

.control-group label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9090b8;
  margin-bottom: 5px;
}

.control-group select,
.control-group input[type="time"] {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 7px;
  color: #e8e8f0;
  padding: 7px 10px;
  font-size: 0.92rem;
  outline: none;
  appearance: none;
  cursor: pointer;
}

.control-group select:focus,
.control-group input[type="time"]:focus {
  border-color: rgba(100,160,255,0.5);
}

.control-group select option {
  background: #0e0e1a;
  color: #e8e8f0;
}

.control-group select option:checked {
  background: #1a1a30;
  color: #ffffff;
}

/* ── Round-trip toggle & dwell input ──────────────────────────────────────── */
.toggle-label {
  display: flex !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-transform: none !important;
  font-size: 0.88rem !important;
  color: #c8c8e8 !important;
}

.toggle-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #9090b8;
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-label input[type="checkbox"]:checked + .toggle-switch {
  background: rgba(100, 128, 204, 0.4);
  border-color: rgba(100, 128, 204, 0.6);
}

.toggle-label input[type="checkbox"]:checked + .toggle-switch::after {
  transform: translateX(16px);
  background: #6480cc;
}

.dwell-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-group input[type="number"] {
  width: 80px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 7px;
  color: #e8e8f0;
  padding: 7px 10px;
  font-size: 0.92rem;
  outline: none;
}

.control-group input[type="number"]:focus {
  border-color: rgba(100,160,255,0.5);
}

.dwell-unit {
  font-size: 0.78rem;
  color: #7878a0;
}

/* ── Return journey panel ────────────────────────────────────────────────── */
#journey-return-panel {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

#journey-return-panel h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7878a0;
  margin-bottom: 10px;
}

/* ── Selection status ─────────────────────────────────────────────────────── */
.selection-status {
  font-size: 0.82rem;
  color: #a0a0c8;
  padding: 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  text-align: center;
  margin-bottom: 12px;
}

.selection-display {
  margin-bottom: 14px;
}

.sel-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0;
  font-size: 0.88rem;
  color: #d8d8f0;
}

.sel-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.from-dot { background: #22c55e; border: 2px solid #22c55e; }
.to-dot   { background: #ef4444; border: 2px solid #ef4444; }

.sel-arrow {
  color: #606080;
  font-size: 1rem;
  flex-shrink: 0;
}

/* Keeps → • DestinationName together as one unbreakable group */
.sel-to {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#reset-btn {
  width: 100%;
  margin-top: 8px;
  padding: 7px;
  background: rgba(180, 50, 50, 0.82);
  border: none;
  border-radius: 7px;
  color: #fff;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#reset-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

#reset-btn:hover { background: rgba(220, 60, 60, 0.92); }

/* ── Journey panel ────────────────────────────────────────────────────────── */
#journey-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

#journey-panel h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7878a0;
  margin-bottom: 10px;
}

.journey-section {
  margin-bottom: 10px;
}

.journey-label-header {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #5050a0;
  font-weight: 700;
  margin-bottom: 5px;
}

.journey-label-header.after { color: #a05050; }

.journey-summary-line {
  font-size: 0.78rem;
  color: #a0a0d0;
  margin-bottom: 5px;
  font-weight: 600;
}

.journey-leg {
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.75rem;
}

.journey-leg:last-child { border-bottom: none; }

.journey-route {
  color: #6878c8;
  font-size: 0.7rem;
  margin-bottom: 1px;
}

.journey-stops {
  color: #c8c8e8;
}

.journey-time {
  color: #8080b0;
  font-size: 0.7rem;
}

.journey-no-service {
  color: #6060a0;
  font-style: italic;
  font-size: 0.78rem;
}

/* ── Stats panel ──────────────────────────────────────────────────────────── */
#stats-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

#stats-panel h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7878a0;
  margin-bottom: 10px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.stats-table th {
  text-align: right;
  color: #7878a0;
  font-weight: 600;
  padding: 3px 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-table th:first-child { text-align: left; }

.stats-table td {
  padding: 4px 4px;
  color: #c8c8e8;
  text-align: right;
}

.stats-table td:first-child {
  text-align: left;
  color: #9090b8;
}

.stats-table tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}

/* ── Bottom panel ─────────────────────────────────────────────────────────── */
#bottom-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(10, 10, 22, 0.95);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 14px 20px 10px;
  z-index: 1000;
  backdrop-filter: blur(10px);
  min-height: 180px;
}

/* ── Route legend (map overlay) ───────────────────────────────────────────── */
#route-legend {
  position: fixed;
  bottom: 248px;
  right: 20px;
  background: rgba(10, 10, 22, 0.88);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 10px 14px;
  z-index: 1001;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.rl-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.72rem;
  color: #b0b0d0;
  margin-bottom: 6px;
}
.rl-row:last-child { margin-bottom: 0; }
.rl-row svg { flex-shrink: 0; }

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10,10,22,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: #a0a0c8;
  z-index: 10;
  border-radius: 0;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.loading-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar-track {
  width: 180px;
  height: 4px;
  background: rgba(255,255,255,0.12);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: #6480cc;
  border-radius: 2px;
  transition: width 0.35s ease;
}

#loading-pct {
  font-size: 0.75rem;
  color: #6480cc;
  min-width: 3ch;
  text-align: center;
}

.spinner {
  width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #6480cc;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Timeline ─────────────────────────────────────────────────────────────── */
#timeline-container { position: relative; }

.timeline-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 5px;
}

.tl-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #5050a0;
  font-weight: 700;
}

.tl-label.after { color: #a05050; }

.tl-summary {
  font-size: 0.78rem;
  color: #9090b8;
}

.timeline-row {
  display: flex;
  width: 100%;
  height: 36px;
  border-radius: 5px;
  overflow: hidden;
  position: relative;
  cursor: crosshair;
  outline: 2px solid transparent;
  outline-offset: 1px;
  transition: outline-color 0.15s;
}

.timeline-row.active-timeline {
  outline-color: rgba(255,255,255,0.35);
}

.timeline-row.inactive-timeline {
  opacity: 0.5;
  transition: opacity 0.15s;
}

.slot-block {
  flex: 1;
  background: var(--slot-empty);
  border-right: 1px solid rgba(0,0,0,0.3);
  transition: filter 0.1s;
  position: relative;
}

.slot-block:last-child { border-right: none; }

.slot-block:hover { filter: brightness(1.35); }

.slot-block.active-slot::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255,255,255,0.7);
  pointer-events: none;
}

/* ── Time axis ────────────────────────────────────────────────────────────── */
.time-axis {
  display: flex;
  justify-content: space-between;
  padding-top: 4px;
  font-size: 0.68rem;
  color: #4a4a70;
}

/* ── Legend ───────────────────────────────────────────────────────────────── */
#legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: #7070a0;
}

.l-box {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── Tooltip ──────────────────────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  background: rgba(12, 12, 28, 0.97);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: #d8d8f0;
  pointer-events: none;
  z-index: 9999;
  max-width: 280px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

#tooltip .tt-time {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 4px;
}

#tooltip .tt-leg {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  color: #b8b8d8;
  font-size: 0.78rem;
}

#tooltip .tt-leg:last-child { border-bottom: none; }

#tooltip .tt-route {
  font-size: 0.7rem;
  color: #6878c8;
  margin-top: 1px;
}

#tooltip .tt-no-service {
  color: #6060a0;
  font-style: italic;
}

/* ── Leaflet stop markers ─────────────────────────────────────────────────── */
.stop-marker-wrapper {
  background: none;
  border: none;
}

/* ── Scrollbar styling ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: rgba(100,100,160,0.4); border-radius: 3px; }

/* ── Share button (fixed above bottom-right of timeline) ─────────────────── */
#share-btn {
  position: fixed;
  bottom: 185px;
  right: 20px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #1a3a8a 0%, #3050c8 100%);
  border: none;
  border-radius: 8px;
  color: #ffffff;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: opacity 0.15s;
  z-index: 1100;
  white-space: nowrap;
}
#share-btn:hover:not(:disabled) { opacity: 0.85; }

.share-icon-desktop {
  width: 16px;
  height: 16px;
  filter: invert(1);
  vertical-align: middle;
  margin-left: 4px;
  flex-shrink: 0;
}
#share-btn:disabled {
  background: linear-gradient(135deg, #2a2a3a 0%, #3a3a50 100%);
  color: #606080;
  cursor: not-allowed;
  opacity: 1;
}

/* ── Share modal ──────────────────────────────────────────────────────────── */
.share-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.share-modal-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
}

.share-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 390px;
  padding: 0 4px;
}

.share-modal-title {
  font-size: 0.88rem;
  color: #a0a0c8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.share-modal-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.share-btn-download {
  background: #3050c8;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.share-btn-download:hover { background: #4060e0; }
.share-btn-download:disabled { opacity: 0.6; cursor: default; }

.share-btn-close {
  position: absolute;
  top: -12px;
  right: -52px;
  background: rgba(255,255,255,0.08);
  color: #c0c0e0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 10;
}
.share-btn-close:hover { background: rgba(255,255,255,0.14); }

/* ── Share card (the PNG target) ─────────────────────────────────────────── */
#share-card {
  width: 480px;
  background: #0e0e1a;
  color: #e8e8f0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  padding: 24px 26px 20px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.06);
  box-sizing: border-box;
}

/* Top bar */
.sc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sc-branding {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.sc-brand-app      { color: #a0a0c8; font-weight: 700; }
.sc-brand-dot      { color: #404060; }
.sc-brand-campaign { color: #d0a030; font-weight: 700; }
.sc-warning-badge {
  background: #8b1a1a;
  color: #ffcccc;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

/* 1. Conclusion headline */
.sc-conclusion {
  font-size: 1.5rem;
  font-weight: 800;
  color: #ff5555;
  line-height: 1.25;
  margin-bottom: 16px;
}

/* 2. Trip comparison block */
.sc-trip-block {
  background: #12122a;
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.sc-trip-route {
  font-size: 0.75rem;
  color: #7070a8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.sc-trip-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
}
.sc-dot        { font-size: 0.68rem; line-height: 1; }
.sc-dot-green  { color: #2e8b57; }
.sc-dot-red    { color: #cc3333; }
.sc-trip-scenario {
  font-size: 0.75rem;
  font-weight: 700;
  color: #9090b8;
  min-width: 76px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sc-trip-after { color: #a05050; }
.sc-trip-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e8e8f0;
}
.sc-trip-after-val { color: #ff7070; }
.sc-trip-value.no-service { color: #554444; }

/* 3. Timeline block */
.sc-tl-block   { margin-bottom: 14px; }
.sc-tl-title {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #5050a0;
  font-weight: 700;
  margin-bottom: 7px;
}
.sc-tl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
.sc-tl-label {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5050a0;
  font-weight: 700;
  min-width: 34px;
}
.sc-tl-after { color: #7a3030; }
.sc-timeline {
  display: flex;
  flex: 1;
  height: 20px;
  border-radius: 3px;
  overflow: hidden;
}
.sc-slot { flex: 1; }

/* 4. Shock block */
.sc-shock-block {
  background: #12122a;
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
  text-align: center;
}
.sc-shock-main {
  font-size: 2rem;
  font-weight: 900;
  color: #ff4444;
  line-height: 1;
  margin-bottom: 5px;
}
.sc-shock-detail {
  font-size: 0.82rem;
  color: #a0a0c8;
}
.sc-shock-wait {
  font-size: 0.75rem;
  color: #7070a8;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.05);
}

/* Footer */
.sc-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 12px;
  text-align: center;
}
.sc-footer-cta {
  font-size: 0.8rem;
  font-weight: 700;
  color: #d0a030;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.sc-footer-sub {
  font-size: 0.62rem;
  color: #404060;
}

/* ── Story Card Carousel ──────────────────────────────────────────────────── */
.carousel-viewport {
  width: 390px;
  height: 700px;
  overflow: hidden;
  border-radius: 14px;
  position: relative;
}

.carousel-track {
  display: flex;
  width: calc(390px * 5);
  height: 100%;
  transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.story-card {
  width: 390px;
  height: 700px;
  flex-shrink: 0;
  background: #08080f;
  color: #e8e8f0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  padding: 28px 24px 20px;
  box-sizing: border-box;
  overflow: hidden;
}

/* Navigation dots */
.carousel-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding-top: 10px;
}
.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  padding: 0;
}
.carousel-dot.active {
  background: #c0392b;
  transform: scale(1.35);
}

/* Arrow buttons — flanking the card */
.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(255,255,255,0.08);
  color: #e8e8f0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.carousel-arrow-left  { left: -56px; }
.carousel-arrow-right { right: -56px; }
.carousel-arrow:hover { background: rgba(255,255,255,0.18); }
.carousel-arrow:disabled { opacity: 0; pointer-events: none; }

/* Slot range label (used in slot-comparison card header) */
.story-slot-range {
  font-size: 0.82rem; color: #8080b0; margin-top: 4px;
}

/* Slot comparison card: chart box */
.story-chart-box {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 14px;
  padding: 18px 20px;
  margin: 14px 0 10px;
}
.story-chart-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.story-chart-label {
  font-size: 0.85rem; color: #9090b8; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.story-chart-value {
  font-size: 1.5rem; font-weight: 900; line-height: 1;
}
.story-chart-value.today { color: #4a90d9; }
.story-chart-value.after { color: #e83535; }

/* Card 1: Bar chart */
.story-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.story-bar-label {
  font-size: 0.72rem; color: #9090b8; font-weight: 700;
  text-transform: uppercase; min-width: 38px;
}
.story-bar-track {
  flex: 1; height: 26px; background: rgba(255,255,255,0.06);
  border-radius: 7px; overflow: hidden;
}
.story-bar-fill { height: 100%; border-radius: 7px; transition: width 0.5s ease; }
.story-bar-fill.today { background: #1a6bb5; }
.story-bar-fill.after { background: #c0392b; }
.story-bar-value {
  font-size: 0.88rem; font-weight: 800; color: #e8e8f0;
  min-width: 76px; text-align: right;
}

/* Card 3: Boat icon grid */
.departure-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 20px 0;
}
.departure-icon {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.departure-icon svg { width: 100%; height: 100%; }
.departure-icon.kept svg {
  fill: #00C8FF;
  filter: drop-shadow(0 0 7px rgba(0, 200, 255, 0.75));
}
.departure-icon.lost svg {
  fill: #4a1a1a;
  opacity: 0.55;
}
.departure-icon.school svg {
  fill: #d63faa;
  filter: drop-shadow(0 0 7px rgba(214, 63, 170, 0.75));
}

/* Card: weekly — compact header to leave more room for the icon grid */
.story-card-weekly .story-brand     { margin-bottom: 6px; }
.story-card-weekly .story-route-day { margin-bottom: 8px; }
.story-card-weekly .story-headline  { font-size: 1.35rem; margin-bottom: 2px; }

/* Card 4: Slot grid */
.slot-grid-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.slot-grid-cell { width: 14px; height: 14px; border-radius: 3px; }

/* Shared story card elements */
.story-brand {
  font-size: 0.68rem; color: #6060a0; text-transform: uppercase;
  letter-spacing: 0.1em; text-align: center; margin-bottom: 14px;
}
.story-route-title {
  font-size: 1.7rem; font-weight: 800; line-height: 1.15;
  color: #ffffff; margin-bottom: 6px;
}
.story-route-day {
  font-size: 0.88rem; color: #7070a8; margin-bottom: 18px;
}
.story-eyebrow {
  font-size: 0.72rem; color: #6868a0; text-transform: uppercase;
  letter-spacing: 0.08em; margin-bottom: 8px;
}
.story-headline {
  font-size: 1.65rem; font-weight: 900; line-height: 1.15;
  color: #ffffff; margin-bottom: 4px;
}
.story-card1-header {
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 28px 24px 18px;
  margin: -28px -24px 0;
  height: 100px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.story-card1-header .story-route-title {
  font-size: 1.25rem;
  margin-bottom: 0;
}
.story-card1-spacer {
  flex: 1;
}
.story-fact-extra {
  font-size: 1.2rem; font-weight: 700; color: #c8c8e8;
  line-height: 1.3; margin-top: 16px;
}
.story-card-fact-actions {
  padding: 0 24px 24px;
  display: flex;
  justify-content: center;
}
.fact-next-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: #c8c8e8;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 10px 24px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
}
.fact-next-btn:hover {
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.35);
}

/* ── Map card ──────────────────────────────────────────────────────────── */
.story-map-toggle {
  display: flex;
  gap: 8px;
  padding: 14px 24px 0;
  justify-content: center;
}
.story-map-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
  color: #a0a0b8;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 8px 20px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
}
.story-map-btn:hover { background: rgba(255,255,255,0.12); }
.story-map-btn.active {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.35);
  color: #e8e8f0;
}
body.light .story-map-btn {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.12);
  color: #666;
}
body.light .story-map-btn:hover { background: rgba(0,0,0,0.08); }
body.light .story-map-btn.active {
  background: rgba(0,0,0,0.1);
  border-color: rgba(0,0,0,0.25);
  color: #222;
}
.story-map-travel-time {
  text-align: center;
  padding: 8px 24px 0;
  font-size: 0.9rem;
  color: #a0a0b8;
}
.story-map-travel-time strong {
  color: #e8e8f0;
}
body.light .story-map-travel-time { color: #666; }
body.light .story-map-travel-time strong { color: #1a1a2e; }
.story-map-img-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 10px;
}
.story-map-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}
.story-map-loading {
  color: #7a7a9a;
  font-size: 0.9rem;
  font-weight: 500;
}
body.light .story-map-loading { color: #999; }

/* ── Share card ─────────────────────────────────────────────────────────── */
.share-card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding-top: 20px;
  min-height: 0;
}
.share-card-content .story-eyebrow {
  text-align: center;
}
.share-card-headline {
  text-align: center;
  margin: 2px 0 18px;
  font-size: 1.35rem;
}
.share-thumb-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 2px 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 212, 212, 0.582) transparent;
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
  cursor: grab;
}
.share-thumb-strip::-webkit-scrollbar { height: 6px; }
.share-thumb-strip::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
.share-thumb {
  flex: 0 0 auto;
  width: 110px;
  background: none;
  border: 2px solid rgba(255,255,255,0.14);
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
  transition: border-color 0.18s, transform 0.18s;
  overflow: visible;
  position: relative;
  display: flex;
  flex-direction: column;
}
.share-thumb:hover { border-color: rgba(255,255,255,0.35); }
.share-thumb.selected {
  border-color: #c0392b;
  transform: translateY(-2px);
}
.share-thumb-badge {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  background: #c0392b;
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 700;
  z-index: 2;
}
.share-thumb.selected .share-thumb-badge {
  display: block;
}
.share-thumb-inner {
  width: 110px;
  height: 196px;
  position: relative;
  overflow: hidden;
  pointer-events: none;
  background: #08080f;
}
/* Cloned .story-card inside a thumbnail: force fixed 390x700 box and scale down */
.share-thumb-inner .story-card.share-thumb-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 390px;
  height: 700px;
  transform: scale(0.2821);    /* 110 / 390 ≈ 0.28; 700*0.28 ≈ 196 */
  transform-origin: top left;
  flex-shrink: 0;
}
.share-thumb-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  color: #9090b8;
  padding: 5px 2px 6px;
  font-weight: 600;
}
.share-thumb.selected .share-thumb-label { color: #e8e8f0; }
.share-mode-toggle {
  padding-top: 10px;
  justify-content: center;
}
.share-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding-top: 14px;
}
.share-action-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: #e8e8f0;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
}
.share-action-btn:hover {
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.35);
}
.share-action-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}
.share-action-btn.share-action-primary {
  background: #3d50ff;
  border-color: #3d50ff;
  color: #ffffff;
}
.share-action-btn.share-action-primary:hover {
  background: #2f40e0;
  border-color: #2f40e0;
}

/* Toast used by copy-link */
.share-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  background: rgba(10,10,20,0.92);
  color: #ffffff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10000;
}
.share-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.story-gap-text {
  font-size: 1.05rem; font-weight: 700; color: #c8c8e8;
  line-height: 1.35; margin: 16px 0 0;
  text-align: center;
}
.story-gap-highlight {
  color: #e83535;
}
.story-big-number {
  font-size: 4.2rem; font-weight: 900; color: #e83535;
  line-height: 1; margin: 12px 0 4px;
}
.story-big-label {
  font-size: 1.2rem; font-weight: 700; color: #c0c0e0; margin-bottom: 20px;
}
.story-detail-text {
  font-size: 0.7rem; color: #6060a0; text-transform: uppercase;
  letter-spacing: 0.07em; line-height: 1.5;
}
.story-footer {
  margin-top: auto; padding-top: 10px;
  font-size: 0.68rem; color: #6060a0; line-height: 1.4;
}
.story-footer-url {
  margin-top: 4px; font-size: 0.72rem; color: #8080c0; font-weight: 600; letter-spacing: 0.02em;
}
.story-footer-cta {
  font-size: 0.82rem; color: #d0a030; font-weight: 700; margin-bottom: 2px;
}
.story-next-hint {
  margin-top: auto; text-align: center;
  font-size: 0.6rem; color: rgba(255,255,255,0.2);
  text-transform: uppercase; letter-spacing: 0.14em;
  line-height: 1.6; padding-top: 6px;
}

/* Card 5: Summary stats grid */
.story-stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0 16px;
}
.story-stat-cell {
  background: #12122a; border: 1px solid rgba(255,255,255,0.07);
  border-radius: 10px; padding: 12px;
}
.story-stat-label {
  font-size: 0.65rem; color: #7070a8; text-transform: uppercase;
  letter-spacing: 0.06em; margin-bottom: 4px;
}
.story-stat-value {
  font-size: 1.2rem; font-weight: 800; color: #e8e8f0;
}
.story-stat-value.reduced { color: #ff5555; }

/* ── Welcome modal ────────────────────────────────────────────────────────── */
.welcome-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 16, 0.90);
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}

.welcome-box {
  background: #111128;
  border: 1px solid rgba(100, 128, 204, 0.28);
  border-radius: 20px;
  padding: 44px 40px 36px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.65);
}

.welcome-brand {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #6480cc;
  margin-bottom: 14px;
  font-weight: 600;
}

.welcome-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: #e8e8f0;
  margin: 0 0 14px;
  line-height: 1.15;
}

.welcome-desc {
  font-size: 0.88rem;
  color: #9090b8;
  line-height: 1.65;
  margin: 0 0 32px;
}

/* ── Startup / server-loading overlay ─────────────────────────────────── */
#startup-overlay { z-index: 13000; }   /* above welcome modal (12000) */
.startup-box { padding-bottom: 44px; }
.startup-spinner-wrap {
  display: flex;
  justify-content: center;
  margin: 28px 0 18px;
}
.startup-spinner {
  width: 36px; height: 36px;
  border-width: 4px;
}
.startup-msg {
  font-size: 0.9rem;
  color: #9090b8;
  margin: 0;
}
body.light .startup-msg { color: #555; }

.welcome-buttons {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.welcome-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 18px 24px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  min-width: 155px;
}

.welcome-btn:hover { transform: translateY(-3px); }

.welcome-btn-primary {
  background: linear-gradient(135deg, #4a6fd4 0%, #2a44a0 100%);
  color: #fff;
  box-shadow: 0 4px 22px rgba(74, 111, 212, 0.38);
}

.welcome-btn-primary:hover {
  box-shadow: 0 8px 30px rgba(74, 111, 212, 0.55);
}

.welcome-btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: #b0b0cc;
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.welcome-btn-icon {
  font-size: 1.5rem;
  line-height: 1;
  margin-bottom: 2px;
}

.welcome-btn-text {
  font-size: 0.97rem;
  font-weight: 600;
}

.welcome-btn-sub {
  font-size: 0.70rem;
  opacity: 0.65;
  font-weight: 400;
}

/* ── Tour simulated cursor ────────────────────────────────────────────────── */
#tour-cursor {
  position: fixed;
  pointer-events: none;
  z-index: 15000;
  display: none;
  filter: drop-shadow(0 1px 4px rgba(0,0,0,0.75));
}

.tour-cursor-ripple {
  position: fixed;
  pointer-events: none;
  z-index: 14999;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(74, 111, 212, 0.95);
  transform: translate(-50%, -50%);
  animation: tourRipple 0.5s ease-out forwards;
}

@keyframes tourRipple {
  0%   { width: 6px;  height: 6px;  opacity: 1; }
  100% { width: 48px; height: 48px; opacity: 0; }
}

/* Hovering pulse: a ring around the cursor's arrow tip while it waits for the user to click. */
#tour-cursor.pulsing::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 2px solid rgba(74, 111, 212, 0.95);
  background: rgba(255, 255, 255, 0.15);
  transform: translate(-50%, -50%);
  animation: tourHoverPulse 1.4s ease-out infinite;
  pointer-events: none;
}

@keyframes tourHoverPulse {
  0%   { width: 6px;  height: 6px;  opacity: 0.95; }
  100% { width: 56px; height: 56px; opacity: 0; }
}

/* ── Tour guide panel ─────────────────────────────────────────────────────── */
#tour-guide {
  position: fixed;
  top: 18px;
  left: 295px;
  width: 310px;
  background: #111128;
  border: 1px solid rgba(100, 128, 204, 0.32);
  border-radius: 14px;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.60);
  z-index: 10500;
  overflow: hidden;
  animation: tourSlideIn 0.28s ease;
}

@keyframes tourSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tour-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  background: rgba(74, 111, 212, 0.16);
  border-bottom: 1px solid rgba(100, 128, 204, 0.18);
}

.tour-label {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: #6480cc;
  font-weight: 700;
  flex: 1;
}

.tour-scenario-indicator {
  font-size: 0.70rem;
  color: #5060a0;
}

.tour-close-btn {
  background: none;
  border: none;
  color: #5060a0;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 1px 3px;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.12s;
}

.tour-close-btn:hover { color: #e8e8f0; }

.tour-content {
  padding: 13px 14px;
  font-size: 0.83rem;
  color: #b8b8d0;
  line-height: 1.58;
  min-height: 72px;
}

.tour-content strong { color: #e8e8f0; }

.tour-content em {
  color: #6070a0;
  font-style: italic;
}

.tour-footer {
  padding: 9px 12px;
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid rgba(100, 128, 204, 0.12);
}

.tour-next-btn {
  background: linear-gradient(135deg, #4a6fd4 0%, #2a44a0 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 15px;
  font-size: 0.80rem;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
  font-weight: 500;
}

.tour-next-btn:hover:not(:disabled) { opacity: 0.82; }

.tour-next-btn:disabled {
  background: #1e1e38;
  color: #4a4a70;
  cursor: default;
}

/* ── Setup / reset buttons (mobile only) ─────────────────────────────────── */
#setup-btn,
#reset-btn-mobile { display: none; }

/* ── Legend info button (mobile only) ────────────────────────────────────── */
#legend-btn { display: none; }

/* ── Mobile share button (inside drawer) ─────────────────────────────────── */
#share-btn-mobile { display: none; }

/* ── Route peek strip (mobile only) ──────────────────────────────────────── */
#route-strip { display: none; }

/* ── Theme toggle button ──────────────────────────────────────────────────── */
#theme-toggle {
  position: fixed;
  top: 80px;
  right: 10px;
  width: 26px;
  height: 26px;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  color: #e8e8f0;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  padding: 0;
}
#theme-toggle:hover {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.35);
}

/* ── Light theme overrides ────────────────────────────────────────────────── */
body.light { --slot-empty: #c8c8d8; }

body.light {
  background: #f0f0f6;
  color: #1a1a2e;
}

body.light #theme-toggle {
  background: rgba(0,0,0,0.07);
  border-color: rgba(0,0,0,0.20);
  color: #1a1a2e;
}
body.light #theme-toggle:hover {
  background: rgba(0,0,0,0.14);
  border-color: rgba(0,0,0,0.35);
}

body.light #control-panel {
  background: rgba(255,255,255,0.96);
  border-color: rgba(0,0,0,0.10);
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}
body.light #control-panel h2 { color: #0e0e20; }
body.light #control-panel .subtitle { color: #7070a0; }
body.light .control-group label { color: #606090; }
body.light .control-group select,
body.light .control-group input[type="time"],
body.light .control-group input[type="number"] {
  background: rgba(0,0,0,0.05);
  border-color: rgba(0,0,0,0.14);
  color: #1a1a2e;
}
body.light .control-group select option { background: #f4f4fa; color: #1a1a2e; }
body.light .toggle-label { color: #2a2a4a !important; }
body.light .toggle-switch {
  background: rgba(0,0,0,0.10);
  border-color: rgba(0,0,0,0.18);
}
body.light .toggle-switch::after { background: #8080b8; }
body.light .dwell-unit { color: #8080a8; }

body.light .selection-status {
  color: #7070a0;
  background: rgba(0,0,0,0.04);
}
body.light .sel-row { color: #1a1a2e; }
body.light .sel-arrow { color: #9090b8; }
body.light #reset-btn {
  background: rgba(180, 50, 50, 0.82);
  color: #fff;
}
body.light #reset-btn:hover { background: rgba(220, 60, 60, 0.92); }

body.light #journey-panel,
body.light #journey-return-panel { border-top-color: rgba(0,0,0,0.07); }
body.light #journey-panel h3,
body.light #journey-return-panel h3 { color: #8080a8; }
body.light .journey-leg { border-bottom-color: rgba(0,0,0,0.06); }
body.light .journey-route { color: #4a5ab8; }
body.light .journey-stops { color: #1a1a2e; }
body.light .journey-time { color: #7070a0; }
body.light .journey-no-service { color: #a0a0b8; }
body.light .journey-label-header { color: #5070c0; }
body.light .journey-label-header.after { color: #b05050; }
body.light .journey-summary-line { color: #5050a0; }

body.light #stats-panel h3 { color: #8080a8; }
body.light #stats-panel { border-top-color: rgba(0,0,0,0.07); }
body.light .stats-table th { color: #8080a8; }
body.light .stats-table td { color: #1a1a2e; }
body.light .stats-table td:first-child { color: #6060a0; }
body.light .stats-table tr:nth-child(even) td { background: rgba(0,0,0,0.025); }

body.light #bottom-panel {
  background: rgba(248,248,252,0.97);
  border-top-color: rgba(0,0,0,0.09);
}
body.light #route-legend {
  background: rgba(248,248,252,0.95);
  border-color: rgba(0,0,0,0.10);
}
body.light .rl-row { color: #3a3a6a; }

body.light #loading-overlay { background: rgba(236,236,246,0.92); color: #6060a0; }
body.light .progress-bar-track { background: rgba(0,0,0,0.10); }

body.light .tl-label { color: #3a5ab0; }
body.light .tl-label.after { color: #b04040; }
body.light .tl-summary { color: #7070a8; }
body.light .timeline-row.active-timeline { outline-color: rgba(0,0,0,0.25); }
body.light .slot-block { border-right-color: rgba(255,255,255,0.5); }
body.light .time-axis { color: #9090b8; }

body.light #legend-note { color: #8080b0; }
body.light .legend-item { color: #6060a0; }

body.light #tooltip {
  background: rgba(250,250,255,0.98);
  border-color: rgba(0,0,0,0.12);
  color: #1a1a2e;
  box-shadow: 0 4px 20px rgba(0,0,0,0.14);
}
body.light #tooltip .tt-time { color: #0a0a1e; }
body.light #tooltip .tt-leg { border-bottom-color: rgba(0,0,0,0.07); color: #2a2a4a; }
body.light #tooltip .tt-route { color: #4a5ab8; }
body.light #tooltip .tt-no-service { color: #9090b8; }

body.light ::-webkit-scrollbar-track { background: rgba(0,0,0,0.06); }
body.light ::-webkit-scrollbar-thumb { background: rgba(80,80,160,0.22); }

body.light #share-btn {
  background: linear-gradient(135deg, #2a55c0 0%, #1a3898 100%);
}

body.light #setup-btn {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231a1a2e' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='4' y1='6' x2='20' y2='6'/%3E%3Ccircle cx='8' cy='6' r='2.5' fill='%231a1a2e' stroke='none'/%3E%3Cline x1='4' y1='12' x2='20' y2='12'/%3E%3Ccircle cx='16' cy='12' r='2.5' fill='%231a1a2e' stroke='none'/%3E%3Cline x1='4' y1='18' x2='20' y2='18'/%3E%3Ccircle cx='10' cy='18' r='2.5' fill='%231a1a2e' stroke='none'/%3E%3C/svg%3E");
  background-color: rgba(230, 230, 246, 0.92);
}
body.light #setup-panel {
  background: rgba(240, 240, 250, 0.97);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  padding: 14px 16px;
  color: #1a1a2e;
}
body.light #setup-panel .control-group:last-child { margin-bottom: 0; }

body.light #legend-btn {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23606080' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E");
  border-color: rgba(0,0,0,0.2);
  background-color: rgba(0,0,0,0.05);
}

body.light #reset-btn-mobile {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E");
  background-color: rgba(200, 60, 60, 0.82);
}

body.light .welcome-overlay { background: rgba(180,180,210,0.88); }
body.light .welcome-box {
  background: #ffffff;
  border-color: rgba(80,100,200,0.22);
  box-shadow: 0 10px 50px rgba(0,0,0,0.18);
}
body.light .welcome-title { color: #0e0e20; }
body.light .welcome-desc { color: #6060a0; }
body.light .welcome-btn-secondary {
  background: rgba(0,0,0,0.05);
  color: #5050a0;
  border-color: rgba(0,0,0,0.12);
}

body.light #tour-guide {
  background: #ffffff;
  border-color: rgba(80,100,200,0.25);
  box-shadow: 0 6px 32px rgba(0,0,0,0.14);
}
body.light .tour-header {
  background: rgba(74,111,212,0.09);
  border-bottom-color: rgba(80,100,200,0.14);
}
body.light .tour-content { color: #2a2a4a; }
body.light .tour-content strong { color: #0e0e20; }
body.light .tour-content em { color: #8080b0; }
body.light .tour-footer { border-top-color: rgba(80,100,200,0.10); }
body.light .tour-next-btn:disabled { background: #e8e8f2; color: #9090b8; }
body.light .tour-close-btn { color: #9090b8; }
body.light .tour-close-btn:hover { color: #1a1a2e; }

/* ── Light theme: share modal & cards ────────────────────────────────────── */
body.light .share-modal-overlay { background: rgba(140,140,170,0.82); }

body.light .share-btn-close {
  background: rgba(0,0,0,0.07);
  color: #3a3a5a;
  border-color: rgba(0,0,0,0.14);
}
body.light .share-btn-close:hover { background: rgba(0,0,0,0.14); }

body.light .carousel-arrow {
  background: rgba(0,0,0,0.08);
  color: #2a2a4a;
  border-color: rgba(0,0,0,0.14);
}
body.light .carousel-arrow:hover { background: rgba(0,0,0,0.16); }

body.light .carousel-dot { background: rgba(0,0,0,0.18); }
body.light .carousel-dot.active { background: #c0392b; }

/* Story cards */
body.light .story-card {
  background: #ffffff;
  color: #1a1a2e;
}
body.light .story-brand { color: #9090b8; }
body.light .story-route-title { color: #0e0e20; }
body.light .story-route-day { color: #7070a8; }
body.light .story-eyebrow { color: #8080b0; }
body.light .story-headline { color: #0e0e20; }
body.light .story-fact-extra { color: #2a2a4a; }
body.light .story-gap-text { color: #2a2a4a; }
body.light .story-detail-text { color: #9090b8; }
body.light .story-footer { color: #9090b8; }
body.light .story-footer-url { color: #9090b8; }
body.light .story-next-hint { color: rgba(0,0,0,0.22); }
body.light .story-slot-range { color: #8080b0; }

body.light .story-card1-header {
  background: rgba(0,0,0,0.03);
  border-bottom-color: rgba(0,0,0,0.08);
}
body.light .story-chart-box {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
}
body.light .story-chart-label { color: #7070a8; }
body.light .story-bar-track { background: rgba(0,0,0,0.07); }
body.light .story-bar-value { color: #1a1a2e; }

/* Share card — light theme */
body.light .share-thumb {
  border-color: rgba(0,0,0,0.22);
}
body.light .share-thumb:hover { border-color: rgba(0,0,0,0.40); }
body.light .share-thumb.selected { border-color: #c0392b; }
body.light .share-thumb-strip { scrollbar-color: rgba(0,0,0,0.3) transparent; }
body.light .share-thumb-strip::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.3); }
body.light .share-thumb-inner { background: #ffffff; }
body.light .share-thumb-label { color: #7070a8; }
body.light .share-thumb.selected .share-thumb-label { color: #1a1a2e; }
body.light .share-action-btn {
  background: rgba(0,0,0,0.05);
  border-color: rgba(0,0,0,0.14);
  color: #1a1a2e;
}
body.light .share-action-btn:hover {
  background: rgba(0,0,0,0.10);
  border-color: rgba(0,0,0,0.28);
}
body.light .share-action-btn.share-action-primary {
  background: #3d50ff;
  border-color: #3d50ff;
  color: #ffffff;
}

/* ── Mobile / phone layout ────────────────────────────────────────────────── */
@media (max-width: 767px) {

  /* ── Phase 1: Control panel → bottom sheet drawer ── */
  #control-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: calc(100svh - 16px);
    overflow-y: hidden;
    border-radius: 18px 18px 0 0;
    padding: 0 18px 6px;
    transform: translateY(calc(100% - 26px));
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1500;
    overscroll-behavior: contain;
  }
  #control-panel.drawer-open {
    transform: translateY(0);
    overflow-y: auto;
  }
  /* Drag handle (real element — can receive click events) */
  .drawer-handle {
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.25);
    border-radius: 2px;
    margin: 12px auto 10px;
    flex-shrink: 0;
    cursor: pointer;
  }
  /* Hide the h2 title on mobile */
  #control-panel > h2 { display: none; }
  body.drawer-open-lock { overflow: hidden; }
  /* Minimized drawer: block internal scroll so the only gesture is swipe-up */
  #control-panel:not(.drawer-open) { overflow-y: hidden; }

  /* ── Phase 2: Bottom panel flows inside the drawer ── */
  #bottom-panel {
    position: relative;
    border-top: 1px solid rgba(255,255,255,0.08);
    border-radius: 0;
    margin-top: 14px;
    min-height: auto;
    padding: 12px 0 4px;
    backdrop-filter: none;
    background: transparent;
  }

  /* ── Phase 3: Buttons & overlays ── */

  /* Setup button: top-left, sliders icon */
  #setup-btn {
    display: flex;
    position: fixed;
    top: 16px;
    left: 10px;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: none;
    padding: 0;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 900;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='4' y1='6' x2='20' y2='6'/%3E%3Ccircle cx='8' cy='6' r='2.5' fill='%23fff' stroke='none'/%3E%3Cline x1='4' y1='12' x2='20' y2='12'/%3E%3Ccircle cx='16' cy='12' r='2.5' fill='%23fff' stroke='none'/%3E%3Cline x1='4' y1='18' x2='20' y2='18'/%3E%3Ccircle cx='10' cy='18' r='2.5' fill='%23fff' stroke='none'/%3E%3C/svg%3E") no-repeat center / 22px 22px,
                rgba(30, 30, 60, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    transition: background-color 0.15s;
  }
  body.setup-open #setup-btn {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='4' y1='6' x2='20' y2='6'/%3E%3Ccircle cx='8' cy='6' r='2.5' fill='%23fff' stroke='none'/%3E%3Cline x1='4' y1='12' x2='20' y2='12'/%3E%3Ccircle cx='16' cy='12' r='2.5' fill='%23fff' stroke='none'/%3E%3Cline x1='4' y1='18' x2='20' y2='18'/%3E%3Ccircle cx='10' cy='18' r='2.5' fill='%23fff' stroke='none'/%3E%3C/svg%3E");
    background-color: rgba(50, 60, 140, 0.92);
  }

  /* Setup panel: floating card, hidden by default */
  #setup-panel {
    display: none;
    position: fixed;
    top: 62px;
    left: 10px;
    width: 230px;
    background: rgba(14, 14, 30, 0.96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 14px 16px 10px;
    z-index: 1600;
    box-shadow: 0 6px 28px rgba(0,0,0,0.55);
  }
  body.setup-open #setup-panel { display: block; }

  /* Remove extra margin from control-groups when in the floating panel */
  #setup-panel .control-group { margin-bottom: 12px; }
  #setup-panel .control-group:last-child { margin-bottom: 2px; }

  /* When a stop is selected the reset button appears; push setup panel down */
  body.has-selection.setup-open #setup-panel { top: 108px; }

  /* Reset button: top-left below setup button, circular-arrow icon */
  #reset-btn-mobile {
    display: none; /* shown via inline style toggle in JS */
    position: fixed;
    top: 62px;
    left: 10px;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: none;
    padding: 0;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1600;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E") no-repeat center / 22px 22px,
                rgba(180, 50, 50, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    z-index: 900;
  }
  #reset-btn-mobile:active { background-color: rgba(220, 60, 60, 0.92); }

  /* Top-right share button replaced by in-drawer button on mobile */
  #share-btn { display: none !important; }

  /* In-drawer share button */
  #share-btn-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px 16px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #1a3a8a 0%, #3050c8 100%);
    border: none;
    border-radius: 9px;
    color: #ffffff;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: opacity 0.15s;
  }
  #share-btn-mobile:hover:not(:disabled) { opacity: 0.85; }
  #share-btn-mobile:disabled {
    background: linear-gradient(135deg, #2a2a3a 0%, #3a3a50 100%);
    color: #606080;
    cursor: not-allowed;
  }
  .share-icon-mobile {
    width: 18px;
    height: 18px;
    filter: invert(1);
    flex-shrink: 0;
  }
  #share-btn-mobile:disabled .share-icon-mobile {
    opacity: 0.4;
  }

  /* Route peek strip: two-row from/to summary, shown when a stop is selected */
  body.has-selection #route-strip {
    display: block;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.07);
    margin-top: 8px;
  }
  /* Hide the strip when the drawer is fully open — selection-display handles it */
  body.drawer-open-lock #route-strip { display: none !important; }

  /* Peek to show both rows of the route strip */
  body.has-selection #control-panel:not(.drawer-open) {
    transform: translateY(calc(100% - 82px));
  }

  /* Legend info button: inline at right of the "I DAG" header */
  #legend-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,0.25);
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aaaacc' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E") no-repeat center / 14px 14px;
    background-color: rgba(255,255,255,0.06);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.15s, border-color 0.15s;
    padding: 0;
  }
  body.legend-open #legend-btn {
    background-color: rgba(80, 80, 180, 0.35);
    border-color: rgba(120, 120, 220, 0.6);
  }

  /* Legend hidden by default on mobile; shown when open */
  #legend, #legend-note { display: none; }
  #bottom-panel.legend-open #legend { display: flex; }
  #bottom-panel.legend-open #legend-note { display: block; }

  /* Hide Leaflet zoom controls — pinch/spread to zoom on touch */
  .leaflet-control-zoom { display: none !important; }

  #share-btn {
    bottom: auto;
    top: 16px;
    right: 10px;
    font-size: 0;
    padding: 0;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8'/%3E%3Cpolyline points='16 6 12 2 8 6'/%3E%3Cline x1='12' y1='2' x2='12' y2='15'/%3E%3C/svg%3E") no-repeat center / 20px 20px,
                linear-gradient(135deg, #1a3a8a 0%, #3050c8 100%);
  }
  #share-btn:disabled {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23606080' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8'/%3E%3Cpolyline points='16 6 12 2 8 6'/%3E%3Cline x1='12' y1='2' x2='12' y2='15'/%3E%3C/svg%3E") no-repeat center / 20px 20px,
                linear-gradient(135deg, #2a2a3a 0%, #3a3a50 100%);
  }
  #theme-toggle {
    top: 16px;
    right: 10px;
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }
  /* Route legend is redundant on mobile — hide it */
  #route-legend { display: none !important; }

  /* Map-level loading indicator (visible while calculating) */
  #map-loading-indicator {
    position: fixed;
    bottom: 94px;    /* above the 82px peek strip */
    right: 18px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1501;   /* above the drawer (1500) */
  }
  #map-loading-indicator .spinner {
    width: 18px;
    height: 18px;
    border-width: 2px;
  }
  #tooltip { display: none !important; }

  /* ── Phase 4: Story card carousel full-width ── */
  .share-modal-overlay {
    padding: 0;
    align-items: flex-end;
    overflow: hidden;     /* prevent horizontal scrollbar from track spill */
  }
  .share-modal-box {
    width: 100%;
    gap: 0;
    padding-bottom: 0;
    position: relative;   /* anchor for absolutely-positioned dots */
  }
  .carousel-viewport {
    width: 100vw;
    height: min(640px, 82vh);
    border-radius: 12px 12px 0 0;
  }
  .story-card {
    width: 100vw;   /* must match cardWidth() = window.innerWidth on mobile */
    height: min(640px, 82vh);
    padding: 20px 18px 52px; /* extra bottom padding keeps content above dots */
  }
  /* Dots overlaid on bottom of card */
  .carousel-dots {
    position: absolute;
    bottom: 18px;
    left: 0;
    right: 0;
    z-index: 10;
  }
  .share-btn-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 9100;
  }
  .carousel-arrow { display: none; }

  /* ── Card content: scale down to fit smaller mobile card ── */

  /* Card padding already set above (20px 18px 16px) */
  /* Header breakout margin must match card padding */
  .story-card1-header {
    padding: 20px 18px 14px;
    margin: -20px -18px 0;
  }
  .story-card1-header .story-route-title { font-size: 1.1rem; }

  .story-brand        { margin-bottom: 8px; }
  .story-route-title  { font-size: 1.35rem; }
  .story-route-day    { font-size: 0.8rem; margin-bottom: 10px; }
  .story-eyebrow      { margin-bottom: 6px; }
  .story-headline     { font-size: 1.3rem; margin-bottom: 4px; }
  .story-fact-extra   { font-size: 1rem; margin-top: 10px; }

  .story-big-number   { font-size: 3rem; margin: 8px 0 2px; }
  .story-big-label    { font-size: 0.95rem; margin-bottom: 12px; }
  .story-gap-text     { font-size: 0.9rem; margin: 10px 0 0; }
  .story-footer       { padding-top: 6px; }

  /* Summary card: sc-* classes */
  .sc-header          { margin-bottom: 10px; padding-bottom: 8px; }
  .sc-conclusion      { font-size: 1.2rem; margin-bottom: 12px; }
  .sc-trip-block      { margin-bottom: 10px; padding: 10px 12px; }
  .sc-shock-block     { padding: 10px 12px; margin-bottom: 10px; }
  .sc-shock-main      { font-size: 1.6rem; }
  .sc-tl-block        { margin-bottom: 10px; }
  .sc-footer          { padding-top: 8px; }

  /* Bar chart rows */
  .story-bar-row      { margin-bottom: 8px; }
  .story-bar-track    { height: 6px; }

  /* Stats grid */
  .story-stats-grid   { gap: 8px; }
  .story-stat-cell    { padding: 10px 8px; }
  .story-stat-value   { font-size: 1.5rem; }

  /* Weekly card */
  .story-card-weekly .story-headline { font-size: 1.15rem; }

  /* ── Phase 5: Tour guide repositioning ── */
  #tour-guide {
    left: 8px;
    right: 8px;
    width: auto;
    top: 8px;
    bottom: auto;
    max-height: calc(100svh - 16px);
    overflow-y: auto;
    z-index: 1600;
    transition: transform 0.35s cubic-bezier(.4,0,.2,1);
  }
  /* Slide the tour card off-screen while the fake cursor demos controls
     inside the drawer (day-select, tur-retur, dwell). Desktop is unaffected. */
  #tour-guide.slide-out {
    transform: translateX(110vw) !important;
  }

  /* ── Guided tour mobile: show only timeline, tour guide just above it ── */
  body.tour-active #control-panel {
    transform: translateY(0) !important;
    overflow: hidden !important;
  }
  /* Hide drag handle during tour */
  body.tour-active #control-panel::before { display: none; }
  /* Hide everything except the timeline panel (control-group stays visible so the cursor can demo it) */
  body.tour-active #control-panel > h2,
  body.tour-active #control-panel > .subtitle,
  body.tour-active #control-panel > #selection-status,
  body.tour-active #control-panel > #selection-display,
  body.tour-active #control-panel > #journey-panel,
  body.tour-active #control-panel > #journey-return-panel { display: none !important; }
  /* Reset button in the drawer is replaced by the top-left mobile button */
  #reset-btn { display: none; }

  /* Subtitle hidden on mobile */
  #control-panel > .subtitle { display: none; }

  /* Timeline panel hidden until data is loaded */
  #bottom-panel { display: none; }
  body.has-data #bottom-panel { display: block; }

  /* Instruction text only useful before data is loaded */
  body.has-data #selection-status { display: none; }

  /* Setup button, reset button, and setup panel stay visible during the
     tour so the fake cursor can open and interact with the settings menu. */

}

/* ── Welcome modal polish (small phones) ─────────────────────────────────── */
@media (max-width: 480px) {
  .welcome-box {
    padding: 32px 20px 28px;
    border-radius: 14px;
  }
  .welcome-title { font-size: 1.4rem; }
  .welcome-btn   { min-width: 120px; padding: 14px 16px; }
}
body.light .story-bar-label { color: #7070a8; }

body.light .story-stat-cell {
  background: #f2f2f8;
  border-color: rgba(0,0,0,0.08);
}
body.light .story-stat-label { color: #7070a8; }
body.light .story-stat-value { color: #0e0e20; }

body.light .fact-next-btn {
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.16);
  color: #2a2a4a;
}
body.light .fact-next-btn:hover {
  background: rgba(0,0,0,0.12);
  border-color: rgba(0,0,0,0.28);
}

/* Share card (#share-card is the PNG export target) */
body.light #share-card {
  background: #ffffff;
  color: #1a1a2e;
  border-color: rgba(0,0,0,0.08);
}
body.light .sc-header { border-bottom-color: rgba(0,0,0,0.08); }
body.light .sc-brand-app { color: #6060a8; }
body.light .sc-brand-dot { color: #c0c0d8; }
body.light .sc-trip-block,
body.light .sc-shock-block {
  background: #f2f2f8;
  border-color: rgba(0,0,0,0.07);
}
body.light .sc-trip-route { color: #8080b0; }
body.light .sc-trip-scenario { color: #7070a8; }
body.light .sc-trip-value { color: #0e0e20; }
body.light .sc-shock-detail { color: #6060a0; }
body.light .sc-shock-wait { color: #8080b0; border-top-color: rgba(0,0,0,0.06); }
body.light .sc-tl-title { color: #5060a8; }
body.light .sc-tl-label { color: #5060a8; }
body.light .sc-footer { border-top-color: rgba(0,0,0,0.07); }
body.light .sc-footer-sub { color: #9090b8; }
