:root {
  --ink: #1f2a44;
  --muted: #6b7690;
  --card: rgba(255, 255, 255, 0.86);
  --card-border: rgba(31, 42, 68, 0.08);
  --accent: #ff6b35;
  --dlr: #00afad;
  --shadow: 0 6px 24px rgba(31, 42, 68, 0.14);
  --radius: 16px;
  font-family: 'Nunito', ui-rounded, system-ui, -apple-system, sans-serif;
  color: var(--ink);
}

body.night {
  --ink: #e8edff;
  --muted: #9aa6c4;
  --card: rgba(22, 29, 50, 0.82);
  --card-border: rgba(255, 255, 255, 0.08);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #b9d495;
  overscroll-behavior: none;
}

body.night {
  background: #2a3550;
}

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#map.dragging {
  cursor: grabbing;
}
#map.pointer {
  cursor: pointer;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink);
}

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

a {
  color: inherit;
}

/* title */
.title {
  position: fixed;
  top: 16px;
  left: 16px;
  padding: 14px 18px;
  max-width: min(360px, calc(100vw - 32px));
}
.title h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.title p {
  margin: 4px 0 10px;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--muted);
}
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 13px;
}
.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2bc46b;
  box-shadow: 0 0 0 0 rgba(43, 196, 107, 0.6);
  animation: pulse 2s infinite;
}
.dot.stale {
  background: #e0a030;
}
@keyframes pulse {
  70% {
    box-shadow: 0 0 0 8px rgba(43, 196, 107, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(43, 196, 107, 0);
  }
}

/* top right chips */
.top-right {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: calc(100vw - 32px);
}
.chip {
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  min-width: 120px;
}
.chip-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}
.chip-value {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

/* plane card */
#plane-card {
  position: fixed;
  top: 84px;
  right: 16px;
  width: 300px;
  max-width: calc(100vw - 32px);
  padding: 14px 16px 16px;
  animation: slide 0.18s ease-out;
}
@keyframes slide {
  from {
    transform: translateX(16px);
    opacity: 0;
  }
}
.pc-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.pc-tail {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex: none;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
}
.pc-titles {
  flex: 1;
  min-width: 0;
}
.pc-call {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.pc-airline {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pc-route {
  margin: 12px 0 4px;
  font-size: 15px;
  font-weight: 700;
  min-height: 20px;
}
.pc-route small {
  display: block;
  font-weight: 500;
  font-size: 12.5px;
  color: var(--muted);
}
.pc-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  margin: 10px 0 12px;
  font-size: 13.5px;
}
.pc-grid dt {
  color: var(--muted);
}
.pc-grid dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.pc-actions {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--card-border), inset 0 0 0 1.5px rgba(127, 127, 127, 0.3);
}
.btn.active {
  background: var(--ink);
  color: var(--card);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: inline-grid;
  place-items: center;
}
.icon-btn:hover {
  filter: brightness(0.96);
}
.icon-btn.on {
  background: var(--ink);
  color: var(--card);
}
.pc-head .icon-btn,
.modal-head .icon-btn {
  box-shadow: none;
  width: 32px;
  height: 32px;
  background: transparent;
}

/* controls */
.controls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(2, 40px);
  gap: 8px;
}

/* trains */
.left-stack {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 320px;
  max-width: calc(100vw - 32px - 96px);
  max-height: calc(100vh - 190px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.panel {
  pointer-events: auto;
  overflow: auto;
  padding: 10px 14px 12px;
  flex: 0 1 auto;
  min-height: 42px;
}
.panel.collapsed #train-list,
.panel.collapsed #departure-list,
.panel.collapsed #arrival-list {
  display: none;
}
.arrival {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 2px 8px;
  align-items: center;
  margin-top: 8px;
  padding: 2px 4px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.arrival:hover,
.arrival.selected {
  background: rgba(255, 107, 53, 0.14);
}
.arrival .chip-tail {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  grid-row: span 2;
}
.arrival .flight {
  font-weight: 800;
}
.arrival .from {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.arrival .eta {
  grid-row: span 2;
  text-align: right;
}
.arrival.far {
  cursor: default;
}
.trains-head {
  all: unset;
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
}
.trains-head .muted {
  font-size: 12px;
  font-weight: 500;
}
.station {
  margin-top: 10px;
  border-radius: 10px;
  transition: background 0.3s;
}
.station.highlight {
  background: rgba(255, 107, 53, 0.14);
  box-shadow: 0 0 0 6px rgba(255, 107, 53, 0.14);
}
.station-name {
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 3px;
}
.train-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  line-height: 1.6;
}
.line-pill {
  font-size: 10.5px;
  font-weight: 800;
  color: #fff;
  border-radius: 6px;
  padding: 0 6px;
  flex: none;
  min-width: 64px;
  text-align: center;
}
.line-pill {
  background: #5b6478;
}
.line-pill.dlr {
  background: var(--dlr);
}
.towards {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.eta {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.eta.now {
  color: var(--accent);
}

/* modals */
.modal {
  padding: 18px 20px 20px;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: auto;
}
.modal::backdrop {
  background: rgba(20, 28, 48, 0.35);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}
.modal h3 {
  margin: 16px 0 6px;
  font-size: 14px;
}
.modal p {
  font-size: 14px;
  line-height: 1.45;
}
.help {
  margin: 0;
  padding-left: 18px;
  font-size: 13.5px;
  line-height: 1.6;
}
.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.livery {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(127, 127, 127, 0.08);
  font-size: 12.5px;
  font-weight: 700;
}
.livery .swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex: none;
  position: relative;
  overflow: hidden;
}
.livery .swatch i {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 45%;
  height: 45%;
  border-top-left-radius: 4px;
}
.livery.locked {
  opacity: 0.4;
  filter: grayscale(1);
}
.livery .count {
  margin-left: auto;
  color: var(--muted);
  font-weight: 500;
}

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
  color: #3d5a2a;
  pointer-events: none;
  transition: opacity 0.4s;
}
.loading.done {
  opacity: 0;
}

@media (max-width: 640px) {
  .title {
    padding: 10px 14px;
  }
  .title h1 {
    font-size: 21px;
  }
  .title p {
    display: none;
  }
  .top-right {
    top: auto;
    bottom: 16px;
    right: 112px;
    left: auto;
    flex-direction: column;
    align-items: flex-end;
  }
  .chip {
    min-width: 0;
    padding: 6px 10px;
  }
  .left-stack {
    bottom: auto;
    top: 104px;
    max-height: 45vh;
    max-width: calc(100vw - 32px);
    width: 280px;
  }
  .pc-grid {
    grid-template-columns: auto 1fr auto 1fr;
    font-size: 12.5px;
  }
  .pc-route {
    margin-top: 8px;
  }
  #plane-card {
    top: auto;
    bottom: 16px;
    left: 16px;
    right: 16px;
    width: auto;
    z-index: 2;
  }
}

/* bare map for tile rendering (?clean=1) */
body.clean > :not(canvas) {
  display: none !important;
}

/* fold marker on the side panels */
.chev {
  display: inline-block;
  width: 16px;
  color: var(--muted);
  transition: transform 0.15s;
}
.panel.collapsed .chev {
  transform: rotate(-90deg);
}

/* the service a selected train belongs to */
.train-row.selected {
  background: rgba(255, 107, 53, 0.18);
  box-shadow: 0 0 0 4px rgba(255, 107, 53, 0.18);
  border-radius: 6px;
}
