:root {
  --page-max-width: 680px;
  --page-pad-x: 14px;
  --page-pad-top: 14px;
  --page-pad-bottom: 24px;
  --card-gap: 12px;
  --card-radius: 16px;
}

@media (min-width: 600px) {
  :root {
    --page-pad-x: 20px;
  }
}

@media (max-width: 899px) {
  :root {
    --page-pad-bottom: calc(82px + max(8px, calc(env(safe-area-inset-bottom, 0px) - 12px)));
  }
}

.page-scroll-shell {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: none;
  box-sizing: border-box;
  padding: calc(var(--page-pad-top) + var(--page-header-inset, 0px)) var(--page-pad-x)
    var(--page-pad-bottom);
}

.page-card-stack,
.card-stack {
  display: flex;
  flex-direction: column;
  gap: var(--card-gap);
  width: 100%;
  min-width: 0;
}

.page-card-stack {
  max-width: var(--page-max-width);
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

*,
*::before,
*::after {
  -webkit-tap-highlight-color: transparent !important;
}

html,
body {
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent !important;
}

button,
a,
[role='button'],
[role='tab'],
.MuiButtonBase-root,
.MuiIconButton-root,
.MuiTab-root,
.MuiBottomNavigationAction-root,
.MuiMenuItem-root {
  -webkit-tap-highlight-color: transparent !important;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
[role='button']:focus:not(:focus-visible),
[role='tab']:focus:not(:focus-visible),
.MuiButtonBase-root:focus:not(:focus-visible) {
  outline: none !important;
}

body {
  margin: 0;
  padding: 0;
}

@media (prefers-color-scheme: dark) {
  body {
    background: #0b0f17;
  }
}

.root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Unified Liquid Glass MapLibre Control Pills */
.maplibregl-ctrl-group {
  border-radius: 999px !important;
  overflow: hidden;
  border: none !important;
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.6),
    0 0 0 0.5px rgba(11, 17, 30, 0.07),
    0 10px 26px -6px rgba(11, 17, 30, 0.16),
    0 2px 6px 0 rgba(11, 17, 30, 0.06) !important;
  background: rgba(255, 255, 255, 0.72) !important;
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
}

.maplibregl-ctrl-group button:not(.active) {
  background-color: transparent !important;
}

.maplibregl-ctrl-group button {
  width: 44px !important;
  height: 44px !important;
  touch-action: manipulation;
  /* Named properties only — never `transition: all`. */
  transition:
    background-color 150ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 150ms cubic-bezier(0.22, 1, 0.36, 1),
    color 150ms cubic-bezier(0.22, 1, 0.36, 1) !important;
}

@media (hover: hover) and (pointer: fine) {
  .maplibregl-ctrl-group button:not(.active):hover {
    background-color: rgba(11, 17, 30, 0.05) !important;
  }
}

.maplibregl-ctrl-group button:active:not(:disabled) {
  transform: scale(0.94) !important;
}

.maplibregl-ctrl-group button + button {
  border-top: 1px solid rgba(11, 17, 30, 0.09) !important;
}

@media (prefers-color-scheme: dark) {
  body:not([data-theme='light']) .maplibregl-ctrl-group {
    background: rgba(15, 22, 35, 0.68) !important;
    border: none !important;
    box-shadow:
      inset 0 1px 0 0 rgba(255, 255, 255, 0.18),
      inset 0 0 0 0.5px rgba(255, 255, 255, 0.11),
      0 10px 26px -6px rgba(0, 0, 0, 0.58),
      0 2px 6px 0 rgba(0, 0, 0, 0.32) !important;
  }
  body:not([data-theme='light']) .maplibregl-ctrl-group button:not(.active) {
    color: #e2e8f0 !important;
  }
  @media (hover: hover) and (pointer: fine) {
    body:not([data-theme='light']) .maplibregl-ctrl-group button:not(.active):hover {
      background-color: rgba(255, 255, 255, 0.1) !important;
    }
  }
  body:not([data-theme='light']) .maplibregl-ctrl-group button + button {
    border-top: 0.5px solid rgba(255, 255, 255, 0.11) !important;
  }
  body:not([data-theme='light']) .maplibregl-ctrl-group button > span.maplibregl-ctrl-icon {
    filter: invert(0.92) hue-rotate(180deg);
  }
  body:not([data-theme='light'])
    .maplibregl-ctrl-group
    button:disabled
    > span.maplibregl-ctrl-icon {
    opacity: 0.42 !important;
  }
}

body[data-theme='dark'] .maplibregl-ctrl-group {
  background: rgba(15, 22, 35, 0.68) !important;
  border: none !important;
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.18),
    inset 0 0 0 0.5px rgba(255, 255, 255, 0.11),
    0 10px 26px -6px rgba(0, 0, 0, 0.58),
    0 2px 6px 0 rgba(0, 0, 0, 0.32) !important;
}

