/* ============================================================================
   Got Bus Anot? — transit departure-board aesthetic.
   Near-black background, single amber/LED accent, monospace for data.
   Mobile-first, single-screen, restrained. Respects reduced motion.
   ========================================================================= */

/* --- Self-hosted fonts (variable; one file per subset covers all weights) --- */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("fonts/space-grotesk-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("fonts/space-grotesk-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg:        #0a0a0b;
  --panel:     #141416;
  --panel-2:   #1c1c20;
  --border:    #2a2a30;
  --text:      #e8e8ea;
  --text-dim:  #8a8a92;
  --accent:    #ffb000; /* amber LED */
  --accent-dim:#8a6010;
  --danger:    #ff5c5c;
  --good:      #5cd08a;

  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-sans: "Space Grotesk", system-ui, -apple-system, sans-serif;

  --radius: 10px;
  --maxw: 34rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  /* Gentle settle on first paint. */
  animation: appIn 0.4s ease both;
}
@keyframes appIn {
  from { opacity: 0; transform: translateY(6px); }
}

/* --- Top bar --------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.topbar__brand { display: flex; align-items: center; gap: 0.55rem; }

/* Blinking amber "live" dot — hard toggle between lit and unlit (never gone). */
.topbar__dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 176, 0, 0.7);
  animation: blink 3s step-end infinite;
}

@keyframes blink {
  50% { background: var(--accent-dim); box-shadow: none; }
}

.topbar__name {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.16em;
  color: var(--text);
}

.topbar__clock { display: flex; align-items: baseline; gap: 0.4rem; }

.topbar__time {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.topbar__tz {
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

/* --- Tagline --------------------------------------------------------------- */

.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.5;
}
.tagline strong { color: var(--text); font-weight: 700; }

/* --- Controls / form ------------------------------------------------------ */

.controls {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.1rem;
}

.field { position: relative; display: flex; flex-direction: column; gap: 0.4rem; }

.field__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

.field__row { display: flex; gap: 0.5rem; }
.field__row--between { justify-content: space-between; align-items: center; }

/* Wraps an input so the clear button can sit inside its right edge. */
.field__control { position: relative; flex: 1; min-width: 0; display: flex; }

.field__input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  padding: 0.75rem 2.4rem 0.75rem 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field__input::placeholder { color: #55555c; }

.field__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 176, 0, 0.18);
}

.field__input:disabled { opacity: 0.5; cursor: not-allowed; }

.field__hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-dim);
}
.field__hint:empty { display: none; }

/* Stop-filter box: same field styling, a touch smaller (right pad leaves room for ×). */
.field__input--filter {
  font-size: 0.95rem;
  padding: 0.6rem 2.4rem 0.6rem 0.9rem;
}
#stop-tools[hidden] { display: none; }
/* Fade the filter + locate row in when a service's stops load (it goes from
   display:none to shown, which restarts this animation). */
#stop-tools:not([hidden]) { animation: toolsIn 0.3s ease both; }
@keyframes toolsIn {
  from { opacity: 0; transform: translateY(-4px); }
}

/* Clear (×) button living inside the right edge of a field — plain glyph. */
.input-clear {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease;
}

.input-clear:hover { color: var(--accent); }
.input-clear:focus-visible {
  outline: none;
  color: var(--accent);
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(255, 176, 0, 0.35);
}
.input-clear[hidden] { display: none; }
.input-clear:active { transform: translateY(-50%) scale(0.85); }
/* Pop in when the field gains text (keeps the -50% centring in every frame). */
.input-clear:not([hidden]) { animation: clearIn 0.18s ease both; }
@keyframes clearIn {
  from { opacity: 0; transform: translateY(-50%) scale(0.6); }
  to   { opacity: 1; transform: translateY(-50%) scale(1); }
}

.locate-btn {
  flex: 0 0 auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.locate-btn:hover:not(:disabled) { border-color: var(--accent); }
.locate-btn:active:not(:disabled) { transform: scale(0.94); }
.locate-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 176, 0, 0.18);
}
.locate-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Icon-only variant: a button holding the "my location" crosshair. */
.locate-btn--icon {
  padding: 0 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}
.locate-icon { width: 1.3rem; height: 1.3rem; display: block; }

/* Lit when the list is sorted by distance. */
.locate-btn.is-active {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: rgba(255, 176, 0, 0.08);
}

