/* SPDX-License-Identifier: AGPL-3.0-or-later */
/* Colours come from the scooter's own display: near-black, pale teal bars, yellow arrows. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f9f7, #121a18);
  --raised: light-dark(#fff, #1d2826);
  --line: light-dark(#c9d8d4, #35433f);
  --text: light-dark(#101715, #eef6f3);
  --soft: light-dark(#465651, #a9bbb5);
  --bad: light-dark(#a8201a, #ff9d92);
  --yellow: #ffd02e;
  --ink: #14140a; /* text on yellow */
  --focus: light-dark(#0b57d0, #a8c7fa);
  --left: max(1rem, env(safe-area-inset-left));
  --right: max(1rem, env(safe-area-inset-right));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 1rem/1.4 system-ui, sans-serif; color: var(--text); background: var(--bg); accent-color: var(--yellow);
  height: 100dvh; overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
  display: grid; grid-template: "top" auto "map" minmax(0, 1fr) "sheet" auto / minmax(0, 1fr);
}
h1, h2, p, dl, dd { margin: 0; }
h1 { font-size: 1.375rem; line-height: 1.2; }
h2 { font-size: 1.125rem; line-height: 1.2; }
dd, #turnDistance, #routeTime, #routeInfo { font-variant-numeric: tabular-nums; }
svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; flex: none; }
::selection { background: var(--yellow); color: var(--ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.note { font-size: .875rem; color: var(--soft); text-wrap: pretty; }
.error { color: var(--bad); }

button, input, select {
  font: inherit; font-weight: 600; color: inherit; min-height: 3rem; padding: 0 1.125rem;
  background: var(--raised); border: 1px solid var(--line); border-radius: .75rem; caret-color: currentColor;
}
button { cursor: pointer; transition: background-color .15s, opacity .15s; touch-action: manipulation; }
button:active { background: var(--line); }
button:disabled, fieldset:disabled button { opacity: .5; cursor: default; }
.primary { background: var(--yellow); border-color: var(--yellow); color: var(--ink); font-size: 1.125rem; min-height: 3.5rem; width: 100%; }
.primary:active { background: #e6b800; }
.round { width: 3rem; padding: 0; border-radius: 50%; display: grid; place-items: center; }

/* Top: search while planning, the next turn while riding */
#top { grid-area: top; z-index: 2; padding: max(.75rem, env(safe-area-inset-top)) var(--right) .75rem var(--left); }
#search:empty { display: none; }
gmp-place-autocomplete { display: block; width: 100%; background-color: var(--raised); border: 1px solid var(--line); border-radius: .75rem; font-size: 1rem; }
#turn { display: none; align-items: center; gap: 1.125rem; }
#turn > div { min-width: 0; }
#turnIcon { width: 5.25rem; height: 5.25rem; color: var(--yellow); stroke-width: 5; }
#turnIcon.mirror { transform: scaleX(-1); }
#turnDistance { font-size: 3.25rem; line-height: 1; font-weight: 700; letter-spacing: -.03em; white-space: nowrap; }
#turnRoad { font-size: 1.375rem; line-height: 1.2; font-weight: 600; margin-top: .375rem; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

#mapArea { grid-area: map; position: relative; background: var(--line); }
#map { position: absolute; inset: 0; }
#locate, #more { position: absolute; right: var(--right); box-shadow: 0 2px 8px rgb(0 0 0 / .25); }
#locate { bottom: 2rem; }
#more { top: .75rem; }

#sheet { grid-area: sheet; display: grid; gap: 1rem; align-content: start; padding: 1rem var(--right) max(1rem, env(safe-area-inset-bottom)) var(--left); overflow-y: auto; }
#message { font-weight: 600; }
#message:empty, #linkHint:empty { display: none; }
#keyForm { display: grid; gap: .75rem; }
#keyForm label { font-weight: 600; margin-top: .5rem; }
#apiKey { width: 100%; font-weight: 400; }

#route { display: none; grid-template-columns: 1fr auto; align-items: center; column-gap: 1rem; }
#routeTime { font-size: 2rem; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; }
#routeInfo { grid-row: 2; color: var(--soft); }
#cancel { grid-area: 1 / 2 / 3 / 3; }
#route .note, #go { grid-column: 1 / -1; margin-top: .75rem; }

#ride { display: none; align-items: center; gap: 1rem; }
#ride dl { flex: 1; display: flex; justify-content: space-between; gap: .5rem; }
#ride dl div { display: flex; flex-direction: column-reverse; }
#ride dt { font-size: .875rem; color: var(--soft); }
#ride dd { font-size: 1.25rem; line-height: 1.2; font-weight: 700; white-space: nowrap; }
#stop { min-height: 3.5rem; }

/* The scooter: one line that always tells its state and offers the one sensible action */
#link { display: flex; align-items: center; gap: .75rem; }
#link > svg { width: 2rem; height: 2rem; stroke-width: 3; color: var(--soft); }
#link > div { flex: 1; min-width: 0; }
#linkText { font-weight: 600; text-wrap: balance; }
#link[data-state=on] > svg { color: var(--text); }
#link[data-state=failed] #linkText { color: var(--bad); }
#link[data-state=busy] > svg { animation: wait 1.2s ease-in-out infinite alternate; }
#link[data-state=press] { background: var(--yellow); color: var(--ink); border-radius: .75rem; padding: .875rem; }
#link[data-state=press] > svg, #link[data-state=press] .note { color: inherit; }
#link[data-state=press] button { background: none; border-color: currentColor; }
[data-view=idle] #link[data-state=off] #connect, [data-view=idle] #link[data-state=failed] #connect { background: var(--yellow); border-color: var(--yellow); color: var(--ink); }
body:has(#link[data-state=press]) #go { background: var(--raised); border-color: var(--line); color: var(--text); } /* one yellow thing at a time */
@keyframes wait { to { opacity: .35; } }

/* Views */
[data-view=setup] { grid-template-rows: 0 0 1fr; }
[data-view=setup] :is(#top, #mapArea, #message, #link) { display: none; }
[data-view=setup] #sheet { grid-row: 1 / -1; align-content: center; max-width: 30rem; width: 100%; margin: 0 auto; }
body:not([data-view=setup]) #keyForm { display: none; }
[data-view=route] #route { display: grid; }
[data-view=ride] {
  /* Riding: the same black as the scooter display, day and night */
  --bg: #0a0d0c; --text: #fff; --soft: #b4c4bf; --raised: #222c2a; --line: #43524e;
}
[data-view=ride] #turn, [data-view=ride] #ride { display: flex; }
[data-view=ride] :is(#search, #locate, #more, #message) { display: none; }
[data-view=ride] #link[data-state=on] { display: none; }

#details {
  width: 100%; max-width: 34rem; height: 100dvh; max-height: none; margin: 0 0 0 auto; border: 0; color: var(--text); background: var(--bg);
  padding: max(.75rem, env(safe-area-inset-top)) var(--right) max(1.5rem, env(safe-area-inset-bottom)) var(--left); overscroll-behavior: contain;
}
#details::backdrop { background: rgb(0 0 0 / .5); }
#details header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
#details fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
#details dl div { display: flex; justify-content: space-between; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
#details dd { font-weight: 700; text-align: right; }
#details :is(section, #settings) { margin-top: 2.5rem; }
#details h2 { margin-bottom: .375rem; }
#details :is(section, #panel) > button { margin-top: .75rem; width: 100%; }
#details #disconnect { margin-top: 1.25rem; }
#settings label { display: flex; justify-content: space-between; align-items: center; margin-top: .75rem; }
#log, #naviLog, #scanLog, #settingsLog { white-space: pre-line; overflow-wrap: anywhere; margin-top: .5rem; }
#log { font-size: .875rem; }
textarea { width: 100%; height: 14rem; margin-top: .75rem; font: 1rem/1.5 ui-monospace, monospace; color: inherit; background: var(--raised); border: 1px solid var(--line); border-radius: .75rem; padding: .75rem; }

/* Phone held sideways, tablet, desktop: map beside the controls */
@media (min-width: 43rem) {
  body:not([data-view=setup]) { grid-template: "top map" auto "sheet map" minmax(0, 1fr) / minmax(20rem, 25rem) minmax(0, 1fr); }
  #sheet { align-content: start; }
}
@media (min-width: 43rem) and (max-height: 30rem) {
  #turnIcon { width: 4rem; height: 4rem; }
  #turnDistance { font-size: 2.5rem; }
}
@media (max-width: 23rem) {
  #turnIcon { width: 4rem; height: 4rem; }
  #turnDistance { font-size: 2.5rem; }
  #ride { flex-wrap: wrap; }
  #stop { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
