:root {
  color-scheme: only light;
  --page: #fffff8;
  --ink: #201912;
  --muted: #78695d;
  --line: rgba(32, 25, 18, 0.1);
  --button: #3b82f6;
  --button-hover: #2563eb;
  --button-ink: #fbf7f1;
  --button-off: #ddd0c1;
}

html[data-theme="dark"] {
  color-scheme: only dark;
  --page: #1a1714;
  --ink: #e8e0d8;
  --muted: #9a8b7f;
  --line: rgba(255, 255, 248, 0.1);
  --button: #3b82f6;
  --button-hover: #60a5fa;
  --button-ink: #fff;
  --button-off: #4a4038;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--page);
  color: var(--ink);
}

.shell {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 12px 16px 6px;
}

.picker {
  width: min(720px, 100%);
  text-align: center;
  padding: 12px 18px 4px;
}

.home-brand-row {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.home-app-title {
  display: inline-block;
  font-family: 'Comfortaa', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: lowercase;
  color: #201912;
}

.title-letter {
  display: inline-block;
  position: relative;
  transition: color 0.18s ease;
}

.title-letter.active {
  color: #3b82f6;
}

.home-version-badge {
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.24);
  color: #3b82f6;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.offline-badge {
  display: inline-block;
  margin: 0 auto 14px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(234, 179, 8, 0.12);
  border: 1px solid rgba(234, 179, 8, 0.32);
  color: #b45309;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

html[data-theme="dark"] .offline-badge {
  color: #fcd34d;
  background: rgba(234, 179, 8, 0.16);
  border-color: rgba(234, 179, 8, 0.4);
}

h1 {
  margin: 0 0 26px;
  font-size: clamp(2rem, 4vw, 3.6rem);
  font-weight: 600;
  letter-spacing: -0.04em;
}

.route-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.route-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.route-button {
  width: clamp(72px, 9vw, 106px);
  aspect-ratio: 1;
  border-radius: 999px;
  border: 0;
  background: var(--button);
  color: var(--button-ink);
  font: inherit;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  cursor: pointer;
  box-shadow: 0 18px 30px rgba(101, 70, 56, 0.18);
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.route-button:hover,
.route-button:focus-visible {
  transform: translateY(-2px);
  background: var(--button-hover);
  outline: none;
}

.route-button[disabled] {
  background: var(--button-off);
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
}

.route-caption {
  min-height: 2.9em;
  padding: 0 4px;
  font-size: 0.92rem;
  line-height: 1.25;
  font-weight: 600;
}

.route-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.route-empty {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--muted);
}

.route-empty--retry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.route-empty-msg {
  margin: 0;
}

.route-empty-retry {
  padding: 10px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.picker-actions {
  margin-top: 22px;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.back-button,
.gps-button {
  padding: 10px 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.back-button:hover,
.gps-button:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--ink);
}

.capture-mode-row {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.capture-mode-row.hidden {
  display: none;
}

.capture-toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  font-size: 0.98rem;
  color: var(--muted);
}

.capture-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.capture-toggle-track {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--button-off);
  transition: background 140ms ease;
  flex: none;
}

.capture-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 140ms ease;
}

.capture-toggle input:checked + .capture-toggle-track {
  background: var(--button);
}

.capture-toggle input:checked + .capture-toggle-track .capture-toggle-thumb {
  transform: translateX(20px);
}

.capture-toggle input:focus-visible + .capture-toggle-track {
  outline: 2px solid var(--button);
  outline-offset: 2px;
}

.capture-mode-row.is-on .capture-toggle-label {
  color: var(--ink);
  font-weight: 700;
}

.capture-mode-help {
  margin: 0;
  max-width: 30rem;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--muted);
}

.gps-button.gps-connected {
  border-color: #22c55e;
  color: #22c55e;
}

.gps-button.gps-pending {
  border-color: #f59e0b;
  color: #f59e0b;
}

.gps-button.gps-missing {
  border-color: #ef4444;
  color: #ef4444;
}

