:root {
  --bg: #f5f2ef; --surface: #ffffff; --surface2: #f1ede9; --ink: #1c1917; --muted: #78716c;
  --line: rgba(28, 25, 23, .09); --glass: rgba(255, 255, 255, .78);
  --a1: #ff8a3d; --a2: #e5383b; --grad: linear-gradient(135deg, var(--a1), var(--a2));
  --live: #16a34a; --warn: #d97706; --shadow: 0 8px 30px rgba(28, 25, 23, .10);
  --r: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e11; --surface: #17181d; --surface2: #1f2127; --ink: #f6f2ee; --muted: #9b958f;
    --line: rgba(255, 255, 255, .09); --glass: rgba(23, 24, 29, .72); --live: #34d399; --warn: #fbbf24;
    --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: light dark; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.15rem; margin: 0; letter-spacing: -.01em; line-height: 1.15; }
h2 { font-size: 1.25rem; margin: 0 0 .15rem; letter-spacing: -.02em; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- landing ---------- */
.hero { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; text-align: center;
  background: radial-gradient(900px 500px at 50% -10%, color-mix(in srgb, var(--a1) 38%, transparent), transparent 70%), var(--bg); }
.hero .badge { width: 116px; filter: drop-shadow(0 14px 24px rgba(229, 56, 59, .35)); animation: float 4s ease-in-out infinite; }
.hero h1 { font-size: clamp(2rem, 7vw, 3rem); margin: 18px 0 6px; }
.hero .big-num { font-size: clamp(3.5rem, 16vw, 7rem); font-weight: 800; line-height: .95; letter-spacing: -.04em; }
.hero p { max-width: 26rem; margin-inline: auto; }
.pill-lock { display: inline-flex; gap: 8px; align-items: center; margin-top: 10px; padding: 8px 14px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: .9rem; }
@keyframes float { 50% { transform: translateY(-8px); } }

/* ---------- map screen ---------- */
.hud { position: absolute; z-index: 1100; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 99px; background: var(--glass); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); box-shadow: var(--shadow); border: 1px solid var(--line); }
.brand img { width: 34px; height: 36px; object-fit: contain; }
.brand p { margin: 0; font-size: .75rem; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 99px; font-size: .85rem; font-weight: 600; background: var(--glass); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); box-shadow: var(--shadow); border: 1px solid var(--line); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.chip.live .dot { background: var(--live); box-shadow: 0 0 0 0 var(--live); animation: pulse 1.6s infinite; }
.chip.live { color: var(--live); }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.mapwrap { position: relative; z-index: 0; isolation: isolate; } /* contain Leaflet's z-indexes so the sheet/card can sit above the map */
#map { height: 62vh; min-height: 380px; width: 100%; background: var(--surface2); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.55); }
}
.leaflet-control-zoom { border: none !important; box-shadow: var(--shadow) !important; border-radius: 14px !important; overflow: hidden; }
.leaflet-control-zoom a { background: var(--glass) !important; color: var(--ink) !important; border: none !important; backdrop-filter: blur(10px); }
.leaflet-control-attribution { background: var(--glass) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); border-radius: 14px; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; font: inherit; }

.pin { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50% 50% 50% 8px; transform: rotate(-45deg); background: var(--surface); border: 3px solid var(--a2); box-shadow: 0 4px 12px rgba(0, 0, 0, .3); }
.pin span { transform: rotate(45deg); font-size: 13px; font-weight: 800; color: var(--a2); }
.pin.end { background: var(--grad); border-color: #fff; } .pin.end span { color: #fff; }
.mk { position: relative; width: 46px; height: 48px; }
.mk img { position: absolute; inset: 0; width: 46px; height: 48px; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .45)); }
.mk .ring { position: absolute; left: 50%; bottom: -2px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; background: color-mix(in srgb, var(--a2) 45%, transparent); animation: ring 1.8s ease-out infinite; }
@keyframes ring { from { transform: scale(.4); opacity: 1; } to { transform: scale(3.4); opacity: 0; } }

