:root {
  --bg: #111111;
  --surface: #1c1c1e;
  --surface-2: #2a2a2d;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --border: #3a3a3e;
  --primary: #22c55e;
  --primary-text: #052e16;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

a { color: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); margin: .75rem 0 0; }

/* ---------- buttons & inputs ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button:disabled { opacity: .5; cursor: default; }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.button.stop { background: var(--surface-2); border-color: var(--danger); color: var(--danger); }
.button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.button.wide { width: 100%; }
.button.small { min-height: 36px; padding: 0 .8rem; font-size: .9rem; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 0 .8rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.field { display: grid; gap: .35rem; margin: 0 0 1rem; }
.field > span { font-size: .85rem; color: var(--muted); }

.colors { display: flex; flex-wrap: wrap; gap: .5rem; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }

/* ---------- home ---------- */

.home {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem calc(1.5rem + var(--safe-bottom));
  background:
    radial-gradient(40rem 30rem at 0% 0%, rgb(34 197 94 / .14), transparent 70%),
    radial-gradient(40rem 30rem at 100% 100%, rgb(30 136 229 / .12), transparent 70%),
    var(--bg);
}

.card {
  width: 100%;
  max-width: 420px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: .75rem; }
.brand h1 { margin: 0; font-size: 1.8rem; letter-spacing: -.02em; }
.card > .muted { margin: .5rem 0 1.5rem; }

.divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1.25rem 0;
  color: var(--muted);
  font-size: .85rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.join { display: flex; gap: .5rem; }
.join input { flex: 1; }

/* ---------- ride ---------- */

.ride { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: #ddd; }

.topbar {
  position: absolute;
  top: calc(8px + var(--safe-top));
  left: 8px;
  right: 8px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 6px;
  border-radius: var(--radius);
  background: rgb(28 28 30 / .92);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgb(0 0 0 / .3);
}
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: .75rem; color: var(--muted); }
.status:empty { display: none; }
.status.warn { color: var(--warn); }

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--text);
}

/* Leaflet controls below the top bar */
.leaflet-top { top: calc(64px + var(--safe-top)); }
.leaflet-control-layers { border-radius: 12px !important; }
.mapy-logo img { display: block; }

.map-buttons {
  position: absolute;
  right: 10px;
  top: calc(124px + var(--safe-top));
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: rgb(28 28 30 / .92);
  color: var(--text);
  box-shadow: 0 4px 16px rgb(0 0 0 / .3);
  cursor: pointer;
}

.panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  max-height: 42vh;
  overflow-y: auto;
  padding: 12px 12px calc(12px + var(--safe-bottom));
  border-radius: 20px 20px 0 0;
  background: rgb(28 28 30 / .96);
  backdrop-filter: blur(8px);
  box-shadow: 0 -4px 20px rgb(0 0 0 / .35);
}
.hint { margin: .5rem 0 0; color: var(--muted); font-size: .8rem; text-align: center; }
.route-summary { margin: .6rem 0 0; font-size: .85rem; color: #90caf9; text-align: center; }

.riders { list-style: none; margin: .5rem 0 0; padding: 0; }
.rider {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .25rem;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.rider.stale { opacity: .55; }
.rider .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgb(255 255 255 / .15); }
.rider-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rider-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rider-detail { font-size: .85rem; color: var(--muted); }
.rider-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.riders .empty { padding: 1rem 0 .25rem; color: var(--muted); font-size: .9rem; text-align: center; }

/* ---------- markers ---------- */

.rider-icon { background: none; border: 0; }
.rider-dot {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--c);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgb(0 0 0 / .6);
  box-shadow: 0 2px 8px rgb(0 0 0 / .45);
}
.rider-dot.me { box-shadow: 0 0 0 4px rgb(255 255 255 / .35), 0 2px 8px rgb(0 0 0 / .45); }
.rider-dot.stale { filter: grayscale(1); opacity: .6; }
.rider-label {
  position: absolute;
  top: 36px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 6px;
  border-radius: 6px;
  background: rgb(17 17 17 / .8);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- dialogs, overlay, toast ---------- */

dialog {
  width: min(92vw, 420px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .6); }
.dialog-body { display: grid; gap: .75rem; padding: 1.25rem; }
.dialog-body h2 { margin: 0; font-size: 1.25rem; }
.dialog-body .field { margin: 0; }
.dialog-body p { margin: 0; }
.steps { margin: 0; padding-left: 1.25rem; display: grid; gap: .35rem; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(0 0 0 / .7);
}
.overlay .card p { margin: 0 0 1rem; font-size: 1.05rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(45vh + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 2000;
  max-width: 90vw;
  padding: .6rem 1rem;
  border-radius: 12px;
  background: #f4f4f5;
  color: #111;
  font-size: .9rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / .4);
}
