:root {
  --red: #e31b23;
  --ink: #141414;
  --muted: #6b7280;
  --line: #e5e7eb;
  --panel: rgba(255, 255, 255, 0.92);
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: #f6f7f8;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

/* Critical Leaflet layout fallback. Keeps tiles/layers positioned even if CDN CSS fails. */
.leaflet-container {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  outline-style: none;
  background: #eef1f2;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  border: 0;
  max-width: none !important;
  max-height: none !important;
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 10px;
}

.leaflet-right {
  right: 8px;
}

.leaflet-bottom {
  bottom: 8px;
}

.leaflet-left {
  left: 10px;
}

.leaflet-control-zoom {
  width: 34px;
  overflow: hidden;
  background: white;
}

.leaflet-control-zoom a {
  display: block;
  width: 34px;
  height: 30px;
  color: #111827;
  font: 700 17px/30px ui-sans-serif, system-ui, sans-serif;
  text-align: center;
  text-decoration: none;
  background: white;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid var(--line);
}

.leaflet-control-attribution {
  display: none;
  padding: 3px 7px;
  color: #6b7280;
  background: rgba(255, 255, 255, 0.82);
  font-size: 11px;
}

.leaflet-interactive {
  cursor: pointer;
}

.leaflet-tooltip {
  position: absolute;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
  white-space: nowrap;
}

.shell {
  position: relative;
  width: 100vw;
  height: 100vh;
}

.map-wrap,
#map {
  width: 100%;
  height: 100%;
}

.leaflet-tile-pane {
  filter: grayscale(1) saturate(0.08) brightness(1.12) contrast(0.86);
}

.leaflet-control-attribution,
.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.08) !important;
}

.leaflet-control-zoom a {
  color: var(--ink) !important;
}

.panel {
  position: absolute;
  z-index: 500;
  top: 18px;
  left: 18px;
  width: min(360px, calc(100vw - 36px));
  padding: 14px;
  border: 1px solid rgba(229, 231, 235, 0.75);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 14px 42px rgba(17, 24, 39, 0.1);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-right: 84px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(227, 27, 35, 0.18));
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: 0;
}

.status {
  margin: 11px 0;
  padding: 9px 10px;
  border: 1px solid #fee2e2;
  border-radius: 8px;
  color: #991b1b;
  background: #fff7f7;
  font-size: 14px;
  line-height: 1.35;
}

.panel-toggle {
  display: none;
}

.panel-details {
  display: block;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 12px;
  margin: 0 0 12px;
}

.stats div {
  min-width: 0;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}

dt {
  color: var(--muted);
  font-size: 12px;
}

dd {
  min-width: 0;
  margin: 3px 0 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.mode-switch {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 1fr 92px;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(249, 250, 251, 0.92);
}

.mode-button {
  width: 100%;
  height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 800;
}

.mode-button::before {
  content: "";
}

.mode-button.active {
  color: white;
  background: var(--red);
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
  font: inherit;
  font-size: 14px;
  outline: none;
}

input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(227, 27, 35, 0.12);
}

button {
  height: 32px;
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: white;
  background: var(--red);
  font: inherit;
  font-size: 0;
  font-weight: 800;
  cursor: pointer;
}

.watch-button::before {
  content: ">";
  font-size: 16px;
  line-height: 1;
}

button:hover {
  background: #c9141b;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: flex;
  gap: 8px;
  align-items: center;
}

.legend i {
  display: inline-block;
  flex: 0 0 auto;
}

.legend .route {
  width: 24px;
  height: 4px;
  border-radius: 999px;
  background: var(--red);
}

.legend .tram {
  width: 18px;
  height: 18px;
}

.legend .tram img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.legend .stop {
  width: 9px;
  height: 9px;
  border: 2px solid var(--red);
  border-radius: 50%;
  background: white;
}

.tram-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 3px solid white;
  border-radius: 50%;
  background: white;
  box-shadow:
    0 0 0 2px rgba(227, 27, 35, 0.95),
    0 9px 18px rgba(17, 24, 39, 0.18);
}

.tram-marker img {
  display: block;
  width: 78%;
  height: 78%;
  object-fit: contain;
}

.tram-marker::after {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(227, 27, 35, 0.24);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%);
}

.tram-marker.selected {
  width: 38px;
  height: 38px;
  box-shadow:
    0 0 0 3px rgba(227, 27, 35, 0.98),
    0 12px 24px rgba(17, 24, 39, 0.22);
}

.tram-marker.selected img {
  width: 80%;
  height: 80%;
}

.tram-marker.selected::after {
  display: block;
}

.stop-marker {
  width: 9px;
  height: 9px;
  border: 2px solid var(--red);
  border-radius: 50%;
  background: white;
}

@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  .shell {
    height: 100svh;
  }

  .panel {
    top: auto;
    right: auto;
    bottom: auto;
    left: 10px;
    top: 10px;
    width: min(370px, calc(100vw - 66px));
    max-height: min(58svh, 440px);
    padding: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .panel.collapsed {
    max-height: none;
  }

  .panel.collapsed .panel-details {
    display: none;
  }

  .panel-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    display: block;
    width: 34px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.92);
  }

  .panel-toggle span,
  .panel-toggle::before,
  .panel-toggle::after {
    position: absolute;
    left: 9px;
    width: 14px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    content: "";
  }

  .panel-toggle::before {
    top: 9px;
  }

  .panel-toggle span {
    top: 14px;
  }

  .panel-toggle::after {
    top: 19px;
  }

  .brand {
    gap: 8px;
    padding-right: 42px;
  }

  .brand-logo {
    width: 27px;
    height: 27px;
  }

  .status {
    margin: 9px 0 0;
    padding: 7px 8px;
    font-size: 12px;
  }

  .panel:not(.collapsed) .status {
    margin-bottom: 12px;
  }

  h1 {
    font-size: 17px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 10px;
  }

  .controls {
    grid-template-columns: 1fr 42px;
    gap: 7px;
  }

  input,
  button {
    height: 30px;
  }

  button {
    padding: 0;
  }

  .watch-button::before {
    content: ">";
    font-size: 16px;
  }

  .mode-button {
    grid-column: auto;
    padding: 0 8px;
  }

  .leaflet-bottom {
    top: auto;
    bottom: 8px;
  }
}
