/* ============================================================
   Cambridge.tours  —  styles.css
   Mobile-first, BEM-ish, deliberately framework-free.
   High-contrast palette for outdoor / sunlight use.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --c-bg:           #0f172a;   /* slate-900   — chrome */
  --c-surface:      #ffffff;
  --c-surface-2:    #f8fafc;
  --c-ink:          #0f172a;
  --c-ink-soft:     #475569;
  --c-line:         #e2e8f0;
  --c-accent:       #0284c7;   /* sky-600 */
  --c-accent-dark:  #0369a1;
  --c-warn:         #b91c1c;
  --c-shadow:       0 6px 24px rgba(15, 23, 42, .18);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
               Roboto, "Helvetica Neue", Arial, sans-serif;

  --radius:     14px;
  --radius-sm:   8px;

  --safe-top:    env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  color: var(--c-ink);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  /* Prevent double-tap-to-zoom on iOS; map and audio handle their own gestures. */
  touch-action: manipulation;
}
button, a, label, input, select {
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }
/* Bigger touch targets where it counts: primary CTAs, map controls,
   the play button. Topbar controls stay compact because the topbar itself
   is compact and they pack into a small horizontal strip. */
.intro__cta,
.sheet__play-btn,
.map-controls__btn,
.map-controls__toggle {
  min-height: 44px;
}
input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: var(--c-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 1000;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.topbar__left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  min-width: 0;   /* allow the title to truncate on narrow screens */
}
.topbar__logo {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  padding: 2px;
  flex: 0 0 auto;
}
.topbar__title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .2px;
}
.topbar__right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar__select {
  background: rgba(255,255,255,.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 13px;
  max-width: 140px;
}
.topbar__select option { color: #0f172a; }
.topbar__icon-btn {
  background: rgba(255,255,255,.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  width: 34px; height: 34px;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.topbar__icon-btn:hover { background: rgba(255,255,255,.16); }

.topbar__pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
}
.topbar__pill-btn:hover { background: rgba(255,255,255,.18); }
.topbar__pill-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: linear-gradient(135deg, #5B8FA8 0%, #f97316 100%);
  border: 1.5px solid #fff;
}

/* ============================================================
   Map
   ============================================================ */
.map-wrap {
  position: absolute;
  inset: 0;
  padding-top: calc(54px + var(--safe-top));
}
#map {
  width: 100%;
  height: 100%;
  background: #cfe7d5;
}

/* Tile-pane CSS filter removed. On iOS Safari, applying filter() to the
   leaflet-tile-pane could break the WebKit tile compositor and the entire
   tile layer would render blank. If marker contrast becomes a worry again,
   reapply per-marker (e.g. heavier strokes) rather than dimming the tiles. */

/* (the over-the-map brand badge has moved into the topbar — see .topbar__logo) */

/* User position pulse */
.user-dot {
  width: 18px; height: 18px;
  background: #2563eb;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, .25);
}

/* POI marker — small SVG teardrop pin (18×23), drawn in JS via L.divIcon. */
.poi-marker-wrap svg {
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.35));
}
.poi-marker-wrap--played svg { opacity: .55; }
.poi-marker--played      svg { opacity: .55; }  /* legacy selector for safety */

/* ============================================================
   Map floating controls
   ============================================================ */
