/* PTV Tram Stop Tracker — kiosk styles
   Target: portrait 1080x1920. Bottom 4/5 tracker, top 1/5 image band.
   Palette: Okabe-Ito derived, colour-blind safe (deuteran/protan/tritan). */

:root {
  --bg: #0b1220;
  --surface: #15203a;
  --surface-alt: #1b284a;
  --text: #f5f7fa;
  --text-dim: #a8b3cf;
  --accent-imminent: #ffb000; /* amber — ≤1 min */
  --accent-soon: #56b4e9;     /* sky blue — 2-5 min */
  --accent-later: #f5f7fa;    /* off-white — 6+ min */
  --accent-badge: #e69f00;    /* Okabe-Ito orange */
  --accent-icon: #56b4e9;
  --accent-warn: #ffb000;
  --accent-error: #ff6b6b;
  --row-radius: 18px;
}

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

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
}

/* The body keeps fixed kiosk dimensions so layout is pixel-exact at the
   target display resolution. The html element keeps default overflow so a
   smaller browser window can scroll to reveal the rest of the kiosk —
   without this the bottom of the URL builder gets clipped during dev. */
body {
  width: 1080px;
  height: 1920px;
  overflow: hidden;
}

.kiosk {
  display: grid;
  grid-template-rows: 384px 110px 1fr 80px;
  width: 1080px;
  height: 1920px;
}

/* === TOP IMAGE BAND (1/5) === */
.band-image {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.band-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

/* === HEADER === */
.band-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 48px;
  background: var(--bg);
  border-bottom: 1px solid rgba(168, 179, 207, 0.12);
}
.stop-name {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 700px;
}
.stop-meta {
  display: flex;
  align-items: center;
  gap: 32px;
  font-size: 36px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.direction-label {
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 24px;
  font-size: 28px;
  color: var(--text);
  font-weight: 600;
}

/* === TRACKER === */
.band-tracker {
  position: relative;
  padding: 18px 28px 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sections {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}
.direction-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.direction-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 6px 6px;
  border-bottom: 2px solid rgba(86, 180, 233, 0.35);
  margin-bottom: 8px;
}
.direction-name {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent-soon);
}
.direction-stop {
  font-size: 18px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
/* Hide the heading when there's only one section (no pairing) */
.band-tracker[data-rows="3"] .direction-heading { display: none; }

.rows {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.row {
  display: grid;
  grid-template-columns: 160px 1fr 240px;
  align-items: center;
  gap: 24px;
  padding: 20px 28px;
  background: var(--surface);
  border-radius: var(--row-radius);
  border-left: 8px solid var(--accent-later);
  min-height: 0;
  overflow: hidden;
}

/* Compact mode when showing two directions (6 rows total). */
.band-tracker[data-rows="6"] .row {
  grid-template-columns: 110px 1fr 180px;
  gap: 18px;
  padding: 10px 20px;
}
.band-tracker[data-rows="6"] .route-badge { width: 100px; height: 100px; }
.band-tracker[data-rows="6"] .route-number { font-size: 60px; }
.band-tracker[data-rows="6"] .destination {
  font-size: 30px;
  line-height: 1.15;
  -webkit-line-clamp: 2;
}
.band-tracker[data-rows="6"] .minutes {
  font-size: 110px;
  letter-spacing: -3px;
}
.band-tracker[data-rows="6"] .min-label { font-size: 28px; }
.band-tracker[data-rows="6"] .row.is-text-label .minutes {
  font-size: 76px;
  letter-spacing: -2px;
}
.band-tracker[data-rows="6"] .row-icons { gap: 10px; min-height: 32px; }
.band-tracker[data-rows="6"] .icon { width: 32px; height: 32px; }
.row:nth-child(even) { background: var(--surface-alt); }
.row[data-urgency="imminent"] { border-left-color: var(--accent-imminent); }
.row[data-urgency="soon"]     { border-left-color: var(--accent-soon); }
.row[data-urgency="later"]    { border-left-color: var(--accent-later); }

.route-badge {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: var(--accent-badge);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}
.route-number {
  font-size: 88px;
  font-weight: 800;
  color: #1a1a1a;
  line-height: 1;
  letter-spacing: -2px;
}

.row-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.destination {
  font-size: 44px;
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  word-break: normal;
  overflow-wrap: break-word;
}
.row-icons {
  display: flex;
  gap: 16px;
  align-items: center;
  min-height: 48px;
}
.icon {
  width: 48px;
  height: 48px;
}
.icon-lowfloor { color: var(--accent-icon); }
.icon-disruption { color: var(--accent-warn); }

.row-time {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
}
.minutes {
  font-size: 170px;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -5px;
  color: var(--accent-later);
}
.min-label {
  font-size: 44px;
  font-weight: 500;
  color: var(--text-dim);
  margin-top: 2px;
}
.row[data-urgency="imminent"] .minutes { color: var(--accent-imminent); }
.row[data-urgency="soon"]     .minutes { color: var(--accent-soon); }
.row[data-urgency="later"]    .minutes { color: var(--accent-later); }

/* "Now" / "Due" labels — when displayLabel isn't numeric, swap the visual */
.row.is-text-label .minutes {
  font-size: 120px;
  letter-spacing: -3px;
}
.row.is-text-label .min-label { display: none; }

/* === FOOTER === */
.band-footer {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 8px 24px 0;
  font-size: 22px;
  color: var(--text-dim);
  background: var(--bg);
  border-top: 1px solid rgba(168, 179, 207, 0.08);
  overflow: hidden;
}
.footer-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 176, 0, 0.15);
  color: var(--accent-warn);
  border: 1px solid rgba(255, 176, 0, 0.35);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 18px;
  font-weight: 600;
  z-index: 2;
}
.footer-source {
  letter-spacing: 1px;
  opacity: 0.45;
  text-transform: uppercase;
  font-size: 14px;
  z-index: 2;
  align-self: flex-start;
  padding-top: 4px;
}

