:root {
  --bg: #0b0b0b;
  --bg-rgb: 11, 11, 11;
  --panel: #1c1c1b;
  --panel-rgb: 28, 28, 27;
  --line: #2c2c2a;
  --tick: #55544f;
  --text: #f1efe8;
  --muted: #888780;
  --ok: #5dcaa5;
  --warn: #ef9f27;
  --over: #e24b4a;
  --over-text: #f09595;
  --sign: #0c447c;
  --sign-dim: #042c53;
  --sign-text: #e6f1fb;
  --dock: 56px;
}
:root[data-theme="light"] {
  --bg: #f4f2ee;
  --bg-rgb: 244, 242, 238;
  --panel: #ffffff;
  --panel-rgb: 255, 255, 255;
  --line: #dcd9d2;
  --tick: #a9a69e;
  --text: #1b1b1a;
  --muted: #77756f;
  --ok: #0f9d76;
  --warn: #d98200;
  --over: #d93a39;
  --over-text: #c62f2e;
  --sign: #185fa5;
  --sign-dim: #0c447c;
  --sign-text: #ffffff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Display", system-ui, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* --app-h est posée par app.js : sur iPhone, une PWA lancée en paysage garde parfois
   une hauteur de page trop courte tant qu'on n'a pas tourné le téléphone */
#app {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--app-h, 100dvh);
  display: grid;
  grid-template-columns: calc(var(--dock) + env(safe-area-inset-left)) minmax(0, 1fr);
}

/* ---------- dock ---------- */
#dock {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px 8px calc(6px + env(safe-area-inset-left));
  border-right: 1px solid var(--line);
}
#dock button {
  height: 54px;
  flex: 0 1 54px;
  border-radius: 14px;
  color: var(--muted);
  display: grid;
  place-items: center;
}
#dock button svg { width: 25px; height: 25px; }
#dock button.on { color: var(--text); background: var(--panel); }
#dock #btn-stop { color: var(--over); background: var(--panel); }
.dock-gap { flex: 0 1 14px; }

/* ---------- scène : carte + compteur ---------- */
#stage { position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--bg); }

#app[data-view="trajet"] { --cw: 50%; --gw: 68%; }
#app[data-view="cruise"] { --cw: 74%; --gw: 62%; }
#app[data-view="nuit"]   { --cw: 100%; --gw: 54%; }

/* le compteur est posé sur un fond plein qui se fond dans la carte */
#cluster {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--cw);
  display: flex;
  pointer-events: none;
  background: linear-gradient(90deg,
    var(--bg) 0%, var(--bg) 56%,
    rgba(var(--bg-rgb), .86) 68%, rgba(var(--bg-rgb), .55) 80%,
    rgba(var(--bg-rgb), .2) 92%, rgba(var(--bg-rgb), 0) 100%);
  transition: width .35s ease;
}
#app[data-view="nuit"] #cluster { justify-content: center; background: var(--bg); }
#app[data-view="nuit"] #map,
#app[data-view="nuit"] #recenter { display: none; }

/* ---------- compteur ---------- */
/* colonne de gauche : le compteur, et dessous la prochaine manœuvre quand un trajet est lancé */
#column {
  width: var(--gw);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 8px 8px;
  min-height: 0;
  position: relative;
  transition: width .35s ease;
}
#info-clock, #info-weather {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#info-clock { left: 14px; }
#info-weather { right: 6px; }
#info-weather svg { width: 19px; height: 19px; }
#info-road {
  flex: none;
  height: 20px;
  line-height: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#gauge { flex: 1 1 0; min-height: 0; width: 100%; }
