:root {
  --bg0: #0c1014;
  --bg1: #141b22;
  --bg2: #1c262f;
  --ink: #e8eef3;
  --muted: #93a4b3;
  --line: rgba(232, 238, 243, 0.12);
  --accent: #e85d04;
  --accent-2: #f48c06;
  --ok: #2a9d8f;
  --danger: #e63946;
  --leader: #ffd60a;
  --font-display: "Bebas Neue", Impact, sans-serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --header-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --touch: 48px;
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background:
    radial-gradient(900px 480px at 10% -10%, rgba(232, 93, 4, 0.2), transparent 55%),
    radial-gradient(700px 400px at 100% 0%, rgba(42, 157, 143, 0.12), transparent 50%),
    linear-gradient(180deg, var(--bg0), #070a0d 120%);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding:
    calc(0.55rem + var(--safe-top))
    calc(0.9rem + var(--safe-right))
    0.55rem
    calc(0.9rem + var(--safe-left));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(12, 16, 20, 0.88);
}

.brand {
  font-family: var(--font-display);
  font-size: 1.45rem;
  letter-spacing: 0.06em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand span { color: var(--accent); }

.site-nav {
  display: flex;
  gap: 0.35rem;
  font-size: 0.88rem;
}
.site-nav a {
  color: var(--muted);
  text-decoration: none;
  min-height: 40px;
  padding: 0.45rem 0.65rem;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
}
.site-nav a:hover,
.site-nav a:active {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

.site-main {
  width: min(720px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 1rem 0 calc(2rem + var(--safe-bottom));
}

.site-main.map-page {
  width: 100%;
  max-width: none;
  padding: 0;
}

.site-footer {
  padding: 1.1rem calc(1rem + var(--safe-right)) calc(1.1rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--line);
}
body.map-mode .site-footer { display: none; }

.hero {
  padding: 1.25rem 0 0.75rem;
  animation: rise 700ms ease both;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 14vw, 4.2rem);
  line-height: 0.92;
  margin: 0 0 0.65rem;
  letter-spacing: 0.04em;
}
.hero p {
  max-width: 36rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
  margin: 0;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1.25rem;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  min-height: var(--touch);
  padding: 0.85rem 1.15rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.btn:active { transform: scale(0.98); }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #120800; }
.btn-primary:hover { background: var(--accent-2); color: #120800; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); color: #041210; }
.btn-sm {
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  width: auto;
}
.actions-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.actions-inline .btn { width: auto; flex: 1 1 auto; }

.panel {
  background: linear-gradient(180deg, rgba(28, 38, 47, 0.94), rgba(20, 27, 34, 0.98));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  animation: rise 700ms ease both;
}
.panel + .panel { margin-top: 0.85rem; }
.panel h2, .panel h3 {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  margin: 0 0 0.65rem;
  font-weight: 400;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

input, textarea, select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  padding: 0.85rem 0.9rem;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  margin-bottom: 0.85rem;
  min-height: var(--touch);
}
textarea {
  min-height: 110px;
  resize: vertical;
  min-height: 110px;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(244, 140, 6, 0.45);
  outline-offset: 1px;
  border-color: rgba(244, 140, 6, 0.55);
}

.flash {
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
  border: 1px solid var(--line);
  font-size: 0.95rem;
}
.flash-ok { background: rgba(42, 157, 143, 0.15); color: #b7f0e7; }
.flash-error { background: rgba(230, 57, 70, 0.15); color: #ffb4ba; }

.ride-list { list-style: none; padding: 0; margin: 0; }
.ride-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.95rem 0;
  border-bottom: 1px solid var(--line);
}
.ride-list li:last-child { border-bottom: 0; }
.muted { color: var(--muted); }
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  font-size: 1.05rem;
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  border: 1px solid var(--line);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.badge-live { color: #ffd6a5; border-color: rgba(232, 93, 4, 0.45); background: rgba(232, 93, 4, 0.12); }
.badge-open { color: #b7f0e7; border-color: rgba(42, 157, 143, 0.4); background: rgba(42, 157, 143, 0.12); }

.code-block {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-start;
}
.code-block .join-code {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 12vw, 3.2rem);
  letter-spacing: 0.16em;
  color: var(--accent-2);
  line-height: 1;
}
.qr-wrap {
  background: #fff;
  padding: 0.55rem;
  border-radius: 12px;
  width: fit-content;
  margin: 0 auto;
}
.qr-wrap img { display: block; width: min(200px, 70vw); height: auto; aspect-ratio: 1; }

/* Admin rider rows: stack as cards on phones */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}
.table th, .table td {
  text-align: left;
  padding: 0.75rem 0.45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table th { color: var(--muted); font-size: 0.78rem; font-weight: 500; }

.rider-cards { display: grid; gap: 0.75rem; }
.rider-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem;
  background: rgba(0, 0, 0, 0.18);
}
.rider-card .row-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.35rem;
}
.rider-card .bike { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.75rem; }

/* —— Live map: mobile-first sheet layout —— */
.map-shell {
  position: relative;
  height: calc(100dvh - var(--header-h) - var(--safe-top));
  min-height: 28rem;
  display: block;
  overflow: hidden;
}

#ride-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #0a1016;
  z-index: 1;
}

.map-sidebar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  max-height: min(72dvh, 34rem);
  background: rgba(10, 14, 18, 0.94);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(14px);
  padding: 0 calc(0.9rem + var(--safe-right)) calc(0.75rem + var(--safe-bottom)) calc(0.9rem + var(--safe-left));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(calc(100% - var(--sheet-peek, 7.5rem)));
  transition: transform 220ms ease;
}
.map-shell.sheet-open .map-sidebar {
  transform: translateY(0);
}

.sheet-handle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0 0.35rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex: 0 0 auto;
}
.sheet-handle::before {
  content: "";
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}
.sheet-summary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.sheet-summary h2 {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  margin: 0;
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1;
}
.sheet-toggle {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border-radius: 999px;
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
}

.sheet-body {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 0.5rem;
}

.map-quick-actions {
  position: absolute;
  right: calc(0.75rem + var(--safe-right));
  bottom: calc(var(--sheet-peek, 7.5rem) + 0.75rem);
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: bottom 220ms ease;
}
.map-shell.sheet-open .map-quick-actions {
  bottom: calc(min(72dvh, 34rem) + 0.5rem);
}

.fab {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(12, 16, 20, 0.92);
  color: var(--ink);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  font-size: 1.1rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.rider-row {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}
.rider-row .marker-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 0.4rem;
  background: var(--accent);
  flex: 0 0 auto;
}
.rider-row.leader .marker-dot {
  background: var(--leader);
  box-shadow: 0 0 0 3px rgba(255, 214, 10, 0.2);
}
.rider-row .name { font-weight: 700; }
.rider-row .bike { color: var(--muted); font-size: 0.88rem; }

.leaflet-div-icon.rider-pin { background: transparent; border: 0; }
.pin {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}
.pin span {
  transform: rotate(45deg);
  font-size: 0.85rem;
  font-weight: 800;
  color: #111;
}
.pin-leader { background: var(--leader); }
.pin-rider { background: var(--accent); }
.pin-you { outline: 3px solid rgba(255, 255, 255, 0.55); }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  min-height: var(--touch);
}
.switch {
  position: relative;
  width: 52px;
  height: 32px;
  flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: #33404c;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.8rem;
  white-space: nowrap;
}

.meta-line {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Larger phones / small tablets */
@media (min-width: 640px) {
  .site-main { width: min(760px, calc(100% - 2rem)); padding-top: 1.25rem; }
  .actions { flex-direction: row; flex-wrap: wrap; }
  .actions > .btn { width: auto; }
  .code-block { flex-direction: row; align-items: center; }
  .qr-wrap { margin: 0; }
  .brand { font-size: 1.6rem; }
}

/* Desktop: side panel + map */
@media (min-width: 900px) {
  :root { --header-h: 58px; }
  .site-main { width: min(1100px, calc(100% - 2rem)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero h1 { font-size: clamp(3rem, 8vw, 5rem); }
  .map-shell {
    display: grid;
    grid-template-columns: minmax(320px, 380px) 1fr;
    height: calc(100dvh - var(--header-h) - var(--safe-top));
  }
  #ride-map {
    position: relative;
    inset: auto;
  }
  .map-sidebar {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    max-height: none;
    height: 100%;
    transform: none;
    border-radius: 0;
    border: 0;
    border-right: 1px solid var(--line);
    box-shadow: none;
    padding: 1rem;
  }
  .map-shell.sheet-open .map-sidebar { transform: none; }
  .sheet-handle { display: none; }
  .sheet-body { overflow: auto; }
  .map-quick-actions { display: none; }
  .btn:hover { transform: translateY(-1px); }
}