body[data-theme='dark'] .maplibregl-ctrl-group button:not(.active) {
  color: #e2e8f0 !important;
}

@media (hover: hover) and (pointer: fine) {
  body[data-theme='dark'] .maplibregl-ctrl-group button:not(.active):hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
  }
}

body[data-theme='dark'] .maplibregl-ctrl-group button + button {
  border-top: 0.5px solid rgba(255, 255, 255, 0.11) !important;
}

body[data-theme='dark'] .maplibregl-ctrl-group button > span.maplibregl-ctrl-icon {
  filter: invert(0.92) hue-rotate(180deg);
}

body[data-theme='dark'] .maplibregl-ctrl-group button:disabled > span.maplibregl-ctrl-icon {
  opacity: 0.42 !important;
}

@media (prefers-reduced-transparency: reduce) {
  .maplibregl-ctrl-group {
    background: #ffffff !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow:
      0 0 0 1px rgba(11, 17, 30, 0.12),
      0 2px 6px 0 rgba(11, 17, 30, 0.14) !important;
  }
  body[data-theme='dark'] .maplibregl-ctrl-group {
    background: #111722 !important;
    box-shadow:
      0 0 0 0.5px #384963,
      0 2px 6px 0 rgba(0, 0, 0, 0.55) !important;
  }
  @media (prefers-color-scheme: dark) {
    body:not([data-theme='light']) .maplibregl-ctrl-group {
      background: #111722 !important;
      box-shadow:
        0 0 0 0.5px #384963,
        0 2px 6px 0 rgba(0, 0, 0, 0.55) !important;
    }
  }
}

@media (prefers-contrast: more) {
  .maplibregl-ctrl-group {
    background: #ffffff !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: 1px solid rgba(11, 17, 30, 0.3) !important;
  }
  body[data-theme='dark'] .maplibregl-ctrl-group {
    background: #111722 !important;
    border: 1px solid rgba(255, 255, 255, 0.34) !important;
  }
  @media (prefers-color-scheme: dark) {
    body:not([data-theme='light']) .maplibregl-ctrl-group {
      background: #111722 !important;
      border: 1px solid rgba(255, 255, 255, 0.34) !important;
    }
  }
}

@media (max-width: 899px) {
  .maplibregl-ctrl-top-right {
    top: 62px !important;
    right: 6px !important;
  }
  .maplibregl-ctrl-top-right .maplibregl-ctrl-group {
    margin-top: 4px !important;
  }
  .maplibregl-ctrl-group button {
    width: 44px !important;
    height: 44px !important;
  }
  .maplibregl-ctrl-compass {
    display: none !important;
  }
  [data-single-vehicle='true'] .maplibregl-ctrl-top-right {
    top: 12px !important;
    right: 12px !important;
  }
  [data-single-vehicle='true'] .maplibregl-ctrl-top-right .maplibregl-ctrl {
    margin: 0 0 6px 0 !important;
  }
  .maplibregl-ctrl-bottom-right {
    bottom: 2px !important;
    right: 6px !important;
    opacity: 0.55;
    transform: scale(0.85);
    transform-origin: bottom right;
  }
}