.g-track, .g-arc, .g-zone { stroke-width: 11; }
.g-track { stroke: var(--line); }
.g-zone { stroke: var(--over); opacity: .3; }
.g-arc { stroke: var(--ok); transition: stroke .3s; }
.g-mark { stroke: var(--over); stroke-width: 3.5; }
.g-tick { stroke: var(--tick); stroke-width: 1.2; }
.g-tick.major { stroke: var(--muted); stroke-width: 1.8; }
.g-num { fill: var(--muted); stroke: none; font-size: 9px; font-variant-numeric: tabular-nums; }
.g-speed { fill: var(--text); stroke: none; font-size: 60px; font-weight: 600; letter-spacing: -1.5px; font-variant-numeric: tabular-nums; transition: fill .3s; }
.g-unit { fill: var(--muted); stroke: none; font-size: 12px; letter-spacing: .5px; }
.g-sign-bg { fill: #ffffff; stroke: #e0312f; stroke-width: 5.5; }
.g-sign-txt { fill: #1b1b1a; stroke: none; font-size: 17px; font-weight: 700; }
#gauge.warn .g-arc { stroke: var(--warn); }
#gauge.over .g-arc { stroke: var(--over); }
#gauge.over .g-speed { fill: var(--over-text); }
#gauge.over #g-sign { animation: pulse 1s ease-in-out infinite; transform-origin: 100px 172px; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* ---------- pastilles ---------- */
#chips {
  position: absolute;
  right: calc(72px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  max-width: 50%;
  pointer-events: none;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(var(--panel-rgb), .93);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 14px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chip svg { width: 17px; height: 17px; }
#chip-status { color: var(--warn); }

#recenter {
  position: absolute;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(var(--panel-rgb), .93);
  display: grid;
  place-items: center;
}
#recenter svg { width: 26px; height: 26px; }

/* ---------- prochaine manœuvre ---------- */
#nav {
  flex: none;
  background: var(--sign);
  color: var(--sign-text);
  border-radius: 14px;
  padding: 8px 10px;
  max-height: 56px;            /* de loin : seulement la ligne flèche + distance */
  overflow: hidden;
  transition: max-height .35s ease;
}
#nav.near { max-height: 250px; }
#nav-main { display: flex; align-items: center; gap: 10px; height: 40px; }
#nav-arrow { flex: none; width: 36px; height: 36px; }
#nav-arrow svg { width: 100%; height: 100%; stroke-width: 2.6; }
#nav-arrow text { fill: currentColor; stroke: none; font-size: 9px; font-weight: 700; }
#nav-text { min-width: 0; flex: 1; }
#nav-eta { flex: none; text-align: right; line-height: 1.25; }
#nav-eta b { display: block; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
#nav-eta span { font-size: 12px; opacity: .85; }
#nav-dist { font-size: 21px; font-weight: 600; line-height: 1.15; font-variant-numeric: tabular-nums; }
#nav-street { font-size: 13px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav-lanes { display: flex; gap: 4px; margin-top: 8px; }
#nav-lanes:empty { display: none; }
/* hauteur fixe : dans les vues où la colonne est large, le dessin est rogné plutôt qu'agrandi */
#nav-junction { display: block; width: 100%; height: 106px; border-radius: 8px; background: var(--sign-dim); margin-top: 8px; }
.lane { flex: 1; display: grid; place-items: center; background: var(--sign-dim); border-radius: 6px; padding: 2px 0; color: rgba(255, 255, 255, .38); }
.lane svg { width: 24px; height: 24px; stroke-width: 2.6; }
.lane.on { background: #ffffff; color: #0c447c; }
.j-roads { stroke: #ffffff; opacity: .28; }
.j-me { fill: #5dcaa5; stroke: #042c53; stroke-width: 2.5; }
.j-route { stroke: #ffffff; stroke-width: 5; }
.j-head { fill: #ffffff; stroke: none; }

/* ---------- carte ---------- */
.puck { width: 34px; height: 34px; }
.puck svg { width: 100%; height: 100%; stroke: none; display: block; }
.dest { width: 26px; height: 26px; border-radius: 50%; background: #e24b4a; border: 4px solid #ffffff; }

/* ---------- panneaux (recherche, réglages) ---------- */
.sheet {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 14px;
}
.sheet header { display: flex; align-items: center; gap: 10px; flex: none; }
.sheet h2 { flex: 1; margin: 0; font-size: 20px; font-weight: 600; }
.sheet-close { background: var(--panel); border-radius: 12px; padding: 12px 18px; font-size: 15px; }
.sheet-msg { color: var(--muted); font-size: 14px; margin: 14px 4px 0; }

#search-input {
  flex: 1;
  min-width: 0;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  padding: 0 14px;
  outline: none;
  -webkit-appearance: none;
  -webkit-user-select: text;
  user-select: text;
}
#search-results { list-style: none; margin: 8px 0 0; padding: 0 0 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#search-results li { padding: 11px 6px; border-bottom: 1px solid var(--line); }
#search-results b { display: block; font-size: 16px; font-weight: 600; }
#search-results small { color: var(--muted); font-size: 13px; }

.rows { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 16px; }
.seg { display: flex; background: var(--panel); border-radius: 12px; padding: 3px; }
.seg button { padding: 9px 16px; border-radius: 9px; font-size: 15px; color: var(--muted); }
.seg button.on { background: var(--ok); color: #04342c; font-weight: 600; }
:root[data-theme="light"] .seg button.on { color: #ffffff; }
.credits { color: var(--muted); font-size: 12px; margin: 12px 2px 0; max-width: 46em; }

/* ---------- écrans plein cadre ---------- */
#start, #rotate {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--app-h, 100dvh);
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
}
#start img { border-radius: 20px; }
#start-btn {
  background: var(--ok);
  color: #04342c;
  font-size: 20px;
  font-weight: 600;
  padding: 16px 44px;
  border-radius: 16px;
}
#start-msg { margin: 0; color: var(--muted); font-size: 14px; max-width: 30em; }
#start .credits { margin: 0; }

#rotate { display: none; z-index: 20; color: var(--muted); }
#rotate svg { width: 56px; height: 56px; }
#rotate p { margin: 0; font-size: 17px; }
@media (orientation: portrait) and (max-width: 700px) { #rotate { display: flex; } }
