/* ═══════════════════════════════════════════════════════════
   SIMULATEUR TRAIN — STYLES
   Concept : configuration sombre façon « poste de commande »,
   puis cabine plein écran avec un pupitre réaliste en bas.
   ═══════════════════════════════════════════════════════════ */
:root {
  --bg: var(--ui-bg);
  --surface: var(--ui-surface);
  --surface2: var(--ui-surface-2);
  --surface3: var(--ui-surface-3);
  --line: var(--ui-border);
  --text: var(--ui-text);
  --muted: var(--ui-muted);
  --acc: var(--ui-accent);
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --seg: 'Share Tech Mono', ui-monospace, monospace;
  --pup-h: clamp(250px, 37vh, 340px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui-font); }
body { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
kbd { font-family: var(--ui-mono); font-size: .78em; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--surface3); }

/* ══════════ Configuration ══════════ */
#setup { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; background:
  radial-gradient(1200px 500px at 85% -10%, rgba(var(--ui-accent-rgb), .10), transparent 60%),
  repeating-linear-gradient(90deg, transparent 0 79px, rgba(255,255,255,.018) 79px 80px), var(--bg); }
.su-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px; padding: 54px 28px 14px; border-bottom: 1px solid var(--line); }
.su-brand { display: flex; align-items: center; gap: 14px; }
.su-brand svg { width: 44px; height: 44px; color: var(--acc); flex: none; }
.su-brand h1 { margin: 0; font: 700 1.6rem/1 var(--cond); letter-spacing: .02em; text-transform: uppercase; }
.su-brand p { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }
.su-steps { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; counter-reset: s; flex-wrap: wrap; }
.su-steps li { counter-increment: s; display: flex; align-items: center; gap: 8px; padding: 7px 12px 7px 8px; border-radius: 999px; font-size: .82rem; color: var(--muted); cursor: pointer; border: 1px solid transparent; }
.su-steps li::before { content: counter(s); display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface3); font: 600 .75rem var(--ui-mono); }
.su-steps li.on { color: var(--text); border-color: var(--line); background: var(--surface); }
.su-steps li.on::before { background: var(--acc); color: #06210f; }
.su-steps li.done::before { content: '✓'; background: rgba(var(--ui-accent-rgb), .25); color: var(--acc); }
.su-body { overflow: auto; padding: 22px 28px 40px; }
.su-body > * { max-width: 1180px; margin-left: auto; margin-right: auto; }
.su-title { font: 700 1.5rem var(--cond); letter-spacing: .02em; text-transform: uppercase; margin: 6px auto 16px; }
.su-foot { display: flex; align-items: center; gap: 16px; padding: 12px 28px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(15,15,19,.9); }
.su-summary { flex: 1; text-align: center; color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 10px 18px; border-radius: 10px; font-weight: 600; }
.btn:hover { border-color: var(--ui-border-strong); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #06210f; }
.btn.primary:disabled { opacity: .4; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.note { color: var(--muted); font-size: .86rem; line-height: 1.5; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.grid3.small { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--ui-radius); padding: 16px; transition: border-color .15s, transform .15s; position: relative; }
.card:hover { border-color: var(--ui-border-strong); transform: translateY(-1px); }
.card.sel { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc), 0 10px 30px rgba(var(--ui-accent-rgb), .12); }
.card.sel::after { content: '✓'; position: absolute; top: 10px; right: 12px; width: 22px; height: 22px; border-radius: 50%; background: var(--acc); color: #06210f; display: grid; place-items: center; font-weight: 800; font-size: .8rem; }
.card h3 { margin: 6px 0 4px; font: 700 1.2rem var(--cond); letter-spacing: .02em; }
.card p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.card.big { padding: 26px; min-height: 200px; }
.card.big .ico { width: 64px; height: 58px; fill: none; stroke: var(--acc); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.card.big .ico circle { fill: var(--acc); stroke: none; }
.card.big h3 { font-size: 1.6rem; margin-top: 14px; }
canvas.side { width: 100%; height: auto; display: block; background: linear-gradient(#1e2029, #16171d); border-radius: 8px; margin-bottom: 8px; }
.specs { margin-top: 10px; }
.tag { display: inline-block; font-size: .7rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface3); color: var(--muted); margin: 0 4px 6px 0; }
.tag.elec { background: rgba(234, 179, 8, .15); color: #facc15; }
.tag.diesel { background: rgba(249, 115, 22, .15); color: #fb923c; }
.specs dl { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 3px 10px; margin: 4px 0 0; font-size: .78rem; }
.specs dt { color: var(--muted); }
.specs dd { margin: 0; font-family: var(--ui-mono); }
.livery, .panel { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--ui-radius); padding: 16px; }
.livery h4, .panel h4, .compo h4 { margin: 0 0 10px; font: 600 1rem var(--cond); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; background: var(--surface2); border: 1px solid var(--line); border-radius: 99px; font-size: .8rem; }
.sw i { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); }
.sw.sel { border-color: var(--acc); }
.sw.custom i { background: conic-gradient(#f43f5e, #f59e0b, #22c55e, #3b82f6, #a855f7, #f43f5e); }
.sw input[type=color] { width: 26px; height: 22px; border: 0; padding: 0; background: none; cursor: pointer; }
.compo { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--ui-radius); padding: 16px; display: grid; gap: 14px; }
.compo-ctl { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; font-size: .84rem; color: var(--muted); }
.field output { color: var(--text); font: 600 1rem var(--ui-mono); }
.field input[type=range] { accent-color: var(--acc); width: 100%; max-width: 520px; }
.field select, .field input[type=text], .field input[type=number] { background: var(--surface2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font: inherit; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .86rem; margin: 12px 0; }
.check input { accent-color: var(--acc); margin-top: 3px; }
.allopts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.chip { background: var(--surface2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 99px; font-size: .78rem; }
.chip:hover { border-color: var(--acc); }
.preview { overflow-x: auto; background: linear-gradient(#20222b, #15161c); border-radius: 10px; border: 1px solid var(--line); }
.preview canvas { display: block; cursor: pointer; }
.pv-tip { font-size: .78rem; color: var(--muted); }
.infos { display: flex; flex-wrap: wrap; gap: 10px; }
.kpi { background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-width: 110px; }
.kpi b { display: block; font: 600 1.05rem var(--ui-mono); }
.kpi span { font-size: .74rem; color: var(--muted); }
.kpi.wide { flex: 1 1 260px; display: flex; align-items: center; }
.route { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 1fr); gap: 16px; }
.map { background: var(--surface); border: 1px solid var(--line); border-radius: var(--ui-radius); min-height: 480px; height: 62vh; overflow: hidden; }
.map canvas { display: block; cursor: crosshair; }
.route-side { display: grid; gap: 12px; align-content: start; }
.hint { margin: 0; font-size: .84rem; color: var(--acc); }
.stops { display: grid; gap: 4px; max-height: 38vh; overflow: auto; }
.stop { display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 7px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; font-size: .86rem; cursor: pointer; }
.stop input { grid-row: span 2; accent-color: var(--acc); }
.stop .km { font-family: var(--ui-mono); font-size: .78rem; color: var(--muted); }
.stop .q { grid-column: 2 / 4; font-size: .72rem; color: var(--muted); }
.stop.end { border-color: rgba(var(--ui-accent-rgb), .5); }
.stop.end .nm { font-weight: 700; }
dl.sum { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .88rem; }
dl.sum dt { color: var(--muted); }
dl.sum dd { margin: 0; }
.kgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 16px; font-size: .84rem; }
@media (max-width: 760px) {
  .su-head { padding: 52px 16px 12px; }
  .su-body { padding: 16px 16px 30px; }
  .su-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .su-summary { display: none; }
  .route { grid-template-columns: 1fr; }
  .map { height: 52vh; min-height: 320px; }
  .su-steps li { font-size: 0; padding: 4px; gap: 0; }
  .su-steps li.on { font-size: .8rem; padding: 6px 10px 6px 6px; gap: 8px; }
}

/* ══════════ Jeu ══════════ */
#game { position: fixed; inset: 0; background: #9fc3e3; }
#view { position: absolute; inset: 0; }
#view canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#view canvas:active { cursor: grabbing; }
#game.nopup #pupitre { transform: translateY(calc(100% - 10px)); }

/* HUD haut */
#hud { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; justify-content: space-between; gap: 10px; pointer-events: none; font-family: var(--cond); }
.hudbox { pointer-events: auto; background: rgba(12, 13, 17, .78); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; padding: 8px 12px; color: #e8edf3; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.hud-l { display: flex; gap: 14px; align-items: center; }
.clock { font: 400 1.7rem/1 var(--seg); letter-spacing: .03em; }
.clock small { font-size: .55em; color: #9aa6b5; }
.tscale { display: flex; gap: 2px; }
.tscale button { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); border-radius: 6px; padding: 3px 7px; font: 600 .8rem var(--ui-mono); color: #aeb8c6; }
.tscale button.on { background: var(--acc); color: #06210f; border-color: var(--acc); }
.nexts { display: grid; gap: 1px; font-size: .95rem; line-height: 1.15; min-width: 170px; }
.nexts b { font-size: 1.1rem; letter-spacing: .02em; }
.nexts span { color: #9aa6b5; font-size: .85rem; }
.nexts .late { color: #ff8a7a; } .nexts .ok { color: #7ee2a8; }
.hud-r { display: flex; gap: 8px; align-items: stretch; }
.assist { display: flex; gap: 12px; align-items: center; }
.asig { display: flex; align-items: center; gap: 8px; }
.asig .mini { width: 22px; height: 46px; background: #111; border-radius: 4px; border: 2px solid #ddd; display: grid; grid-template-rows: repeat(4, 1fr); padding: 2px; gap: 2px; }
.asig .mini i { border-radius: 50%; background: #2a2a2a; }
.asig .mini i.r { background: #ff3b30; box-shadow: 0 0 6px #ff3b30; } .asig .mini i.y { background: #ffc400; box-shadow: 0 0 6px #ffc400; } .asig .mini i.g { background: #2bd96b; box-shadow: 0 0 6px #2bd96b; }
.asig div { font-size: .9rem; line-height: 1.15; }
.asig b { display: block; font-size: 1.05rem; }
.tiv { width: 44px; height: 44px; border-radius: 6px; background: #f6d33c; color: #111; display: grid; place-items: center; font: 700 1.2rem var(--cond); border: 2px solid #111; outline: 2px solid #f6d33c; }
.tiv.white { background: #f3f3f3; outline-color: #f3f3f3; }
.hudbtn { pointer-events: auto; background: rgba(12,13,17,.78); border: 1px solid rgba(255,255,255,.08); color: #dfe6ee; border-radius: 10px; padding: 0 10px; font: 600 .85rem var(--cond); letter-spacing: .04em; text-transform: uppercase; }
.hudbtn:hover { border-color: var(--acc); }

/* Check-list */
#checklist { position: absolute; left: 10px; top: 76px; width: min(330px, calc(100vw - 20px)); max-height: calc(100% - var(--pup-h) - 96px); overflow: auto; background: rgba(12, 13, 17, .84); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; font-size: .8rem; color: #dfe6ee; transition: opacity .2s; }
#checklist.min .cl-body { display: none; }
#checklist.gone { display: none; }
.cl-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; background: rgba(20,21,27,.96); border-bottom: 1px solid rgba(255,255,255,.07); font: 700 .95rem var(--cond); letter-spacing: .05em; text-transform: uppercase; cursor: pointer; }
.cl-head span { color: var(--acc); font-family: var(--ui-mono); font-size: .78rem; }
.cl-body { padding: 4px 0 8px; }
.cl-ph { padding: 8px 12px 3px; font: 600 .74rem var(--cond); letter-spacing: .08em; text-transform: uppercase; color: #8994a3; }
.cl-it { display: grid; grid-template-columns: 18px 1fr; gap: 8px; padding: 4px 12px; line-height: 1.3; color: #b9c2ce; }
.cl-it i { width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid #4b5563; margin-top: 1px; display: grid; place-items: center; font-style: normal; font-size: .7rem; }
.cl-it.ok { color: #7f8b99; } .cl-it.ok i { background: rgba(var(--ui-accent-rgb), .25); border-color: var(--acc); color: var(--acc); }
.cl-it.ok i::before { content: '✓'; }
.cl-it.cur { color: #fff; background: rgba(var(--ui-accent-rgb), .1); box-shadow: inset 3px 0 var(--acc); }
.cl-it.cur small { display: block; color: #9aa6b5; margin-top: 2px; }
.cl-it.opt { font-style: italic; }
.cl-it small { display: none; }

/* Messages */
#toasts { position: absolute; right: 10px; bottom: calc(var(--pup-h) + 10px); display: grid; gap: 6px; justify-items: end; pointer-events: none; max-width: min(460px, calc(100vw - 20px)); }
.toast { background: rgba(12,13,17,.88); border: 1px solid rgba(255,255,255,.1); border-left: 3px solid #60a5fa; padding: 7px 12px; border-radius: 8px; font-size: .84rem; color: #e8edf3; animation: tin .25s ease; }
.toast.ok { border-left-color: var(--acc); } .toast.warn { border-left-color: #f59e0b; } .toast.bad { border-left-color: #ef4444; background: rgba(60, 12, 12, .9); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }

/* ══════════ Pupitre ══════════ */
#pupitre { position: absolute; left: 0; right: 0; bottom: 0; height: var(--pup-h); transition: transform .3s ease; font-family: var(--cond); color: #d7dbe0; user-select: none; -webkit-user-select: none; touch-action: none; }
.desk { position: absolute; inset: 0; padding: 14px 12px calc(8px + env(safe-area-inset-bottom)); display: flex; gap: 10px; overflow-x: auto; overflow-y: hidden;
  background:
    linear-gradient(180deg, #3c3f44 0, #2b2d31 10px, #232428 40%, #1b1c1f 100%);
  border-top: 2px solid #55595f;
  box-shadow: 0 -12px 30px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.12);
  scrollbar-width: thin; }
.desk::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 8px; background: repeating-linear-gradient(90deg, rgba(255,255,255,.025) 0 2px, transparent 2px 5px); pointer-events: none; }
.pnl { position: relative; flex: none; background: linear-gradient(180deg, #1c1d20, #17181b); border: 1px solid #0d0e10; border-radius: 10px; box-shadow: inset 0 1px 0 rgba(255,255,255,.05), inset 0 0 0 1px rgba(255,255,255,.02), 0 2px 0 rgba(255,255,255,.05); padding: 8px 10px 6px; display: flex; flex-direction: column; }
.pnl::before, .pnl::after { content: ''; position: absolute; top: 5px; width: 5px; height: 5px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #8b8f96, #36383c); }
.pnl::before { left: 5px; } .pnl::after { right: 5px; }
.pnl h5 { margin: 0 0 6px; font: 600 .68rem var(--cond); letter-spacing: .14em; text-transform: uppercase; color: #8d939b; text-align: center; }
.pnl .row { display: flex; gap: 8px; align-items: flex-start; justify-content: center; }
.pnl .grid { display: grid; gap: 8px 6px; justify-items: center; align-items: start; }

/* Cadrans */
.gauge { display: block; }
.gwrap { display: flex; gap: 6px; align-items: center; }

/* Boutons poussoirs */
.pb { display: grid; justify-items: center; gap: 4px; width: 58px; background: none; border: 0; padding: 0; color: #c9ced5; }
.pb .cap { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 40% 30%, #6b6f75, #2a2c30 70%); border: 3px solid #0e0f11; box-shadow: 0 0 0 2px #3a3d42, 0 3px 4px rgba(0,0,0,.6), inset 0 -3px 4px rgba(0,0,0,.4); transition: transform .06s, box-shadow .15s, background .15s; position: relative; }
.pb:active .cap, .pb.pressed .cap { transform: translateY(1px) scale(.96); box-shadow: 0 0 0 2px #3a3d42, 0 1px 1px rgba(0,0,0,.6), inset 0 2px 4px rgba(0,0,0,.6); }
.pb .lbl { font: 600 .66rem/1.05 var(--cond); letter-spacing: .04em; text-transform: uppercase; text-align: center; max-width: 64px; }
.pb.red .cap { background: radial-gradient(circle at 40% 30%, #e46a5c, #8f1d14 70%); }
.pb.green .cap { background: radial-gradient(circle at 40% 30%, #6fd394, #1b6b3a 70%); }
.pb.yellow .cap { background: radial-gradient(circle at 40% 30%, #ffe27a, #a37a0a 70%); }
.pb.blue .cap { background: radial-gradient(circle at 40% 30%, #79a8ef, #1d3f80 70%); }
.pb.white .cap { background: radial-gradient(circle at 40% 30%, #fafafa, #9da3aa 70%); }
.pb.on .cap::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.95), rgba(255,255,255,0) 70%); mix-blend-mode: screen; }
.pb.on.green .cap { box-shadow: 0 0 0 2px #3a3d42, 0 0 14px #4ade80, inset 0 -3px 4px rgba(0,0,0,.2); }
.pb.on.yellow .cap { box-shadow: 0 0 0 2px #3a3d42, 0 0 14px #facc15; }
.pb.on.red .cap { box-shadow: 0 0 0 2px #3a3d42, 0 0 14px #f87171; }
.pb.on.white .cap { box-shadow: 0 0 0 2px #3a3d42, 0 0 14px #fff; }
.pb.on.blue .cap { box-shadow: 0 0 0 2px #3a3d42, 0 0 14px #60a5fa; }
.pb.big .cap { width: 48px; height: 48px; }
.pb.mush .cap { width: 50px; height: 50px; background: radial-gradient(circle at 40% 30%, #ff6b5a, #9b1309 70%); border-color: #f2c12e; border-width: 4px; }
.pb.hint .cap, .tg.hint .sw, .rot.hint .knob, .lever.hint, .key.hint .kslot { animation: hint 1.1s ease-in-out infinite; }
@keyframes hint { 50% { box-shadow: 0 0 0 3px var(--acc), 0 0 18px var(--acc); } }

/* Interrupteurs à levier */
.tg { display: grid; justify-items: center; gap: 4px; width: 58px; background: none; border: 0; padding: 0; color: #c9ced5; }
.tg .sw { width: 26px; height: 40px; border-radius: 6px; background: linear-gradient(#111, #26282c); border: 1px solid #000; box-shadow: 0 0 0 2px #3a3d42; position: relative; }
.tg .sw::after { content: ''; position: absolute; left: 6px; right: 6px; height: 20px; top: 16px; border-radius: 4px; background: linear-gradient(90deg, #8b9097, #e6e8eb, #8b9097); box-shadow: 0 3px 3px rgba(0,0,0,.6); transition: top .12s; }
.tg.on .sw::after { top: 3px; }
.tg .lbl { font: 600 .66rem/1.05 var(--cond); text-transform: uppercase; letter-spacing: .04em; text-align: center; }
.tg .st { font: .62rem var(--ui-mono); color: #7d848d; }
.tg.on .st { color: #4ade80; }

/* Commutateurs rotatifs */
.rot { display: grid; justify-items: center; gap: 3px; width: 70px; background: none; border: 0; padding: 0; color: #c9ced5; }
.rot .dial { position: relative; width: 50px; height: 50px; }
.rot .knob { position: absolute; inset: 7px; border-radius: 50%; background: radial-gradient(circle at 40% 30%, #555a61, #1c1d20 75%); border: 2px solid #0b0c0e; box-shadow: 0 2px 4px rgba(0,0,0,.6); transition: transform .15s; }
.rot .knob::after { content: ''; position: absolute; left: 50%; top: 2px; width: 5px; height: 15px; margin-left: -2.5px; border-radius: 2px; background: #f2f2f2; }
.rot .pos { position: absolute; font: 600 .56rem var(--ui-mono); color: #8d939b; }
.rot .pos.on { color: #facc15; }
.rot .lbl { font: 600 .66rem var(--cond); text-transform: uppercase; letter-spacing: .04em; }

/* Clé */
.key { display: grid; justify-items: center; gap: 4px; width: 62px; background: none; border: 0; padding: 0; color: #c9ced5; }
.key .kslot { width: 44px; height: 44px; border-radius: 50%; background: radial-gradient(circle, #b9a46a, #6e5d2c 70%); border: 3px solid #1b1c1f; box-shadow: 0 0 0 2px #3a3d42; position: relative; }
.key .kslot::after { content: ''; position: absolute; left: 50%; top: 50%; width: 8px; height: 28px; margin: -14px 0 0 -4px; background: linear-gradient(90deg, #555, #ddd, #555); border-radius: 3px; transition: transform .2s; }
.key.on .kslot::after { transform: rotate(90deg); }
.key .lbl { font: 600 .66rem var(--cond); text-transform: uppercase; }

/* Voyants */
.lamps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.lamp { width: 52px; height: 22px; border-radius: 4px; background: #1a1210; border: 1px solid #000; box-shadow: inset 0 1px 3px rgba(0,0,0,.8); display: grid; place-items: center; font: 700 .64rem var(--cond); letter-spacing: .04em; color: #4a3d36; text-transform: uppercase; }
.lamp.on.r { background: #ff4a3a; color: #3a0500; box-shadow: 0 0 10px #ff4a3a; }
.lamp.on.y { background: #ffc531; color: #3d2a00; box-shadow: 0 0 10px #ffc531; }
.lamp.on.g { background: #3ddc7a; color: #032b12; box-shadow: 0 0 10px #3ddc7a; }
.lamp.on.b { background: #5aa2ff; color: #021432; box-shadow: 0 0 10px #5aa2ff; }
.lamp.on.w { background: #f4f4f4; color: #222; box-shadow: 0 0 10px #fff; }
.lamp.blink.on { animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { filter: brightness(.35); box-shadow: none; } }

/* Écrans */
.scr { background: #050806; border: 2px solid #000; border-radius: 6px; box-shadow: inset 0 0 18px rgba(0,0,0,.9), 0 0 0 2px #2e3136; font-family: var(--seg); color: #9ef7b6; padding: 6px 8px; position: relative; overflow: hidden; }
.scr::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 1px, transparent 1px 3px); pointer-events: none; }
.kvb { display: flex; gap: 8px; align-items: center; justify-content: center; }
.kvb .seg { font: 400 1.6rem/1 var(--seg); color: #ffb21f; text-shadow: 0 0 8px rgba(255,178,31,.6); min-width: 64px; text-align: center; background: #120a00; padding: 3px 6px; border-radius: 4px; }
.kvb .seg.g { color: #36e070; text-shadow: 0 0 8px rgba(54,224,112,.6); background: #001208; }
.tvm { display: grid; place-items: center; width: 92px; height: 54px; font: 400 2rem/1 var(--seg); background: #000; color: #fff; border-radius: 4px; border: 2px solid #333; }
.tvm.c000 { background: #d01c1c; } .tvm.cwarn { background: #f2f2f2; color: #000; } .tvm.off { color: #333; }
.dmi { font-size: .78rem; line-height: 1.35; width: 230px; height: 112px; display: flex; flex-direction: column; justify-content: flex-end; }
.dmi p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dmi p.warn { color: #ffcf5a; } .dmi p.bad { color: #ff6b5e; } .dmi p.dim { color: #4e8a60; }

/* Manettes */
.lever { position: relative; width: 74px; height: calc(var(--pup-h) - 64px); min-height: 170px; touch-action: none; cursor: ns-resize; border-radius: 10px; }
.lever .slot { position: absolute; left: 50%; top: 10px; bottom: 10px; width: 12px; margin-left: -6px; border-radius: 6px; background: #050506; box-shadow: inset 0 2px 4px rgba(0,0,0,.9), 0 0 0 1px #3a3d42; }
.lever .notch { position: absolute; right: 0; left: 50%; margin-left: 10px; font: 600 .56rem var(--ui-mono); color: #7d848d; transform: translateY(-50%); white-space: nowrap; }
.lever .notch::before { content: ''; display: inline-block; width: 6px; height: 1px; background: #5a5f66; vertical-align: middle; margin-right: 3px; }
.lever .notch.on { color: #facc15; }
.lever .handle { position: absolute; left: 6px; width: 34px; height: 30px; transform: translateY(-50%); border-radius: 8px; background: linear-gradient(90deg, #2a2c30, #6d7178 45%, #2a2c30); border: 1px solid #000; box-shadow: 0 4px 6px rgba(0,0,0,.7); transition: top .08s; }
.lever .handle::after { content: ''; position: absolute; left: -6px; right: -6px; top: 9px; height: 12px; border-radius: 6px; background: linear-gradient(#4d5056, #111); }
.lever.brake .handle::after { background: linear-gradient(#c93a2b, #5e120a); }
.lever.trac .handle::after { background: linear-gradient(#e2e4e7, #6b7078); }
.lever-wrap { display: flex; flex-direction: column; align-items: center; }
.lever-wrap .lbl { font: 600 .66rem var(--cond); letter-spacing: .08em; text-transform: uppercase; color: #8d939b; margin-top: 2px; }
.lever-wrap .val { font: .7rem var(--ui-mono); color: #facc15; }

/* Pupitre : mode compact */
@media (max-width: 900px), (max-height: 600px) {
  :root { --pup-h: clamp(220px, 42vh, 300px); }
  #checklist { top: 70px; width: min(270px, calc(100vw - 20px)); font-size: .74rem; }
  .nexts { min-width: 0; }
  .hud-l .nexts span { display: none; }
}

/* ══════════ Modales ══════════ */
#modal { position: fixed; inset: 0; z-index: 9500; display: grid; place-items: center; background: rgba(5,6,8,.6); backdrop-filter: blur(4px); padding: 16px; }
.md-box { width: min(620px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--ui-radius); padding: 20px; box-shadow: var(--ui-shadow); }
.md-box h3 { margin: 0 0 4px; font: 700 1.4rem var(--cond); text-transform: uppercase; letter-spacing: .03em; }
.md-box .sub { margin: 0 0 14px; color: var(--muted); font-size: .86rem; }
.md-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.md-box .err { color: #f87171; font-size: .84rem; min-height: 1.2em; }
.vis-list { display: grid; gap: 6px; }
.vis-it { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 9px 12px; background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; font-size: .88rem; }
.vis-it small { display: block; color: var(--muted); font-size: .76rem; }
.vis-it .st { font: 600 .78rem var(--ui-mono); }
.vis-it.ok { border-color: rgba(var(--ui-accent-rgb), .5); }
.vis-it.ok .st { color: var(--acc); }
.vis-it.fault { border-color: #f59e0b; }
.vis-it.fault .st { color: #f59e0b; }
.vis-it button { padding: 6px 12px; border-radius: 8px; background: var(--surface3); border: 1px solid var(--line); font-size: .8rem; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.seg-radio { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-radio label { padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface2); font-size: .84rem; cursor: pointer; }
.seg-radio input { display: none; }
.seg-radio label:has(input:checked) { border-color: var(--acc); color: var(--acc); }
.doc { font-size: .86rem; }
.doc table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: .82rem; }
.doc th, .doc td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.doc th { color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.doc td.m { font-family: var(--ui-mono); }
.doc tr.past td { color: var(--muted); }
.doc tr.next td { color: var(--acc); }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { background: var(--surface2); border: 1px solid var(--line); padding: 6px 12px; border-radius: 8px; font-size: .82rem; }
.tabs button.on { border-color: var(--acc); color: var(--acc); }
.report .big { font: 700 3rem/1 var(--cond); color: var(--acc); }
.report ul { padding-left: 18px; max-height: 240px; overflow: auto; font-size: .84rem; }
.report li.neg { color: #f87171; } .report li.pos { color: #4ade80; }

/* Chargement */
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.ld-box { text-align: center; color: var(--muted); }
.ld-bar { width: 240px; height: 4px; border-radius: 4px; background: var(--surface3); overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 40%; background: var(--acc); animation: ld 1s ease-in-out infinite alternate; }
@keyframes ld { to { transform: translateX(150%); } }
@media (max-width: 640px) {
  #hud { top: 54px; flex-wrap: wrap; }
  #checklist { top: 150px; }
  .clock { font-size: 1.3rem; }
}

.toast .fix { display: block; margin-top: 4px; color: #b9f5cf; font-size: .8rem; line-height: 1.35; }
.toast.warn .fix { color: #ffe3a3; }
.dmi p.warn, .dmi p.bad { white-space: normal; }
