/* Vánoční flotila. Tokens first: one spacing scale, one type scale, colours with fixed roles. */
:root {
  /* colour roles */
  --night: #0d1730;      /* brand surface (header, hero) */
  --night-2: #1a2a55;
  --paper: #fffdf8;      /* sheet surface */
  --card: #ffffff;
  --line: #ece6da;
  --ink: #1b1f2a;
  --ink-2: #4a5163;
  --muted: #6b7280;
  --brand: #d62839;      /* Christmas red: brand + selection accent */
  --gold: #f4b942;       /* selection highlight */
  --live: #1f9d55;       /* live / on time */
  --late: #c2410c;       /* delay */
  --tram: #7a0603; --bus: #007da8; --trolley: #80166f; --service: #a16207;

  /* spacing scale (rule 5) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  /* type scale (rule 15) */
  --t-xs: 12px; --t-sm: 14px; --t-md: 16px; --t-lg: 18px; --t-xl: 24px; --t-2xl: 32px;

  --radius: 16px;
  --radius-lg: 24px;
  --shadow: 0 8px 24px rgba(9, 15, 34, .28);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-sheet: cubic-bezier(.32, .72, 0, 1);   /* iOS sheet curve */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sheet-visible: 46vh;
  /* iOS home-screen app only: how far the screen reaches below the reported viewport (set in app.js) */
  --pwa-gap: 0px;
  --pwa-pad: 0px;

  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); }
button { font: inherit; color: inherit; }
a { color: #a61e2c; }
[hidden] { display: none !important; }
.ic { display: block; flex: none; }

#map { position: fixed; inset: 0; bottom: calc(-1 * var(--pwa-gap)); z-index: 0; background: var(--night); }
.raster-fallback .leaflet-tile-pane { filter: invert(1) hue-rotate(195deg) brightness(.85) saturate(.6) contrast(.9); }
.leaflet-gl-layer { z-index: 1; }
.leaflet-container .leaflet-control-attribution {
  background: rgba(13, 23, 48, .6); color: #93a0c4; font-size: 10px; line-height: 1.4;
  border-radius: 0 0 0 8px; padding: 2px 6px;
}
.leaflet-container .leaflet-control-attribution a { color: #c9d1e6; }
.leaflet-top.leaflet-right { top: var(--safe-top); }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; z-index: 500;
  padding: calc(var(--safe-top) + var(--s3)) var(--s4) 0;
}
.brand {
  display: flex; align-items: center; gap: var(--s3);
  background: rgba(13, 23, 48, .92);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  color: var(--paper);
  padding: var(--s2) var(--s1) var(--s2) var(--s3);
  border-radius: 999px; box-shadow: var(--shadow);
}
.brand-logo { display: block; width: 32px; height: 32px; }
.brand h1 {
  margin: 0; font-family: 'Baloo 2', 'Nunito', sans-serif; font-weight: 800;
  font-size: var(--t-lg); line-height: 1.1;
}
.status { margin: 0; font-size: var(--t-xs); font-weight: 700; opacity: .85; display: flex; align-items: center; gap: 6px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 2.4s var(--ease-out) infinite; }
.status .dot.off { background: var(--gold); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 157, 85, .55); }
  70%, 100% { box-shadow: 0 0 0 8px rgba(31, 157, 85, 0); }
}
.brand-info {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: none;
  color: #c9d1e6; display: grid; place-items: center; cursor: pointer;
}
.brand-info:active { background: rgba(255, 255, 255, .1); }

