:root {
  --accent: #ff5a1f;
  --accent-2: #ffb020;
  --bg: rgba(14, 17, 23, 0.78);
  --bg-solid: #10141b;
  --panel: rgba(20, 24, 33, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --ok: #22c55e;
  --warn: #eab308;
  --bad: #ef4444;
  --hr: #ff4d6d;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg-solid); color: var(--text); }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input[type=range] { padding: 0; accent-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
[hidden] { display: none !important; }

.btn { background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-radius: 10px; padding: 9px 16px; font-weight: 600; transition: background .15s, transform .05s; }
.btn:hover { background: rgba(255,255,255,0.15); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff7140; }
.btn.danger { background: rgba(239,68,68,0.85); border-color: transparent; }
.btn.big { padding: 14px 34px; font-size: 18px; border-radius: 12px; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon { width: 42px; height: 42px; padding: 0; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.pill { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 99px; background: rgba(255,255,255,0.12); font-size: 12px; }
.pill.on { background: var(--ok); color: #04210f; }

/* ---------- Accueil ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
#home { background: linear-gradient(90deg, rgba(10,12,16,0.92) 0%, rgba(10,12,16,0.75) 55%, rgba(10,12,16,0.2) 100%); justify-content: flex-start; align-items: flex-start; padding-top: 6vh; }
.home-panel { width: min(760px, 100%); max-height: calc(94vh - 24px); overflow: auto; padding: 8px 8px 8px 24px; }
.brand { margin-bottom: 18px; }
.logo { font-size: 42px; font-weight: 900; letter-spacing: 2px; font-style: italic; }
.logo span { color: var(--accent); }
.tagline { color: var(--muted); }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tab { background: none; border: none; padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { display: none; }
.tabpane.active { display: block; }
h3 { margin: 22px 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.mode small { color: var(--muted); }
.mode.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card .t { font-weight: 700; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .desc { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.card canvas { width: 100%; height: 46px; display: block; }
.card[data-route] { cursor: pointer; }
.card .cat [data-delroute] { cursor: pointer; float: right; padding: 0 4px; }
.card .endmode { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.card .endmode button { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 2px 8px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.card .endmode button.on { border-color: var(--accent); color: var(--accent); }
.card .cat { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--accent-2); }
.import { font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--accent); cursor: pointer; border: 1px dashed var(--accent); border-radius: 8px; padding: 4px 10px; }
.start-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 26px 0 10px; }
.hint { color: var(--muted); font-size: 13.5px; }
.hint b { color: var(--text); }
.warning { background: rgba(234,179,8,0.12); border: 1px solid rgba(234,179,8,0.5); color: #fde68a; padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.note { color: var(--muted); font-size: 12.5px; line-height: 1.45; }

.devices { display: grid; gap: 8px; }
.device { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.device .ico { font-size: 22px; text-align: center; }
.device .n { font-weight: 650; }
.device .s { color: var(--muted); font-size: 12.5px; }
.device .s.on { color: var(--ok); }
.device .acts { display: flex; gap: 6px; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; background: var(--panel); display: grid; gap: 10px; }
legend { padding: 0 6px; color: var(--accent-2); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .8px; }
fieldset label { display: grid; gap: 5px; font-size: 13.5px; color: var(--muted); }
fieldset label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
fieldset output { color: var(--text); font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.history { display: grid; gap: 8px; }
.hist { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.hist .t { font-weight: 650; }
.hist .m { color: var(--muted); font-size: 13px; }
.hist .acts { display: flex; gap: 6px; }
.empty { color: var(--muted); padding: 20px 0; }

/* ---------- HUD ---------- */
/* grand écran : --ui (app.js, applyUiScale) agrandit les blocs du HUD et les fenêtres, sans toucher au monde 3D */
.hud-top, .hud-left, .hud-right, .hud-bottom, .hud-actions, #hud .banner, #hud .toast, #hud .help, .modal-box { zoom: var(--ui, 1); }
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud .btn, #hud canvas, #hud button { pointer-events: auto; }
.hud-top { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px; backdrop-filter: blur(8px); }
.metric { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; align-items: baseline; column-gap: 3px; padding: 2px 12px; min-width: 78px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: none; }
.metric .v { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; }
.metric .u { font-size: 12px; color: var(--muted); }
.metric .l { grid-column: 1 / 3; font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.metric.big .v { font-size: 44px; color: var(--accent); line-height: 1; }
.metric.big { min-width: 120px; }
.metric.hr .v { color: var(--hr); }

.hud-left { position: absolute; left: 18px; top: 120px; display: grid; gap: 10px; width: 132px; }
.grade-badge, .gear-box, .zone-box, .draft-box { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; text-align: center; backdrop-filter: blur(8px); }
.grade-badge { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.grade-badge small { font-size: 16px; color: var(--muted); }
.grade-badge.up { color: #fca5a5; }
.grade-badge.steep { color: #f87171; }
.grade-badge.down { color: #86efac; }
.gear-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.gear-num { font-size: 40px; font-weight: 850; line-height: 1.1; }
.gear-bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.1); overflow: hidden; }
.gear-bar div { height: 100%; background: var(--accent); width: 50%; transition: width .15s; }
.gear-box.flash { animation: flash .35s; }
@keyframes flash { 0% { background: rgba(255,90,31,0.6); } 100% { background: var(--bg); } }
.zone-box span { font-size: 24px; font-weight: 800; display: block; }
.zone-box small { color: var(--muted); }
.draft-box { font-weight: 750; color: #7dd3fc; }
/* pente, zone et aspiration regroupées dans une seule carte */
.status-card { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; text-align: center; backdrop-filter: blur(8px); }
.status-card > .grade-badge, .status-card > .zone-box, .status-card > .draft-box { background: none; border: 0; border-radius: 0; padding: 0; backdrop-filter: none; }
.status-card > :not(:first-child):not([hidden]) { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.draft-box small { display: block; font-weight: 500; color: var(--muted); }
.sensor-dots { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; pointer-events: auto; cursor: pointer; }
.sensor-dots span { font-size: 11px; padding: 3px 7px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.sensor-dots span.on { color: var(--ok); border-color: rgba(34,197,94,0.5); }

.hud-right { position: absolute; right: 18px; top: 120px; width: 440px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; backdrop-filter: blur(8px); }
.wk-title { font-weight: 700; font-size: 14px; margin-bottom: 8px; color: var(--muted); }
.wk-current { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wk-current div { display: flex; flex-direction: column; }
.wk-current .l { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.wk-current .v { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.wk-current .u { font-size: 12px; color: var(--muted); }
.wk-label { margin-top: 4px; font-weight: 650; }
.wk-next { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.hud-right canvas { width: 100%; height: 120px; display: block; }
#powerChart { height: 270px; }
.wk-controls { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.wk-controls span { min-width: 48px; text-align: center; font-weight: 700; }
.wk-controls #skipSeg { margin-left: auto; }
#wkChart { height: 250px; }
.erg-toggle { min-width: 64px; font-weight: 800; }
.erg-toggle.on { background: #ff5a1f; border-color: #ff5a1f; color: #fff; }
.wk-delta { font-size: 12px; font-weight: 700; margin-top: 2px; }
.wk-delta.ok { color: #86efac; }
.wk-delta.over { color: #fca5a5; }
.wk-delta.under { color: #7dd3fc; }
.free-stats { display: grid; grid-template-columns: repeat(5, 1fr); margin-top: 8px; font-weight: 700; }
.free-stats .l { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 500; }

.hud-bottom { position: absolute; left: 18px; right: 18px; bottom: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 8px 12px 6px; backdrop-filter: blur(8px); }
.hud-bottom canvas { width: 100%; height: 90px; display: block; }
.route-name { position: absolute; top: 8px; right: 16px; font-size: 12px; color: var(--muted); font-weight: 600; pointer-events: none; }
.hud-actions { position: absolute; right: 18px; bottom: 132px; display: flex; gap: 8px; }
.hud-actions .btn { background: var(--bg); backdrop-filter: blur(8px); }
.hud-actions .btn.danger { background: rgba(239,68,68,0.85); }

.banner { position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%); font-size: 46px; font-weight: 900; letter-spacing: 6px; background: var(--bg); padding: 14px 34px; border-radius: 16px; border: 1px solid var(--line); }
.banner.wait { font-size: 34px; letter-spacing: 2px; text-align: center; }
.banner small { display: block; font-size: 14px; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-top: 4px; }
.toast { position: absolute; top: 108px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--accent); padding: 10px 18px; border-radius: 12px; font-weight: 600; max-width: 80vw; text-align: center; }
.help { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 24px; pointer-events: auto; }
.help h4 { margin: 0 0 8px; }
.help ul { margin: 0; padding-left: 18px; line-height: 1.9; }
kbd { background: rgba(255,255,255,0.12); border-radius: 5px; padding: 1px 6px; font-family: inherit; font-size: 12px; border: 1px solid var(--line); }

/* ---------- Modales ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.modal-box { background: var(--bg-solid); border: 1px solid var(--line); border-radius: 18px; padding: 18px 22px 20px; width: min(560px, 100%); max-height: calc(90vh / var(--ui, 1)); overflow: auto; }
.modal-box.wide { width: min(760px, 100%); }
.modal-box h3 { margin-top: 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 20px; }
.close { background: none; border: none; font-size: 26px; color: var(--muted); line-height: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.sum-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sum-grid div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.sum-grid .l { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }
.sum-grid .v { font-size: 22px; font-weight: 800; }
#summaryBody canvas { width: 100%; height: 140px; margin-top: 12px; display: block; }

.loading { background: rgba(10,12,16,0.85); flex-direction: column; gap: 14px; z-index: 20; color: var(--muted); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .hud-right { width: 320px; }
  .metric { min-width: 64px; padding: 2px 8px; }
  .metric .v { font-size: 20px; }
  .metric.big .v { font-size: 34px; }
}
@media (max-width: 760px) {
  #home { background: rgba(10,12,16,0.9); }
  .home-panel { padding: 0; }
  .mode-switch { grid-template-columns: 1fr; }
  .hud-top { flex-wrap: wrap; justify-content: center; width: calc(100vw - 24px); }
  .hud-right, .hud-left { display: none; }
  .sum-grid { grid-template-columns: repeat(2, 1fr); }
}

#shareWrap { margin-top: 14px; text-align: center; }
#shareWrap .share-title { display: flex; align-items: center; gap: 10px; max-width: 520px; margin: 0 auto 10px; color: var(--muted); font-size: 13px; white-space: nowrap; }
#shareWrap .share-opts { display: flex; justify-content: center; align-items: center; gap: 16px; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
#shareWrap .share-opts label { display: flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; }
#shareWrap img { max-width: 100%; max-height: 52vh; border-radius: 12px; border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0,0,0,.4); }
