:root {
  --timebar-h: 76px; /* measured at runtime (the bar wraps on narrow screens) */
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: rgba(26, 26, 25, 0.86);
  --surface-solid: #1a1a19;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --ink-1: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --live: #d03b3b;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --gutter: 16px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

:root[data-theme='light'] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: rgba(252, 252, 251, 0.92);
  --surface-solid: #fcfcfb;
  --surface-hover: rgba(11, 11, 11, 0.05);
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

/* Elements with their own display rule must still honour the hidden attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--page);
  color: var(--ink-1);
  font: 14px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}

#map {
  position: fixed;
  inset: 0;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
}

body.cinema #panel,
body.cinema #timebar,
body.cinema #vehicle,
body.cinema .search,
body.cinema .maplibregl-ctrl-top-right,
body.cinema .maplibregl-ctrl-bottom-right {
  display: none !important;
}
body.cinema #hud {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* ------------------------------------------------------------------ HUD */
#hud {
  position: fixed;
  top: var(--gutter);
  left: var(--gutter);
  width: 320px;
  padding: 14px 16px 12px;
  z-index: 5;
}
.hud-title h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.hud-sub {
  margin: 2px 0 0;
  color: var(--ink-2);
  font-size: 12.5px;
}
.hud-clock {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 10px;
}
.clock {
  font-size: 54px;
  line-height: 0.95;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.clock small {
  font-size: 22px;
  color: var(--ink-2);
  font-weight: 500;
  margin-left: 2px;
}
.clock-meta {
  padding-bottom: 4px;
  min-width: 0;
}
.clock-date {
  color: var(--ink-2);
  font-size: 12.5px;
  white-space: nowrap;
}
.mode-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.mode-badge.live {
  color: #fff;
  background: var(--live);
  border-color: transparent;
}
.mode-badge.recorded {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
}
.hud-stat {
  margin-top: 10px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.stat-value {
  font-size: 22px;
  font-weight: 650;
}
.stat-label {
  color: var(--ink-2);
  font-size: 13px;
}

/* search */
.search {
  position: relative;
  margin-top: 12px;
}
.search input {
  width: 100%;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-hover);
  outline: none;
}
.search input:focus {
  border-color: var(--accent);
}
.search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 46vh;
  overflow: auto;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 20;
}
.search-results li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.search-results li[aria-selected='true'],
.search-results li:hover {
  background: var(--surface-hover);
}
.search-results .res-text {
  min-width: 0;
  flex: 1;
}
.search-results .res-main {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-results .res-sub {
  color: var(--ink-3);
  font-size: 12px;
}
.search-results .empty {
  color: var(--ink-3);
  cursor: default;
}

/* ------------------------------------------------------------------ panel */
#panel {
  position: fixed;
  top: var(--gutter);
  right: var(--gutter);
  width: 268px;
  padding: 12px 14px;
  z-index: 5;
  max-height: calc(100vh - 164px); /* stays clear of the attribution above the time bar */
  overflow: auto;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-head h2,
.modal-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#panel.collapsed .panel-body {
  display: none;
}
#panel.collapsed #panel-toggle svg {
  transform: rotate(180deg);
}
.legend {
  list-style: none;
  margin: 10px 0 4px;
  padding: 0;
}
.legend li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 5px 6px;
  margin: 0 -6px;
  border-radius: 7px;
  cursor: pointer;
  user-select: none;
}
.legend li:hover {
  background: var(--surface-hover);
}
.legend li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--surface-solid);
}
.legend li.off .swatch {
  background: transparent !important;
  box-shadow: inset 0 0 0 1.5px var(--ink-3);
}
.legend li.off .lg-label,
.legend li.off .lg-count {
  color: var(--ink-3);
}
.legend .lg-count {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.legend.static li {
  cursor: default;
}
.legend.static li:hover {
  background: none;
}
.sub-head {
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ring-key {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-2);
  background: color-mix(in srgb, var(--ink-2) 15%, transparent);
  flex: none;
}
.hud-sched {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 2px;
  color: var(--ink-2);
  font-size: 12.5px;
}
.hint.warn {
  color: var(--ink-1);
}
.hint {
  margin: 2px 0 12px;
  font-size: 11.5px;
  color: var(--ink-3);
}
.field {
  display: grid;
  grid-template-columns: 82px 1fr;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.field label {
  color: var(--ink-2);
  font-size: 13px;
}
select {
  width: 100%;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-solid);
}
input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
}
.check input {
  accent-color: var(--accent);
  margin: 0;
}
.panel-foot {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.text-btn {
  background: none;
  border: 0;
  padding: 4px 8px;
  border-radius: 7px;
  color: var(--ink-2);
  cursor: pointer;
}
.text-btn:hover {
  background: var(--surface-hover);
  color: var(--ink-1);
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--ink-1);
}