@media (min-width: 900px) {
  [data-single-vehicle='true'] .maplibregl-ctrl-top-right {
    top: 12px !important;
    right: 12px !important;
  }
  [data-single-vehicle='true'] .maplibregl-ctrl-top-right .maplibregl-ctrl {
    margin: 0 0 6px 0 !important;
  }
  .maplibregl-ctrl-bottom-left {
    bottom: 72px !important;
    left: 12px !important;
  }
}

/* Dark-mode MapLibre scale & attribution pills (WCAG AA >= 4.5:1) */
@media (prefers-color-scheme: dark) {
  body:not([data-theme='light']) .maplibregl-ctrl-attrib,
  body:not([data-theme='light']) .maplibregl-ctrl-scale {
    background: rgba(17, 23, 34, 0.9) !important;
    color: #cbd5e1 !important;
    border-color: rgba(148, 163, 184, 0.35) !important;
    border-radius: 999px !important;
  }
  body:not([data-theme='light']) .maplibregl-ctrl-attrib a {
    color: #cbd5e1 !important;
  }
  body:not([data-theme='light']) .maplibregl-ctrl-attrib-button {
    filter: invert(0.92) hue-rotate(180deg);
  }
}

body[data-theme='dark'] .maplibregl-ctrl-attrib,
body[data-theme='dark'] .maplibregl-ctrl-scale {
  background: rgba(17, 23, 34, 0.9) !important;
  color: #cbd5e1 !important;
  border-color: rgba(148, 163, 184, 0.35) !important;
  border-radius: 999px !important;
}

body[data-theme='dark'] .maplibregl-ctrl-attrib a {
  color: #cbd5e1 !important;
}

body[data-theme='dark'] .maplibregl-ctrl-attrib-button {
  filter: invert(0.92) hue-rotate(180deg);
}

/* ==========================================================================
   Reports inline mini-map (.inline-report-map)
   ==========================================================================
   The report cards embed a 240-285px map preview whose React "Dismiss" X sits
   at top: 8px. The MapLibre rail therefore starts below it at 50px and uses a
   single 36px column (button / Layers / zoom pair) so the stack never grows
   into the © Google attribution pill in the bottom-right corner.
   ========================================================================== */
.inline-report-map .maplibregl-ctrl-top-right {
  top: 50px !important;
  right: 8px !important;
}

.inline-report-map .maplibregl-ctrl-top-right .maplibregl-ctrl-group {
  margin: 0 0 6px 0 !important;
  border-radius: 999px !important;
}

.inline-report-map .maplibregl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
}

/* A 3D compass is meaningless in a static 240px preview. */
.inline-report-map .maplibregl-ctrl-compass {
  display: none !important;
}

.inline-report-map .maplibregl-ctrl-attrib,
.inline-report-map .maplibregl-ctrl-scale {
  background: rgba(255, 255, 255, 0.86) !important;
  color: #475569 !important;
  /* MapLibre ships `border: 2px solid #333; border-top: none` on the scale
     control, which reads as a heavy black U-bracket on the "2 km" pill.
     A hairline keeps the pill legible without the bracket. */
  border: 1px solid rgba(15, 23, 42, 0.09) !important;
  /* Law 1 — a standalone pill, so the pill tier: 999px. */
  border-radius: 999px !important;
  box-shadow: none !important;
  font-size: 10px !important;
  line-height: 16px !important;
  margin: 6px 8px !important;
  padding: 2px 7px !important;
  min-height: 0 !important;
}

.inline-report-map .maplibregl-ctrl-attrib-button,
.inline-report-map .maplibregl-ctrl-attrib.maplibregl-compact::after {
  display: none !important;
}

.inline-report-map .maplibregl-ctrl-attrib a {
  color: inherit !important;
}