.theme-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: inherit;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.footer-sep {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.screen-footer {
  flex: 0 0 auto;
  padding: 0 16px max(10px, env(safe-area-inset-bottom));
}

.admin-link {
  font-size: 0.9rem;
  text-align: center;
}

.admin-link a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.admin-link a:hover {
  color: var(--ink);
}

/* ── Inline PIN keypad (under driver circle) ── */
.inline-pin {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.inline-pin-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: 18px;
}

.inline-pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--button-off);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.inline-pin-dot.filled {
  background: var(--button);
  border-color: var(--button);
}

.inline-pin-error {
  color: #dc2626;
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 1.1em;
}

.inline-pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 180px;
}

.inline-pin-key {
  width: 52px;
  height: 46px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s;
}

.inline-pin-key:active {
  background: rgba(59, 130, 246, 0.12);
}

.inline-pin-empty {
  visibility: hidden;
  pointer-events: none;
}

.inline-pin-del {
  font-size: 1.3rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .shell {
    padding: 8px 10px 4px;
  }

  .picker {
    padding: 8px 8px 2px;
  }

  .home-brand-row {
    gap: 10px;
    margin-bottom: 14px;
  }

  .home-app-title {
    font-size: 1.45rem;
  }

  .home-version-badge {
    font-size: 11px;
  }

  h1 {
    margin-bottom: 18px;
    font-size: clamp(1.5rem, 7vw, 2rem);
    line-height: 1.05;
  }

  .route-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    align-items: start;
  }

  .route-card {
    gap: 8px;
  }

  .route-button {
    width: min(100%, 68px);
    font-size: 1.2rem;
  }

  .route-caption {
    min-height: 2.8em;
    font-size: 0.74rem;
    line-height: 1.15;
  }

  .route-meta {
    font-size: 0.66rem;
    line-height: 1.15;
  }

  .admin-link {
    font-size: 0.84rem;
  }

  .inline-pin-pad {
    max-width: 156px;
    gap: 5px;
  }

  .inline-pin-key {
    width: 44px;
    height: 40px;
    font-size: 1rem;
    border-radius: 8px;
  }

  .inline-pin-dot {
    width: 12px;
    height: 12px;
  }
}

html[data-theme="dark"] body {
  background: var(--page);
}

html[data-theme="dark"] .home-app-title {
  color: var(--ink);
}

html[data-theme="dark"] .route-button {
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .back-button:hover,
html[data-theme="dark"] .gps-button:hover {
  background: rgba(255, 255, 255, 0.08);
}


/* ── Signed-in team indicator (launcher / admin) ──────────── */
.team-session-bar {
  margin: -6px 0 18px;
  font-size: 0.92rem;
  color: var(--muted);
  text-align: center;
}

.team-session-bar-top {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  left: auto;
  margin: 0;
  z-index: 20;
  text-align: right;
  max-width: min(420px, calc(100vw - 32px));
}

.team-session-bar strong {
  color: var(--ink);
  font-weight: 700;
}

.team-session-bar .theme-link {
  font-size: inherit;
}

/* ── Team login page (login/) ─────────────────────────────── */
.team-login-form {
  width: min(340px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.team-login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
}

.team-login-field input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.team-login-field input:focus-visible {
  outline: none;
  border-color: var(--button);
}

.team-login-error {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #b91c1c;
}

html[data-theme="dark"] .team-login-error {
  color: #fca5a5;
}

/* Non-error status under the login form (e.g. signed in from the cached
   verifier because the server was unreachable). */
.team-login-notice {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #b45309;
}

html[data-theme="dark"] .team-login-notice {
  color: #fcd34d;
}

.team-login-submit {
  margin-top: 4px;
  padding: 13px 28px;
  border: 0;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}

.team-login-submit:hover:not([disabled]),
.team-login-submit:focus-visible {
  background: var(--button-hover);
  transform: translateY(-1px);
  outline: none;
}

.team-login-submit[disabled] {
  background: var(--button-off);
  color: var(--muted);
  cursor: wait;
  transform: none;
}

@media (forced-colors: active) {
  .route-button {
    forced-color-adjust: none;
    background: #3b82f6;
    color: #fbf7f1;
  }
  .route-button[disabled] {
    background: #ddd0c1;
    color: #78695d;
  }
  .home-version-badge {
    forced-color-adjust: none;
    background: rgba(59, 130, 246, 0.12);
    color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.24);
  }
  .inline-pin-dot.filled {
    forced-color-adjust: none;
    background: #3b82f6;
    border-color: #3b82f6;
  }
}
