/* ============================================================
   NEXT BUS · a Singapore LED departure board
   amber dot-matrix on night black · Doto + Overpass
   ============================================================ */

:root {
  --night: #08090b;
  --asphalt: #0d0f12;
  --bezel: #16181c;
  --bezel-edge: #23262c;
  --board: #0a0a08;
  --amber: #ffb000;
  --amber-dim: #6e4d09;
  --amber-glow: rgba(255, 176, 0, 0.45);
  --sea: #45e07c;      /* seats available */
  --sda: #ffc24d;      /* standing available */
  --lsd: #ff5d5d;      /* limited standing */
  --ink: #d8d3c8;
  --ink-dim: #7a766d;
  --led-font: "Doto", monospace;
  --ui-font: "Overpass", sans-serif;
}

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

html { height: 100%; }

body {
  min-height: 100dvh;
  background: var(--night);
  color: var(--ink);
  font-family: var(--ui-font);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: 4px;
}

button { touch-action: manipulation; }

/* ---------- night backdrop ---------- */

.night {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(120% 70% at 50% -10%, #14161c 0%, transparent 60%),
    linear-gradient(180deg, #0a0b0e 0%, var(--night) 45%, #060708 100%);
}

.streetglow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(45% 30% at 18% 0%, rgba(255, 176, 0, 0.05), transparent 70%),
    radial-gradient(50% 35% at 85% 8%, rgba(120, 160, 255, 0.04), transparent 70%);
}

.grain {
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- layout ---------- */

.scene {
  max-width: 860px;
  margin: 0 auto;
  padding: clamp(24px, 5vh, 56px) 20px calc(48px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 16px;
  animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.masthead-title {
  font-family: var(--led-font);
  font-weight: 900;
  font-size: clamp(22px, 4vw, 30px);
  letter-spacing: 0.12em;
  color: var(--ink);
  display: flex;
  align-items: baseline;
}

.masthead-slash {
  font-family: var(--ui-font);
  font-weight: 300;
  font-size: 1.25em;
  line-height: 0;
  color: rgba(216, 211, 200, 0.16);
  margin: 0 0.45em 0 0.55em;
  transform: skewX(-12deg) translateY(0.04em);
  user-select: none;
}

.masthead-zh {
  font-family: var(--ui-font);
  font-weight: 300;
  font-size: 0.62em;
  letter-spacing: 0.4em;
  color: var(--ink-dim);
}

/* ---------- the board ---------- */

.board {
  position: relative;
  border-radius: 14px;
  background:
    linear-gradient(180deg, var(--bezel-edge), var(--bezel) 8%, #101216 92%, #0a0b0d),
    var(--bezel);
  padding: 14px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 -1px 0 rgba(0, 0, 0, 0.6) inset,
    0 24px 60px -18px rgba(0, 0, 0, 0.9),
    0 0 90px -30px var(--amber-glow);
  animation: rise 0.7s 0.12s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.board-top,
.rows,
.board-bottom {
  position: relative;
  z-index: 1;
  background: var(--board);
}

.board-top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px 10px;
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid #1c1a12;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--led-font);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--sea);
}

.live.is-down { color: var(--lsd); }

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}

.stopline {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
  overflow: hidden;
  white-space: nowrap;
}

.stop-code {
  font-family: var(--led-font);
  font-weight: 900;
  font-size: clamp(17px, 2.6vw, 22px);
  letter-spacing: 0.1em;
  color: var(--amber);
  text-shadow: 0 0 14px var(--amber-glow);
}

.stop-name {
  font-family: var(--led-font);
  font-weight: 600;
  font-size: clamp(13px, 2vw, 16px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--amber);
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stop-road {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.clock {
  font-family: var(--led-font);
  font-weight: 700;
  font-size: clamp(14px, 2.2vw, 18px);
  letter-spacing: 0.12em;
  color: var(--amber);
  text-shadow: 0 0 12px var(--amber-glow);
  font-variant-numeric: tabular-nums;
}

/* ---------- service rows ---------- */

.rows {
  min-height: 180px;
  display: flex;
  flex-direction: column;
}

.row {
  display: grid;
  grid-template-columns: minmax(64px, auto) 1fr repeat(3, minmax(64px, 78px));
  align-items: center;
  gap: 8px 14px;
  padding: 13px 18px;
  border-bottom: 1px solid #15130c;
  animation: poweron 0.5s ease-out both;
}

.row:nth-child(1) { animation-delay: 0.05s; }
.row:nth-child(2) { animation-delay: 0.14s; }
.row:nth-child(3) { animation-delay: 0.23s; }
.row:nth-child(4) { animation-delay: 0.32s; }
.row:nth-child(5) { animation-delay: 0.41s; }
.row:nth-child(6) { animation-delay: 0.50s; }
.row:nth-child(7) { animation-delay: 0.59s; }
.row:nth-child(8) { animation-delay: 0.68s; }

.row:last-child { border-bottom: 0; }

.svc {
  font-family: var(--led-font);
  font-weight: 900;
  font-size: clamp(24px, 4.4vw, 34px);
  letter-spacing: 0.06em;
  color: var(--amber);
  text-shadow: 0 0 16px var(--amber-glow);
  text-align: left;
  line-height: 1;
}

.dest {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dest-name {
  font-family: var(--led-font);
  font-weight: 600;
  font-size: clamp(12px, 1.9vw, 15px);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--amber);
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dest-meta {
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.eta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1;
}

.eta-min {
  font-family: var(--led-font);
  font-weight: 900;
  font-size: clamp(22px, 4vw, 30px);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.eta-sub {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.eta.l-sea .eta-min { color: var(--sea); text-shadow: 0 0 14px rgba(69, 224, 124, 0.4); }
.eta.l-sda .eta-min { color: var(--sda); text-shadow: 0 0 14px rgba(255, 194, 77, 0.4); }
.eta.l-lsd .eta-min { color: var(--lsd); text-shadow: 0 0 14px rgba(255, 93, 93, 0.4); }

.eta.is-empty .eta-min { color: var(--amber-dim); text-shadow: none; }

.eta.is-arr .eta-min {
  font-size: clamp(15px, 2.6vw, 19px);
  letter-spacing: 0.14em;
  animation: blink 1s steps(2, start) infinite;
}

.eta.is-sched .eta-min { opacity: 0.55; text-shadow: none; }

.board-msg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 18px;
  font-family: var(--led-font);
  font-weight: 700;
  font-size: clamp(14px, 2.4vw, 18px);
  letter-spacing: 0.3em;
  color: var(--amber-dim);
  text-align: center;
  animation: blink 2.4s steps(2, start) infinite;
}

/* ---------- board footer ---------- */

.board-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 18px 12px;
  border-radius: 0 0 8px 8px;
  border-top: 1px solid #1c1a12;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.lg { display: inline-flex; align-items: center; gap: 6px; }

.lded {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.l-sea.lded { background: var(--sea); box-shadow: 0 0 6px var(--sea); }
.l-sda.lded { background: var(--sda); box-shadow: 0 0 6px var(--sda); }
.l-lsd.lded { background: var(--lsd); box-shadow: 0 0 6px var(--lsd); }

.refresh {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.sweep {
  width: 72px;
  height: 3px;
  border-radius: 2px;
  background: #1c1a12;
  overflow: hidden;
}

.sweep-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber-glow);
  transform-origin: left;
  transform: scaleX(0);
}

.sweep-fill.is-running { animation: sweep 20s linear forwards; }

/* ---------- LED texture + glass ---------- */

.led-grid {
  position: absolute;
  inset: 14px;
  z-index: 2;
  pointer-events: none;
  border-radius: 8px;
  background-image: radial-gradient(circle, transparent 0 34%, rgba(0, 0, 0, 0.55) 38%);
  background-size: 3px 3px;
  opacity: 0.5;
}

.board-glass {
  position: absolute;
  inset: 14px;
  z-index: 3;
  pointer-events: none;
  border-radius: 8px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.05) 0%, transparent 28%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7) inset;
}

/* ---------- console (stop picker) ---------- */

.console {
  position: relative;
  z-index: 20; /* search dropdown must overlay the board below it */
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: rise 0.7s 0.06s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.searchwrap { position: relative; }

.search-label {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--ink-dim);
  pointer-events: none;
}

.search {
  width: 100%;
  min-height: 48px;
  padding: 13px 16px 12px 122px;
  border: 1px solid #22242a;
  border-radius: 9px;
  background: var(--asphalt);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 16px; /* ≥16px keeps iOS from auto-zooming on focus */
  font-weight: 400;
  letter-spacing: 0.04em;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search::placeholder { color: #4a4c52; }

.search:focus {
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 3px rgba(255, 176, 0, 0.08);
}

.results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 10;
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #22242a;
  border-radius: 9px;
  background: #101216;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.85);
}

.results li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-height: 44px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #1a1c21;
}

.results li:last-child { border-bottom: 0; }

.results li:hover,
.results li.is-active { background: rgba(255, 176, 0, 0.07); }

.r-code {
  font-family: var(--led-font);
  font-weight: 700;
  font-size: 13px;
  color: var(--amber);
  flex-shrink: 0;
}

.r-name { font-size: 13px; font-weight: 600; }

.r-road {
  margin-left: auto;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  flex-shrink: 0;
}

.recent {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-height: 36px;
  padding: 8px 14px 7px;
  border: 1px solid #22242a;
  border-radius: 99px;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--ui-font);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.chip:hover { border-color: var(--amber-dim); color: var(--ink); }

.chip:active { transform: scale(0.97); }

.chip .c-code {
  font-family: var(--led-font);
  font-weight: 700;
  color: var(--amber);
  opacity: 0.85;
}

/* ---------- waypost (map noticeboard on two posts) ---------- */

.waypost {
  display: flex;
  flex-direction: column;
  animation: rise 0.7s 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.sign-alert {
  margin: 0 0 12px;
  padding: 10px 16px 9px;
  border: 2px solid rgba(255, 93, 93, 0.65);
  border-radius: 8px;
  background: rgba(60, 14, 14, 0.55);
  color: #ffb8b8;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.mapframe {
  position: relative;
  z-index: 1;
  border-radius: 14px;
  background:
    linear-gradient(180deg, var(--bezel-edge), var(--bezel) 8%, #101216 92%, #0a0b0d),
    var(--bezel);
  padding: 10px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 -1px 0 rgba(0, 0, 0, 0.6) inset,
    0 24px 60px -18px rgba(0, 0, 0, 0.9);
}

.map {
  height: clamp(320px, 48vh, 460px);
  border-radius: 8px;
  background: var(--asphalt);
  z-index: 1;
}

.locate-fab {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 1001; /* above leaflet panes and controls */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #2a2d34;
  border-radius: 10px;
  background: linear-gradient(180deg, #16181d, #0e1013);
  color: var(--amber);
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 10px 24px -8px rgba(0, 0, 0, 0.85);
  transition: color 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.locate-fab:hover {
  border-color: var(--amber-dim);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 10px 24px -8px rgba(0, 0, 0, 0.85),
    0 0 18px -4px var(--amber-glow);
}

.locate-fab:active { transform: scale(0.94); }

.locate-fab[aria-busy="true"] svg { animation: spin 1.1s linear infinite; }

.maphint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 1001;
  padding: 7px 14px 6px;
  border-radius: 6px;
  border: 1px solid #2a2d34;
  background: rgba(8, 9, 11, 0.85);
  color: var(--ink-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  pointer-events: none;
  white-space: nowrap;
}

/* two mounting posts: the map card reads as a street noticeboard */

.posts {
  display: flex;
  justify-content: space-between;
  padding: 0 16%;
  height: 88px;
  margin-top: -6px;
}

.post {
  position: relative;
  width: 16px;
  height: 100%;
  background: linear-gradient(90deg, #15171b 0%, #2c3038 38%, #1b1e23 62%, #0d0f12 100%);
  border-radius: 0 0 3px 3px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}

/* base plate bolted to the ground */
.post::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: -8px;
  right: -8px;
  height: 7px;
  border-radius: 3px 3px 1px 1px;
  background: linear-gradient(180deg, #1d2026, #0c0e11);
}

/* pooled street-light shadow under each post */
.post::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 84px;
  height: 14px;
  background: radial-gradient(50% 50% at 50% 50%, rgba(0, 0, 0, 0.75), transparent 70%);
}

/* leaflet dark-theme overrides */

.leaflet-container {
  background: var(--asphalt);
  font-family: var(--ui-font);
}

.leaflet-control-zoom a {
  background: #101216 !important;
  color: var(--ink) !important;
  border-color: #22242a !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
}

.leaflet-control-zoom a:hover { background: #1a1d22 !important; color: var(--amber) !important; }

.leaflet-bar { border: 1px solid #22242a !important; box-shadow: 0 8px 20px -8px rgba(0,0,0,0.8) !important; }

.leaflet-control-attribution {
  background: rgba(8, 9, 11, 0.75) !important;
  color: #54565c !important;
  font-size: 9px !important;
}

.leaflet-control-attribution a { color: #7d8089 !important; }

.leaflet-tooltip.stop-tip {
  background: #101216;
  border: 1px solid var(--amber-dim);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.8);
}

.leaflet-tooltip.stop-tip::before { display: none; }

.user-dot {
  background: #fff;
  border: 2px solid var(--amber);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--amber-glow);
}

/* ---------- colophon ---------- */

.colophon {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  text-align: center;
  gap: 6px 24px;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.1em;
  color: #54565c;
  animation: rise 0.7s 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.colophon a { color: #7d8089; text-decoration: none; border-bottom: 1px solid #2a2c33; }
.colophon a:hover { color: var(--amber); border-color: var(--amber-dim); }

.noscript {
  padding: 24px;
  text-align: center;
  font-family: var(--ui-font);
  color: var(--lsd);
}

/* ---------- animation ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes poweron {
  0% { opacity: 0; }
  30% { opacity: 0.9; }
  45% { opacity: 0.2; }
  60% { opacity: 1; }
  72% { opacity: 0.55; }
  100% { opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

@keyframes sweep {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

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

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .sweep-fill.is-running { animation: none; transform: scaleX(1); }
}

/* ---------- small screens ---------- */

@media (max-width: 560px) {
  .scene { padding-left: 14px; padding-right: 14px; gap: 18px; }
  .row { grid-template-columns: minmax(48px, auto) 1fr repeat(3, minmax(42px, 50px)); gap: 8px; padding: 12px 12px; }
  .board { padding: 10px; }
  .led-grid, .board-glass { inset: 10px; }
  .board-top { flex-wrap: wrap; gap: 10px; padding: 12px 12px 8px; }
  .stopline { order: 3; flex-basis: 100%; }
  .board-bottom { padding: 8px 12px 10px; }
  .search { padding-left: 16px; }
  .search-label { display: none; }
  .stop-road { display: none; }
  .legend .lg-note { display: none; }
  .map { height: clamp(300px, 44vh, 420px); }
  .mapframe { padding: 8px; }
  .locate-fab { top: 18px; right: 18px; }
  .posts { padding: 0 13%; height: 64px; }
  .post { width: 13px; }
  .post::after { width: 64px; }
}
