:root {
  --bg: #0b1020;
  --bg2: #131a30;
  --card: #18213b;
  --card2: #1f2a4a;
  --line: #2c3a63;
  --text: #e8eefc;
  --muted: #94a3c7;
  --accent: #4fb8ff;
  --accent2: #7fe3ff;
  --gold: #ffd76a;
  --good: #57e39a;
  --warn: #ffb347;
  --danger: #ff6b6b;
  --radius: 14px;
  --ui: 1;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
body.hc { --muted: #c9d4ee; --line: #6b7fb8; --card: #0e1428; --text: #ffffff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  font: calc(15px * var(--ui)) / 1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
h2 { font-size: 1.25em; margin: 4px 0 10px; }
h3 { font-size: .95em; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.big { font-size: 1.2em; font-weight: 700; }
.label { font-size: .75em; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
[hidden] { display: none !important; }

/* ---------- Hangar layout ---------- */
#hangar { display: flex; flex-direction: column; height: 100%; max-width: 640px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: linear-gradient(var(--bg2), var(--bg)); border-bottom: 1px solid var(--line);
}
.wallet { font-size: 1.5em; font-weight: 800; display: flex; align-items: baseline; gap: 6px; flex: 1; font-variant-numeric: tabular-nums; }
.wallet .unit { font-size: .55em; color: var(--muted); }
.coin { color: var(--gold); }
.rank { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; display: flex; flex-direction: column; gap: 3px; font-size: .8em; min-width: 78px; }
.xpbar { height: 4px; background: #0006; border-radius: 3px; overflow: hidden; display: block; }
.xpbar i { display: block; height: 100%; background: var(--gold); width: 0; }
.icon-btn { background: var(--card); border: 1px solid var(--line); border-radius: 10px; width: 44px; height: 44px; font-size: 1.2em; }

#screens { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px 24px; }
.screen { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.hint { border-color: var(--gold); background: #2a2614; }
.ship-card { display: flex; gap: 12px; align-items: center; background: radial-gradient(circle at 30% 50%, #1d2e5a, var(--card)); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
#shipPreview { width: 50%; max-width: 240px; height: auto; }
.ship-meta { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.meter { height: 10px; background: #0007; border-radius: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--good); width: 100%; transition: width .3s; }
.meter.low i { background: var(--danger); }

.btn { display: block; width: 100%; padding: 14px; border-radius: 12px; border: 0; background: var(--accent); color: #04122a; font-weight: 800; font-size: 1em; min-height: 48px; }
.btn:active { transform: scale(.98); }
.btn.ghost { background: transparent; color: var(--accent2); border: 1px solid var(--line); }
.btn:disabled { opacity: .45; }
.btn.small-btn { width: auto; padding: 8px 14px; min-height: 40px; font-size: .9em; }
.btn.gold { background: var(--gold); }
.btn.launch { font-size: 1.4em; letter-spacing: .12em; padding: 18px; background: linear-gradient(90deg, #4fb8ff, #7fe3ff); box-shadow: 0 6px 24px #4fb8ff55; position: sticky; bottom: 0; }

.drone-anim { width: 52px; height: 52px; border-radius: 50%; border: 2px dashed var(--line); position: relative; animation: spin 6s linear infinite; }
.drone-anim span { position: absolute; top: -5px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 3px; background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .drone-anim { animation: none; } }

.recent .rl { display: flex; justify-content: space-between; font-size: .9em; padding: 2px 0; }

/* segmented control */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; background: none; border: 0; padding: 10px; border-radius: 9px; font-weight: 700; color: var(--muted); min-height: 44px; }
.seg button.on { background: var(--card2); color: var(--text); }

/* upgrade rows */
.up { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
.up + .up { margin-top: 10px; }
.up .name { font-weight: 800; }
.up .pips { display: flex; gap: 3px; margin-top: 4px; }
.up .pips i { width: 16px; height: 6px; border-radius: 2px; background: #0007; border: 1px solid var(--line); }
.up .pips i.on { background: var(--accent); border-color: var(--accent); }
.up .eff { font-size: .85em; color: var(--muted); grid-column: 1 / -1; }
.up .eff b { color: var(--good); }
.up .buy { min-width: 96px; }
.tag { display: inline-block; font-size: .7em; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: var(--gold); color: #2a2000; margin-left: 6px; vertical-align: middle; }
.tag.blue { background: var(--accent); color: #04122a; }
.tag.grey { background: var(--line); color: var(--text); }

/* regions */
.region { position: relative; overflow: hidden; }
.region.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.region .mats { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { font-size: .78em; padding: 3px 8px; border-radius: 20px; background: #0005; border: 1px solid var(--line); display: inline-flex; gap: 5px; align-items: center; }
.chip .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.req { font-size: .85em; }
.req .ok { color: var(--good); } .req .no { color: var(--danger); }
.region.locked { opacity: .75; }

/* contracts */
.contract .prog { height: 8px; background: #0007; border-radius: 5px; overflow: hidden; margin: 8px 0 4px; }
.contract .prog i { display: block; height: 100%; background: var(--gold); }

/* tabs */
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--bg2); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; background: none; border: 0; padding: 8px 2px 10px; color: var(--muted); font-size: .75em; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; min-height: 56px; }
.tabs button span { font-size: 1.4em; line-height: 1.1; }
.tabs button.on { color: var(--accent2); }
.tabs .dot { position: absolute; top: 6px; right: calc(50% - 22px); width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; background: #000b; display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: 100%; max-width: 420px; max-height: 88vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.modal h2 { margin: 0; }
.modal .sum { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.modal .sum.total { font-size: 1.2em; font-weight: 800; border: 0; color: var(--gold); }
.modal .neg { color: var(--danger); }
.modal .pos { color: var(--good); }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.setting input[type=range] { width: 46%; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 16px; background: var(--line); position: relative; flex-shrink: 0; cursor: pointer; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { left: 23px; }

#toast { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); background: var(--card2); border: 1px solid var(--gold); padding: 10px 16px; border-radius: 12px; z-index: 60; font-weight: 700; max-width: 90vw; text-align: center; }

/* ---------- Sortie ---------- */
#sortie { position: fixed; inset: 0; background: #000; touch-action: none; }
#game { position: absolute; inset: 0; display: block; touch-action: none; }
#hud { position: absolute; inset: 0; pointer-events: none; padding: calc(8px + var(--safe-t)) 10px 0; }
#hud button { pointer-events: auto; }
.hud-top { display: flex; gap: 8px; align-items: flex-start; }
.hud-bars { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; background: #0009; border-radius: 10px; padding: 6px 8px; }
.hbar { display: flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 800; letter-spacing: .05em; }
.hbar span { width: 40px; color: var(--muted); }
.hbar div { flex: 1; height: 8px; background: #fff2; border-radius: 4px; overflow: hidden; }
.hbar i { display: block; height: 100%; width: 100%; }
.hbar.hull i { background: var(--good); }
.hbar.fuel i { background: var(--warn); }
.hbar.energy i { background: var(--accent); }
.hbar.heat i { background: #ff8a5c; }
.hbar.warn span { color: var(--danger); }
.hbar.warn i { background: var(--danger); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .4; } }
.hud-right { background: #0009; border-radius: 10px; padding: 6px 10px; text-align: right; min-width: 74px; }
.hud-credits { font-size: 1.15em; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-time { font-size: .85em; color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-time.warn { color: var(--danger); font-weight: 800; }
.hud-sub { font-size: 11px; color: var(--muted); margin: 4px 2px; }
#targetInfo { background: #000a; border-radius: 10px; padding: 6px 10px; width: min(260px, 70vw); margin-top: 4px; }
#targetInfo .trow { display: flex; justify-content: space-between; font-size: 13px; }
#targetInfo .trow span { color: var(--gold); font-weight: 800; }
.thp { height: 6px; background: #fff2; border-radius: 3px; overflow: hidden; margin: 4px 0; }
.thp i { display: block; height: 100%; background: var(--accent2); }
#tutorial { position: absolute; left: 50%; bottom: calc(300px + var(--safe-b)); transform: translateX(-50%); width: min(340px, 88vw); background: #0b1020e6; border: 1px solid var(--gold); color: var(--text); border-radius: 12px; padding: 12px 14px; text-align: center; font-weight: 700; }
#captions { position: absolute; left: 0; right: 0; bottom: calc(250px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.caption { background: #000c; border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 700; transition: opacity .5s; border-left: 4px solid var(--accent); }
.caption.warn { border-color: var(--warn); }
.caption.danger { border-color: var(--danger); }
.caption.good { border-color: var(--good); }
.caption.out { opacity: 0; }

#controls { --ctl-opacity: .8; position: absolute; right: 12px; bottom: calc(14px + var(--safe-b)); display: grid; grid-template-columns: auto auto auto; grid-template-rows: auto auto auto; gap: 10px; align-items: end; }
.ctl { pointer-events: auto; touch-action: none; border-radius: 50%; border: 2px solid #fff5; color: #fff; font-weight: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; opacity: var(--ctl-opacity); font-size: 14px; letter-spacing: .04em; }
.ctl small { font-size: 9px; font-weight: 600; opacity: .8; }
.ctl.mine { width: 96px; height: 96px; background: radial-gradient(circle, #4fb8ffcc, #1b5d8fcc); grid-column: 3; grid-row: 3; }
.ctl.mine.auto { background: radial-gradient(circle, #57e39acc, #1c7a4bcc); }
.ctl.boost { width: 72px; height: 72px; background: radial-gradient(circle, #a77bffcc, #4d2f99cc); grid-column: 2; grid-row: 3; }
.ctl.boost.auto { background: radial-gradient(circle, #57e39acc, #1c7a4bcc); }
.ctl.boost.empty { filter: grayscale(1); }
.ctl.return { grid-column: 1 / -1; grid-row: 2; border-radius: 12px; height: 44px; width: auto; background: #ff6b6bcc; flex-direction: row; gap: 8px; justify-self: end; padding: 0 14px; }
.ctl.down { transform: scale(.94); filter: brightness(1.3); }
body.lefty #controls { right: auto; left: 12px; }
body.lefty .ctl.mine { grid-column: 1; }
body.lefty .ctl.boost { grid-column: 2; }
body.lefty .wpn-wrap { grid-column: 3; }
body.lefty .ctl.return { justify-self: start; }
.toggles { grid-column: 1 / -1; grid-row: 1; display: flex; gap: 6px; justify-content: flex-end; }
body.lefty .toggles { justify-content: flex-start; }
.tgl { pointer-events: auto; opacity: var(--ctl-opacity); min-width: 56px; height: 44px; border-radius: 10px; border: 2px solid #fff3; background: #000a; color: var(--muted); font-weight: 900; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 6px; }
.tgl small { font-size: 8px; font-weight: 700; }
.tgl.on { border-color: var(--good); color: #fff; background: #1c7a4bcc; }

body.in-sortie #hangar { display: none; }

@media (orientation: landscape) and (max-height: 500px) {
  .hud-bars { max-width: 420px; }
  #captions { bottom: 20px; }
  #tutorial { bottom: auto; top: 70px; }
}

.drone-meter { margin: 10px 0 6px; }
.drone-meter i { background: var(--gold); }
.drone-anim.idle { animation-play-state: paused; opacity: .5; }
.proj { margin: 6px 0; }
.proj .sum, .formula .sum, .card .sum { display: flex; justify-content: space-between; gap: 8px; font-size: .85em; padding: 4px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.formula { margin: 6px 0 10px; }
.formula summary { cursor: pointer; color: var(--accent2); font-weight: 700; font-size: .9em; padding: 6px 0; }
.sum.pos { color: var(--good); }

/* secondary weapon */
.wpn-wrap { grid-column: 1; grid-row: 3; position: relative; align-self: end; }
.ctl.weapon { width: 66px; height: 66px; background: radial-gradient(circle, #ff9a3ccc, #8a4210cc); line-height: 1; }
.ctl.weapon span { font-size: 18px; }
.ctl.weapon b { font-size: 11px; }
.ctl.weapon.empty { filter: grayscale(1); opacity: .45; }
.swap { pointer-events: auto; position: absolute; top: -18px; right: -6px; width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff5; background: #000c; color: #fff; font-size: 15px; opacity: var(--ctl-opacity); }
.wcard .wicon { font-size: 26px; width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: #0006; flex-shrink: 0; }
.wcard .wstats { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.wcard .btns { display: flex; gap: 8px; }
.wpn-wrap::before { content: ''; position: absolute; inset: -5px; border-radius: 50%; background: conic-gradient(var(--gold) var(--salv, 0deg), #fff2 0); -webkit-mask: radial-gradient(circle, transparent 36px, #000 37px); mask: radial-gradient(circle, transparent 36px, #000 37px); opacity: var(--ctl-opacity); pointer-events: none; }
.reload { pointer-events: auto; position: absolute; top: -18px; left: -10px; min-width: 40px; height: 34px; border-radius: 17px; border: 2px solid var(--gold); background: #2a2000e6; color: var(--gold); font-size: 12px; font-weight: 900; line-height: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 5px; opacity: var(--ctl-opacity); }
.reload small { font-size: 8px; font-weight: 700; }
.reload.off { border-color: #fff3; color: var(--muted); background: #000c; }
.hbar.o2 i { background: #b5f0ff; }
.tgl.eva { border-color: var(--gold); color: var(--gold); }
.tgl.eva.on { background: #6b5200cc; color: #fff; }
.dups { display: grid; gap: 8px; margin-top: 8px; }
.dup { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dup .pips { display: flex; gap: 3px; margin-top: 3px; }
.dup .pips i { width: 14px; height: 5px; border-radius: 2px; background: #0007; border: 1px solid var(--line); }
.dup .pips i.on { background: var(--good); border-color: var(--good); }
.mods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; }
.mod { background: #0005; border: 1px solid var(--line); border-radius: 10px; padding: 8px 6px; display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; min-height: 44px; }
.mod .micon { font-size: 20px; }
.mod b { font-size: .75em; }
.mod small { font-size: .62em; color: var(--muted); line-height: 1.2; }
.mod em { font-style: normal; font-size: .72em; font-weight: 800; color: var(--accent2); margin-top: auto; }
.mod.on { border-color: var(--good); background: #1c7a4b55; }
.mod.on em { color: var(--good); }
.mod.poor { opacity: .55; }

/* Account / cloud save */
.icon-btn.acct { position: relative; color: var(--muted); }
.icon-btn.acct.on { color: var(--good); border-color: var(--good); }
.icon-btn.acct.warn { color: var(--danger); border-color: var(--danger); }
.icon-btn.acct .dot { position: absolute; top: 4px; right: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--gold); }
.acct-form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field input { font: inherit; font-size: 16px; /* 16px stops iOS zooming in */ padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); min-height: 48px; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.acct-msg:empty { display: none; }
.acct-msg.pos { color: var(--good); }
.acct-msg.neg { color: var(--danger); }
.modal .card .btn { margin-top: 8px; }