@media (prefers-color-scheme: dark) {
  body:not([data-theme='light']) .inline-report-map .maplibregl-ctrl-attrib,
  body:not([data-theme='light']) .inline-report-map .maplibregl-ctrl-scale {
    background: rgba(19, 25, 36, 0.82) !important;
    color: #94a3b8 !important;
    border: 1px solid rgba(148, 163, 184, 0.22) !important;
  }
}

body[data-theme='dark'] .inline-report-map .maplibregl-ctrl-attrib,
body[data-theme='dark'] .inline-report-map .maplibregl-ctrl-scale {
  background: rgba(19, 25, 36, 0.82) !important;
  color: #94a3b8 !important;
  border: 1px solid rgba(148, 163, 184, 0.22) !important;
}

/* ==========================================================================
   Reduced motion
   ==========================================================================
   `prefers-reduced-motion: reduce` has to disable *large surface* motion,
   not just the tactile press feedback:
     - the bottom sheet drag physics (the whole sheet tracks the finger)
     - the `grid-template-rows: 0fr -> 1fr` drawer unfolds (180-280ms)
     - the Replay chapter-seekbar `scaleY(1.75)` inflation
     - the `sectionReveal` / `barGrowUp` keyframes

   Why `0.01ms` and not `none` / `0s`:
     MUI's Grow / Fade / Dialog wait for a `transitionend` (or `animationend`)
     event before they consider themselves "entered". `transition: none`
     swallows that event and leaves dialogs, menus and popovers stuck
     half-open. A 0.01ms transition still fires the event, it just completes
     instantly.

   Why `!important`:
     The app writes inline `style.transition` / `style.animation` values (the
     bottom sheet scrubs its own height, the drawers set their own
     `grid-template-rows` transition). Inline declarations beat a normal
     stylesheet rule, so the reset has to be `!important` to reach them.

   The sheet drag keeps working: the drag itself writes `style.height`
   directly with `transition: none`, and the detent snap afterwards is
   reduced to an instant jump instead of a 180ms slide.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
  }

  /* `prefers-reduced-motion` means "no movement", not "no feedback". The
     universal reset above zeroes every transition, which also kills the tonal
     fill / opacity cues that say "this tab is selected", "this toggle is on",
     "this toast is leaving". Re-state colour + opacity only on the surfaces
     that carry that meaning; transform and box-shadow stay instant so nothing
     travels. 150ms = tok.motion.duration.fast. */
  .MuiButtonBase-root,
  .MuiButton-root,
  .MuiIconButton-root,
  .MuiMenuItem-root,
  .MuiSwitch-track,
  .MuiBottomNavigationAction-root,
  .m3-nav-item,
  .m3-nav-pill,
  .m3-nav-icon-out,
  .m3-nav-icon-fill,
  [role='button'][aria-pressed] {
    transition:
      opacity 150ms ease,
      background-color 150ms ease,
      color 150ms ease !important;
  }

  .m3-nav-pill {
    transform: scaleX(1) !important;
  }

  .m3-nav-item:active .m3-nav-inner,
  .m3-nav-icon-out,
  .m3-nav-icon-fill {
    transform: none !important;
  }

  /* The bottom-nav indicator animates opacity (state) and scaleX (movement)
     in one rule; keep only the state half. */
  .MuiBottomNavigationAction-root::before {
    transition: opacity 150ms ease !important;
  }

  /* The MapLibre control pills carry their own `!important` transition, which
     out-specifies the universal reset above. Restate it here (same file, same
     specificity, later in source order) and drop the press-scale so the map
     controls do not zoom under the finger either. */
  .maplibregl-ctrl-group button {
    transition-duration: 0.01ms !important;
  }

  .maplibregl-ctrl-group button:active {
    transform: none !important;
  }

  /* A loading spinner still has to say "working", so MUI's CircularProgress
     keeps a (slower) rotation instead of freezing into a static arc. Same
     decision as the boot loader in index.html. */
  .MuiCircularProgress-root {
    animation-duration: 3s !important;
    animation-iteration-count: infinite !important;
  }
}

