/* Tuju map trial. Layered on the site's own site.css (tokens, .btn, .seg, .switch-row, .textlink, .fine).
   Map colours are the Everyday tokens (ios/BetterTuju/GrabMaps/EverydayMapStyle.swift); chrome night colours
   come from the approved Everyday mockup (.design/map-styles/a.html, `.night .phone`). */

:root {
  --ui: #fff; --fg: var(--ink); --fg-2: var(--muted-strong); --border-ui: var(--handle); --page: var(--land);
  --accent: var(--blue); --ctl-shadow: 0 2px 5px rgba(23, 40, 62, .07);
}
:root[data-scheme="night"] {
  --ui: #17283E; --fg: #F2F5F9; --fg-2: #BDC9D9; --border-ui: #52657D; --page: #0F1A28;
  --accent: #9DBBFF; --ctl-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

html, body { height: 100%; }
body { background: var(--page); color: var(--fg); overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3 { color: var(--fg); }

.trial { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* ---------- header ---------- */
.trial-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .625rem var(--gx) .5rem; }
.trial-id { display: flex; align-items: center; gap: .625rem; min-width: 0; }
.trial-mark { flex: none; width: 2.25rem; height: 2.25rem; }
.trial-title { font: 700 1.25rem/1.1 var(--display); letter-spacing: -0.02em; }
.trial-sub { font-size: .8125rem; line-height: 1.3; color: var(--fg-2); }
.trial-scheme { flex: none; width: 9.5rem; }
.trial-scheme .seg { background: var(--page); border-color: var(--border-ui); }
.trial-scheme .seg span { min-height: 2.75rem; font-size: .9375rem; color: var(--fg-2); }
.trial-scheme .seg input:checked + span { background: var(--ui); color: var(--fg); }

/* ---------- tools row ---------- */
.trial-tools { display: flex; align-items: flex-end; gap: .625rem; padding: 0 var(--gx) .625rem; }
.trial-place { flex: 1 1 auto; min-width: 0; }
.trial-place .field-label { color: var(--fg); font-size: .8125rem; margin-bottom: .25rem; }
.select-wrap { position: relative; }
.select-wrap select { appearance: none; -webkit-appearance: none; display: block; width: 100%; min-height: 3rem; padding: .5rem 2.75rem .5rem .875rem; border: 1px solid var(--border-ui); border-radius: 12px; background: var(--ui); color: var(--fg); font: 600 1rem/1.3 var(--text); cursor: pointer; box-shadow: var(--ctl-shadow); }
.select-wrap select:hover { border-color: var(--fg-2); }
.select-wrap select:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.select-wrap svg { position: absolute; right: .875rem; top: 50%; width: 1.25rem; height: 1.25rem; margin-top: -.625rem; pointer-events: none; fill: none; stroke: var(--fg); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.trial-route-toggle.switch-row { flex: 0 1 auto; width: auto; margin-top: 0 !important; min-height: 3rem; padding: .375rem .875rem; background: var(--ui); border-color: var(--border-ui); color: var(--fg); box-shadow: var(--ctl-shadow); font-size: .9375rem; }
.trial-route-toggle small { display: block; font-weight: 500; font-size: .75rem; color: var(--fg-2); }
.trial-route-toggle .switch { width: 2.75rem; height: 1.6875rem; }
.trial-route-toggle .switch .thumb { width: calc(1.6875rem - 4px); height: calc(1.6875rem - 4px); }
.trial-route-toggle[aria-checked="true"] .switch .thumb { transform: translateX(1.0625rem); }
:root[data-scheme="night"] .trial-route-toggle .switch { background: #2A3B52; }
:root[data-scheme="night"] .trial-route-toggle[aria-checked="true"] .switch { background: var(--blue); }

/* ---------- map stage ---------- */
.trial-stage { position: relative; flex: 1 1 auto; min-height: 16rem; margin: 0 var(--gx); border: 1px solid var(--border-ui); border-radius: 20px; overflow: hidden; isolation: isolate; background: var(--page); }
.trial-map { position: absolute; inset: 0; }
.trial-map .maplibregl-canvas:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }

.map-status { position: absolute; z-index: 3; top: .625rem; left: .625rem; display: flex; align-items: center; gap: .5rem; max-width: calc(100% - 1.25rem); padding: .375rem .75rem .375rem .625rem; border: 1px solid var(--border-ui); border-radius: 999px; background: var(--ui); color: var(--fg); font: 650 .8125rem/1.3 var(--text); box-shadow: var(--ctl-shadow); }
.map-status-dot { flex: none; width: .5rem; height: .5rem; border-radius: 50%; background: var(--fg-2); }
[data-map-state="loading"] .map-status-dot { animation: pulse 1.1s ease-in-out infinite; }
[data-map-state="ready"] .map-status-dot { background: #1F8A5B; }
[data-map-state="degraded"] .map-status-dot { background: #B7791F; }
[data-map-state="error"] .map-status-dot { background: var(--danger); }
:root[data-scheme="night"][data-map-state="ready"] .map-status-dot { background: #5FD39B; }
@keyframes pulse { 50% { opacity: .3; } }
/* Once ready, the pill steps back so it isn't read as part of the map. */
[data-map-state="ready"] .map-status { opacity: .92; }

.route-chip { position: absolute; z-index: 3; left: .625rem; right: 4.375rem; top: 3.125rem; display: flex; gap: .5rem; align-items: flex-start; max-width: 26rem; padding: .5rem .75rem; border: 1px solid var(--border-ui); border-radius: 12px; background: var(--ui); color: var(--fg); font-size: .8125rem; line-height: 1.4; box-shadow: var(--ctl-shadow); }
.route-chip svg { flex: none; width: 1.25rem; height: 1.5625rem; margin-top: .0625rem; }
.route-chip svg path { fill: var(--blue); stroke: #fff; stroke-width: 2.5; stroke-linejoin: round; }
.route-chip svg circle { fill: #fff; }

/* map buttons: 48 px, like the approved mockup's .map-button */
.map-buttons { position: absolute; z-index: 3; right: .625rem; bottom: .625rem; display: flex; flex-direction: column; gap: .5rem; }
.map-btn { display: grid; place-items: center; width: 3rem; height: 3rem; padding: 0; border: 1px solid var(--border-ui); border-radius: 14px; background: var(--ui); color: var(--fg); box-shadow: var(--ctl-shadow); cursor: pointer; }
.map-btn svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.map-btn:hover { outline: 2px solid var(--fg); outline-offset: -2px; }
.map-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.map-btn:disabled { opacity: .45; cursor: default; outline: none; }
.map-zoom { display: grid; border: 1px solid var(--border-ui); border-radius: 14px; overflow: hidden; box-shadow: var(--ctl-shadow); }
.map-zoom .map-btn { border: 0; border-radius: 0; box-shadow: none; }
.map-zoom .map-btn + .map-btn { border-top: 1px solid var(--border-ui); }
#fullscreen .fs-exit, #fullscreen[aria-pressed="true"] .fs-enter { display: none; }
#fullscreen[aria-pressed="true"] .fs-exit { display: inline; }

.map-error { position: absolute; z-index: 5; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(22rem, calc(100% - 2rem)); padding: 1.25rem; border: 1px solid var(--border-ui); border-radius: 18px; background: var(--ui); color: var(--fg); box-shadow: var(--shadow); }
.map-error > * + * { margin-top: .625rem; }
.map-error-title { font: 700 1.125rem/1.25 var(--text); }
.map-error .fine { color: var(--fg-2) !important; overflow-wrap: anywhere; }
.map-error .fine:empty { display: none; }

/* ---------- details: a compact sheet over the map (phones), a side card (wide screens) ---------- */
.details { position: absolute; z-index: 4; left: 0; right: 0; bottom: 0; max-height: 72%; display: flex; flex-direction: column; background: var(--ui); color: var(--fg); border-top: 1px solid var(--border-ui); border-radius: 20px 20px 0 0; box-shadow: 0 -12px 32px rgba(23, 40, 62, .14); }
.details-head, .credits-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem .75rem .25rem 1.125rem; }
.details-title { font: 700 1.25rem/1.2 var(--display); letter-spacing: -0.015em; }
.details-head .map-btn, .credits-head .map-btn { box-shadow: none; border-color: transparent; }
.details-body, .credits-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 1.125rem 1.125rem; font-size: .9375rem; line-height: 1.5; }
.details-body h3, .credits-body h3 { margin: 1.125rem 0 .375rem; font: 700 .9375rem/1.3 var(--text); }
.details-body .fine, .credits-body .fine { color: var(--fg-2) !important; font-size: .8125rem; }
.details-body a, .credits-body a { color: var(--fg); }
.details-lead { color: var(--fg); }
.kv { margin: .375rem 0 0; display: grid; gap: 0; border-top: 1px solid var(--border-ui); }
.kv > div { display: grid; grid-template-columns: 8.5rem 1fr; gap: .75rem; padding: .4375rem 0; border-bottom: 1px solid var(--border-ui); }
.kv dt { color: var(--fg-2); font-size: .8125rem; }
.kv dd { margin: 0; font-size: .875rem; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.details-btn { margin-top: .5rem; background: var(--page); color: var(--fg); border: 1px solid var(--border-ui); }
.details-btn:hover { border-color: var(--fg-2); }
.details-links { margin-top: .75rem; }

/* ---------- footer: the map credit sits right under the map ---------- */
.trial-foot { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .375rem calc(var(--gx) + .25rem) .5rem; font-size: .8125rem; color: var(--fg-2); }
.trial-credit { display: flex; flex-wrap: wrap; align-items: center; gap: 0 .375rem; }
.trial-credit a { color: var(--fg); font-weight: 600; text-underline-offset: 3px; }
.linkish { min-height: 2.75rem; padding: 0 .25rem; border: 0; background: none; color: var(--fg); font: 600 .8125rem/1.2 var(--text); text-decoration: underline; text-decoration-color: var(--border-ui); text-decoration-thickness: 2px; text-underline-offset: 4px; cursor: pointer; }
.linkish:hover { text-decoration-color: var(--accent); }
.trial-details-toggle { flex: none; }
.trial-details-toggle[aria-expanded="true"] { text-decoration-color: var(--accent); }

/* ---------- credits dialog ---------- */
.credits { width: min(34rem, calc(100% - 1.25rem)); max-height: min(44rem, calc(100dvh - 2rem)); padding: 0; border: 1px solid var(--border-ui); border-radius: 20px; background: var(--ui); color: var(--fg); box-shadow: var(--shadow); }
.credits[open] { display: flex; flex-direction: column; }
.credits::backdrop { background: rgba(15, 26, 40, .45); }
.credits-body p + p { margin-top: .5rem; }

.map-noscript { position: fixed; inset: auto 1rem 1rem; padding: 1rem; background: #fff; color: var(--ink); border-radius: 14px; }

/* MapLibre's own controls are off; keep its canvas container from adding a focus ring of its own colour. */
.maplibregl-map { font: inherit; }

@media (min-width: 40em) {
  :root { --gx: 1rem; }
  .trial-head { padding-top: .875rem; }
  .trial-title { font-size: 1.5rem; }
  .trial-tools { justify-content: flex-start; }
  .trial-place { flex: 0 1 18rem; }
}
@media (min-width: 64em) {
  :root { --gx: 1.5rem; }
  .details { left: auto; top: .625rem; right: 4.375rem; bottom: .625rem; width: 23rem; max-height: none; border: 1px solid var(--border-ui); border-radius: 18px; }
  .map-status { top: .875rem; left: .875rem; }
  .route-chip { top: 3.375rem; left: .875rem; }
}
@media (max-width: 26em) {
  .trial-sub { font-size: .75rem; }
  .trial-scheme { width: 7.75rem; }
  .trial-route-toggle small { display: none; }
  .kv > div { grid-template-columns: 7rem 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  [data-map-state="loading"] .map-status-dot { animation: none; }
}
