:root {
  --cyan: #5ff7e2;
  --cyan-dark: #0faeac;
  --blue: #2595ff;
  --orange: #ffbd4a;
  --red: #ff5d68;
  --ink: #eefcff;
  --muted: #8daabd;
  --panel: #0b2032;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #030913; color: var(--ink); }
body { font-family: "Nunito", "Segoe UI", sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
button:disabled { cursor: default; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.cockpit { position: fixed; inset: 0; pointer-events: none; z-index: 2; border: 7px solid #172b3d; box-shadow: inset 0 0 0 2px #345065, inset 0 0 45px #000; }
.cockpit::before, .cockpit::after { content: ""; position: absolute; left: 0; right: 0; height: 12px; background: linear-gradient(#284155, #0b1724 55%, #3d5668 58%, #111f2c); }
.cockpit::before { top: 0; }
.cockpit::after { bottom: 0; }
.strut { position: absolute; top: 0; bottom: 0; width: 42px; background: linear-gradient(90deg, #0b1622, #304a5e 55%, #101e2b 60%, #07111c); box-shadow: 0 0 15px #000; }
.strut.left { left: 0; clip-path: polygon(0 0, 70% 0, 100% 36%, 55% 100%, 0 100%); }
.strut.right { right: 0; transform: scaleX(-1); clip-path: polygon(0 0, 70% 0, 100% 36%, 55% 100%, 0 100%); }

.hud { position: fixed; z-index: 6; top: calc(12px + var(--safe-t)); left: calc(24px + var(--safe-l)); right: calc(20px + var(--safe-r)); height: 62px; display: none; align-items: center; gap: 24px; pointer-events: none; }
.mode-play .hud, .mode-end .hud { display: flex; }
.brand { display: flex; align-items: center; gap: 9px; font: 800 17px/1 "Exo 2", sans-serif; letter-spacing: 1px; text-shadow: 0 2px 5px #000; }
.brand > span:last-child > span { color: var(--cyan); }
.brand-mark { display: grid; place-items: center; width: 36px; height: 40px; color: #052132; background: var(--cyan); font-size: 24px; font-weight: 900; clip-path: polygon(50% 0, 100% 100%, 50% 79%, 0 100%); }
.sector { display: flex; align-items: baseline; gap: 9px; padding-left: 20px; border-left: 1px solid #496071; white-space: nowrap; }
.hud small { display: block; font: 700 10px/1.2 "Exo 2", sans-serif; letter-spacing: 1.6px; color: var(--muted); }
.sector strong { font: 700 17px/1 "Exo 2", sans-serif; letter-spacing: 1px; }
.engines { margin-left: auto; display: flex; align-items: center; gap: 12px; padding: 9px 14px; border: 1px solid #345267; border-radius: 10px; background: rgba(4, 18, 29, .88); box-shadow: 0 5px 20px #0008; }
#engine-list { display: flex; gap: 6px; }
.engine { position: relative; width: 19px; height: 26px; border: 2px solid #55d6d1; border-radius: 5px 5px 8px 8px; background: linear-gradient(90deg, #0d6b72, #43e9d1, #0d6b72); box-shadow: 0 0 8px #34dec766; transition: .3s; }
.engine::after { content: ""; position: absolute; left: 4px; right: 4px; bottom: -6px; height: 5px; border-radius: 50%; background: #7affeb; box-shadow: 0 0 7px #31ffe1; }
.engine.damaged { border-color: #82444b; background: #3b3037; box-shadow: none; transform: rotate(12deg); }
.engine.damaged::after { background: #ff755f; box-shadow: 0 0 6px #ff543d; height: 2px; }
.engine.hit { animation: engine-hit .55s; }
@keyframes engine-hit { 30% { transform: scale(1.5) rotate(-15deg); background: var(--red); } }
.icon-button { pointer-events: auto; width: 46px; height: 46px; display: grid; place-items: center; padding: 10px; border: 1px solid #426175; border-radius: 12px; background: #0a1e2de8; }
.icon-button svg, .repeat svg, .button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button svg path:first-child, .repeat svg path:first-child { fill: currentColor; stroke: none; }
.sound-off, .icon-button[aria-pressed="true"] .sound-on { display: none; }
.icon-button[aria-pressed="true"] .sound-off { display: block; }

.game { display: none; }
.mode-play .game { display: block; }
.enemy-hud { position: fixed; z-index: 5; top: calc(88px + var(--safe-t)); left: 50%; transform: translateX(-50%); min-width: 240px; padding: 8px 16px; text-align: center; border: 1px solid #53708088; border-radius: 10px; background: #071724bb; pointer-events: none; }
.enemy-hud > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
#enemy-name { font: 800 13px/1 "Exo 2", sans-serif; letter-spacing: 1.5px; }
#enemy-status { font: 700 8px/1 "Exo 2", sans-serif; color: #ff9299; letter-spacing: 1px; }
.enemy-health { display: flex; justify-content: center; gap: 5px; margin-top: 7px; }
.enemy-health i { display: block; width: 52px; height: 5px; border-radius: 4px; background: #263849; }
.enemy-health i.full { background: linear-gradient(90deg, #ff5368, #ff9b69); box-shadow: 0 0 6px #ff536877; }

.console { position: fixed; z-index: 7; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); width: min(690px, calc(100vw - 70px)); padding: 13px 20px 15px; border: 2px solid #466174; border-radius: 24px 24px 16px 16px; background: linear-gradient(145deg, #20394c, #0b1c2b 18%, #102a3d 80%, #07131f); box-shadow: 0 -3px 0 #142b3d, 0 -12px 45px #0009, inset 0 1px 0 #688297; }
.console::before { content: ""; position: absolute; inset: 6px; border: 1px solid #ffffff0d; border-radius: 18px; pointer-events: none; }
.console-lights { position: absolute; top: 6px; left: 28px; display: flex; gap: 6px; }
.console-lights i { width: 4px; height: 4px; border-radius: 50%; background: #38e7d0; box-shadow: 0 0 5px #38e7d0; }
.console-lights i:nth-child(4) { background: var(--orange); box-shadow: 0 0 5px var(--orange); }
.console-lights i:nth-child(5) { background: #52697a; box-shadow: none; }
.mission { position: relative; display: flex; align-items: center; gap: 14px; min-height: 42px; margin-bottom: 9px; }
.repeat { display: flex; align-items: center; gap: 7px; padding: 6px 10px; border: 1px solid #3d6779; border-radius: 9px; background: #102c3d; color: var(--cyan); font-size: 12px; font-weight: 800; }
.repeat svg { width: 21px; height: 21px; }
.mission-copy { flex: 1; }
.mission-copy small { display: block; color: #6f9cb0; font: 700 9px/1.2 "Exo 2", sans-serif; letter-spacing: 1.5px; }
.mission-copy strong { display: block; margin-top: 2px; font-size: 17px; line-height: 1.1; }
.signal { display: flex; align-items: end; gap: 3px; height: 23px; }
.signal i { width: 3px; height: 8px; background: var(--cyan); border-radius: 3px; animation: signal .8s infinite alternate; }
.signal i:nth-child(2) { height: 18px; animation-delay: -.3s; }
.signal i:nth-child(3) { height: 13px; animation-delay: -.6s; }
.signal i:nth-child(4) { height: 22px; animation-delay: -.1s; }
@keyframes signal { to { transform: scaleY(.35); opacity: .45; } }
.writer { position: relative; height: clamp(128px, 22vh, 190px); overflow: hidden; border: 3px solid #2b5a65; border-radius: 13px; background: radial-gradient(ellipse at center, #103c43, #061c27 75%); box-shadow: inset 0 0 24px #000b, 0 0 0 4px #07131d; }
.writer::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .13; background-image: linear-gradient(#7fffff 1px, transparent 1px), linear-gradient(90deg, #7fffff 1px, transparent 1px); background-size: 24px 24px; }
#drawing { position: absolute; z-index: 2; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.writer-hint { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; color: #5a9298; }
.writer-hint span { font: 700 18px/1 "Exo 2", sans-serif; letter-spacing: 4px; }
.writer-hint small { margin-top: 8px; font-size: 12px; }
.writer.has-ink .writer-hint, .writer.locked .writer-hint { display: none; }
.writer.locked #drawing { cursor: wait; }
.scanning { position: absolute; z-index: 4; inset: 0; display: none; align-items: center; justify-content: center; background: #03131d99; color: #d6fffa; font-weight: 800; }
.writer.scanning .scanning { display: flex; }
.scanning i { position: absolute; left: 0; right: 0; height: 3px; background: var(--cyan); box-shadow: 0 0 16px 4px var(--cyan); animation: scan 1.1s linear infinite; }
.scanning span { padding: 8px 15px; border-radius: 20px; background: #06212eee; }
@keyframes scan { from { top: 0; } to { top: 100%; } }
.correction { position: absolute; z-index: 5; inset: 0; display: none; align-items: center; justify-content: center; gap: 24px; background: #071c29f5; }
.correction.show { display: flex; }
.correction small { color: var(--orange); font: 700 12px/1 "Exo 2", sans-serif; letter-spacing: 2px; }
.correction strong { color: #fff; font: 800 105px/.8 "Exo 2", sans-serif; text-shadow: 0 0 20px #5ff7e288; }
.console-actions { display: grid; grid-template-columns: 125px 1fr 190px; align-items: center; gap: 12px; margin-top: 12px; }
.button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 11px; padding: 10px 18px; font-weight: 900; transition: transform .08s, filter .15s; }
.button:not(:disabled):active { transform: translateY(3px); }
.button.secondary { border: 1px solid #456275; background: #1a3346; box-shadow: 0 3px 0 #07111c; color: #d1e2ec; }
.button.primary { color: #052a2b; background: linear-gradient(#78ffe7, #35d5c1); box-shadow: 0 4px 0 #138c86, 0 0 18px #42e8d02e; }
.button:disabled { filter: grayscale(.8); opacity: .38; box-shadow: none; }
.feedback { margin: 0; text-align: center; font-size: 14px; font-weight: 800; color: #a5c1d1; }
.feedback.good { color: #75f5c5; }
.feedback.bad { color: #ff9c96; }
.feedback.retry { color: #ffcf77; }

.overlay { position: fixed; z-index: 20; inset: 0; display: none; place-items: center; padding: calc(20px + var(--safe-t)) calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l)); overflow: auto; background: radial-gradient(ellipse at 50% 40%, #092f46b8, #020710e8 72%); }
.mode-menu .menu, .mode-end .end { display: grid; }
.panel { position: relative; width: min(540px, 100%); padding: 32px 38px; text-align: center; border: 1px solid #49768d; border-radius: 26px; background: linear-gradient(145deg, #102c40f5, #071724fa); box-shadow: 0 25px 90px #000, inset 0 1px 0 #8dc6dc44; }
.panel::before, .panel::after { content: ""; position: absolute; width: 36px; height: 36px; border-color: var(--cyan); opacity: .7; }
.panel::before { left: 12px; top: 12px; border-left: 3px solid; border-top: 3px solid; border-radius: 10px 0 0; }
.panel::after { right: 12px; bottom: 12px; border-right: 3px solid; border-bottom: 3px solid; border-radius: 0 0 10px; }
.eyebrow, .end-badge { color: var(--cyan); font: 700 11px/1 "Exo 2", sans-serif; letter-spacing: 3px; }
h1 { margin: 14px 0 0; font: 900 clamp(39px, 9vw, 63px)/.95 "Exo 2", sans-serif; letter-spacing: -2px; }
h1 span { display: block; color: var(--cyan); letter-spacing: 3px; }
.tagline { margin: 15px 0 22px; color: #bcd5e4; font-size: 20px; font-weight: 800; }
.mission-card { display: flex; align-items: center; gap: 20px; padding: 16px; text-align: left; border: 1px solid #33576b; border-radius: 16px; background: #06152299; }
.mission-card p { margin: 0; font-size: 15px; line-height: 1.45; color: #c6d9e4; }
.mini-alien { position: relative; flex: 0 0 65px; height: 59px; border-radius: 48% 52% 42% 45%; background: #a96bff; box-shadow: inset 8px 8px 0 #d59aff, 0 0 22px #a96bff55; }
.mini-alien i { position: absolute; top: 18px; width: 16px; height: 20px; border-radius: 50%; background: white; }
.mini-alien i:first-child { left: 12px; transform: rotate(-12deg); }
.mini-alien i:nth-child(2) { right: 12px; transform: rotate(12deg); }
.mini-alien i::after { content: ""; position: absolute; width: 7px; height: 10px; left: 5px; top: 6px; border-radius: 50%; background: #122039; }
.mini-alien b { position: absolute; left: 25px; bottom: 8px; width: 18px; height: 6px; border-bottom: 3px solid #351755; border-radius: 50%; }
.rules { display: flex; justify-content: center; gap: 30px; margin: 20px 0; color: #94afbf; font-size: 13px; }
.rules b { color: #fff; font-size: 18px; margin-right: 4px; }
.launch { min-width: 210px; min-height: 57px; color: #062b30; background: linear-gradient(180deg, #83ffe9, #35d9c4); box-shadow: 0 5px 0 #128f89, 0 0 28px #4ff9dc35; font: 900 21px/1 "Exo 2", sans-serif; text-transform: uppercase; letter-spacing: 1px; }
.parent-note { margin: 20px 0 0; color: #6f8c9e; font-size: 11px; line-height: 1.4; }
.end h2 { margin: 14px 0 8px; font: 900 40px/1 "Exo 2", sans-serif; color: var(--cyan); }
.end p { color: #bdd2df; font-size: 18px; }
.end-stats { display: flex; justify-content: center; gap: 12px; margin: 24px 0; }
.end-stats div { min-width: 110px; padding: 12px; border: 1px solid #355569; border-radius: 12px; background: #071522; }
.end-stats strong { display: block; font: 800 27px/1 "Exo 2", sans-serif; color: #fff; }
.end-stats small { color: #88a7b9; }
#flash { position: fixed; z-index: 15; inset: 0; pointer-events: none; opacity: 0; background: #ff334d; }
#flash.hit { animation: flash .65s; }
@keyframes flash { 25% { opacity: .45; } 100% { opacity: 0; } }
body.shake { animation: shake .45s; }
@keyframes shake { 20% { transform: translate(8px, -4px); } 40% { transform: translate(-7px, 5px); } 60% { transform: translate(5px, 3px); } 80% { transform: translate(-3px, -2px); } }
.noscript { position: fixed; z-index: 50; inset: 40% 20%; color: white; text-align: center; }

@media (max-width: 620px) {
  .hud { left: calc(14px + var(--safe-l)); right: calc(12px + var(--safe-r)); top: calc(8px + var(--safe-t)); height: 52px; gap: 10px; }
  .brand { font-size: 13px; gap: 5px; }
  .brand-mark { width: 27px; height: 32px; font-size: 19px; }
  .sector { padding-left: 9px; gap: 5px; }
  .sector small { display: none; }
  .sector strong { font-size: 13px; }
  .engines { gap: 6px; padding: 7px 8px; }
  .engines > small { display: none; }
  #engine-list { gap: 4px; }
  .engine { width: 13px; height: 21px; border-width: 1px; }
  .engine::after { left: 3px; right: 3px; }
  .icon-button { width: 38px; height: 38px; padding: 8px; border-radius: 9px; }
  .enemy-hud { top: calc(67px + var(--safe-t)); min-width: 205px; padding: 6px 12px; }
  .enemy-health i { width: 43px; }
  .console { width: calc(100vw - 24px); bottom: calc(8px + var(--safe-b)); padding: 12px 13px 12px; border-radius: 19px 19px 13px 13px; }
  .mission { margin-bottom: 8px; min-height: 38px; }
  .repeat { padding: 6px 8px; }
  .repeat span { display: none; }
  .mission-copy strong { font-size: 15px; }
  .writer { height: clamp(130px, 21vh, 180px); }
  .console-actions { grid-template-columns: 92px 1fr 132px; gap: 8px; margin-top: 10px; }
  .console-actions .button { min-height: 45px; padding: 8px 9px; font-size: 12px; }
  .console-actions .button svg { display: none; }
  .feedback { font-size: 12px; line-height: 1.2; }
  .panel { padding: 28px 22px; }
  .mission-card { gap: 14px; }
  .mini-alien { flex-basis: 58px; transform: scale(.9); }
}

@media (min-aspect-ratio: 1/1) and (max-height: 650px) {
  .hud { right: calc(365px + var(--safe-r)); }
  .engines { margin-left: auto; }
  .enemy-hud { left: calc((100vw - 340px) / 2); top: calc(72px + var(--safe-t)); }
  .console { left: auto; right: calc(12px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); transform: none; width: 330px; padding: 10px 13px 12px; }
  .mission { min-height: 35px; margin-bottom: 7px; }
  .mission-copy strong { font-size: 14px; }
  .writer { height: clamp(105px, 29vh, 160px); }
  .console-actions { grid-template-columns: 80px 1fr 118px; gap: 6px; margin-top: 8px; }
  .console-actions .button { min-height: 41px; padding: 6px; font-size: 11px; }
  .console-actions .button svg { display: none; }
  .feedback { font-size: 11px; }
  .panel { padding: 22px 30px; }
  h1 { font-size: 45px; }
  .tagline { margin: 10px 0 14px; }
  .mission-card { padding: 10px 14px; }
  .rules { margin: 12px 0; }
  .parent-note { margin-top: 13px; }
}

@media (max-height: 500px) and (max-width: 620px) {
  .hud { right: calc(300px + var(--safe-r)); }
  .brand > span:last-child { display: none; }
  .console { width: 280px; }
  .enemy-hud { left: calc((100vw - 280px) / 2); }
  .writer { height: 95px; }
  .mission-copy small, .signal { display: none; }
  .panel { width: min(620px, 90%); }
  .mission-card { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .signal i, .scanning i { animation-duration: 2s; }
  body.shake { animation: none; }
}
