: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-color: var(--page);
  background-image:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.1), transparent 30%),
    linear-gradient(180deg, #ffffff 0%, var(--page) 100%);
  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-size: clamp(1.35rem, 3vw, 1.9rem);
  font-weight: 700;
  letter-spacing: 2px;
  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;
}

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);
}

.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);
}

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

.theme-toggle {
  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;
}

.theme-toggle:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--ink);
}

.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);
}

/* ── 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-image:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.15), transparent 30%),
    linear-gradient(180deg, #1f1b16 0%, var(--page) 100%);
}

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);
}

html[data-theme="dark"] .theme-toggle {
  border-color: var(--line);
  color: var(--muted);
}

@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;
  }
}
