/* Revv - interface pensee pour l'ecran d'une voiture :
   contraste fort, cibles tactiles larges, aucun element sous 44 px. */

:root {
  --bg: #0b0c0e;
  --panel: #16181c;
  --panel-2: #1e2126;
  --line: #2b2f36;
  --text: #f2f4f7;
  --muted: #8d949e;
  --accent: #ff7a33;
  --accent-2: #ffb648;
  --ok: #4ec97f;
  --bad: #ff5f5f;
  --r: 14px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Un selecteur de classe portant display: bat l'attribut [hidden] de la
   feuille navigateur. Sans ce garde, .panel et .pedals restent visibles. */
[hidden] { display: none !important; }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Barre superieure ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: baseline; gap: 16px; min-width: 0; }

.logo {
  font-weight: 800;
  letter-spacing: 0.16em;
  font-size: 20px;
  background: linear-gradient(92deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.status {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  background: var(--muted);
  vertical-align: middle;
}
.status.ok { color: var(--ok); }
.status.ok::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status.wait::before { background: var(--accent-2); animation: pulse 1.4s ease-in-out infinite; }
.status.bad { color: var(--bad); }
.status.bad::before { background: var(--bad); }

@keyframes pulse { 50% { opacity: 0.25; } }

.bar-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 20px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.icon:active { background: var(--panel-2); }

/* ---------- Scene ---------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  padding: 20px;
}

.dial-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

#tacho {
  width: 100%;
  height: 100%;
  max-width: min(100%, 62vh);
  max-height: 100%;
  aspect-ratio: 1;
}

.speed-box {
  position: absolute;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}
.speed-box b {
  display: block;
  font-size: clamp(38px, 7vh, 68px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.speed-box small { color: var(--muted); font-size: 14px; letter-spacing: 0.1em; }

/* ---------- Colonne laterale ---------- */

/* La colonne se decoupe en deux : une zone qui defile, et un pied fixe.
   Le bouton principal ne doit jamais recouvrir un reglage : sur un ecran de
   voiture, un controle masque est un controle inutilisable. */
.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.side-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 13px;
}
.stat span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }
.stat b { display: block; font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat b i { font-style: normal; color: var(--muted); font-size: 17px; }
.stat small { color: var(--muted); font-size: 11px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; }
.field label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }

select {
  appearance: none;
  background: var(--panel) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%238d949e' stroke-width='2' fill='none' stroke-linecap='round'/></svg>") no-repeat right 14px center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 40px 11px 14px;
  width: 100%;
}
select:disabled { opacity: 0.5; }

.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 9px;
  font-weight: 600;
  min-height: 42px;
}
.seg button.on { background: var(--accent); color: #14100c; }

.paddles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.paddles button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 8px;
  font-weight: 600;
}
.paddles button:active { background: var(--accent); color: #14100c; }

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 34px;
  background: transparent;
}
input[type=range]::-webkit-slider-runnable-track { height: 8px; background: var(--panel-2); border-radius: 4px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 30px; height: 30px;
  margin-top: -11px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #14100c;
}
input[type=range]::-moz-range-track { height: 8px; background: var(--panel-2); border-radius: 4px; }
input[type=range]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); border: 3px solid #14100c; }

.primary {
  background: linear-gradient(92deg, var(--accent-2), var(--accent));
  color: #14100c;
  border: 0;
  border-radius: 12px;
  padding: 15px 20px;
  font-weight: 700;
  font-size: 16px;
}
.primary:disabled { opacity: 0.4; }
.primary.big { padding: 17px; font-size: 19px; flex: 0 0 auto; }
body.running .primary.big { background: var(--panel); color: var(--text); border: 1px solid var(--line); }

.empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
}
.empty h2 { margin: 0 0 6px; font-size: 18px; }
.empty p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.empty button { width: 100%; }

/* ---------- Pedales du mode demo ---------- */