/* ------------------------------------------------------------------ vehicle card */
#vehicle {
  position: fixed;
  left: var(--gutter);
  bottom: calc(var(--timebar-h) + var(--gutter) * 2);
  width: 340px;
  max-height: calc(100vh - 420px);
  min-height: 180px;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  z-index: 6;
}
#vehicle[hidden] {
  display: none;
}
.vehicle-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.route-badge {
  flex: none;
  min-width: 34px;
  padding: 3px 8px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  line-height: 1.35;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vehicle-titles {
  flex: 1;
  min-width: 0;
}
.vehicle-title {
  font-weight: 650;
  font-size: 15px;
}
.vehicle-sub {
  color: var(--ink-2);
  font-size: 12.5px;
}
.vehicle-status {
  margin: 10px 0 8px;
  font-size: 13px;
  color: var(--ink-1);
}
.vehicle-status .muted {
  color: var(--ink-3);
}
.vehicle-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface-hover);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--ink-3);
}
.chip[aria-pressed='true'],
.chip[aria-expanded='true'] {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.stops {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 60px;
  border-top: 1px solid var(--border);
}
.stops li {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
  font-size: 13px;
  position: relative;
}
.stops li::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--ink-3);
  background: var(--surface-solid);
  justify-self: center;
  z-index: 1;
}
.stops li::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--grid);
}
.stops li:first-child::after {
  top: 50%;
}
.stops li:last-child::after {
  bottom: 50%;
}
.stops li.passed {
  color: var(--ink-3);
}
.stops li.passed::before {
  border-color: var(--ink-3);
  background: var(--ink-3);
}
.stops li.next {
  font-weight: 650;
}
.stops li.next::before {
  border-color: var(--accent);
}
.stops .st-time {
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.stops li.passed .st-time {
  color: var(--ink-3);
}
/* Times from MÁV+'s timetable: the vehicle was outside the real-time feed. */
.stops .st-time.tt {
  font-style: italic;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

/* ------------------------------------------------------------------ timebar */
#timebar {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  bottom: var(--gutter);
  height: 76px;
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 8px 12px;
  z-index: 5;
}
.time-controls,
.time-side {
  display: flex;
  align-items: center;
  gap: 8px;
}
.play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--ink-1);
  color: var(--surface-solid);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