/* === TRAM ANIMATION === */
.tram-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  pointer-events: none;
}
.tram-rail {
  position: absolute;
  bottom: 10px;
  left: 24px;
  right: 24px;
  height: 2px;
  background: linear-gradient(
    to right,
    rgba(168, 179, 207, 0.05) 0%,
    rgba(168, 179, 207, 0.25) 50%,
    rgba(168, 179, 207, 0.05) 100%
  );
  border-radius: 1px;
}
.tram-station {
  position: absolute;
  bottom: 15px;
  left: 88%;
  height: 60px;
  width: auto;
  z-index: 1;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
}

.tram {
  position: absolute;
  bottom: 16px;
  width: 120px;
  height: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.55));
  /* Start the cycle at the station (refresh moment) so the rhythm
     visually aligns with the 60 s polling cadence. */
  animation: tram-journey 60s linear infinite;
  will-change: left;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  z-index: 2;
}

/*
 * 60-second cycle keyed to the kiosk's 60 s refresh.
 *  0% .. 10%  — tram at station (≈ 6 s pause that frames the refresh tick)
 * 10% .. 18%  — rolling off the right edge
 * 18.001%     — teleport to just off-screen left (invisible)
 * 18.001% .. 100% — gliding back across to the station for next arrival
 */
@keyframes tram-journey {
  /* At the station (refresh moment) */
  0%        { left: 92%; animation-timing-function: linear; }
  /* Pause ~6 s while the new data lands */
  10%       { left: 92%; animation-timing-function: cubic-bezier(0.45, 0, 1, 0.7); }
  /* Accelerate off the right edge */
  18%       { left: calc(100% + 60px); animation-timing-function: linear; }
  /* Invisible teleport to just off the left edge */
  18.001%   { left: -80px; animation-timing-function: cubic-bezier(0.2, 0, 0.2, 1); }
  /* Decelerate gracefully as it pulls in to the station */
  100%      { left: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .tram { animation: none; left: 92%; }
}

/* === STATES === */
.state-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background: var(--bg);
}
.state-card {
  text-align: center;
  max-width: 900px;
}
.state-title {
  font-size: 72px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.05;
  margin-bottom: 32px;
}
.state-sub {
  font-size: 40px;
  color: var(--text-dim);
  line-height: 1.4;
}
.state-foot {
  font-size: 28px;
  color: var(--text-dim);
  margin-top: 48px;
  opacity: 0.7;
}
.state-icon {
  width: 200px;
  height: 200px;
  margin-bottom: 32px;
}
.state-card-error .state-title { color: var(--accent-error); }

