/* Budapest Mozgásban — porcelain by day, indigo ink by night */

:root {
  --paper: oklch(0.955 0.012 85);
  --ink: oklch(0.24 0.02 270);
  --ink-soft: oklch(0.24 0.02 270 / 0.62);
  --ink-faint: oklch(0.24 0.02 270 / 0.34);
  --panel: oklch(0.97 0.01 85 / 0.78);
  --panel-line: oklch(0.24 0.02 270 / 0.12);
  --accent: oklch(0.84 0.17 92); /* tram yellow */
  --good: oklch(0.72 0.17 145);
  --bad: oklch(0.6 0.21 25);
  --shadow: 0 2px 24px oklch(0.24 0.02 270 / 0.10);
}
body[data-theme="night"] {
  --paper: oklch(0.205 0.022 277);
  --ink: oklch(0.93 0.015 85);
  --ink-soft: oklch(0.93 0.015 85 / 0.6);
  --ink-faint: oklch(0.93 0.015 85 / 0.3);
  --panel: oklch(0.23 0.024 277 / 0.74);
  --panel-line: oklch(0.93 0.015 85 / 0.1);
  --shadow: 0 2px 30px oklch(0.1 0.02 277 / 0.5);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Archivo", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.8s ease, color 0.8s ease;
}

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

#grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 2;
  opacity: 0.5; mix-blend-mode: multiply;
  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.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}
body[data-theme="night"] #grain { mix-blend-mode: screen; opacity: 0.35; }

#labels { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.stn {
  position: absolute; left: 0; top: 0;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--ink-soft);
  text-shadow: 0 0 6px var(--paper), 0 0 2px var(--paper);
  white-space: nowrap; transform: translate(-50%, 8px);
  will-change: transform, opacity;
}

/* ---------- masthead ---------- */
#masthead {
  position: fixed; top: clamp(14px, 3vh, 38px); left: clamp(16px, 3vw, 44px);
  z-index: 5; pointer-events: none; user-select: none;
}
#masthead h1 {
  margin: 0; font-family: "Bricolage Grotesque", sans-serif;
  display: flex; flex-direction: column; line-height: 0.92;
}
#masthead .t1 {
  font-size: clamp(30px, 4.6vw, 64px); font-weight: 800;
  letter-spacing: -0.015em;
}
#masthead .t2 {
  font-size: clamp(15px, 2.32vw, 32.2px); font-weight: 600;
  letter-spacing: 0.305em; color: var(--ink-soft); margin-top: 4px;
}
#masthead .sub {
  margin: 10px 0 0; font-size: clamp(11px, 1.1vw, 13px);
  color: var(--ink-soft); letter-spacing: 0.02em;
}
#masthead .feed {
  margin-top: 8px; display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-soft);
}
#clock { font-weight: 700; color: var(--ink); letter-spacing: 0.06em; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; transition: background .3s; }
.dot.stale { background: var(--bad); }

/* ---------- mode chips ---------- */
#modes {
  position: fixed; left: clamp(16px, 3vw, 44px); bottom: clamp(16px, 3.4vh, 40px);
  z-index: 5; display: flex; flex-wrap: wrap; gap: 8px; max-width: min(92vw, 560px);
}
.chip {
  appearance: none; border: 1px solid var(--panel-line);
  background: var(--panel); color: var(--ink);
  backdrop-filter: blur(10px);
  border-radius: 999px; padding: 7px 14px 7px 10px;
  font: 600 12px/1 "Archivo", sans-serif; letter-spacing: 0.03em;
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; transition: opacity .45s ease, transform .45s cubic-bezier(.22,1,.36,1), border-color .25s;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(14px);
}
.chip.in { opacity: 1; transform: translateY(0); }
.chip.in:hover { transform: translateY(-1px); }
.chip .swatch { width: 10px; height: 10px; border-radius: 3px; }
.chip .count { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-weight: 500; }
.chip[data-off="1"] { opacity: 0.38; }
.chip[data-off="1"] .swatch { filter: grayscale(1); }

/* ---------- vehicle card ---------- */
#card {
  position: fixed; right: clamp(16px, 3vw, 44px); top: clamp(14px, 3vh, 38px);
  z-index: 6; width: min(330px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--panel-line);
  backdrop-filter: blur(14px);
  border-radius: 14px; padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card-top { display: flex; align-items: center; gap: 12px; }