.pedals {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  padding: 0 20px 16px;
  flex: 0 0 auto;
}
.pedal {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  padding: 20px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.04em;
  touch-action: none;
  user-select: none;
  transition: background 0.06s, transform 0.06s;
}
.pedal.gas.down { background: var(--accent); color: #14100c; transform: scale(0.985); }
.pedal.brake.down { background: var(--bad); color: #1a0c0c; transform: scale(0.985); }

/* ---------- Panneau des packs ---------- */

.panel {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 8, 0.72);
  backdrop-filter: blur(6px);
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
}
.panel-inner {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 18px;
  width: min(880px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.panel-head h2 { margin: 0; font-size: 19px; }
.panel-body { padding: 20px; overflow-y: auto; }
.panel-body h3 { font-size: 15px; margin: 24px 0 10px; }
.lead { color: var(--muted); font-size: 14px; margin: 0 0 16px; }

.drop {
  border: 2px dashed var(--line);
  border-radius: var(--r);
  padding: 28px 20px;
  text-align: center;
  display: grid;
  gap: 6px;
  background: var(--panel);
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--panel-2); }
.drop strong { font-size: 16px; }
.drop span { font-size: 13px; color: var(--muted); }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

.pm-meta { display: flex; gap: 14px; margin: 18px 0 12px; flex-wrap: wrap; }
.pm-meta label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.pm-meta input, .pm-meta select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: 15px;
}
.pm-meta label:first-child { flex: 1 1 240px; }

.pm-rows { display: flex; flex-direction: column; gap: 7px; }
.pm-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 60px 106px 56px 138px 42px;
  gap: 7px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 7px 9px;
}
.pm-row.bad { border-color: var(--bad); }
.pm-row button, .pm-row input, .pm-row select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 6px;
  color: var(--text);
  min-height: 40px;
  font-size: 14px;
}
.pm-fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.pm-dur { font-size: 12px; color: var(--muted); text-align: right; }
.pm-rpm { text-align: center; font-variant-numeric: tabular-nums; }
.pm-guess { font-size: 12px; color: var(--muted); }
.pm-del { color: var(--bad); font-size: 20px; line-height: 1; }
.pm-play { color: var(--accent); }

.hint { font-size: 13px; color: var(--accent-2); min-height: 20px; margin: 12px 0 0; }
.pm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.pm-actions button { background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 13px 20px; }
.pm-actions .primary { border: 0; }

.pm-list { display: flex; flex-direction: column; gap: 8px; }
.pm-saved {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 14px;
}
.pm-saved .muted { font-size: 13px; margin-left: 10px; }
.pm-rm { background: transparent; border: 1px solid var(--line); border-radius: 9px; padding: 9px 14px; color: var(--bad); }

.guide { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.guide summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.guide ol { color: var(--muted); font-size: 14px; line-height: 1.6; padding-left: 20px; }
.guide li { margin-bottom: 7px; }

/* ---------- Adaptations ---------- */

/* Ecrans etroits ou portrait : la colonne passe sous le cadran. */
@media (max-width: 900px), (orientation: portrait) {
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(220px, 1fr) auto; overflow-y: auto; }
  .side-scroll { overflow: visible; min-height: auto; }
  #tacho { max-width: min(100%, 46vh); }
  .pm-row { grid-template-columns: 40px 1fr 92px 40px; grid-template-areas: "play name rpm del" "bus bus guess guess"; }
  .pm-row .pm-play { grid-area: play; }
  .pm-row .pm-fname { grid-area: name; }
  .pm-row .pm-dur { display: none; }
  .pm-row .pm-rpm { grid-area: rpm; }
  .pm-row .pm-guess { grid-area: guess; }
  .pm-row .pm-bus { grid-area: bus; }
  .pm-row .pm-del { grid-area: del; }
}

/* Ecran Tesla en paysage : on gagne de la place en hauteur. */
@media (min-height: 700px) and (min-width: 1100px) {
  .stage { gap: 32px; padding: 24px 28px; }
  .side { gap: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Onglets d'import de pack ---------- */

.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: -1px;
}
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }

.sw-head { display: flex; gap: 12px; margin: 16px 0 12px; flex-wrap: wrap; }
.sw-head label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sw-head select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  min-width: 104px;
}

/* Courbe de regime detectee sur la montee */
.sw-curve {
  width: 100%;
  height: 190px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  display: block;
}

/* ---------- Panneau de reglages ---------- */

.panel-head-actions { display: flex; gap: 8px; align-items: center; }
.panel-head-actions > button:not(.icon) {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
}

.tn-group { margin-bottom: 26px; }
.tn-group h3 { font-size: 14px; margin: 0 0 4px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; }
.tn-group > p { margin: 0 0 12px; }

.tn-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px 82px;
  gap: 14px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.tn-row:last-child { border-bottom: 0; }
.tn-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tn-label span { font-size: 14px; }
.tn-label small { font-size: 11px; color: var(--muted); line-height: 1.35; }
.tn-val { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--accent-2); text-align: right; }
.tn-range { width: 100%; height: 30px; }

.tn-toggle {
  grid-column: 2 / 4;
  justify-self: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 22px;
  color: var(--muted);
  font-weight: 600;
  min-width: 84px;
}
.tn-toggle.on { background: var(--accent); color: #14100c; border-color: transparent; }

.tn-foot { padding: 12px 20px; border-top: 1px solid var(--line); margin: 0; flex: 0 0 auto; }

@media (max-width: 720px) {
  .tn-row { grid-template-columns: 1fr 70px; grid-template-areas: "label val" "range range"; }
  .tn-label { grid-area: label; }
  .tn-val { grid-area: val; }
  .tn-range { grid-area: range; }
  .tn-toggle { grid-column: auto; grid-area: val; min-width: 0; padding: 8px 12px; }
}

/* Attribution du pack courant. Obligatoire pour les licences CC BY / CC BY-SA. */
.credit { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
.credit a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.credit a:hover { color: var(--accent); }
