:root {
  /* Light theme (default). */
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-border: #d5dbe3;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --bad: #dc2626;
  --good: #16a34a;
}

/* Follow system: dark when the OS prefers it and no explicit choice is set. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111827;
    --panel: #1f2937;
    --panel-border: #374151;
    --text: #f9fafb;
    --muted: #9ca3af;
    --accent: #3b82f6;
    --bad: #ef4444;
    --good: #22c55e;
  }
}

/* Explicit dark choice (overrides the system preference). */
:root[data-theme='dark'] {
  --bg: #111827;
  --panel: #1f2937;
  --panel-border: #374151;
  --text: #f9fafb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --bad: #ef4444;
  --good: #22c55e;
}

/* Dark-mode tile styling, matching the legacy site: invert the base map so
   the vector tiles read as a dark basemap. */
:root[data-theme='dark'] .leaflet-layer {
  filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .leaflet-layer {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
  }
}

:root[data-theme='dark'] .leaflet-container {
  background: #333;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .leaflet-container {
    background: #333;
  }
}

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

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.routes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  flex: 1;
}

.route-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* Subway route badges are perfect circles with the line name centered. */
.route-badge.subway {
  width: 24px;
  min-width: 24px;
  max-width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  line-height: 24px;
}

.route-badge.status-bad {
  outline: 2px solid var(--bad);
  outline-offset: 1px;
}

/* Map fills the whole viewport */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Bottom bar: menu button to the left of the weather banner */
.bottom-bar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1100;
}

/* Hamburger menu button */
.menu-btn {
  width: 43px;
  height: 43px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Thin floating weather banner at the bottom */
.weather-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 313px;
  height: 43px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 0 16px;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weather-alert-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bad);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.forecast-list {
  max-height: 50vh;
  overflow-y: auto;
}

.forecast-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--panel-border);
}

.forecast-time {
  width: 44px;
  flex-shrink: 0;
  font-weight: 700;
}

.forecast-words {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.forecast-detail {
  flex-shrink: 0;
  font-weight: 600;
}

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  position: relative;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  left: 0;
}

.hamburger::before {
  top: -6px;
}

.hamburger::after {
  top: 6px;
}

.menu-btn.open .hamburger {
  background: transparent;
}

.menu-btn.open .hamburger::before {
  transform: translateY(6px) rotate(45deg);
}

.menu-btn.open .hamburger::after {
  transform: translateY(0) rotate(-45deg);
}

/* "You are here" blue dot */
.user-location {
  background: #4285f4;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.4), 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* Slide-out menu drawer */
#menu {
  margin: 0;
}

/* Info panel */
/* Info panel — centered modal */
.panel {
  position: fixed;
  top: calc(46% - 15px);
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  max-width: 92vw;
  max-height: 80vh;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px;
  overflow-y: auto;
  scrollbar-width: none;
  z-index: 1000;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.panel::-webkit-scrollbar {
  display: none;
}

/* Station modal: taller and shifted down 30px */
#info {
  max-height: calc(80vh + 90px);
  top: calc(44% + 15px);
}

#infoName {
  padding-top: 8px;
  padding-bottom: 4px;
}

#infoRoutes {
  margin-top: 4px;
}

.panel h2 {
  font-size: 1.2rem;
  margin: 0 0 6px;
  padding-right: 28px;
  position: sticky;
  top: -20px;
  z-index: 9998;
  background: var(--panel);
  padding-top: 12px;
  padding-bottom: 6px;
  margin-top: -12px;
}

.panel .close {
  position: sticky;
  top: 0;
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  z-index: 9999;
}

.panel .close:hover {
  color: var(--text);
}

.section {
  margin-top: 16px;
}

.section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 4px;
}

.stopList {
  list-style: none;
  padding: 0;
  margin: 0;
}

.stopList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.2);
}

.stopList li:last-child {
  border-bottom: none;
}

