:root {
  --ink: #f4f1e8;
  --panel: rgba(12, 18, 24, 0.62);
  --accent: #ffb547;
  --warn: #ff5a4e;
  --ok: #7be0a5;
}
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1016; color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; }
#globe { position: absolute; inset: 0; }
.cesium-viewer-bottom { opacity: .75; }

#hud { position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 8px 10px; background: var(--panel); border-radius: 10px;
  backdrop-filter: blur(4px); pointer-events: none; flex-wrap: wrap; justify-content: center;
  max-width: calc(100vw - 32px); box-sizing: border-box; }
#hud .cell { display: flex; flex-direction: column; align-items: center; min-width: 62px; }
#hud .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
#hud .val { font-size: 22px; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }
#hud .unit { font-size: 10px; opacity: .6; }

#horizon { position: absolute; right: 16px; bottom: 70px; width: 110px; height: 110px; border-radius: 50%;
  overflow: hidden; border: 2px solid rgba(255,255,255,.5); background: #7a5230; pointer-events: none; }
#hz-sky { position: absolute; left: -50%; width: 200%; height: 200%; top: -150%; background: #3d8fd6;
  border-bottom: 2px solid #fff; transform-origin: 50% 100%; }
#hz-mark { position: absolute; left: 25%; right: 25%; top: 50%; height: 3px; margin-top: -1px; background: var(--accent); }
#hz-mark::after { content: ""; position: absolute; left: 50%; top: -4px; width: 6px; height: 6px; margin-left: -3px;
  background: var(--accent); border-radius: 50%; }

#where { position: absolute; left: 16px; bottom: 70px; padding: 6px 10px; background: var(--panel);
  border-radius: 8px; font-size: 13px; pointer-events: none; }
#alert { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); padding: 8px 16px;
  border-radius: 8px; font-weight: 700; letter-spacing: .05em; display: none; text-align: center; }
#alert.warn { display: block; background: rgba(255, 90, 78, .85); }
#alert.info { display: block; background: rgba(20, 30, 40, .85); color: var(--ok); }

#spawns { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; gap: 4px; }
#spawns button, #help-go { background: var(--panel); color: var(--ink); border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px; padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer; text-align: left; }
#spawns button:hover { border-color: var(--accent); }

#help { position: absolute; inset: 0; z-index: 10; margin: auto; width: min(460px, calc(100vw - 32px)); height: fit-content;
  max-height: calc(100vh - 32px); overflow: auto; box-sizing: border-box;
  background: rgba(12, 18, 24, .92); border-radius: 12px; padding: 18px 22px; display: none; }
#help.open { display: block; }
#help h1 { margin: 0 0 6px; font-size: 22px; color: var(--accent); }
#help table { border-collapse: collapse; width: 100%; font-size: 14px; }
#help td { padding: 3px 6px; border-bottom: 1px solid rgba(255,255,255,.08); }
#help td:first-child { white-space: nowrap; color: var(--accent); font-weight: 600; }
#help .small { font-size: 12px; opacity: .7; }
#help-go { margin-top: 8px; background: var(--accent); color: #111; font-weight: 700; text-align: center; width: 100%; }

@media (max-width: 700px) {
  #spawns { top: auto; bottom: 190px; }
  #hud .cell { min-width: 48px; }
  #hud .val { font-size: 17px; }
}

/* ---------- Mobile ---------- */
#touch, #menu-btn, #rotate, #help .tactile { display: none; }
body.mobile #help .keys, body.mobile #help .small:not(#cache-info):not(.credits) { display: none; }
body.mobile #help .tactile { display: table; }
body.mobile #help { padding: 14px 16px; }
body.mobile #help h1 { font-size: 19px; }
body.mobile #help p { font-size: 13px; margin: 4px 0 8px; }
body.mobile #help td { font-size: 13px; }