.map-controls {
  position: absolute;
  right: 12px;
  bottom: calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 700;
}
.map-controls__btn {
  width: 44px; height: 44px;
  border-radius: 999px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  font-size: 20px;
  color: var(--c-ink);
  box-shadow: var(--c-shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.map-controls__btn:active { transform: scale(0.96); }
/* Inner SVG icons must NOT capture clicks — let the parent button catch them. */
.map-controls__btn svg,
.map-controls__btn svg * { pointer-events: none; }
/* ============================================================
   Slide-up settings panel
   ============================================================ */
.menu-panel {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  background: var(--c-surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 14px 16px calc(16px + var(--safe-bottom));
  box-shadow: 0 -6px 24px rgba(15, 23, 42, .25);
  z-index: 950;     /* above the bottom sheet so it always wins focus */
  animation: sheet-in .22s ease-out;
  max-height: 70vh;
  overflow-y: auto;
}
.menu-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.menu-panel__title {
  margin: 0;
  font-size: 18px;
}
.menu-panel__close {
  background: var(--c-surface-2);
  border: none;
  width: 32px; height: 32px;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
}
.menu-panel__group {
  border-top: 1px solid var(--c-line);
  padding: 10px 0;
}
.menu-panel__group:first-of-type { border-top: none; padding-top: 0; }
.menu-panel__group-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--c-ink-soft);
}
.menu-panel__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  cursor: pointer;
  min-height: 48px;
}
.menu-panel__row-title {
  display: block;
  font-size: 15px;
  font-weight: 500;
}
.menu-panel__row-hint {
  display: block;
  font-size: 12px;
  color: var(--c-ink-soft);
  margin-top: 2px;
}
.menu-panel__row-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}
.menu-panel__cat-chip {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 1.5px solid #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
  flex: 0 0 auto;
}
.menu-panel__switch {
  /* native checkbox; styled bigger so it's a clear tap target. */
  width: 22px; height: 22px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--c-accent);
}

/* ============================================================
   Toast (smart-tour proximity prompt)
   ============================================================ */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  background: #0f172a;
  color: #fff;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--c-shadow);
  z-index: 800;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast__btn {
  background: var(--c-accent);
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
}
.toast__dismiss {
  background: transparent;
  color: #cbd5e1;
  border: none;
  font-size: 18px;
  padding: 0 4px;
}

/* ============================================================
   Bottom sheet (POI details + audio)
   ─ Two zones:
     .sheet__top  — fixed, always visible (close, title, audio).
     .sheet__body — scrollable area for description + transcript.
   The flex layout below keeps the top zone pinned regardless of how
   long the narration is.
   ============================================================ */
.sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  background: var(--c-surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 14px 16px calc(16px + var(--safe-bottom));
  max-height: 80vh;
  box-shadow: 0 -6px 24px rgba(15, 23, 42, .25);
  z-index: 900;
  animation: sheet-in .22s ease-out;
  display: flex;
  flex-direction: column;
}
.sheet__top {
  flex: 0 0 auto;   /* never shrinks — title + audio controls always visible */
}
.sheet__body {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;    /* allows the flex child to shrink below content height */
  margin-top: 10px;
  -webkit-overflow-scrolling: touch;
}
@keyframes sheet-in {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.sheet__close {
  position: absolute;
  top: 8px; right: 10px;
  width: 32px; height: 32px;
  border-radius: 999px;
  border: none;
  background: var(--c-surface-2);
  font-size: 20px;
  line-height: 1;
  z-index: 2;
}
.sheet__header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  padding-right: 36px;
}
.sheet__category-chip {
  display: inline-block;
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--c-surface-2);
  color: var(--c-ink-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.sheet__title {
  font-size: 20px;
  margin: 0;
  line-height: 1.2;
}
.sheet__thumb {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}
.sheet__description {
  margin: 6px 0 14px;
  color: var(--c-ink-soft);
  font-size: 15px;
  line-height: 1.4;
}

/* Audio block — flex column. Top row is the action buttons (Play + Look
   around), then time meta, then seek bar. */
.sheet__audio {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}
.sheet__audio-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sheet__play-btn {
  flex: 1 1 auto;
  background: var(--c-accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.sheet__play-btn:hover { background: var(--c-accent-dark); }
.sheet__play-btn.is-playing .sheet__play-icon::before { content: "❚❚"; }
.sheet__play-icon::before { content: "▶"; }
.sheet__play-icon { display: inline-block; font-size: 13px; }

.sheet__lookaround-btn {
  flex: 0 0 auto;
  background: var(--c-surface-2);
  color: var(--c-ink);
  border: 1px solid var(--c-line);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.sheet__lookaround-btn:hover { background: #eef2f6; }
.sheet__lookaround-btn:active { transform: scale(0.97); }
.sheet__lookaround-btn svg { pointer-events: none; }

.sheet__audio-meta {
  font-size: 13px;
  color: var(--c-ink-soft);
}
.sheet__audio-tag {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--c-surface-2);
  font-size: 11px;
  color: var(--c-ink-soft);
}
.sheet__seek {
  width: 100%;
}

/* Walk-there button — full-width strip below the audio controls.
   Pale Cambridge Blue background so it picks up the brand colour
   without competing with the bright primary Play button. */
.sheet__directions {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 10px;
  background: #dceae3;             /* pale Cambridge Blue */
  border: 1px solid #b8d3c5;
  color: #1f2a26;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  min-height: 44px;
  cursor: pointer;
}
.sheet__directions:hover { background: #cfe2d6; }
.sheet__directions:active { transform: scale(0.99); }
.sheet__directions svg { pointer-events: none; color: #2d5b48; }
.sheet__directions-label { flex: 1 1 auto; text-align: left; }
.sheet__directions-distance {
  flex: 0 0 auto;
  color: #4a665a;
  font-size: 13px;
  font-weight: 600;
}

.sheet__transcript {
  border-top: 1px solid var(--c-line);
  padding-top: 10px;
  margin-top: 6px;
  font-size: 14px;
  color: var(--c-ink-soft);
}
.sheet__transcript summary {
  cursor: pointer;
  color: var(--c-ink);
  font-weight: 600;
  margin-bottom: 6px;
}

/* ============================================================
   Legend overlay
   ============================================================ */
.legend {
  position: fixed;
  top: calc(60px + var(--safe-top));
  right: 12px;
  width: 240px;
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--c-shadow);
  z-index: 950;
}
.legend__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.legend__header h2 { margin: 0; font-size: 14px; }
.legend__close {
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--c-ink-soft);
}
.legend__list {
  list-style: none;
  padding: 0; margin: 0;
  display: grid;
  gap: 6px;
}
.legend__list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.legend__chip {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  flex: 0 0 auto;
}

/* ============================================================
   Street View overlay (Google Street View per POI)
   ============================================================ */
.streetview {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1200;
  display: flex;
  flex-direction: column;
}
.streetview__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: linear-gradient(180deg, rgba(15, 23, 42, .85) 0%, rgba(15, 23, 42, 0) 100%);
  color: #fff;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 2;
  pointer-events: none;
}
.streetview__title {
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
  pointer-events: auto;
  max-width: calc(100% - 60px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.streetview__close {
  width: 40px; height: 40px;
  border-radius: 999px;
  border: none;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  pointer-events: auto;
  cursor: pointer;
}
.streetview__close:hover { background: rgba(0, 0, 0, .75); }
.streetview__pano {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  position: relative;
}
.streetview__loading,
.streetview__error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  padding: 24px;
  text-align: center;
  font-size: 15px;
  line-height: 1.5;
}
.streetview__error strong { font-size: 16px; display: block; margin-bottom: 6px; }
.streetview__error code {
  font-family: monospace;
  background: rgba(255,255,255,.1);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ============================================================
   Intro / Help overlay
   ============================================================ */
.intro {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1100;
}
.intro__card {
  background: var(--c-surface);
  border-radius: var(--radius);
  max-width: 420px;
  width: 100%;
  padding: 22px 22px 18px;
  box-shadow: var(--c-shadow);
}
.intro__card h2 {
  margin-top: 0;
  font-size: 22px;
}
.intro__steps {
  margin: 12px 0;
  padding-left: 20px;
  line-height: 1.45;
  color: var(--c-ink-soft);
}
.intro__steps li { margin-bottom: 6px; }
.intro__note {
  font-size: 12px;
  color: var(--c-ink-soft);
  background: var(--c-surface-2);
  padding: 8px 10px;
  border-radius: 8px;
}
.intro__cta {
  width: 100%;
  margin-top: 12px;
  background: var(--c-accent);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
}
.intro__cta:hover { background: var(--c-accent-dark); }

.intro__legend-title {
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-ink-soft);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.intro__legend {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  font-size: 13px;
}
.intro__legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Email capture inside the intro overlay */
.intro__email {
  margin: 14px 0 8px;
  padding: 12px;
  background: var(--c-surface-2);
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.06);
}
.intro__email-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-ink);
  margin-bottom: 6px;
}
.intro__email-input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  font-size: 16px; /* 16px prevents iOS Safari from zooming on focus */
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--c-ink);
}
.intro__email-input:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(91, 143, 168, 0.25);
}
.intro__email-input[aria-invalid="true"] {
  border-color: #b91c1c;
}
.intro__consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--c-ink-soft);
  cursor: pointer;
}
.intro__consent input[type="checkbox"] {
  margin-top: 2px;
  flex: 0 0 auto;
}
.intro__email-error {
  margin-top: 8px;
  font-size: 12px;
  color: #b91c1c;
}