.mono {
  font-family: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color: var(--accent-soon);
}

/* === EXPLAINER (search UI) === */
.state-overlay:has(.explainer) {
  align-items: stretch;
  justify-content: stretch;
  padding: 24px 36px 0;
}

/* In explainer mode the entire page scrolls naturally instead of using an
   internal scroll container. The kiosk's fixed 1080×1920 frame is loosened
   so the URL builder, route chips, and customise panels can flow as a long
   page. The kiosk view (when a stop is selected) is untouched. */
body.is-explainer-mode {
  height: auto;
  min-height: 100vh;
  overflow: visible;
}
body.is-explainer-mode .kiosk {
  height: auto;
  min-height: 100vh;
}
body.is-explainer-mode .band-tracker {
  overflow: visible;
  min-height: 0;
}
body.is-explainer-mode .state-overlay {
  position: relative;
  inset: auto;
  height: auto;
  overflow: visible;
}
.explainer {
  width: 100%;
  max-width: none;
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: left;
  /* Leave room at the end so the sticky builder bar never covers the last
     row of content when fully scrolled. */
  padding-bottom: 24px;
}
.explainer-title {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
}
.explainer-sub {
  font-size: 22px;
  color: var(--text-dim);
}
.explainer-search {
  width: 100%;
  padding: 18px 22px;
  background: var(--surface);
  border: 2px solid rgba(86, 180, 233, 0.35);
  border-radius: 14px;
  color: var(--text);
  font-size: 26px;
  font-family: inherit;
  outline: none;
}
.explainer-search:focus {
  border-color: var(--accent-soon);
  background: var(--surface-alt);
}
.explainer-search::placeholder { color: var(--text-dim); }

.explainer-section-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.route-chips {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
.route-chip {
  background: var(--surface);
  border: 1px solid rgba(168, 179, 207, 0.2);
  border-radius: 10px;
  padding: 14px 0;
  color: var(--text);
  font-family: inherit;
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  transition: background 80ms ease, transform 80ms ease;
  font-variant-numeric: tabular-nums;
}
.route-chip:hover { background: var(--surface-alt); }
.route-chip.is-selected {
  background: var(--accent-badge);
  color: #1a1a1a;
  border-color: var(--accent-badge);
}

.explainer-stops {
  display: flex;
  flex-direction: column;
}
.stops-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stop-pair {
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 16px;
  border-left: 4px solid var(--accent-badge);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stop-pair-info { display: flex; flex-direction: column; gap: 2px; }
.stop-pair-name { font-size: 20px; font-weight: 600; line-height: 1.2; }
.stop-pair-suburb { font-size: 14px; color: var(--text-dim); }
.stop-pair-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.stop-pair-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  background: var(--surface-alt);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--accent-soon);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(86, 180, 233, 0.25);
  transition: background 80ms ease;
}
.stop-pair-btn:hover { background: rgba(86, 180, 233, 0.18); }
.stop-pair-btn.is-disabled {
  opacity: 0.3;
  pointer-events: none;
  filter: grayscale(0.6);
}
.stop-pair-btn .dir-arrow { font-size: 15px; line-height: 1; }
.stop-pair-btn .dir-tid {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  opacity: 0.7;
}
.stop-pair-btn.dir-both {
  background: var(--accent-badge);
  color: #1a1a1a;
  border-color: var(--accent-badge);
}
.stop-pair-btn.dir-both:hover { background: var(--accent-imminent); }
.stop-pair-btn.is-selected {
  outline: 2px solid var(--accent-soon);
  outline-offset: 2px;
  filter: brightness(1.15);
}
.stop-pair.has-selection {
  border-left-color: var(--accent-soon);
}