body.mobile { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.mobile #touch { display: block; }
#joy { position: absolute; left: calc(18px + env(safe-area-inset-left)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 136px; height: 136px; border-radius: 50%; background: rgba(12, 18, 24, .35);
  border: 2px solid rgba(255,255,255,.35); touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: rgba(255, 181, 71, .85); box-shadow: 0 2px 8px rgba(0,0,0,.4); pointer-events: none; }
body.tilt #joy { opacity: .25; pointer-events: none; }
#thr { position: absolute; right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 150px; border-radius: 12px; background: rgba(12, 18, 24, .45);
  border: 2px solid rgba(255,255,255,.35); overflow: hidden; touch-action: none; }
#thr-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(255, 181, 71, .75); pointer-events: none; }
#thr span { position: absolute; top: 6px; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 700;
  letter-spacing: .08em; pointer-events: none; }
#tbtns { position: absolute; right: calc(88px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px; }
#tbtns button, #menu-btn, #rotate button { background: rgba(12, 18, 24, .6); color: var(--ink); border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; touch-action: manipulation; }
#tbtns button.on { background: var(--accent); color: #111; }
#t-recal { display: none; }
body.tilt #t-recal { display: block; }

body.mobile #menu-btn { display: block; position: absolute; top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left)); font-size: 18px; padding: 4px 11px; }
body.mobile #spawns { display: none; top: calc(50px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left));
  bottom: auto; z-index: 5; }
body.mobile #spawns.open { display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  max-height: calc(100vh - 60px - env(safe-area-inset-top)); overflow-y: auto; }
body.mobile #spawns button { padding: 8px 12px; font-size: 14px; }

body.mobile #hud { top: calc(6px + env(safe-area-inset-top)); padding: 4px 8px; gap: 8px; flex-wrap: nowrap;
  max-width: calc(100vw - 120px); }
body.mobile #hud .cell { min-width: 40px; }
body.mobile #hud .val { font-size: 16px; }
body.mobile #hud .lbl { font-size: 8px; }
body.mobile #hud .unit { display: none; }
body.mobile #horizon { width: 64px; height: 64px; right: calc(8px + env(safe-area-inset-right)); bottom: auto;
  top: calc(8px + env(safe-area-inset-top)); }
body.mobile #where { left: 50%; transform: translateX(-50%); bottom: auto; top: calc(56px + env(safe-area-inset-top));
  font-size: 11px; padding: 3px 8px; white-space: nowrap; }
body.mobile #alert { top: calc(84px + env(safe-area-inset-top)); font-size: 13px; max-width: calc(100vw - 32px); }
body.mobile .cesium-viewer-fullscreenContainer { display: none !important; }
body.mobile .cesium-viewer-bottom { transform: scale(.75); transform-origin: left bottom; left: 170px; }

#rotate { position: absolute; inset: 0; z-index: 20; background: rgba(11, 16, 22, .94); flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px; box-sizing: border-box; }
#rotate.show { display: flex; }
#rotate p { font-size: 17px; max-width: 280px; }

/* portrait : le HUD passe sur deux lignes */
@media (orientation: portrait) {
  body.mobile #hud { flex-wrap: wrap; max-width: calc(100vw - 130px); }
  body.mobile #where { top: calc(96px + env(safe-area-inset-top)); }
  body.mobile #alert { top: calc(124px + env(safe-area-inset-top)); }
}

/* boost */
#spawns button.on { border-color: var(--accent); color: var(--accent); }
body.boosting #h-spd { color: #ff7ad9 !important; }
body.boosting #hud { box-shadow: 0 0 0 2px #ff7ad9; }

/* bouton d'installation dans l'aide */
#help .secondaire { margin-top: 8px; width: 100%; background: transparent; color: var(--ink); border: 1px solid rgba(255,255,255,.25);
  border-radius: 6px; padding: 7px 10px; font: inherit; font-size: 14px; cursor: pointer; }