/* Spin the crosshair while acquiring a fix. */
.locate-btn.is-locating .locate-icon { animation: spin 0.9s linear infinite; }
/* A single turn as feedback when toggling with a cached fix. */
.locate-icon.spin-once { animation: spin 0.5s ease; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Stop list + direction toggle ----------------------------------------- */

/* Shared segmented control: a bordered track with a sliding amber "thumb" that
   stretches toward the other side as it moves (liquid flow). overflow:hidden so
   the stretch is clipped to the track, reading as the yellow flowing across.
   Used for the stop-list direction toggle, the result switcher, and (as a
   single static segment) the loop-service header. */
.dir-toggle {
  position: relative;
  overflow: hidden;
  display: flex;
  gap: 0;
  padding: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.dir-toggle:not(.dir-toggle--static):active { transform: scale(0.99); }
.dir-toggle[hidden] { display: none; }
/* Fade the direction toggle in when it first appears for a service. */
#stop-dir-toggle:not([hidden]) { animation: toolsIn 0.3s ease both; }
.dir-toggle:not(.dir-toggle--static):hover { border-color: var(--accent-dim); }
.dir-toggle:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 176, 0, 0.18);
}
/* Nudge the inactive label brighter on hover to hint it's tappable. */
.dir-toggle:not(.dir-toggle--static):hover .dir-toggle__seg:not([aria-selected="true"]) {
  color: var(--text);
}
/* A single-direction (loop) route: same shape, but a dim outlined fill and
   amber text (a header, not a solid tappable button). */
.dir-toggle--static { cursor: default; }
.dir-toggle--static .dir-toggle__fill {
  background: rgba(255, 176, 0, 0.08);
  border: 1px solid var(--accent-dim);
  box-shadow: none;
}
.dir-toggle--static .dir-toggle__seg[aria-selected="true"] { color: var(--accent); }

#stop-dir-toggle { margin-bottom: 0.7rem; }

/* Positioned wrapper that slides between segments. */
.dir-toggle__thumb {
  position: absolute;
  top: 0.25rem;
  bottom: 0.25rem;
  left: 0.25rem;
  width: calc((100% - 0.5rem) / var(--n, 2));
  pointer-events: none;
  transition: transform 0.32s cubic-bezier(0.34, 1.3, 0.64, 1);
}
/* The visible amber; scales horizontally mid-slide to "flow". */
.dir-toggle__fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  border-radius: calc(var(--radius) - 4px);
  box-shadow: 0 0 12px rgba(255, 176, 0, 0.3);
}
.dir-toggle__thumb.is-flowing .dir-toggle__fill {
  animation: thumbFlow 0.34s ease;
}
@keyframes thumbFlow {
  0%, 100% { transform: scaleX(1); }
  45%      { transform: scaleX(1.6); }
}

.dir-toggle__seg {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.6rem;
  transition: color 0.2s ease;
}
.dir-toggle__seg[aria-selected="true"] {
  color: var(--bg);
  font-weight: 700;
}