/* ==========================================================================
   Keyboard focus visibility
   ==========================================================================
   MUI's ButtonBase resets the user-agent focus ring with `outline: 0`, and
   this app disables ripples (`disableRipple`), so a keyboard-focused
   Button / IconButton / Tab had *no* visible focus indicator at all.
   Paint an explicit brand-cyan ring instead.

   The ring is inset on Tabs because `MuiTabs` clips its overflow and an
   outset ring would be cut in half.
   ========================================================================== */
.MuiButton-root:focus-visible,
.MuiIconButton-root:focus-visible,
.MuiButtonBase-root:focus-visible,
.MuiMenuItem-root:focus-visible,
.MuiTab-root:focus-visible,
.m3-nav-item:focus-visible,
button:focus-visible,
a:focus-visible,
[role='button']:focus-visible,
[role='tab']:focus-visible,
[role='menuitem']:focus-visible {
  outline: 2px solid currentColor !important;
  outline-offset: 2px !important;
}

.MuiTab-root:focus-visible,
.MuiMenuItem-root:focus-visible,
.m3-nav-item:focus-visible,
[role='menuitem']:focus-visible {
  outline-offset: -2px !important;
}

/* MUI's Popover / Modal root and paper receive programmatic focus on open.
   Safari paints a UA focus ring that flashes as a bright 1px line under the
   search pill when the vehicle-list dropdown opens. The container is not an
   interactive element, so it gets no ring — the keyboard `:focus-visible`
   rings on buttons and tabs stay cyan. */
.MuiPopover-root:focus,
.MuiPopover-paper:focus,
.MuiModal-root:focus,
.MuiDialog-container:focus {
  outline: none !important;
}

@media (pointer: coarse) {
  .page-scroll-shell {
    scrollbar-width: none;
  }
  .page-scroll-shell::-webkit-scrollbar {
    display: none;
  }
  /* 16px floor on any touch screen so iOS Safari never zooms into a field.
     `!important` is required: several fields carry an inline `font-size`
     (e.g. the 68px cadence inputs), which no author rule can otherwise beat. */
  input:not([type='checkbox']):not([type='radio']):not([type='range']),
  select,
  textarea {
    font-size: 16px !important;
  }
}

@media (hover: none), (pointer: coarse) {
  button:hover,
  a:hover,
  [role='button']:hover,
  [role='tab']:hover,
  .MuiButtonBase-root:hover {
    filter: none !important;
  }

  /* Law 7 — a latched touch :hover falls back to the element's own resting
     fill. `--omp-btn-rest-bg` is declared by any icon button that sits on a
     well / glass fill; without it the button would go see-through. */
  .MuiIconButton-root:hover {
    background-color: var(--omp-btn-rest-bg, transparent);
  }

  .maplibregl-ctrl-group button:not(.active):hover,
  .maplibregl-ctrl-group button:focus:not(:focus-visible) {
    background-color: transparent !important;
    outline: none !important;
  }

  button:focus:not(:focus-visible),
  a:focus:not(:focus-visible),
  [role='button']:focus:not(:focus-visible),
  [role='tab']:focus:not(:focus-visible),
  [role='menuitem']:focus:not(:focus-visible),
  .MuiButtonBase-root:focus:not(:focus-visible),
  .MuiButton-root:focus:not(:focus-visible),
  .MuiIconButton-root:focus:not(:focus-visible),
  .MuiTab-root:focus:not(:focus-visible),
  .MuiMenuItem-root:focus:not(:focus-visible),
  .MuiBottomNavigationAction-root:focus:not(:focus-visible),
  .m3-nav-item:focus:not(:focus-visible) {
    outline: none !important;
  }
}

@keyframes navFadeMap {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

@keyframes navFadeThrough {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

@keyframes sectionReveal {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes barGrowUp {
  from {
    transform: scaleY(0.08);
    opacity: 0.35;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

@media print {
  * {
    height: auto !important;
    overflow: visible !important;
  }
}