/* ---------- Panneau de crash (boutons, utilisables au doigt) ---------- */
#crash { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.96); z-index: 15;
  width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 24px); overflow: auto; box-sizing: border-box;
  background: rgba(12, 18, 24, .93); border: 1px solid rgba(255, 90, 78, .5); border-radius: 18px; padding: 18px 18px 16px;
  text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
#crash.visible { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
.crash-titre { font-size: 26px; font-weight: 800; margin-bottom: 12px; }
.crash-oui { width: 100%; border: 0; border-radius: 12px; padding: 14px; font: 800 19px system-ui, sans-serif; cursor: pointer;
  background: var(--accent); color: #111; touch-action: manipulation; }
.crash-sous { margin: 14px 0 8px; font-size: 13px; opacity: .7; }
#crash-departs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
#crash-departs button { background: rgba(255,255,255,.06); color: var(--ink); border: 1px solid rgba(255,255,255,.18); border-radius: 9px;
  padding: 9px 6px; font: 600 14px system-ui, sans-serif; cursor: pointer; touch-action: manipulation; }
#crash-departs button:hover { border-color: var(--accent); }
@media (max-height: 430px) { .crash-titre { font-size: 20px; margin-bottom: 8px; } .crash-oui { padding: 11px; font-size: 17px; }
  #crash { padding: 12px; } #crash-departs { grid-template-columns: repeat(5, 1fr); } #crash-departs button { padding: 7px 4px; font-size: 12px; } }

/* hélico : repère du vol stationnaire au milieu de la barre des gaz */
body.helico #thr::after { content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 2px; margin-top: -1px;
  background: #fff; opacity: .85; box-shadow: 0 0 4px rgba(0,0,0,.6); pointer-events: none; }

/* boutons tactiles propres à l'hélico : glissade à la place du frein */
#t-glisse { display: none; gap: 6px; }
#t-glisse button { flex: 1; font-size: 18px; padding: 6px 0; }
body.helico #t-glisse { display: flex; }
body.helico #t-brake { display: none; }
#t-appareil { font-weight: 700; }

/* bouton contextuel : sortir de l'appareil / remonter */
#b-action { position: absolute; z-index: 9; left: 50%; transform: translateX(-50%); bottom: 132px; padding: 12px 22px; border: 0; border-radius: 999px;
  background: var(--accent); color: #111; font: 800 17px system-ui, sans-serif; box-shadow: 0 10px 26px rgba(0,0,0,.45); cursor: pointer; touch-action: manipulation; }
#b-action[hidden] { display: none; }
body.mobile #b-action { bottom: auto; top: calc(66px + env(safe-area-inset-top)); padding: 10px 18px; font-size: 15px; }
body.jeu #b-action { bottom: 150px; }
body.mobile.jeu #b-action { bottom: auto; }
#spawns button:disabled { opacity: .4; cursor: default; }

/* mode de jeu (vol libre / contrebande), toujours visible ; le toucher propose de changer */
#mode { position: absolute; top: 12px; left: 150px; z-index: 4; background: rgba(12, 18, 24, .6); color: var(--ink);
  border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; font-weight: 700;
  touch-action: manipulation; cursor: pointer; }
body.jeu #mode { border-color: #ffd43b; color: #ffe066; }
body.mobile #mode { top: calc(50px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); font-size: 12px; padding: 4px 10px; }
body.jeu #help-multi { display: none; }

/* hélico : la barre des gaz devient un levier monter / descendre, à ressort */
#thr .lev-haut, #thr .lev-bas { display: none; position: absolute; left: -2px; right: -2px; text-align: center; font-size: 9px; line-height: 1.15;
  font-weight: 700; letter-spacing: -.03em; pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
#thr .lev-haut { top: 7px; } #thr .lev-bas { bottom: 7px; }
body.helico #thr .lev-haut, body.helico #thr .lev-bas { display: block; }
body.helico #thr span { display: none; }
#thr-fill.desc { background: rgba(77, 171, 247, .75); }
