/* ==========================================================================
   Boston in Motion — mission-control aesthetic.
   Near-black ink, one glass console, MBTA line colors as the only saturated
   hues. Display: Bricolage Grotesque. Telemetry: IBM Plex Mono.
   ========================================================================== */

:root {
  --ink: #07090d;
  --panel: rgba(13, 17, 23, 0.94);
  --hairline: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --text: #e8eaed;
  --text-dim: #9aa3ad;
  --text-faint: #5c6570;
  --live: #2fd27d;
  --amber: #ffb454;
  --red: #ff5c5c;
  --font-display: 'Bricolage Grotesque', 'Segoe UI', sans-serif;
  --font-body: 'IBM Plex Sans', 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', Consolas, monospace;
  /* The T's own palette, used for the title gradient */
  --t-red: #da291c;
  --t-orange: #ed8b00;
  --t-green: #00843d;
  --t-blue: #003da5;
}

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

html, body {
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
}

a { color: var(--text-dim); text-decoration: none; border-bottom: 1px solid var(--hairline-strong); }
a:hover { color: var(--text); border-bottom-color: var(--text-dim); }

#map { position: absolute; inset: 0; background: var(--ink); }

/* ==========================================================================
   The console
   ========================================================================== */

#panel {
  position: absolute;
  top: 14px;
  left: 14px;
  bottom: 14px;
  width: 332px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--hairline);
  border-radius: 14px;
  background:
    radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1.4px) 0 0 / 16px 16px,
    linear-gradient(180deg, rgba(15, 19, 26, 0.96), rgba(9, 12, 17, 0.94));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.panel-head {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--hairline);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  margin-bottom: 10px;
}

h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 34px;
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--text);
}

h1 .grad {
  background: linear-gradient(90deg, var(--t-red), var(--t-orange) 38%, var(--t-green) 68%, #4d7fd6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}
.panel-scroll::-webkit-scrollbar { width: 8px; }
.panel-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 4px; }

.panel-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline);
}
.panel-section:last-child { border-bottom: none; }

h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.count-chip {
  font-size: 9.5px;
  padding: 1px 6px;
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
  color: var(--text-dim);
}

/* ---- line rows ---------------------------------------------------------- */

.line-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
}

.master-row { padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px dashed var(--hairline); }

.bullet {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--line-color, #39424c);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.bullet-t { background: #f4f6f8; color: #10141a; text-shadow: none; }

.line-name {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
}

.badge {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.badge.major { background: var(--red); box-shadow: 0 0 8px rgba(255, 92, 92, 0.7); }
.badge.minor { background: var(--amber); box-shadow: 0 0 8px rgba(255, 180, 84, 0.55); }

.count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  min-width: 20px;
  text-align: right;
}

/* toggle switch */
.switch { position: relative; flex: none; width: 32px; height: 18px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.switch .knob {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--hairline-strong);
  transition: background 0.18s ease;
}
.switch .knob::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch input:checked + .knob { background: color-mix(in srgb, var(--line-color, #39424c) 55%, transparent); border-color: transparent; }
.switch input:checked + .knob::after { transform: translateX(14px); background: #fff; }
.switch input:focus-visible + .knob { outline: 2px solid var(--text-dim); outline-offset: 2px; }

/* rows whose line is toggled off read as dormant */
.line-row:has(input:not(:checked)) .line-name,
.line-row:has(input:not(:checked)) .count { opacity: 0.4; }
.line-row:has(input:not(:checked)) .bullet { filter: saturate(0.15) brightness(0.6); }

.modal-divider { margin: 10px 0; border-top: 1px dashed var(--hairline); }

.bullet.dark-text { color: #10141a; text-shadow: none; }

.line-row.needs-key .line-name,
.line-row.needs-key .bullet { opacity: 0.5; }
.line-row.needs-key .switch { opacity: 0.35; cursor: not-allowed; }
.get-key {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px solid var(--hairline-strong);
  border-radius: 4px;
  padding: 1px 5px;
}
.get-key:hover { color: var(--text); }

/* ---- future layers (roadmap) -------------------------------------------- */

.future-rows { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--hairline); }

.future-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  opacity: 0.42;
}
.future-row .line-name { font-size: 12.5px; }
.future-row .bullet.ghost {
  background: transparent;
  border: 1px dashed var(--hairline-strong);
  color: var(--text-faint);
  font-size: 9px;
  text-shadow: none;
}
.tag {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---- alerts -------------------------------------------------------------- */

.alerts-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.alert-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border-left: 2px solid var(--text-faint);
  background: rgba(255, 255, 255, 0.025);
  border-radius: 0 8px 8px 0;
}
.alert-item.major { border-left-color: var(--red); }
.alert-item.minor { border-left-color: var(--amber); }

.alert-effect {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.alert-item.major .alert-effect { color: var(--red); }
.alert-item.minor .alert-effect { color: var(--amber); }

.alert-text {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.alert-empty {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
}

.alert-item.clickable { cursor: pointer; position: relative; padding-right: 22px; transition: background 0.15s ease; }
.alert-item.clickable::after {
  content: '›';
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-55%);
  color: var(--text-faint);
  font-size: 15px;
}
.alert-item.clickable:hover,
.alert-item.clickable:focus-visible { background: rgba(255, 255, 255, 0.06); }
.alert-item.clickable:hover::after { color: var(--text); }

/* Expanding ring dropped on the map when an alert is focused */
.alert-ping {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 92, 92, 0.85);
  box-shadow: 0 0 12px rgba(255, 92, 92, 0.8);
  position: relative;
}
.alert-ping::before,
.alert-ping::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 92, 92, 0.75);
  animation: ping 1.6s ease-out infinite;
}
.alert-ping::after { animation-delay: 0.8s; }
@keyframes ping {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(3.4); opacity: 0; }
}

/* ---- footer / status ------------------------------------------------------ */

.panel-foot {
  border-top: 1px solid var(--hairline);
  padding: 12px 20px 14px;
  background: rgba(0, 0, 0, 0.25);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text);
  margin-bottom: 8px;
}