/* ---------- sheet ---------- */
.sheet { display: flow-root; position: relative; z-index: 2; background: var(--bg); padding: 0 max(14px, calc((100% - 44rem) / 2)) 60px; }
.sheet > .card:first-child { margin-top: -44px; box-shadow: var(--shadow); }
.wrap { max-width: 44rem; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat b { display: block; font-size: 1.55rem; line-height: 1.1; letter-spacing: -.03em; }
.stat span { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.bar { position: relative; height: 10px; background: var(--surface2); border-radius: 99px; margin: 14px 0 6px; }
.bar > div { height: 100%; border-radius: 99px; background: var(--grad); width: 0; transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.bar i { position: absolute; top: -3px; width: 2px; height: 16px; background: var(--line); border-radius: 2px; }
.sim { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.sim span { font-size: .85rem; color: var(--muted); }

/* ---------- sections timeline ---------- */
.sec-title { margin: 22px 4px 10px; }
.sec-title p { color: var(--muted); font-size: .9rem; }
.leg { position: relative; padding-left: 44px; margin-bottom: 10px; }
.leg::before { content: ""; position: absolute; left: 17px; top: 38px; bottom: -14px; width: 2px; background: var(--line); }
.leg:last-child::before { display: none; }
.leg .num { position: absolute; left: 0; top: 10px; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; background: var(--grad); box-shadow: 0 6px 14px rgba(229, 56, 59, .3); }
.leg details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 1px 2px rgba(0, 0, 0, .04); transition: box-shadow .2s; }
.leg details[open] { box-shadow: var(--shadow); }
.leg summary { list-style: none; cursor: pointer; padding: 12px 14px; display: grid; gap: 6px; }
.leg summary::-webkit-details-marker { display: none; }
.leg .route-line { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.leg .route-line::after { content: "›"; font-size: 1.4rem; color: var(--muted); transition: transform .2s; }
.leg details[open] .route-line::after { transform: rotate(90deg); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag { padding: 3px 10px; border-radius: 99px; background: var(--surface2); font-size: .78rem; color: var(--muted); font-weight: 600; }
.tag.time { color: var(--a2); background: color-mix(in srgb, var(--a2) 11%, transparent); }
.avatars { display: flex; margin-left: auto; }
.av { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .7rem; font-weight: 800; color: #fff; border: 2px solid var(--surface); margin-left: -8px; }
.leg .body { padding: 0 14px 14px; }
ul.plain { list-style: none; padding: 0; margin: 4px 0 8px; }
ul.plain li { padding: 8px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
ul.plain li .who { display: flex; gap: 10px; align-items: center; min-width: 0; }
ul.plain li .av { margin: 0; flex: none; }

/* ---------- forms ---------- */
label { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin: 10px 0 5px; letter-spacing: .02em; }
input, button, select { font: inherit; }
input { padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface2); color: var(--ink); min-height: 44px; }
input:focus { outline: 2px solid color-mix(in srgb, var(--a1) 70%, transparent); outline-offset: 1px; }
input[type=text], input[type=password] { width: 100%; }
input[type=time] { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 7rem; }
button { cursor: pointer; min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--grad); color: #fff; font-weight: 700; box-shadow: 0 6px 16px rgba(229, 56, 59, .28); transition: transform .12s, box-shadow .12s, opacity .12s; }
button:active { transform: scale(.97); box-shadow: 0 2px 6px rgba(229, 56, 59, .28); }
button.secondary { background: var(--surface2); color: var(--ink); box-shadow: none; border: 1px solid var(--line); }
button.danger { background: var(--surface2); color: var(--warn); box-shadow: none; border: 1px solid var(--line); }
button.small { min-height: 32px; padding: 0 12px; font-size: .8rem; }
button:disabled { opacity: .45; cursor: default; }
form button[type=submit] { width: 100%; margin-top: 12px; }
.err { color: var(--warn); font-size: .88rem; min-height: 1.2em; margin: 6px 0 0; }
.big { font-size: 1.15rem; font-weight: 700; }
code { background: var(--surface2); padding: 1px 6px; border-radius: 6px; font-size: .85em; }

/* ---------- admin / tracker ---------- */
.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.status-big { display: flex; align-items: center; gap: 10px; font-size: 1.3rem; font-weight: 800; }
.status-big .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.status-big.on .dot { background: var(--live); animation: pulse 1.6s infinite; }
.link-out { word-break: break-all; padding: 12px; border-radius: 12px; background: var(--surface2); font-size: .9rem; margin-top: 10px; }
.link-out:empty { display: none; }

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

/* ---------- explainer banner ---------- */
.explainer { background: var(--grad); color: #fff; padding: 12px 16px; text-align: center; font-weight: 700; letter-spacing: -.01em; }
.explainer small { display: block; font-weight: 500; opacity: .9; margin-top: 2px; }
.mapwrap .hud { top: 0; }
.row > * { min-width: 0; }
input[type=time] { min-width: 0; }
.row > div { flex: 1 1 8rem; }
input[type=time] { padding: 11px 8px; font-size: .92rem; }
.leaflet-bottom { margin-bottom: 50px; } /* keep zoom + attribution clear of the stats card that overlaps the map edge */