.explainer-palettes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.palette-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.palette-preset {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid rgba(168, 179, 207, 0.2);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: transform 80ms ease, background 80ms ease;
}
.palette-preset:hover {
  background: var(--surface-alt);
  transform: translateY(-1px);
}
.palette-preset.is-applied {
  border-color: var(--accent-soon);
  box-shadow: 0 0 0 2px rgba(86, 180, 233, 0.25);
}
.palette-preset-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.palette-preset-swatches {
  display: flex;
  gap: 4px;
  height: 28px;
}
.palette-preset-swatches span {
  flex: 1;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.palette-preset-hex {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-hint,
.logo-hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}
.palette-hint.is-toast {
  color: var(--accent-soon);
  font-weight: 600;
}

/* === CUSTOMISE PANEL (palette + format + logo, two columns) === */
.explainer-customise {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: flex-start;
}
.customise-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* === FORMAT PRESETS === */
.format-presets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.format-preset {
  background: var(--surface);
  border: 1px solid rgba(168, 179, 207, 0.2);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: background 80ms ease;
}
.format-preset:hover { background: var(--surface-alt); }
.format-preset.is-selected {
  background: var(--accent-soon);
  color: #0a1224;
  border-color: var(--accent-soon);
}
.format-preset-name {
  font-size: 15px;
  font-weight: 700;
}
.format-preset-dims {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}

.logo-input {
  padding: 12px 16px;
  font-size: 18px;
}

/* === URL BUILDER BAR === */
.explainer-builder {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border: 1px solid rgba(86, 180, 233, 0.45);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Subtle outer glow so it reads as floating above the scroll content. */
  box-shadow: 0 -8px 24px rgba(11, 18, 32, 0.65);
  z-index: 5;
}
.builder-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.builder-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent-soon);
}
.builder-url {
  background: var(--bg);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 15px;
  color: var(--text);
  word-break: break-all;
  overflow-wrap: anywhere;
  border: 1px solid rgba(168, 179, 207, 0.1);
  min-height: 36px;
  line-height: 1.4;
}
.builder-actions { display: flex; gap: 8px; }
.builder-btn {
  flex: 1;
  background: var(--surface-alt);
  border: 1px solid rgba(168, 179, 207, 0.2);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 80ms ease;
}
.builder-btn:hover:not(.is-disabled):not(:disabled) {
  background: var(--accent-soon);
  color: #0a1224;
  border-color: var(--accent-soon);
}
.builder-btn.builder-open {
  background: var(--accent-badge);
  color: #1a1a1a;
  border-color: var(--accent-badge);
}
.builder-btn.builder-open:hover:not(.is-disabled) {
  background: var(--accent-imminent);
}
.builder-btn:disabled,
.builder-btn.is-disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.builder-btn.is-toast {
  background: var(--accent-soon);
  color: #0a1224;
}

.explainer-status {
  font-size: 18px;
  color: var(--text-dim);
  text-align: center;
  padding: 12px 0;
}
.explainer-foot {
  font-size: 16px;
  color: var(--text-dim);
  border-top: 1px solid rgba(168, 179, 207, 0.1);
  padding-top: 14px;
  line-height: 1.6;
}

/* === SKELETON === */
.row.skeleton { background: var(--surface); }
.skeleton-block {
  background: linear-gradient(90deg, rgba(168, 179, 207, 0.06) 0%, rgba(168, 179, 207, 0.18) 50%, rgba(168, 179, 207, 0.06) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.8s linear infinite;
  border-radius: 12px;
  min-height: 56px;
  width: 100%;
}
.row.skeleton .route-badge.skeleton-block { width: 150px; height: 150px; border-radius: 50%; }
.row.skeleton .destination.skeleton-block { width: 70%; }
.row.skeleton .minutes.skeleton-block     { width: 200px; height: 140px; }
.band-tracker[data-rows="6"] .row.skeleton .route-badge.skeleton-block { width: 100px; height: 100px; }
.band-tracker[data-rows="6"] .row.skeleton .minutes.skeleton-block     { width: 140px; height: 90px; }

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* === HIDDEN === */
[hidden] { display: none !important; }
