:root { --el: #6dffa8; --amber: #ffb43a; --bg: #04070b; }
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--el);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; }
#hud { pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }

#top { position: fixed; top: max(8px, env(safe-area-inset-top)); left: 12px; display: flex; gap: 6px; z-index: 5; }
#top button { background: rgba(4,18,18,.75); border: 1px solid rgba(109,255,168,.35); padding: 6px 11px; font-size: 11px; letter-spacing: .12em; }

/* ---------- DSKY ---------- */
#dsky { position: fixed; right: 14px; bottom: 14px; width: 348px; z-index: 6; transform-origin: bottom right; transition: transform .28s, opacity .28s; }
#dsky.closed { transform: translateX(110%) scale(.9); opacity: 0; pointer-events: none; }
.plate { position: relative; padding: 16px 14px 14px; border-radius: 8px; border: 1px solid #6b737a;
  background: repeating-linear-gradient(97deg, rgba(255,255,255,.025) 0 1px, transparent 1px 3px), linear-gradient(160deg, #565e65, #2c3237 60%, #3b4248);
  box-shadow: 0 14px 40px rgba(0,0,0,.65), inset 0 1px 0 rgba(255,255,255,.25); }
.screw { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: linear-gradient(45deg, #1c2023 40%, #aab2b8 50%, #1c2023 60%); }
.tl { top: 4px; left: 4px } .tr { top: 4px; right: 4px } .bl { bottom: 4px; left: 4px } .br { bottom: 4px; right: 4px }
.upper { display: grid; grid-template-columns: 1fr 1.18fr; gap: 10px; }
#lamps { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; background: #14181b; padding: 5px; border-radius: 4px; align-content: stretch; }
.lamp { display: flex; align-items: center; justify-content: center; text-align: center; font: 700 8px/1.15 "Arial Narrow", Arial, sans-serif; letter-spacing: .04em;
  color: #14181b; background: #6d7272; border-radius: 2px; min-height: 27px; padding: 1px; }
.lamp.on.w { background: #f4f7e6; box-shadow: 0 0 12px #f4f7e6; }
.lamp.on.y { background: var(--amber); box-shadow: 0 0 12px var(--amber); }
#el { background: radial-gradient(ellipse at 50% 30%, #0b1a14, #030806); border: 2px solid #111; border-radius: 4px; padding: 6px 8px 5px;
  box-shadow: inset 0 0 18px #000; }
.row { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 4px; }
.field { display: flex; flex-direction: column; align-items: center; margin-left: auto; }
.row .field:first-child { margin-left: 0; }
.tag, #compActy { font: 700 8px/1.15 "Arial Narrow", Arial, sans-serif; letter-spacing: .08em; color: #06140d; background: var(--el); box-shadow: 0 0 7px rgba(109,255,168,.55); padding: 1px 9px; border-radius: 1px; text-align: center; }
#compActy { padding: 5px 7px; opacity: .13; align-self: flex-start; }
#compActy.on { opacity: 1; background: #d8ffe9; }
.digits { display: flex; gap: 2px; margin-top: 3px; transform: skewX(-4deg); }
.digits svg { width: 17px; height: 28px; overflow: visible; }
.digits polygon { fill: rgba(109,255,168,.055); }
.digits polygon.on { fill: #a4ffcd; filter: drop-shadow(0 0 2.5px #35ff8e); }
.reg { justify-content: flex-end; }
.reg svg { width: 18px; height: 27px; }
.rule { height: 2px; background: var(--el); box-shadow: 0 0 6px var(--el); opacity: .75; margin-top: 3px; }
.reglabel { display: block; font-size: 8px; letter-spacing: .14em; opacity: .65; height: 11px; padding-top: 2px; }
#keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
#keys button { height: 36px; border-radius: 4px; border: 1px solid #000; font: 700 12px/1 "Arial Narrow", Arial, sans-serif; color: #e9f2ea;
  background: linear-gradient(#2c2f31, #0e1011); box-shadow: 0 3px 0 #000, inset 0 1px 0 rgba(255,255,255,.18); text-shadow: 0 0 5px rgba(180,255,210,.55); }
#keys button:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; color: var(--el); }
#keys button:nth-child(1), #keys button:nth-child(6), #keys button:nth-child(8), #keys button:nth-child(13), #keys button:nth-child(14), #keys button:nth-child(20), #keys button:nth-child(21) { font-size: 9px; }

/* ---------- toque ---------- */
:root { --sl: env(safe-area-inset-left); --sr: env(safe-area-inset-right); --sb: env(safe-area-inset-bottom); --st: env(safe-area-inset-top);
  --u: clamp(54px, 15.5vmin, 76px); }
#touchUi, #btnGo, .touchOnly { display: none; }
body.touch #touchUi { display: block; }
body.touch .actions .touchOnly { display: inline-block; }
body.touch section.touchOnly { display: block; }
body.touch .keysOnly { display: none; }
body, button { -webkit-touch-callout: none; }
#stickZone { position: fixed; left: 0; top: 150px; bottom: 0; width: 48%; touch-action: none; }
body.wing #stickZone { display: none; }
body.stick #turnPad { display: none; }
#stickBase { display: none; position: fixed; width: 126px; height: 126px; margin: -63px 0 0 -63px; border-radius: 50%; border: 1px solid rgba(109,255,168,.5); background: radial-gradient(circle, rgba(109,255,168,.12), transparent 70%); pointer-events: none; }
#stickKnob { position: absolute; left: 39px; top: 39px; width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--el); box-shadow: 0 0 16px rgba(109,255,168,.6); }
#turnPad { position: fixed; left: calc(10px + var(--sl)); bottom: calc(12px + var(--sb)); display: flex; gap: 8px; padding: 8px 4px 0 0; touch-action: none; z-index: 3; }
#turnPad span { display: flex; align-items: center; justify-content: center; width: calc(var(--u) * 1.2); height: calc(var(--u) * 1.45); font-size: 26px;
  border: 2px solid rgba(109,255,168,.45); border-radius: 14px; background: rgba(5,22,20,.42); }
#turnPad span.on { background: rgba(109,255,168,.34); box-shadow: 0 0 22px rgba(109,255,168,.45); }
#buttons { position: fixed; right: calc(10px + var(--sr)); bottom: calc(12px + var(--sb)); display: grid; z-index: 3;
  grid-template-columns: repeat(3, var(--u)); grid-template-areas: "pst flare msl" "brake gun ab"; gap: 8px; align-items: end; justify-items: center; }
#buttons button { width: calc(var(--u) * .86); height: calc(var(--u) * .86); border-radius: 50%; border: 1px solid rgba(109,255,168,.5); background: rgba(5,22,20,.5); font-size: 9px; letter-spacing: .04em; touch-action: none; }
#buttons .pst { grid-area: pst } #buttons .flare { grid-area: flare } #buttons .msl { grid-area: msl } #buttons .brake { grid-area: brake }
#buttons .gun { grid-area: gun; width: var(--u); height: var(--u); border: 2px solid #ff7a4a; color: #ff9a6a; font-size: 10px; }
#buttons .ab { grid-area: ab; width: var(--u); height: var(--u); border-width: 2px; font-size: 10px; }
#buttons button.on { background: rgba(109,255,168,.35); }
/* em pé: armas empilhadas em duas colunas para não disputar espaço com o manche */
@media (orientation: portrait) {
  #buttons { grid-template-columns: repeat(2, var(--u)); grid-template-areas: "pst flare" "brake msl" "gun ab"; }
  #turnPad span { width: calc(var(--u) * 1.08); }
}
body.touch #btnGo:not([hidden]) { display: block; }
#btnGo { position: fixed; left: 50%; top: 68%; transform: translate(-50%, -50%); z-index: 4; padding: 14px 30px; font-weight: 700; letter-spacing: .14em;
  background: var(--amber); color: #1a1000; border: 0; box-shadow: 0 0 28px rgba(255,180,58,.6); }

/* DSKY no toque: centralizado, em escala, e os controles saem da frente */
body.touch #dsky { right: auto; bottom: auto; left: 50%; top: 50%; transform-origin: center; transform: translate(-50%, -50%) scale(var(--dsky, 1)); }
body.touch #dsky.closed { transform: translate(-50%, 40%) scale(.6); }
body.touch.dskyOpen #touchUi { display: none; }
body.touch #top { top: calc(8px + var(--st)); left: calc(8px + var(--sl)); }
body.touch #top button { padding: 11px 13px; min-width: 44px; }
body.paused #touchUi, body.paused #btnGo { display: none !important; }

/* ---------- menu ---------- */
#menu { position: fixed; inset: 0; z-index: 10; display: none; overflow: auto; touch-action: pan-y; padding: 4vh 12px;
  background: radial-gradient(ellipse at 50% 40%, rgba(4,14,16,.72), rgba(2,4,7,.93)); backdrop-filter: blur(3px); }
#menu.open { display: block; }
.panel { max-width: 920px; margin: 0 auto; border: 1px solid rgba(109,255,168,.3); background: rgba(3,12,12,.85); padding: 22px; box-shadow: 0 0 60px rgba(30,255,150,.08); }
h1 { font-size: clamp(34px, 7vw, 62px); letter-spacing: .2em; text-shadow: 0 0 22px rgba(109,255,168,.7); }
h1 em { color: var(--amber); font-style: normal; }
header p { font-size: 11px; letter-spacing: .22em; opacity: .65; margin-bottom: 18px; }
.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.modes button { text-align: left; padding: 12px; background: rgba(109,255,168,.06); border: 1px solid rgba(109,255,168,.3); font-size: 13px; letter-spacing: .06em; }
.modes button b { display: block; color: var(--amber); font-size: 10px; margin-bottom: 4px; }
.modes small { display: block; opacity: .55; font-size: 10px; margin-top: 3px; }
.modes .hot { border-color: #ff7a4a; background: rgba(255,100,50,.08); }
.modes button:hover, .actions button:hover { background: rgba(109,255,168,.2); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.actions button { background: transparent; border: 1px solid rgba(109,255,168,.35); padding: 9px 13px; font-size: 11px; }
#resume { background: var(--el); color: #03140b; font-weight: 700; }
.actions #resume:hover { background: #c3ffdd; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 22px; }
h2 { font-size: 11px; letter-spacing: .2em; color: var(--amber); margin: 10px 0 7px; border-bottom: 1px solid rgba(255,180,58,.3); padding-bottom: 4px; }
.list div { display: flex; gap: 10px; font-size: 11px; padding: 2px 0; }
.list b { min-width: 104px; }
.list span { opacity: .65; }
section p { font-size: 11px; line-height: 1.6; opacity: .7; }

details summary { cursor: pointer; font-size: 11px; letter-spacing: .2em; color: var(--amber); padding: 8px 0; }
body:not(.touch) details summary { display: none; }
#touchHelp p { margin-bottom: 6px; }
@media (max-width: 760px), (max-height: 520px) {
  #menu { padding: calc(8px + var(--st)) calc(8px + var(--sr)) calc(16px + var(--sb)) calc(8px + var(--sl)); }
  .panel { padding: 14px; }
  h1 { font-size: 30px; }
  header p { font-size: 9px; letter-spacing: .12em; margin-bottom: 10px; }
  .modes { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .modes button { padding: 9px; font-size: 11px; }
  .modes small { display: none; }
  .actions { margin: 10px 0; }
  .actions button { padding: 11px 12px; }
  #resume { flex: 1 0 100%; }
  .cols { grid-template-columns: 1fr; gap: 6px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .modes { grid-template-columns: repeat(3, 1fr); }
  header { display: flex; align-items: baseline; gap: 14px; }
  #resume { flex: 0 0 auto; }
}

#dskyClose { position: absolute; right: -10px; top: -14px; width: 40px; height: 40px; border-radius: 50%; z-index: 2; font-size: 17px; font-weight: 700;
  background: var(--amber); color: #1a1000; border: 2px solid #1a1000; box-shadow: 0 3px 10px rgba(0,0,0,.6); }
body.touch #dskyClose { width: 48px; height: 48px; top: -18px; right: -8px; }
#top { z-index: 7; }