/* ---------- floating buttons ---------- */
.fabs {
  position: fixed; right: var(--s4); z-index: 500;
  bottom: calc(var(--sheet-visible) + var(--s4) - var(--pwa-gap));
  display: flex; flex-direction: column; gap: var(--s3);
  transition: bottom .45s var(--ease-sheet);
}
.fab {
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: var(--paper); color: var(--night); box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer;
  transition: transform .15s var(--ease-out), background-color .2s, color .2s;
}
.fab:active { transform: scale(.92); }
.fab.on { background: #2b6fe0; color: #fff; }

/* ---------- bottom sheet ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: calc(-1 * var(--pwa-gap)); z-index: 600;
  height: calc(100% + var(--pwa-gap) - var(--safe-top) - 72px);
  transform: translate3d(0, calc(100% - var(--sheet-visible)), 0);
  transition: transform .45s var(--ease-sheet);
  background: var(--paper);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -8px 32px rgba(9, 15, 34, .3);
  display: flex; flex-direction: column;
  will-change: transform;
}
.sheet.dragging, .sheet.dragging ~ .fabs { transition: none; }
.sheet-grab { flex: none; touch-action: none; }
.sheet-handle {
  border: 0; background: none; padding: var(--s3) 0; cursor: grab; width: 100%;
  display: grid; place-items: center;
}
.sheet-handle span { width: 40px; height: 5px; border-radius: 5px; background: #d6d0c3; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 0 var(--s4) calc(max(var(--safe-bottom), var(--pwa-pad)) + var(--s5));
  flex: 1;
}
.view.enter { animation: view-in .28s var(--ease-out); }
.view.enter.back { animation-name: view-in-back; }
@keyframes view-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes view-in-back { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }

.sheet-title {
  font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: var(--t-xl);
  line-height: 1.2; margin: 0 0 var(--s3);
}
.sheet-title.muted { color: var(--muted); font-size: var(--t-lg); margin-top: var(--s6); }

/* ---------- vehicle cards ---------- */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.card {
  display: flex; align-items: center; gap: var(--s3); width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s3); cursor: pointer;
  transition: transform .12s var(--ease-out);
}
.card:active { transform: scale(.98); }
/* type glyph tiles: one coloured layer, the type colour (rule 16) */
.glyph { display: inline-grid; place-items: center; flex: none; color: #fff; background: var(--tram); border-radius: var(--s3); }
.glyph.bus { background: var(--bus); }
.glyph.trolleybus { background: var(--trolley); }
.glyph.lubricator { background: var(--service); }
.card-art { width: 48px; height: 48px; }
.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 800; font-size: var(--t-md); line-height: 1.25; }
.card-sub {
  font-size: var(--t-sm); color: var(--ink-2); margin-top: var(--s1); font-weight: 700;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.live-tag { color: var(--live); display: inline-flex; align-items: center; gap: 6px; }
.live-tag::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--live); }
.card-dist {
  flex: none; text-align: right; font-family: 'Baloo 2', sans-serif; font-weight: 800;
  font-size: var(--t-lg); color: var(--night); line-height: 1;
}
.card-dist small { display: block; font-family: 'Nunito', sans-serif; font-size: var(--t-xs); color: var(--muted); font-weight: 700; margin-top: var(--s1); }
.rest .card { padding: var(--s2) var(--s3); }
.rest .card-art { opacity: .55; }

.line-pill {
  display: inline-grid; place-items: center; min-width: 28px; height: 22px; padding: 0 var(--s2);
  border-radius: 6px; background: var(--tram); color: #fff; font-weight: 800; font-size: var(--t-xs);
}
.line-pill.bus { background: var(--bus); }
.line-pill.trolleybus { background: var(--trolley); }
.line-pill.lubricator { background: var(--service); }

.banner {
  display: flex; gap: var(--s2); align-items: flex-start;
  background: #fff4d6; color: #6b5a2b; border-radius: var(--s3);
  padding: var(--s3); font-weight: 700; font-size: var(--t-sm); margin-bottom: var(--s3);
}
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--s2);
  text-align: center; padding: var(--s5) var(--s3); color: var(--muted); font-weight: 700;
}

/* ---------- detail ---------- */
.detail-top { display: flex; align-items: center; margin-bottom: var(--s3); }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: var(--s3);
  background: #f0ebe1; color: var(--ink); display: grid; place-items: center; cursor: pointer;
  transition: transform .12s var(--ease-out);
}
.icon-btn:active { transform: scale(.92); }
.hero {
  display: flex; align-items: center; gap: var(--s4);
  background: linear-gradient(135deg, var(--night), var(--night-2));
  color: var(--paper); border-radius: var(--radius-lg); padding: var(--s4); margin-bottom: var(--s4);
}
.hero-art { width: 64px; height: 64px; border-radius: var(--s4); }
.hero h2 { margin: 0; font-family: 'Baloo 2', sans-serif; font-size: var(--t-xl); line-height: 1.1; }
.hero p { margin: var(--s1) 0 0; opacity: .8; font-weight: 700; font-size: var(--t-sm); }

.distance {
  display: flex; align-items: center; gap: var(--s3);
  background: #fff4d6; border-radius: var(--radius); padding: var(--s4); margin-bottom: var(--s4);
}
.distance .num { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: var(--t-2xl); line-height: 1; color: var(--night); }
.distance .lbl { font-weight: 700; color: #6b5a2b; font-size: var(--t-sm); display: flex; align-items: center; gap: 6px; margin-top: var(--s1); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 48px; border: 0; border-radius: var(--s3); padding: 0 var(--s4);
  font-weight: 800; font-size: var(--t-md); cursor: pointer; text-decoration: none;
  background: var(--night); color: #fff;
  transition: transform .12s var(--ease-out);
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); }
.btn.quiet { background: #f0ebe1; color: var(--ink); }
.distance .btn { margin-left: auto; }

/* one card of rows instead of a border around every fact (rules 17, 18) */
.rows { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); }
.row + .row { border-top: 1px solid var(--line); }
.row .ic { color: var(--muted); }
.row .k { color: var(--muted); font-size: var(--t-sm); font-weight: 700; flex: none; width: 104px; }
.row .v { font-weight: 800; font-size: var(--t-md); flex: 1; min-width: 0; }
.v.late { color: var(--late); }
.v.ok { color: var(--live); }

