/* Spårvagn Live – Göteborg
   Palett: älvnatt (navy), hamnblått, stadsvapnets guld, kranrött och stenstadens sand. */
:root {
  --navy: #0b2540;
  --navy-2: #12355a;
  --sea: #145d8a;
  --sky: #a8d8f0;
  --gold: #ffc72c;
  --red: #e2473a;
  --sand: #f6efe2;
  --ink: #13283d;
  --muted: #5d6f80;
  --card: rgba(255, 252, 246, 0.92);
  --card-solid: #fffcf6;
  --line: rgba(11, 37, 64, 0.1);
  --shadow: 0 18px 40px -18px rgba(11, 37, 64, 0.45), 0 2px 6px rgba(11, 37, 64, 0.08);
  --radius: 22px;
  --display: "Bricolage Grotesque", "Inter", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
.dark {
  --card: rgba(13, 33, 54, 0.9);
  --card-solid: #0f2742;
  --ink: #f3ede2;
  --muted: #9fb3c6;
  --line: rgba(255, 255, 255, 0.1);
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--navy);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
#map { position: fixed; inset: 0; background: #dfe7ea; }
.dark #map { background: #1b2733; }

.glass {
  background: var(--card);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

/* ---------- Header ---------- */
.brand {
  position: fixed;
  z-index: 800;
  top: calc(12px + var(--safe-t));
  left: 12px;
  right: 72px;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 10px;
  border-radius: var(--radius);
}
.brand-icon { border-radius: 13px; flex: none; }
.brand-text { min-width: 0; flex: 1; }
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 21px;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
}
.brand h1 span {
  color: var(--sea);
  background: linear-gradient(transparent 62%, var(--gold) 62%, var(--gold) 90%, transparent 90%);
  padding: 0 2px;
}
.dark .brand h1 span { color: var(--gold); background: none; }
.tagline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot-sep { color: var(--gold); }
.tag-text { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 380px) { .tag-text { display: none; } }
.live {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--navy);
  color: var(--sand);
  white-space: nowrap;
}
.dark .live { background: var(--gold); color: var(--navy); }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
  animation: pulse 2s infinite;
}
.dark .live-dot { background: #0b7a3b; }
.live.stale .live-dot { background: var(--red); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
  70% { box-shadow: 0 0 0 9px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.map-buttons {
  position: fixed;
  z-index: 800;
  top: calc(12px + var(--safe-t));
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.round {
  width: 50px; height: 50px;
  border-radius: 16px;
  display: grid; place-items: center;
  color: var(--ink);
  transition: transform 0.15s ease;
}
.round:active { transform: scale(0.94); }
#btn-locate.active { color: var(--sea); }
.dark #btn-locate.active { color: var(--gold); }

/* ---------- Bottom sheet ---------- */
.sheet {
  position: fixed;
  z-index: 900;
  left: 0; right: 0; bottom: 0;
  max-height: 48vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card-solid);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -18px 40px -20px rgba(11, 37, 64, 0.5);
  padding: 4px 16px calc(14px + var(--safe-b));
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
.sheet.collapsed { transform: translateY(calc(100% - 150px - var(--safe-b))); overflow: hidden; }
.grip {
  display: block;
  width: 100%;
  padding: 8px 0 6px;
  border: 0;
  background: none;
  position: sticky;
  top: 0;
}
.grip span {
  display: block;
  margin: 0 auto;
  width: 44px; height: 5px;
  border-radius: 99px;
  background: var(--line);
  box-shadow: inset 0 0 0 10px rgba(11,37,64,0.15);
}
.dark .grip span { box-shadow: inset 0 0 0 10px rgba(255,255,255,0.18); }

@media (min-width: 820px) {
  .sheet {
    left: 16px; right: auto; bottom: 16px;
    top: calc(96px + var(--safe-t));
    width: 400px;
    max-height: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    padding-top: 14px;
  }
  .sheet.collapsed { transform: none; overflow-y: auto; }
  .grip { display: none; }
  .brand { right: auto; width: 400px; left: 16px; top: 16px; }
  .map-buttons { top: 16px; right: 16px; }
  .leaflet-bottom.leaflet-right { margin-right: 6px; }
}

.stop-head { display: flex; align-items: flex-start; gap: 10px; margin-top: 4px; }
.stop-title { flex: 1; min-width: 0; }
.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--sea);
}
.dark .eyebrow { color: var(--gold); }
.stop-head h2 {
  margin: 2px 0 2px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 27px;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.stop-meta { font-size: 13px; color: var(--muted); font-weight: 500; }
.fav {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: transparent;
  display: grid; place-items: center;
}
.fav svg { fill: none; stroke: var(--muted); stroke-width: 1.8; }
.fav.on svg { fill: var(--gold); stroke: #c79400; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 2px 4px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip.on { background: var(--navy); color: var(--sand); border-color: var(--navy); }
.dark .chip.on { background: var(--gold); color: var(--navy); border-color: var(--gold); }
.chip .dist { opacity: 0.65; font-weight: 500; }
.chip.home::before { content: "★"; color: var(--gold); }
.dark .chip.home.on::before { color: var(--navy); }

.departures { list-style: none; margin: 8px 0 4px; padding: 0; }
.dep {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px dashed var(--line);
}
.dep:last-child { border-bottom: 0; }
.badge {
  flex: none;
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: 18px;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.06);
}
.dep-main { flex: 1; min-width: 0; }
.dep-dir { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dep-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.dep-time {
  flex: none;
  text-align: right;
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
  line-height: 1;
}
.dep-time small { display: block; font-family: var(--body); font-size: 11px; font-weight: 600; color: var(--muted); margin-top: 3px; }
.dep-time.now { color: var(--red); }
.dep.cancelled .dep-dir, .dep.cancelled .dep-time { text-decoration: line-through; opacity: 0.55; }
.rt { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; margin-right: 5px; vertical-align: 1px; }
.empty { padding: 18px 4px; color: var(--muted); font-weight: 500; }

.section-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 14px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.link { border: 0; background: none; color: var(--sea); font-size: 12px; font-weight: 700; letter-spacing: 0; text-transform: none; padding: 0; }
.dark .link { color: var(--gold); }
.lines .chip { padding: 0; width: 42px; height: 42px; justify-content: center; font-family: var(--display); font-size: 17px; font-weight: 800; border-width: 2px; }
.lines .chip.off { opacity: 0.32; filter: grayscale(0.6); }

.credits { margin: 14px 0 0; font-size: 11px; color: var(--muted); }
.credits a { color: inherit; }

/* ---------- Vehicle card ---------- */
.vehicle-card {
  margin: 6px 0 10px;
  padding: 14px;
  border-radius: 18px;
  background: var(--navy);
  color: var(--sand);
  display: flex;
  align-items: center;
  gap: 12px;
}
.dark .vehicle-card { background: #0a1c30; border: 1px solid var(--line); }
.vehicle-card .badge { height: 46px; min-width: 46px; font-size: 22px; }
.vehicle-card .v-main { flex: 1; min-width: 0; }
.vehicle-card .v-dir { font-family: var(--display); font-weight: 800; font-size: 18px; line-height: 1.15; }
.vehicle-card .v-sub { font-size: 12.5px; opacity: 0.75; margin-top: 3px; }
.vehicle-card .v-actions { display: flex; flex-direction: column; gap: 6px; }
.vbtn { border: 0; border-radius: 10px; padding: 7px 10px; font-size: 12.5px; font-weight: 700; background: rgba(255,255,255,0.12); color: inherit; }
.vbtn.primary { background: var(--gold); color: var(--navy); }

/* ---------- Map markers ---------- */
.tram {
  position: relative;
  width: 34px; height: 34px;
  transition: opacity 0.3s;
}
.tram-arrow {
  position: absolute;
  inset: -9px;
  transform-origin: 50% 50%;
}
.tram-arrow::before {
  content: "";
  position: absolute;
  left: 50%; top: 0;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 10px solid var(--tram-bg);
  filter: drop-shadow(0 -1px 0 rgba(255,255,255,0.9));
}
.tram-body {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--tram-bg);
  color: var(--tram-fg);
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 0 0 2.5px #fff, 0 4px 10px rgba(11, 37, 64, 0.4);
}
.dark .tram-body { box-shadow: 0 0 0 2.5px #0b2540, 0 4px 12px rgba(0,0,0,0.6); }
.tram.selected .tram-body { box-shadow: 0 0 0 3px var(--gold), 0 0 0 7px rgba(255,199,44,0.35), 0 6px 14px rgba(11,37,64,0.5); }
.tram.dim { opacity: 0.18; }
.small .tram { transform: scale(0.72); }
.tiny .tram { transform: scale(0.5); }
.tiny .tram-arrow { display: none; }

.me { position: relative; width: 22px; height: 22px; }
.me::before {
  content: "";
  position: absolute; inset: -16px;
  border-radius: 50%;
  background: rgba(20, 93, 138, 0.22);
  animation: me-pulse 2.4s ease-out infinite;
}
.me::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--sea);
  border: 3.5px solid #fff;
  box-shadow: 0 2px 8px rgba(11,37,64,0.5);
}
.dark .me::after { background: var(--gold); border-color: var(--navy); }
@keyframes me-pulse { 0% { transform: scale(0.4); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }

.stop-tip {
  background: var(--navy) !important;
  color: var(--sand) !important;
  border: 0 !important;
  border-radius: 10px !important;
  font-family: var(--body);
  font-weight: 700;
  font-size: 12.5px;
  padding: 5px 9px !important;
  box-shadow: var(--shadow) !important;
}
.stop-tip::before { display: none; }

.leaflet-container { font-family: var(--body); }
.leaflet-control-attribution { display: none; }
.leaflet-control-zoom { border: 0 !important; box-shadow: var(--shadow) !important; border-radius: 14px !important; overflow: hidden; }
.leaflet-control-zoom a { width: 40px !important; height: 40px !important; line-height: 40px !important; background: var(--card-solid) !important; color: var(--ink) !important; border-color: var(--line) !important; }
@media (max-width: 819px) {
  .leaflet-control-zoom { display: none; }
}

/* ---------- Toast & setup ---------- */
.toast {
  position: fixed;
  z-index: 1000;
  left: 50%;
  top: calc(84px + var(--safe-t));
  transform: translateX(-50%);
  background: var(--navy);
  color: var(--sand);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  text-align: center;
}
.setup {
  position: fixed; inset: 0; z-index: 1100;
  display: grid; place-items: center;
  background: rgba(11, 37, 64, 0.75);
  padding: 20px;
}
.setup-card {
  background: var(--sand);
  color: var(--navy);
  border-radius: 26px;
  padding: 30px 26px;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
}
.setup-card img { border-radius: 18px; }
.setup-card h2 { font-family: var(--display); font-weight: 800; font-size: 28px; margin: 14px 0 6px; }
.setup-card p { color: #3d5163; line-height: 1.5; margin: 0 0 18px; }
.btn { display: inline-block; background: var(--navy); color: var(--gold); padding: 13px 20px; border-radius: 14px; font-weight: 700; text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  .live-dot, .me::before { animation: none; }
  .sheet { transition: none; }
}