.stopListDir {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: none !important;
  padding-top: 10px;
}

.timeName {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.times {
  display: flex;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.trainTime {
  color: var(--text);
}

.trainClose {
  color: #cc0;
  font-weight: 700;
}

.trainHere {
  color: #171;
  font-weight: 700;
}

.alert-item {
  margin-bottom: 8px;
  padding: 8px;
  background: rgba(239, 68, 68, 0.1);
  border-left: 3px solid var(--bad);
  border-radius: 4px;
}

.alert-type {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--bad);
  text-transform: uppercase;
}

.alert-hdr {
  margin: 2px 0;
  font-weight: 600;
}

/* Subway line circle embedded in alert text, sized to fit the line. */
.route-badge.subway.alert-line {
  display: inline-flex;
  width: 14px;
  min-width: 14px;
  max-width: 14px;
  height: 14px;
  line-height: 14px;
  padding: 0;
  font-size: 0.75em;
  vertical-align: middle;
  margin: 0 1px;
}

.alert-desc {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text);
  white-space: pre-wrap;
}

.alert-more {
  margin-top: 4px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.8rem;
}

.good {
  color: var(--good);
  font-weight: 700;
}

.bad {
  color: var(--bad);
  font-weight: 700;
}

.partial {
  color: #eab308;
  font-weight: 700;
}

.alert-item p {
  margin-top: 4px;
  font-size: 0.85rem;
}

.alert-item .alert-when {
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Entrances list */
.entrances {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
}

.entrances li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.2);
}

.entrances li:last-child {
  border-bottom: none;
}

.entrance-near {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.entrance-here {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.accessibility {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
}

.accessibility li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.2);
}

.accessibility li:last-child {
  border-bottom: none;
}

.access-label {
  display: block;
}

.access-outage {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.access-alt {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  border-top: 1px solid rgba(127, 127, 127, 0.2);
  padding-top: 4px;
}

/* Details definition list */
.panel dl {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 12px;
  font-size: 0.9rem;
}

.panel dt {
  color: var(--muted);
}

.panel dd {
  color: var(--text);
}

.panel dd a {
  color: #aaaadd;
}

.panel dd a:hover {
  color: #8a8abf;
}

/* Leaflet tooltip overrides */
.stop-label {
  background: #fff;
  color: #111;
  border: transparent;
  box-shadow: none;
  font-size: 0.625rem;
  padding: 2px;
  white-space: nowrap;
}

/* Menu: nearby stations + saved places lists */
.menu-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.2);
  cursor: pointer;
}

.menu-list li:last-child {
  border-bottom: none;
}

.menu-list li.clickable:hover {
  background: rgba(255, 255, 255, 0.06);
}

.menu-name {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-dist {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.menu-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.menu-none {
  color: var(--muted);
  font-style: italic;
  font-weight: 400;
}

/* Jump-to-station autocomplete */
.jump-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
}

.jump-input:focus {
  border-color: var(--accent);
}

.jump-results {
  margin-top: 6px;
  max-height: 200px;
  overflow-y: auto;
}

/* Save-this-station buttons in the info modal */
.save-buttons {
  display: flex;
  gap: 8px;
}
.save-btn {
  flex: 1;
  padding: 8px 0;
  background: var(--panel-border);
  color: var(--text);
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.save-btn:hover {
  background: var(--accent);
}

.save-btn.saved {
  background: var(--good);
  color: #04120a;
}

/* Appearance theme buttons in the Settings section */
.theme-buttons {
  display: flex;
  gap: 8px;
}

.theme-btn {
  flex: 1;
  padding: 8px 0;
  background: var(--panel-border);
  color: var(--text);
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-btn:hover {
  background: var(--accent);
}

.theme-btn.active {
  background: var(--accent);
  color: #fff;
}

@media (max-width: 640px) {
  .panel {
    width: 94vw;
    max-height: 70vh;
    padding: 16px;
  }
}