.section { margin-bottom: var(--s4); }
.section h3 { margin: 0 0 var(--s2); font-size: var(--t-md); font-weight: 800; display: flex; align-items: center; gap: var(--s2); }
.section h3 .ic { color: var(--muted); }
.section p { margin: 0 0 var(--s2); font-size: var(--t-sm); color: var(--ink-2); }
.times { display: flex; flex-wrap: wrap; gap: var(--s2); }
.times span { background: #e8f5ee; color: #17663a; font-weight: 800; border-radius: var(--s2); padding: var(--s1) var(--s3); font-size: var(--t-md); }
.times span.first { background: var(--live); color: #fff; }
.upcoming { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.upcoming li { display: flex; gap: var(--s3); align-items: center; padding: var(--s3) var(--s4); font-weight: 700; font-size: var(--t-sm); }
.upcoming li + li { border-top: 1px solid var(--line); }
.upcoming .d { width: 88px; color: var(--ink-2); }
.note { color: var(--muted); font-size: var(--t-xs); margin: var(--s2) 0 var(--s4); }
.actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s5); }
.actions .btn { flex: 1; }

/* ---------- about ---------- */
.about { position: fixed; inset: 0; bottom: calc(-1 * var(--pwa-gap)); z-index: 900; display: grid; place-items: end center; }
.about-backdrop { position: absolute; inset: 0; background: rgba(5, 9, 22, .55); animation: fade-in .25s ease-out; }
.about-card {
  position: relative; width: min(520px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--paper); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--s5) var(--s5) calc(var(--safe-bottom) + var(--s5));
  animation: rise-in .4s var(--ease-sheet);
}
.about-card h2 { font-family: 'Baloo 2', sans-serif; font-size: var(--t-xl); margin: var(--s3) 0 var(--s2); }
.about-card h3 { font-size: var(--t-md); margin: var(--s5) 0 var(--s2); }
.about-card p { font-size: var(--t-sm); color: var(--ink-2); margin: 0 0 var(--s2); line-height: 1.5; }
.about-list { margin: 0; padding-left: var(--s4); font-size: var(--t-sm); color: var(--ink-2); line-height: 1.5; }
.about-list li + li { margin-top: var(--s2); }
.about-close { position: absolute; top: var(--s4); right: var(--s4); }
.about-hero { display: flex; gap: var(--s2); padding-right: 52px; }
.about-hero .glyph { width: 48px; height: 48px; }
.muted-text { color: var(--muted) !important; font-size: var(--t-xs) !important; margin-top: var(--s4) !important; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise-in { from { transform: translateY(100%); } }
.about.closing .about-backdrop { animation: fade-out .2s ease-in forwards; }
.about.closing .about-card { animation: sink-out .22s ease-in forwards; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes sink-out { to { transform: translateY(100%); } }

/* ---------- map markers ---------- */
.veh-marker { background: none; border: 0; overflow: visible; }
.pin {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, calc(-100% + 8px));
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer; --lift: 0px;
}
.pin { transition: opacity .2s; }
.pin.clustered { opacity: 0; pointer-events: none; }
.cluster {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 2px;
  height: 32px; padding: 0 var(--s3) 0 var(--s2); border-radius: 16px; border: 0;
  background: var(--night); color: #fff; cursor: pointer; white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .45), 0 0 0 2px var(--gold);
  animation: pin-in-c .25s var(--ease-out);
}
.cluster b { font: 800 var(--t-sm)/1 'Nunito', sans-serif; margin-left: var(--s1); }
@keyframes pin-in-c { from { opacity: 0; transform: translate(-50%, -50%) scale(.7); } }
.pin.new { animation: pin-in .4s var(--ease-out); }
@keyframes pin-in { from { opacity: 0; transform: translate(-50%, calc(-100% + 20px)) scale(.6); } }
.pill {
  display: flex; align-items: center; gap: var(--s1);
  height: 28px; padding: 0 var(--s2) 0 6px; border-radius: 14px;
  background: var(--tram); color: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .45), 0 0 0 2px rgba(255, 253, 248, .95);
  transform-origin: 50% 100%;
  transition: transform .3s var(--ease-out), box-shadow .2s;
}
.pin.bus .pill { background: var(--bus); }
.pin.trolleybus .pill { background: var(--trolley); }
.pin.lubricator .pill { background: var(--service); }
.pill .ln { font: 800 var(--t-sm)/1 'Nunito', sans-serif; }
.pin.selected .pill { transform: scale(1.15); box-shadow: 0 6px 18px rgba(0, 0, 0, .5), 0 0 0 3px var(--gold); }
.stem { width: 2px; height: calc(6px + var(--lift)); background: rgba(255, 253, 248, .85); transition: height .35s var(--ease-out); }
.pin.selected .stem { height: calc(12px + var(--lift)); }
.dot {
  position: relative; width: 14px; height: 14px; border-radius: 50%;
  background: var(--brand); border: 2.5px solid var(--paper); box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
  transition: background-color .2s;
}
.pin.selected .dot { background: var(--gold); }
.dot i { position: absolute; inset: -9px; pointer-events: none; transition: transform .6s var(--ease-out); }
.dot i::before {
  content: ''; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  border: 4px solid transparent; border-bottom: 6px solid var(--paper); border-top: 0;
}
.me-dot {
  width: 20px; height: 20px; border-radius: 50%; background: #2b6fe0; border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(43, 111, 224, .25), 0 2px 6px rgba(0, 0, 0, .3);
}
.stop-dot { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--live); }