/* Terminal name truncates rather than wrapping. */
.dir-toggle__seg-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-lists {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Subtle fade/rise of the whole list box — masks the empty-box flash while the
   rows stagger in on top of it. */
@keyframes listEnter {
  from { opacity: 0; transform: translateY(4px); }
}

/* Staggered entrance for the stop list, so it builds up instead of snapping in.
   A fresh service rises up; a direction toggle slides the rows in horizontally
   from the side the thumb travels toward. --enter-x/-y set the start offset and
   --i (both set per item) offsets each row's start. */
.stop-list--reveal { animation: listEnter 0.28s ease; }
.stop-list--reveal .stop-list__item {
  --enter-x: 0px;
  --enter-y: 9px;
  opacity: 0;
  animation: stopItemIn 0.34s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
  animation-delay: calc(var(--i, 0) * 32ms);
}
.stop-list--reveal-fwd  .stop-list__item { --enter-x: 24px;  --enter-y: 0px; }
.stop-list--reveal-back .stop-list__item { --enter-x: -24px; --enter-y: 0px; }
@keyframes stopItemIn {
  from { opacity: 0; transform: translate(var(--enter-x), var(--enter-y)); }
  to   { opacity: 1; transform: none; }
}

/* Light whole-list fade as the filter narrows the matches — no per-item stagger
   so it stays smooth when it re-runs on every keystroke. */
.stop-list--filter { animation: listEnter 0.16s ease; }

.stop-list {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* The stops scroll within the list so the panel stays a manageable height. */
.stop-list__items {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 22rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;                       /* Firefox */
  scrollbar-color: var(--border) transparent;
}

/* Slim, themed scrollbar (WebKit/Blink). */
.stop-list__items::-webkit-scrollbar { width: 10px; }
.stop-list__items::-webkit-scrollbar-track { background: transparent; }
.stop-list__items::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 3px solid var(--bg);                 /* insets the thumb so it reads as a thin pill */
}
.stop-list__items::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

.stop-list__item {
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.stop-list__item:last-child { border-bottom: none; }
.stop-list__item:hover { background: var(--panel-2); }
/* Press feedback — the row dips slightly when tapped. */
.stop-list__item:active { transform: scale(0.99); }

.stop-list__item.is-selected {
  background: rgba(255, 176, 0, 0.08);
  box-shadow: inset 3px 0 0 var(--accent);
}

.stop-list__item:focus-visible {
  outline: none;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 2px var(--accent-dim);
}

.stop-list__name { font-size: 0.92rem; }
.stop-list__sub {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.stop-list__dist {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}

/* Shown when the filter matches no stops. */
.stop-lists__empty {
  margin: 0;
  padding: 0.9rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* --- Result panel --------------------------------------------------------- */

.result {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.1rem 1.25rem;
}

/* Fade/rise the card in on each pick, with the schedule rows rising in after
   it (--i, set per row, staggers them). */
.result--enter { animation: resultIn 0.28s ease; }
@keyframes resultIn {
  from { opacity: 0; transform: translateY(8px); }
}
.result--enter .times tbody tr {
  opacity: 0;
  animation: rowIn 0.34s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
  animation-delay: calc(0.12s + var(--i, 0) * 70ms);
}
@keyframes rowIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.result__head { margin-bottom: 0.9rem; }

/* Service badge + terminal, divided from the stop line below. */
.result__service {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-bottom: 0.85rem;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.result__badge {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--bg);
  background: var(--accent);
  border-radius: 8px;
  padding: 0.15rem 0.7rem;
  letter-spacing: 0.02em;
  box-shadow: 0 0 16px rgba(255, 176, 0, 0.3);
}

.result__terminal {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 1rem;
  color: var(--text);
}

.result__stopline {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
}

.result__stop {
  font-family: var(--font-sans);
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.result__road {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.result__code {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 0.78rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1rem 0.5rem;
  font-variant-numeric: tabular-nums;
}

/* --- Times table ---------------------------------------------------------- */

.times {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.times th,
.times td {
  text-align: left;
  padding: 0.85rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.times th {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  font-weight: 500;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.times td {
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--text);
}
.times td:first-child {
  color: var(--text-dim);
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
}

.times tbody tr:last-child td { border-bottom: none; }

/* Amber colon for the departure-board look; digits keep the cell colour. */
.t-colon { color: var(--accent); }

/* Small dim "+1" marking an after-midnight (next-day) time. */
.t-next {
  font-size: 0.55em;
  color: var(--text-dim);
  vertical-align: super;
  margin-left: 0.15rem;
  font-weight: 400;
}

/* "TODAY" pill next to the current day's label. */
.today-badge {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.05rem 0.4rem;
  border-radius: 5px;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* Today's row is highlighted in the accent colour, with a left marker bar. */
.times tr.is-today td {
  color: var(--accent);
  background: rgba(255, 176, 0, 0.06);
}
.times tr.is-today td:first-child {
  color: var(--accent);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent);
}
/* On the highlighted row the colon already matches — keep it amber. */
.times tr.is-today .t-colon { color: var(--accent); }

/* --- Message / empty state ------------------------------------------------ */

.message {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 1rem;
}

/* --- Footer --------------------------------------------------------------- */

.footer {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.footer p { margin: 0 0 0.5rem; }
.footer a { color: var(--accent); text-decoration: underline; }
.footer a:hover { color: var(--accent); }
.footer__freshness { color: #55555c; }

/* --- Reduced motion ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  /* The staggered stops/rows start hidden and rely on their animation to
     reveal; without it they must show immediately. */
  .stop-list--reveal .stop-list__item,
  .result--enter .times tbody tr { opacity: 1; }
}
