/* style.css — Spoor */

/* Hammersmith One — Johnston-flavoured display face for all UI text
   (self-hosted; the map SVGs keep their own baked-in lettering). */
@font-face {
  font-family: 'Hammersmith One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/shared/fonts/hammersmith-one-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Hammersmith One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/shared/fonts/hammersmith-one-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #fff;
  font-family: 'Hammersmith One', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #333;
}

/* ── Map ─────────────────────────────────────────────────────────────── */

#map-container {
  width: 100%;
  height: 100%;
  position: relative;
  touch-action: none;
  /* Clip the zoomed map at the viewport. The SVGs inside use overflow:visible
     so the inner-<g> scale doesn't let the viewBox clip away content that
     scaled past the SVG's bounds — clipping happens here instead. */
  overflow: hidden;
}

#tube-map,
#train-overlay {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  /* Let zoomed content render past the SVG's box; #map-container clips it. */
  overflow: visible;
}

/* ── Error banner ────────────────────────────────────────────────────── */

#error-banner {
  border-radius: 0;
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  font-size: 12px;
  font-family: inherit;
  padding: 6px 16px;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#error-banner.visible {
  opacity: 1;
}

/* Prevent SVG map elements from interfering with drag/click events.
   Train layer (#train-layer) is excluded — its children need pointer events. */
#tube-map > g:not(#train-layer),
#tube-map > g:not(#train-layer) * {
  pointer-events: none;
}

/* Train markers are interactive */
#train-layer circle,
#train-layer path {
  pointer-events: all;
  cursor: pointer;
}

/* ── Status bar ──────────────────────────────────────────────────────── */

/* Default position — only used briefly before ui.js moves it into the legend
   stack. After move, #legend #status (below) overrides positioning. */
#status {
  border-radius: 0;
  position: fixed;
  bottom: 12px;
  left: 16px;
  background: #111;
  color: #fff;
  font-size: 12px;
  padding: 4px 12px;
  pointer-events: none;
  white-space: nowrap;
}

/* Inside the legend stack: lay out as a normal flex item, no fixed position.
   Drop the pill background — the legend-items panel already provides one. */
#legend #status {
  position: static;
  background: transparent;
  backdrop-filter: none;
  padding: 0 0 6px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  align-self: stretch;
}

#status[data-type="error"] {
  color: #ff6b6b;
}

#status[data-type="stale"] {
  color: #f39c12;
}

/* ── Legend panel (placeholder — wired in ticket 010) ────────────────── */

/* ── Legend panel ────────────────────────────────────────────────────── */

#legend {
  position: fixed;
  bottom: 12px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  z-index: 100;
  pointer-events: auto;
}

/* Items container — hidden when collapsed, grows upward when expanded.
   Uses max-height transition since display:none can't be animated. */
#legend-items {
  border-radius: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #111;
  padding: 0 14px;
  margin-bottom: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.35);
  /* Collapsed state: clamp height to 0, hide content */
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.22s ease;
}

#legend-items.expanded {
  /* tall lists (Berlin: 18 rows) scroll instead of clipping; the viewport
     term keeps the panel clear of the top edge on short screens */
  max-height: min(70vh, 620px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.3) transparent;
  opacity: 1;
  pointer-events: auto;
  padding: 10px 14px;
}

/* Toggle button */
#legend-toggle {
  border-radius: 0;
  background: #111;
  border: none;
  color: #fff;
  font-size: 12px;
  font-family: inherit;
  padding: 5px 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

#legend-toggle:hover {
  background: #222;
}

/* Line rows */
.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: #fff;
  cursor: pointer;
  user-select: none;
  padding: 3px 0;
  opacity: 1;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.legend-item.hidden {
  opacity: 0.35;
}

@media (hover: hover) {
  .legend-item:hover {
    opacity: 0.85;
  }
}

/* Show/Hide all button — sits below the line list */
#legend-bulk {
  margin-top: 8px;
  padding: 4px 0;
  background: transparent;
  border: none;
  border-top: 1px solid rgba(255,255,255,0.12);
  color: #fff;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  align-self: stretch;
  user-select: none;
  transition: color 0.15s;
}

@media (hover: hover) {
  #legend-bulk:hover {
    color: #fff;
  }
}

.legend-swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Info panel ──────────────────────────────────────────────────────── */

#info-panel {
  border-radius: 0;
  position: fixed;
  top: 16px;
  right: 16px;
  background: #111;
  padding: 14px 16px;
  min-width: 210px;
  max-width: 280px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.4);
  /* Always flex so opacity transition fires; pointer-events controls interactivity */
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 13px;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

/* Visible state: fade in, enable interaction */
#info-panel.visible {
  opacity: 1;
  pointer-events: auto;
}

#info-panel button {
  transition: background 0.1s;
}

#info-panel button:hover {
  background: rgba(255,255,255,0.2) !important;
}

/* ── Train markers ───────────────────────────────────────────────────── */

/* Each marker is a <g class="train-marker" data-train-id="…"> */

/* Train markers need pointer events for click (info panel, follow mode) */
.train-marker,
.train-marker * {
  pointer-events: all;
  cursor: pointer;
}

/* ── Burger menu ─────────────────────────────────────────────────────── */

#site-menu {
  position: fixed;
  top: 12px;
  left: 16px;
  z-index: 150;
}

#menu-toggle {
  display: flex;
  align-items: center;
  border-radius: 0;
  background: #111;
  border: none;
  color: #fff;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.15s;
}

#menu-toggle:hover,
#menu-toggle[aria-expanded="true"] {
  background: #222;
  color: #fff;
}

#menu-items {
  border-radius: 0;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  display: flex;
  flex-direction: column;
  min-width: 150px;
  background: #111;
  padding: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  /* Collapsed by default */
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

#menu-items.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #fff;
  font-size: 13px;
  text-decoration: none;
  padding: 7px 10px;
  border-radius: 0;
  white-space: nowrap;
  transition: background 0.12s;
}

@media (hover: hover) {
  .menu-item:hover {
    background: rgba(255, 255, 255, 0.12);
  }
}

.menu-item.current {
  background: rgba(255, 255, 255, 0.16);
  pointer-events: none;
}

.menu-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