/* ============================================================
   Utility
   ============================================================ */
[hidden] { display: none !important; }

/* ============================================================
   Narrow phones (≤ 380px) — compact the chrome
   ============================================================ */
@media (max-width: 380px) {
  .topbar { padding: calc(6px + var(--safe-top)) 8px 6px; gap: 4px; }
  .topbar__title { display: none; }
  .topbar__select {
    max-width: 96px;
    padding: 6px;
    font-size: 12px;
  }
  .topbar__pill-btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  .topbar__pill-btn span:last-child { display: none; }   /* show only the dot */
  .topbar__icon-btn { width: 32px; height: 32px; }

  .map-wrap { padding-top: calc(48px + var(--safe-top)); }

  .map-controls {
    right: 8px;
    bottom: calc(12px + var(--safe-bottom));
  }
  .map-controls__toggle {
    padding: 6px 8px;
    font-size: 12px;
  }
  .map-controls__toggle--cat span:last-child { display: none; }  /* chip-only */

  .topbar__logo { width: 26px; height: 26px; }

  .legend {
    left: 8px;
    right: 8px;
    width: auto;
  }

  .intro__card { padding: 18px; }
  .intro__legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    font-size: 12px;
  }

  .sheet { padding: 12px 12px calc(14px + var(--safe-bottom)); }
  .sheet__title { font-size: 18px; }
  .sheet__thumb { height: 130px; }
  /* Tight screens: drop the Look-around text, keep the 360° icon only. */
  .sheet__lookaround-label { display: none; }
  .sheet__lookaround-btn { padding: 10px; }
}

/* ============================================================
   Tablets (≥ 720px) — cap sheet width, give legend more room
   ============================================================ */
@media (min-width: 720px) {
  .sheet {
    left: 50%;
    transform: translateX(-50%);
    max-width: 540px;
    border-radius: var(--radius);
    bottom: 16px;
  }
  .legend { width: 300px; }

  .map-controls { right: 16px; bottom: calc(20px + var(--safe-bottom)); }

  .intro__card { max-width: 480px; }
  .intro__legend { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ============================================================
   Larger tablets / landscape (≥ 1024px) — comfortable but still touch-friendly
   ============================================================ */
@media (min-width: 1024px) {
  .topbar__title { font-size: 17px; }
  .sheet { max-width: 600px; }
  .legend { width: 320px; }
  .map-controls__toggle { font-size: 14px; }
}

/* ============================================================
   Reduce-motion preference — turn off non-essential transitions
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .topbar__pill-btn, .map-controls__btn { transition: none; }
}
