/* Cold Gas Roadster: UI modelled on Kerbal Space Program's flight scene
   (grey-blue panels, orange highlights, navball plate, small-caps window headers). */
:root {
  --panel-a: #313a41; --panel-b: #1f262b; --line: #55666f; --line-dim: #3b484f;
  --text: #cfdde2; --dim: #8498a1; --orange: #f5a21f; --orange-d: #b9740a; --green: #a6d94a; --cyan: #52c6dc; --red: #e5503c;
  --font: "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1c2227; color: var(--text); font: 13px/1.35 var(--font); user-select: none; -webkit-user-select: none; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#mapc { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 20; background: #14191d; }
.hidden { display: none !important; }
kbd { font: 600 10px/1 var(--font); color: var(--dim); border: 1px solid var(--line-dim); border-radius: 3px; padding: 2px 4px; background: rgba(0,0,0,.25); margin-left: 4px; }

/* ---------- windows ---------- */
.win { position: fixed; background: linear-gradient(#323b42, #20272c); border: 1px solid var(--line); border-radius: 5px; box-shadow: 0 2px 10px rgba(0,0,0,.45); pointer-events: none; }
.win > header { font: 700 10.5px/1 var(--font); letter-spacing: .14em; color: #e8eff2; padding: 7px 10px 6px; background: rgba(0,0,0,.28); border-bottom: 1px solid var(--line-dim); border-radius: 5px 5px 0 0; display: flex; align-items: center; gap: 7px; }
.win > header .dot { width: 7px; height: 7px; background: var(--orange); border-radius: 1px; display: inline-block; }
.win button { pointer-events: auto; }

#topbar { top: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 1px; padding: 0; overflow: hidden; }
#topbar .cell { padding: 6px 14px 7px; min-width: 96px; background: rgba(0,0,0,.12); border-right: 1px solid var(--line-dim); text-align: center; }
#topbar .cell:last-child { border-right: 0; }
#topbar label { display: block; font: 700 9px/1 var(--font); letter-spacing: .14em; color: var(--dim); margin-bottom: 4px; }
#topbar b { font: 600 17px/1 var(--font); font-variant-numeric: tabular-nums; color: #f1f6f8; }
#topbar i { font-style: normal; font-size: 11px; color: var(--dim); margin-left: 3px; }

#log { top: 8px; left: 8px; width: 214px; }
#log table { width: 100%; border-collapse: collapse; margin: 4px 0 6px; }
#log td { padding: 3px 10px; font-size: 12px; }
#log td:first-child { color: var(--dim); }
#log td:last-child { text-align: right; font-variant-numeric: tabular-nums; color: #eef4f6; }

#res { top: 8px; right: 8px; width: 246px; }
.res { padding: 8px 10px 0; }
.rlabel { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; letter-spacing: .1em; color: var(--dim); font-weight: 700; margin-bottom: 4px; }
.rlabel b { font: 600 13px/1 var(--font); letter-spacing: 0; color: #f1f6f8; font-variant-numeric: tabular-nums; }
.bar { height: 11px; background: #0f1417; border: 1px solid var(--line-dim); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(#b6e85c, #7bb82d); transition: background .2s; }
.bar.bat i { background: linear-gradient(#ffd166, #d99a1d); }
.bar.low i { background: linear-gradient(#ffc04d, #e08a12); }
.bar.crit i { background: linear-gradient(#ff7a62, #c93a24); animation: blink .4s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.rsub { font-size: 10.5px; color: var(--dim); margin-top: 3px; font-variant-numeric: tabular-nums; }
.resrow { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px; gap: 8px; }
.ring { width: 66px; height: 66px; flex: none; }
.ring .bg { fill: rgba(0,0,0,.35); stroke: #3a474e; stroke-width: 6; }
.ring .fg { fill: none; stroke: var(--orange); stroke-width: 6; stroke-linecap: butt; stroke-dasharray: 169.6; stroke-dashoffset: 169.6; }
.ring text { fill: #f1f6f8; font: 700 20px var(--font); }
.ring text.sm { font: 700 7.5px var(--font); letter-spacing: .1em; fill: var(--orange); }

#groups { bottom: 10px; right: 8px; width: 270px; }
#groups .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 8px 4px; }
#groups .subrow { display: flex; gap: 6px; padding: 2px 8px 6px; }
#groups .subrow .kbtn.small { padding: 6px 5px; white-space: nowrap; min-width: 0; }
.grp { display: flex; align-items: center; justify-content: flex-start; gap: 8px; text-align: left; padding: 9px 8px; }
.grp kbd { margin: 0; color: var(--orange); border-color: var(--orange-d); font-size: 12px; padding: 3px 6px; }
.grp span { font-weight: 600; font-size: 12px; line-height: 1.15; }
.grp.busy { background: linear-gradient(#f5a21f, #c17a0d); color: #15191c; border-color: #ffd48a; }
.grp.busy kbd { color: #15191c; border-color: #15191c55; }

#thr { bottom: 10px; left: 8px; width: 338px; }
.thrbody { display: flex; gap: 10px; padding: 10px; align-items: stretch; }
.gauge { width: 38px; height: 130px; position: relative; background: #0f1417; border: 1px solid var(--line-dim); border-radius: 3px; overflow: hidden; flex: none; }
.gauge .gfill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(#ffc766, #e58a10); }
.gauge .gfill.lift { background: linear-gradient(#8fe5f3, #2fa0b8); }
.gauge .gnum { position: absolute; top: 4px; left: 0; right: 0; text-align: center; font: 700 11px var(--font); text-shadow: 0 1px 2px #000; font-variant-numeric: tabular-nums; }
.gauge span { position: absolute; bottom: 3px; left: 0; right: 0; text-align: center; font: 700 8.5px var(--font); letter-spacing: .1em; color: #fff; text-shadow: 0 1px 2px #000; }
#tmap { width: 170px; height: 130px; background: #0f1417; border: 1px solid var(--line-dim); border-radius: 3px; }

/* ---------- navball ---------- */
#navwrap { position: fixed; left: 50%; bottom: 0; width: 360px; height: 238px; transform: translateX(-50%); pointer-events: none; }
#navplate { position: absolute; left: 50%; bottom: -118px; width: 330px; height: 330px; margin-left: -165px; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #39434a 0, #232b31 62%, #1a2025 100%); border: 2px solid #55666f; box-shadow: 0 0 18px rgba(0,0,0,.6); }
#navball { position: absolute; left: 50%; bottom: 10px; width: 190px; height: 190px; margin-left: -95px; }
#speedplate { position: absolute; left: 50%; bottom: 207px; transform: translateX(-50%); min-width: 176px; text-align: center; padding: 4px 12px 5px;
  background: linear-gradient(#2a3238, #1c2227); border: 1px solid var(--line); border-radius: 4px; pointer-events: auto; cursor: pointer; white-space: nowrap; }
#speedplate label { display: block; font: 700 8.5px/1 var(--font); letter-spacing: .16em; color: var(--dim); }
#speedplate b { font: 600 20px/1.15 var(--font); font-variant-numeric: tabular-nums; color: #f6fafb; }
#speedplate i { font-style: normal; color: var(--dim); font-size: 11px; margin-left: 4px; }
#speedplate em { font-style: normal; display: block; font-size: 10.5px; color: var(--orange); font-variant-numeric: tabular-nums; }
.navcol { position: absolute; bottom: 14px; display: flex; flex-direction: column; gap: 5px; pointer-events: auto; }
#navL { left: -2px; } #navR { right: -2px; }
.lamp { font: 700 10px/1 var(--font); letter-spacing: .08em; color: #aebfc7; background: linear-gradient(#364047, #232b30); border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; min-width: 56px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.lamp b { font: inherit; }
.lamp:hover { border-color: var(--orange); }
.lamp.on { color: #121619; background: linear-gradient(#bfe96a, #86b82e); border-color: #d6f58f; }
.lamp.on kbd { color: #121619; border-color: #12161955; }
.lamp.warn { color: #121619; background: linear-gradient(#ffcf78, #e6951a); }
.lamp.mode.on { background: linear-gradient(#ffcf78, #e6951a); border-color: #ffe0a8; }

/* ---------- buttons ---------- */
.kbtn { font: 600 12.5px var(--font); color: #d8e6eb; background: linear-gradient(#3b464e, #272f35); border: 1px solid var(--line); border-radius: 4px; padding: 8px 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.kbtn:hover { border-color: var(--orange); color: #fff; }
.kbtn:active { background: var(--orange); color: #14181b; }
.kbtn.small { padding: 6px 8px; font-size: 11px; flex: 1; }
.kbtn.big { font-size: 15px; letter-spacing: .12em; padding: 12px 26px; background: linear-gradient(#f5a21f, #c17a0d); color: #14181b; border-color: #ffd48a; }
.kbtn.big:hover { filter: brightness(1.1); }
.kbtn.inf { font-size: 14px; letter-spacing: .06em; padding: 10px 14px; flex: 1; }
.kbtn.inf.on { color: #14181b; background: linear-gradient(#ffd77a, #e0a02a); border-color: #fff0c4; box-shadow: 0 0 14px rgba(245,162,31,.65); }
.kbtn.inf.on kbd { color: #14181b; border-color: #14181b55; }
.kbtn.small.on { background: linear-gradient(#bfe96a, #86b82e); color: #121619; border-color: #d6f58f; }

/* ---------- toasts / banner ---------- */
#toasts { position: fixed; top: 74px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; }
.toast { background: rgba(24,30,35,.92); border: 1px solid var(--line); border-left: 4px solid var(--orange); border-radius: 4px; padding: 7px 14px; font-weight: 600; font-size: 14px; color: #f3f8fa; box-shadow: 0 2px 10px rgba(0,0,0,.5); animation: toast 3.2s forwards; }
.toast.good { border-left-color: var(--green); } .toast.bad { border-left-color: var(--red); } .toast.rec { border-left-color: var(--cyan); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
#banner { position: fixed; top: 38%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; z-index: 5; font: 800 26px/1.2 var(--font); letter-spacing: .12em; color: #fff; text-shadow: 0 2px 14px rgba(0,0,0,.8); }
#banner small { display: block; font: 600 13px var(--font); letter-spacing: .1em; color: var(--orange); margin-top: 6px; }
#banner.bad { color: var(--red); }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px;
  background: radial-gradient(circle at 30% 35%, rgba(36,48,58,.55), rgba(10,14,17,.88)); }
#title { background: radial-gradient(circle at 25% 40%, rgba(40,52,62,.35), rgba(8,12,15,.82)); }
.card { background: linear-gradient(#313a41, #1d2429); border: 1px solid var(--line); border-radius: 6px; padding: 26px 30px; max-width: 520px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.6); border-left: 5px solid var(--orange); position: relative; max-height: calc(100vh - 32px); overflow-y: auto; }
.card.wide { max-width: 760px; } .card.menu { max-width: 600px; padding: 16px 20px 20px; }
.eyebrow { font: 700 10.5px var(--font); letter-spacing: .18em; color: var(--orange); text-transform: uppercase; }
h1 { font: 800 clamp(34px, 7vw, 54px)/.98 var(--font); letter-spacing: .02em; margin: 10px 0 12px; color: #f5f9fa; text-transform: uppercase; }
h2 { font: 700 18px var(--font); letter-spacing: .08em; text-transform: uppercase; margin: 0 0 12px; }
.lead { font-size: 14.5px; line-height: 1.5; color: #c9d8de; margin: 0 0 18px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.tiny { font-size: 11px; color: var(--dim); margin: 16px 0 0; }
.dim { color: var(--dim); }
.back { position: fixed; top: 14px; left: 16px; color: var(--dim); text-decoration: none; font-weight: 600; }
.back:hover { color: var(--orange); }
#loadmsg { position: absolute; bottom: 22px; left: 0; right: 0; text-align: center; color: var(--dim); font-size: 12px; letter-spacing: .08em; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-dim); margin-bottom: 14px; flex-wrap: wrap; }
.tab { font: 700 11px var(--font); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; }
.tab:hover { color: #fff; } .tab.on { color: var(--orange); border-bottom-color: var(--orange); }
.pane { display: flex; flex-direction: column; gap: 8px; }
.pane > p { margin: 0 0 8px; line-height: 1.5; }
.set { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 4px 0; }
.set.chk { justify-content: flex-start; gap: 8px; }
select, input[type=range] { background: #12181c; color: var(--text); border: 1px solid var(--line); border-radius: 3px; padding: 5px 6px; font: inherit; min-width: 190px; }
input[type=range] { padding: 0; accent-color: var(--orange); }
.krow { display: grid; grid-template-columns: 112px 1fr; gap: 3px 12px; padding: 5px 0; border-bottom: 1px solid var(--line-dim); font-size: 12.5px; }
.krow:last-child { border: 0; }
.krow b { color: var(--orange); font-weight: 700; }
.kgroup { font: 700 10px var(--font); letter-spacing: .14em; color: var(--dim); text-transform: uppercase; margin: 12px 0 2px; }
.rec { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line-dim); }
.rec b { font-variant-numeric: tabular-nums; }
.rec .ok { color: var(--green); }

@media (max-width: 980px) {
  #log { display: none; }
  #groups { width: 230px; } #groups .grp span { font-size: 11px; }
  #thr { width: 270px; } #tmap { width: 120px; }
  #navwrap { transform: translateX(-50%) scale(.85); transform-origin: bottom center; }
  #topbar .cell { min-width: 70px; padding: 6px 8px; }
}
@media (max-width: 720px) {
  #thr, #res .res + .res { display: none; }
  #groups { right: 4px; bottom: 4px; width: 190px; } #groups .subrow { display: none; }
}
@media (display-mode: standalone) { .only-browser { display: none !important; } }

/* ---------- touch overlay ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 8; touch-action: none; }
#touch > * { pointer-events: auto; touch-action: none; }
#touch .stick { position: absolute; left: 22px; bottom: 150px; width: 120px; height: 120px; border-radius: 50%; background: rgba(30,38,44,.6); border: 2px solid var(--line); }
#touch .stick i { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: var(--orange); opacity: .85; }
#touch .tthr { position: absolute; left: 160px; bottom: 150px; width: 34px; height: 120px; accent-color: var(--orange); writing-mode: vertical-lr; direction: rtl; }
#touch .tbtns { position: absolute; right: 12px; bottom: 150px; display: flex; flex-direction: column; gap: 8px; align-items: stretch; width: 150px; }
#touch .tbtns button { font: 700 14px var(--font); color: #e8f0f3; background: rgba(40,50,58,.85); border: 1px solid var(--line); border-radius: 6px; padding: 12px 6px; flex: 1; }
#touch .tbtns .big { font-size: 18px; padding: 20px 6px; background: linear-gradient(#f5a21f, #c17a0d); color: #14181b; }
#touch .tbtns .r2 { display: flex; gap: 8px; }
#touch .tbtns button.on { background: var(--orange); color: #14181b; }
body.touch #thr, body.touch #log, body.touch #groups .subrow { display: none; }
body.touch #groups { bottom: 8px; }

/* phones held upright: ask for landscape */
#rotate { display: none; position: fixed; inset: 0; z-index: 60; align-items: center; justify-content: center; text-align: center; background: #1c2227; color: var(--text); font-weight: 600; }
#rotate b { display: block; font-size: 56px; color: var(--orange); margin-bottom: 8px; }
@media (orientation: portrait) and (max-width: 720px) { body.touch #rotate { display: flex; } }
/* landscape phones: compact HUD. The thruster view shrinks into the bottom-left corner and the navball sits above it,
   small and at the left edge, so the middle of the screen stays free for the car. */
@media (orientation: landscape) and (max-height: 520px) {
  #res { width: 200px; } #res .res + .res, #res .rsub { display: none; }
  #groups { width: 210px; } #groups .grp { padding: 6px; } #groups .grp span { font-size: 10.5px; }
  #toasts { top: 56px; }
  #thr { width: 164px; left: 6px; bottom: 6px; }
  #thr .thrbody { padding: 6px; gap: 6px; } #thr .gauge { width: 24px; height: 66px; } #thr .gauge span { font-size: 7px; }
  #tmap { width: 92px; height: 66px; }
  #navwrap { left: -20px; bottom: 112px; transform: scale(.5); transform-origin: bottom left; }
  #navplate { display: none; }
  #navL { left: auto; right: -2px; bottom: 150px; }
  body.touch #thr { display: none; }
  body.touch #navwrap { bottom: 134px; }
  #touch .stick { bottom: 14px; left: 14px; width: 104px; height: 104px; } #touch .tthr { left: 132px; bottom: 14px; height: 104px; }
  #touch .tbtns { bottom: 118px; right: 8px; width: 132px; }
}