.play-btn .i-pause,
.playing .play-btn .i-play {
  display: none;
}
.playing .play-btn .i-pause {
  display: block;
}
.speed select {
  width: 82px;
}
#dataset {
  width: 168px;
}
.chart-wrap {
  position: relative;
  flex: 1;
  min-width: 120px;
}
#chart {
  width: 100%;
  height: 100%;
  display: block;
  cursor: ew-resize;
  outline: none;
  border-radius: 6px;
}
#chart:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}
.chart-tip {
  position: absolute;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  min-width: 190px;
  padding: 8px 10px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 12.5px;
  pointer-events: none;
  z-index: 30;
}
.chart-tip .tip-head {
  color: var(--ink-2);
  margin-bottom: 4px;
}
.chart-tip .tip-row,
.map-tip .tip-row {
  display: grid;
  grid-template-columns: 12px auto 1fr;
  align-items: center;
  gap: 7px;
}
.tip-key {
  width: 12px;
  height: 2px;
  border-radius: 1px;
}
.tip-val {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.tip-name {
  color: var(--ink-2);
}
.live-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
}
.live-chip[aria-pressed='true'] {
  background: var(--live);
}
.live-chip[aria-pressed='true'] .live-dot {
  background: #fff;
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* ------------------------------------------------------------------ map tooltip */
.map-tip {
  position: fixed;
  pointer-events: none;
  padding: 7px 10px;
  max-width: 300px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 12.5px;
  z-index: 40;
}
.map-tip .mt-title {
  font-weight: 650;
}
.map-tip .mt-sub {
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ modals */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  z-index: 50;
  background: var(--surface-solid);
}
.modal[hidden] {
  display: none;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.modal-body {
  overflow: auto;
  color: var(--ink-2);
  line-height: 1.55;
}
.modal-body h3 {
  color: var(--ink-1);
  font-size: 14px;
  margin: 14px 0 4px;
}
.modal-body p {
  margin: 6px 0;
}
.modal-body a {
  color: var(--accent);
}
.modal-body kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 12px var(--font);
  text-align: center;
  color: var(--ink-1);
}
.keys {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  align-items: center;
}
.keys .k {
  white-space: nowrap;
  color: var(--ink-3);
}
.table-scroll {
  overflow: auto;
}
#table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}
#table th,
#table td {
  padding: 4px 8px;
  text-align: right;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#table th {
  color: var(--ink-2);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface-solid);
  white-space: normal;
  vertical-align: bottom;
  line-height: 1.25;
}
#table th:first-child,
#table td:first-child {
  text-align: left;
}
#table .th-key {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}

/* ------------------------------------------------------------------ toast & loading */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--timebar-h) + var(--gutter) * 2);
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 60;
}
.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--page);
  z-index: 100;
  transition: opacity 0.4s;
}
.loading.done {
  opacity: 0;
  pointer-events: none;
}
.loading-card {
  width: min(360px, calc(100vw - 32px));
  text-align: center;
}
.loading-title {
  font-size: 22px;
  font-weight: 650;
}
.loading-text {
  margin: 8px 0 14px;
  color: var(--ink-2);
  min-height: 1.4em;
}
.loading-text.error {
  color: #e66767;
}
.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--grid);
  overflow: hidden;
}
#loading-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s;
}

/* ------------------------------------------------------------------ maplibre chrome */
.maplibregl-ctrl-top-right {
  top: 0;
  right: 296px;
}
.maplibregl-ctrl-group {
  background: var(--surface-solid) !important;
  border: 1px solid var(--border);
}
.maplibregl-ctrl-group button + button {
  border-top-color: var(--border) !important;
}
:root[data-theme='dark'] .maplibregl-ctrl-group button .maplibregl-ctrl-icon {
  filter: invert(1);
}
.maplibregl-ctrl-bottom-right {
  bottom: calc(var(--timebar-h) + var(--gutter) + 8px);
}
.maplibregl-ctrl-attrib {
  background: var(--surface) !important;
  color: var(--ink-2);
}
.maplibregl-ctrl-attrib a {
  color: var(--ink-2) !important;
}
:root[data-theme='dark'] .maplibregl-ctrl-attrib-button {
  filter: invert(1);
}

/* ------------------------------------------------------------------ small screens */
@media (max-width: 760px) {
  :root {
    --gutter: 10px;
  }
  #hud {
    width: auto;
    right: 64px;
    padding: 10px 12px;
  }
  .hud-sub,
  .hud-title {
    display: none;
  }
  .hud-clock {
    margin-top: 0;
  }
  .clock {
    font-size: 40px;
  }
  .hud-stat {
    margin-top: 6px;
  }
  .search {
    margin-top: 8px;
  }
  #panel {
    top: auto;
    bottom: calc(var(--timebar-h) + var(--gutter) * 2);
    left: var(--gutter);
    right: var(--gutter);
    width: auto;
    max-height: 50vh;
  }
  #timebar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px;
  }
  .chart-wrap {
    order: 3;
    flex-basis: 100%;
    height: 44px;
  }
  .time-side {
    margin-left: auto;
  }
  #dataset {
    width: 150px;
  }
  #vehicle {
    left: var(--gutter);
    right: var(--gutter);
    width: auto;
    max-height: 45vh;
  }
  .maplibregl-ctrl-top-right {
    right: 0;
  }

}