/* ---------- gentle snow ---------- */
.snow {
  position: fixed; inset: 0; bottom: calc(-1 * var(--pwa-gap)); pointer-events: none; z-index: 400;
  background-image:
    radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,.9), transparent),
    radial-gradient(2px 2px at 120px 80px, rgba(255,255,255,.8), transparent),
    radial-gradient(3px 3px at 200px 150px, rgba(255,255,255,.7), transparent),
    radial-gradient(2px 2px at 300px 40px, rgba(255,255,255,.8), transparent);
  background-size: 340px 220px;
  animation: snow 24s linear infinite;
  opacity: .45;
}
@keyframes snow { to { background-position: 0 220px, 40px 220px, -30px 220px, 20px 220px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .snow { display: none; }
}

/* Desktop: side panel instead of a bottom sheet */
@media (min-width: 900px) {
  :root { --sheet-visible: 0px !important; }
  .sheet, .sheet.dragging {
    left: auto; top: 0; width: 420px; height: 100%;
    transform: none !important; border-radius: 0; box-shadow: -8px 0 32px rgba(9, 15, 34, .25);
    padding-top: var(--s4);
  }
  .sheet-grab { display: none; }
  .fabs { right: 444px; bottom: var(--s5); }
  .about { place-items: center; }
  .about-card { border-radius: var(--radius-lg); }
}

/* ---------- native timetables ---------- */
.trip { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.trip li { position: relative; display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s4); min-height: 44px; font-size: var(--t-sm); font-weight: 700; }
.trip .tl { position: relative; width: 12px; align-self: stretch; flex: none; }
.trip .tl::before { content: ''; position: absolute; left: 5px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.trip .tl::after { content: ''; position: absolute; left: 1px; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 50%; background: var(--card); border: 2px solid #b9b2a4; }
.trip li:first-child .tl::before { top: 50%; }
.trip li:last-child .tl::before { bottom: 50%; }
.trip .nm { flex: 1; min-width: 0; }
.trip .tm { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.trip li.done { color: var(--muted); }
.trip li.done .tl::after { background: #d6d0c3; border-color: #d6d0c3; }
.trip li.next { color: var(--ink); background: #fff8e6; }
.trip li.next .tl::after { width: 14px; height: 14px; left: -1px; margin-top: -7px; background: var(--gold); border-color: #fff; box-shadow: 0 0 0 2px var(--gold); }
.trip li.next .nm::after { content: ' · teď jede sem'; color: #8a6d1d; font-weight: 700; }
.daytt { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.daytt li { padding: var(--s3) var(--s4); }
.daytt li + li { border-top: 1px solid var(--line); }
.daytt .st { display: flex; align-items: baseline; gap: var(--s2); margin-bottom: var(--s2); font-weight: 800; font-size: var(--t-sm); }
.daytt .dist { color: var(--muted); font-weight: 700; font-size: var(--t-xs); }
.daytt .times span { font-size: var(--t-sm); padding: 2px var(--s2); }
.daytt em { color: var(--muted); font-size: var(--t-sm); }
.link-btn {
  display: inline-flex; align-items: center; gap: var(--s1); min-height: 44px;
  border: 0; background: none; padding: 0; color: #a61e2c; font-weight: 800; font-size: var(--t-sm); cursor: pointer;
}
.ic.flip { transform: rotate(180deg); }
.map-attr {
  position: fixed; left: var(--s2); z-index: 450;
  bottom: calc(var(--sheet-visible) + var(--s1) - var(--pwa-gap));
  font-size: 10px; color: #93a0c4; text-decoration: none;
  background: rgba(13, 23, 48, .6); padding: 1px 6px; border-radius: 6px;
  transition: bottom .45s var(--ease-sheet);
}
.sheet.dragging ~ .map-attr { transition: none; }
@media (min-width: 900px) { .map-attr { bottom: var(--s2); } }

.lbl.flush { margin: 0; }