.badge {
  min-width: 44px; height: 36px; padding: 0 10px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font: 800 19px "Bricolage Grotesque", sans-serif; letter-spacing: 0;
}
.card-head { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#cardHeadsign { font-weight: 700; font-size: 14px; }
#cardModel { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cardLore { margin: 10px 0 8px; font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); font-style: italic; }
.card-stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
#cardSpeed { font-weight: 700; color: var(--ink); }
#cardDelay.late { color: var(--bad); font-weight: 600; }
#cardDelay.ontime { color: var(--good); font-weight: 600; }
#cardDoor { color: var(--accent); font-weight: 700; }

/* ---------- controls / colophon ---------- */
#controls { position: fixed; right: clamp(16px, 3vw, 44px); bottom: clamp(16px, 3.4vh, 40px); z-index: 5; display: flex; align-items: center; gap: 8px; }
#vehScaleControl {
  height: 40px; width: 118px; border-radius: 999px;
  border: 1px solid var(--panel-line); background: var(--panel);
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; padding: 0 11px;
}
#vehScaleControl span {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-faint); line-height: 1;
}
#vehScale {
  width: 62px; accent-color: var(--accent); cursor: ew-resize;
  appearance: none; background: transparent;
}
#vehScale::-webkit-slider-runnable-track {
  height: 3px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 26%, transparent);
}
#vehScale::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px; margin-top: -5.5px;
  border-radius: 50%; border: 1px solid var(--panel-line);
  background: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
#vehScale::-moz-range-track {
  height: 3px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 26%, transparent);
}
#vehScale::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--panel-line);
  background: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.18);
}
#themeBtn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--panel-line); background: var(--panel);
  backdrop-filter: blur(10px); cursor: pointer; box-shadow: var(--shadow);
  position: relative;
}
#themeBtn::after {
  content: ""; position: absolute; inset: 11px; border-radius: 50%;
  background: var(--accent);
  box-shadow: inset -4px -3px 0 1px var(--paper);
  transition: box-shadow .5s;
}
body[data-theme="day"] #themeBtn::after { box-shadow: none; }

#colophon {
  position: fixed; right: clamp(16px, 3vw, 44px); bottom: 4px; z-index: 4;
  font-size: 10px; letter-spacing: 0.05em; color: var(--ink-faint);
  pointer-events: none;
}
@media (max-width: 640px) {
  #colophon { right: auto; left: 50%; transform: translateX(-50%); }
  #card { top: auto; bottom: clamp(70px, 12vh, 110px); right: 16px; }
}

#intro-veil { position: fixed; inset: 0; background: var(--paper); z-index: 10; pointer-events: none; }

/* selection ring — breathes gently around the chosen vehicle */
#ring {
  position: fixed; left: 0; top: 0; z-index: 4; pointer-events: none;
  border: 2px solid var(--ink); border-radius: 50%;
  opacity: 0.55; will-change: transform, width, height;
  animation: ringPulse 2.2s ease-in-out infinite;
}
@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 0 oklch(0.24 0.02 270 / 0.25); }
  50% { box-shadow: 0 0 0 7px oklch(0.24 0.02 270 / 0); }
}
body[data-theme="night"] #ring {
  border-color: oklch(0.93 0.015 85 / 0.8);
}

#followBtn {
  margin-top: 10px; width: 100%;
  border: 1px solid var(--panel-line); border-radius: 8px;
  background: transparent; color: var(--ink);
  font: 600 12px "Archivo", sans-serif; letter-spacing: 0.06em;
  padding: 7px 0; cursor: pointer;
  transition: background .25s, color .25s;
}
#followBtn:hover { background: oklch(0.24 0.02 270 / 0.07); }
#followBtn[data-on="1"] { background: var(--ink); color: var(--paper); }

#perfHud {
  position: fixed; left: clamp(16px, 3vw, 44px); top: clamp(120px, 18vh, 190px);
  z-index: 7; pointer-events: none;
  min-width: 210px; padding: 8px 10px;
  border: 1px solid var(--panel-line); border-radius: 8px;
  background: var(--panel); color: var(--ink);
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  font: 600 11px/1.45 "Archivo", sans-serif;
  font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