.live-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}
.live-dot.live { background: var(--live); animation: pulse 2.2s ease-out infinite; }
.live-dot.paused { background: var(--amber); }
.live-dot.error { background: var(--red); animation: pulse-red 1.1s ease-out infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 210, 125, 0.55); }
  70% { box-shadow: 0 0 0 9px rgba(47, 210, 125, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 210, 125, 0); }
}
@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(255, 92, 92, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(255, 92, 92, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 92, 92, 0); }
}

.credits {
  font-size: 10.5px;
  line-height: 1.7;
  color: var(--text-faint);
}

/* ==========================================================================
   Loading overlay
   ========================================================================== */

#overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(7, 9, 13, 0.78);
  backdrop-filter: blur(3px);
  transition: opacity 0.45s ease;
}
#overlay.hidden { opacity: 0; pointer-events: none; }

.radar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--hairline-strong);
  background: conic-gradient(from 0deg, rgba(47, 210, 125, 0.5), transparent 120deg);
  animation: spin 1.6s linear infinite;
}
#overlay.fatal .radar { background: conic-gradient(from 0deg, rgba(255, 92, 92, 0.5), transparent 120deg); animation-duration: 3s; }

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

#overlay-text {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  max-width: 340px;
  text-align: center;
  line-height: 1.8;
}

/* ==========================================================================
   MapLibre chrome, re-skinned dark
   ========================================================================== */

.maplibregl-popup-content {
  background: rgba(13, 17, 23, 0.96);
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--font-body);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: rgba(13, 17, 23, 0.96); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: rgba(13, 17, 23, 0.96); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: rgba(13, 17, 23, 0.96); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: rgba(13, 17, 23, 0.96); }
.maplibregl-popup-close-button { color: var(--text-faint); font-size: 16px; right: 4px; top: 2px; }
.maplibregl-popup-close-button:hover { color: var(--text); background: none; }

.popup-title { font-family: var(--font-mono); font-size: 10px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }
.popup-dest { font-family: var(--font-display); font-weight: 700; font-size: 16px; color: var(--text); margin: 3px 0 6px; }
.popup-status { font-size: 12.5px; color: var(--text-dim); }
.popup-meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); margin-top: 7px; }

.maplibregl-ctrl-group {
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid var(--hairline);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--hairline); }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(0.85); }
.maplibregl-ctrl button:not(:disabled):hover { background: rgba(255, 255, 255, 0.06); }

.maplibregl-ctrl-attrib {
  background: rgba(7, 9, 13, 0.75) !important;
  font-size: 10px;
  color: var(--text-faint);
}
.maplibregl-ctrl-attrib a { color: var(--text-dim); border-bottom: none; }

/* ==========================================================================
   Mobile
   ========================================================================== */

#panel-toggle {
  display: none;
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--hairline-strong);
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

@media (max-width: 760px) {
  #panel {
    width: min(86vw, 340px);
    transform: translateX(calc(-100% - 24px));
    transition: transform 0.28s ease;
  }
  body.panel-open #panel { transform: translateX(0); }
  #panel-toggle { display: block; }
  body.panel-open #panel-toggle { left: calc(min(86vw, 340px) + 22px); }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot.live, .live-dot.error, .radar { animation: none; }
  #panel { transition: none; }
}

/* rows that zoom the map on click */
.line-row.zoomable {
  cursor: pointer;
  border-radius: 8px;
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
}
.line-row.zoomable:hover { background: rgba(255, 255, 255, 0.045); }
