:root {
  --ink: #071017;
  --panel: #101e28;
  --line: #38515c;
  --cream: #f4e9ce;
  --cyan: #63d9df;
  --orange: #ff7a2f;
  --red: #f14646;
  --yellow: #ffd166;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--ink); color: var(--cream); }

body {
  font-family: "Courier New", monospace;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 20%, #173245 0, #071017 50%),
    repeating-linear-gradient(90deg, transparent 0 31px, #13222b 32px);
}

button { font: inherit; }

.game-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: auto;
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto minmax(420px, 1fr) auto;
  gap: 10px;
}

.topbar, .status-panel, .controls {
  display: flex;
  align-items: center;
  border: 2px solid var(--line);
  background: rgba(10, 24, 32, .94);
}

.topbar { min-height: 48px; padding: 8px 12px; justify-content: space-between; }
.brand { font-weight: 900; letter-spacing: 2px; }
.brand span { color: var(--orange); }
.level-readout { color: #8ca1aa; }
.level-readout strong { color: var(--cyan); font-size: 1.3rem; }
.topbar-actions { display: flex; gap: 7px; }

.icon-button {
  color: var(--cyan); background: transparent; border: 1px solid var(--line);
  padding: 7px 10px; cursor: pointer;
}
.reset-button { color: var(--orange); }

.status-panel { min-height: 64px; justify-content: space-between; }
.stat { padding: 8px 18px; display: flex; flex-direction: column; gap: 3px; }
.stat > span { color: #80949e; font-size: .7rem; letter-spacing: 1px; }
.stat strong { font-size: 1.45rem; color: var(--yellow); }
.score { text-align: center; border-inline: 1px solid var(--line); flex: 1; }
.hull-stat { flex-direction: row; align-items: center; gap: 12px; }

.hull-display { width: 55px; height: 42px; position: relative; transition: filter .2s; }
.hull-display img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; transform: rotate(90deg); }
.hull-cracks { position: absolute; inset: 0; pointer-events: none; }
.hull-display.damage-1 { filter: sepia(.2); }
.hull-display.damage-2 { filter: sepia(.4) saturate(1.2); }
.hull-display.damage-3 { filter: sepia(.7) saturate(2); }
.hull-display.damage-4 { filter: sepia(1) saturate(4) hue-rotate(330deg); animation: hullBlink .5s steps(2) infinite; }
.hull-display.damage-5 { filter: brightness(.2) grayscale(1); }
.hull-cracks::before, .hull-cracks::after { content: ""; display: none; position: absolute; background: var(--red); height: 2px; transform: rotate(35deg); }
.damage-2 .hull-cracks::before { display: block; width: 25px; left: 16px; top: 16px; }
.damage-3 .hull-cracks::after, .damage-4 .hull-cracks::after, .damage-5 .hull-cracks::after { display: block; width: 30px; left: 10px; top: 25px; transform: rotate(-28deg); }

.viewport {
  position: relative; overflow: hidden; isolation: isolate; cursor: none;
  border: 3px solid #263d48; box-shadow: inset 0 0 0 3px #071017, inset 0 0 45px #000;
  background: linear-gradient(#03070c, #08131c 70%, #102630);
  touch-action: manipulation;
}

.viewport::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(115deg, rgba(99,217,223,.05), transparent 35%, rgba(255,122,47,.04));
}

.stars { position: absolute; inset: -50%; background-repeat: repeat; pointer-events: none; }
.stars-far { background-image: radial-gradient(#fff 1px, transparent 1px); background-size: 39px 37px; opacity: .35; animation: drift 24s linear infinite; }
.stars-near { background-image: radial-gradient(#9ddde0 1px, transparent 2px); background-size: 93px 81px; opacity: .5; animation: drift 12s linear infinite; }

.moon {
  position: absolute; width: clamp(80px, 12vw, 150px); aspect-ratio: 1; top: 12%; right: 10%;
  border-radius: 50%; background: #d8d0b9; box-shadow: 0 0 30px #ccd7c955, inset -22px -12px #9a9b91;
  transition: transform 1s linear; overflow: hidden;
}
.camera-right .moon { right: auto; left: 10%; }
.moon::before, .moon::after, .moon span { content: ""; position: absolute; border-radius: 50%; background: #8e928c66; }
.moon::before { width: 25%; height: 18%; left: 18%; top: 22%; }
.moon::after { width: 17%; height: 17%; right: 20%; bottom: 23%; }
.moon span { width: 11%; height: 11%; left: 35%; bottom: 15%; }

.camera-label { position: absolute; top: 18px; left: 20px; z-index: 5; color: var(--cyan); font-size: .75rem; letter-spacing: 1px; }
.camera-label i { display: inline-block; width: 8px; height: 8px; margin-right: 7px; background: var(--red); animation: blink 1.2s steps(2) infinite; }
.scanlines { position: absolute; inset: 0; z-index: 20; pointer-events: none; opacity: .14; background: repeating-linear-gradient(0deg, #000 0 2px, transparent 2px 5px); }

.asteroid-field { position: absolute; inset: 0; z-index: 10; }
.asteroid {
  position: absolute; width: var(--size); height: var(--size); padding: 0; border: 0; cursor: none;
  background: transparent; transform: translate(-50%, -50%) scale(var(--scale)); image-rendering: pixelated;
}
.asteroid::before {
  content: ""; position: absolute; inset: 10%;
  background: #776b5d; clip-path: polygon(28% 0,75% 8%,100% 36%,88% 79%,57% 100%,15% 85%,0 52%,8% 20%);
  box-shadow: inset -8px -7px #433c37, inset 7px 5px #9c8a70;
}
.asteroid::after {
  content: ""; position: absolute; width: 18%; height: 16%; top: 31%; left: 25%; background: #433c37;
  box-shadow: calc(var(--size) * .35) calc(var(--size) * .18) 0 #504840, calc(var(--size) * .42) calc(var(--size) * -.08) 0 #a38e70;
}
.asteroid.destroyed { animation: explode .25s steps(3) forwards; pointer-events: none; }
.pixel-explosion { position: absolute; z-index: 12; width: 10px; height: 10px; transform: translate(-50%, -50%); pointer-events: none; }
.pixel-explosion::before { content: ""; position: absolute; inset: -8px; background: var(--yellow); box-shadow: 0 0 0 6px var(--orange); animation: blastFlash .22s steps(2) forwards; }
.pixel-explosion i { position: absolute; left: 3px; top: 3px; width: 6px; height: 6px; background: var(--orange); animation: pixelFragment .42s steps(4) var(--delay) forwards; }
.pixel-explosion i:nth-child(3n) { background: var(--yellow); width: 4px; height: 4px; }
.pixel-explosion i:nth-child(3n + 1) { background: #9c8a70; }

.warning {
  display: none; position: absolute; right: 18px; top: 50%; z-index: 30; transform: translateY(-50%);
  align-items: center; gap: 10px; padding: 10px 12px; color: var(--red); border: 2px solid var(--red);
  background: #160b0be8; animation: warningPulse .55s steps(2) infinite;
}
.warning.visible { display: flex; }
.warning-arrow { font-size: 2rem; font-weight: bold; }
.camera-right .warning { right: auto; left: 18px; }
.camera-right .warning-arrow { transform: rotate(180deg); }
.warning div { display: flex; flex-direction: column; font-size: .7rem; }
.warning div span { color: var(--cream); }

.camera-wipe {
  position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  color: var(--cyan); letter-spacing: 3px; background: #071017; transform: scaleY(0); transform-origin: center;
}
.camera-wipe.active { animation: cameraSwitch .6s steps(5); }
.crosshair { position: absolute; z-index: 14; left: 50%; top: 50%; width: 25px; height: 25px; border: 1px solid #63d9df88; transform: translate(-50%, -50%); pointer-events: none; will-change: left, top; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: #63d9df44; }
.crosshair.over-moon { border: 2px solid #071017; }
.crosshair.over-moon::before, .crosshair.over-moon::after { background: #071017; }
.crosshair::before { width: 39px; height: 1px; left: -8px; top: 11px; }
.crosshair::after { height: 39px; width: 1px; top: -8px; left: 11px; }

.controls { min-height: 66px; justify-content: space-between; padding: 8px 12px; }
.controls p { margin: 0; color: #80949e; font-size: .75rem; }
.switch-button { display: flex; align-items: center; gap: 12px; border: 0; color: var(--cream); background: transparent; cursor: pointer; font-weight: bold; }
.key { padding: 7px 20px; color: var(--ink); background: var(--cream); box-shadow: 0 4px #8e8a7f; }

.overlay { position: fixed; inset: 0; z-index: 100; display: none; place-items: center; padding: 18px; overflow-y: auto; background: #02070ced; }
.overlay.visible { display: grid; animation: fadeIn .35s ease-out; }
.mission-card { width: min(620px, 100%); padding: clamp(22px, 5vw, 48px); text-align: center; border: 3px solid var(--line); background: #0c1a23; box-shadow: 12px 12px 0 #020508; }
#startScreen { padding: 6px; overflow: hidden; }
#startScreen .mission-card { width: min(920px, 100%); max-height: calc(100dvh - 12px); padding: clamp(10px, 2vh, 20px) clamp(12px, 3vw, 30px); }
#startScreen .hero-shuttle { width: clamp(42px, 8vh, 68px); height: clamp(42px, 8vh, 68px); }
#startScreen h1 { margin: 2px 0 6px; font-size: clamp(2rem, 5.5vh, 3.6rem); }
#startScreen .mission-card > p { margin: 5px auto; font-size: clamp(.66rem, 1.4vh, .85rem); line-height: 1.3; }
#startScreen .eyebrow { margin: 0 auto 2px; }
#startScreen .instructions { margin: clamp(5px, 1vh, 10px) 0; padding: clamp(7px, 1vh, 11px) 12px; }
#startScreen .instructions h2 { margin-bottom: 5px; }
#startScreen .instructions ol { display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; }
#startScreen .instructions li { padding-block: 1px; }
#startScreen .briefing { margin: clamp(5px, 1vh, 10px) 0; }
#startScreen .briefing span { padding: 5px 3px; }
#startScreen .volume-control { margin: 0 auto clamp(6px, 1.2vh, 12px); }
#startScreen .difficulty-picker { margin-bottom: clamp(6px, 1.2vh, 12px); }
#startScreen .difficulty-picker legend { margin-bottom: 4px; }
#startScreen .difficulty-option { padding: 6px 4px; }
#startScreen .primary-button { padding: 10px 20px; }
.eyebrow { color: var(--orange) !important; font-weight: bold; letter-spacing: 3px; font-size: .75rem; }
.hero-shuttle { width: 110px; height: 110px; image-rendering: pixelated; }
h1, h2 { margin: 8px 0 16px; line-height: .9; font-size: clamp(2.4rem, 8vw, 5rem); letter-spacing: -4px; }
h1 span { color: var(--cyan); }
.mission-card > p { max-width: 500px; margin: 12px auto; color: #a8b6bc; line-height: 1.5; }
.instructions { margin: 22px 0; padding: 16px 18px; text-align: left; border: 1px solid var(--line); background: #071017; }
.instructions h2 { margin: 0 0 11px; color: var(--cyan); font-size: .8rem; letter-spacing: 2px; }
.instructions ol { margin: 0; padding-left: 25px; color: #9babb2; font-size: .72rem; line-height: 1.45; }
.instructions li { padding: 3px 0 3px 5px; }
.instructions li::marker { color: var(--orange); font-weight: bold; }
.instructions b { color: var(--cream); }
.instructions strong { color: var(--yellow); }
.pause-overlay { background: #02070cb8; backdrop-filter: blur(3px); }
.pause-card { max-width: 440px; }
.pause-card h2 { color: var(--yellow); }
.replay-overlay { z-index: 110; background: #02070cb8; backdrop-filter: blur(3px); }
.replay-card { max-width: 600px; }
.replay-card h2 { color: var(--cyan); font-size: clamp(2.2rem, 7vw, 4rem); }
.replay-difficulty-picker { margin-top: 24px; }
.briefing { margin: 25px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.briefing span { padding: 10px 5px; border: 1px solid var(--line); font-size: .65rem; color: #8ca1aa; }
.briefing b { display: block; margin-bottom: 5px; color: var(--cream); }
.volume-control { width: min(360px, 100%); display: grid; grid-template-columns: 62px 1fr 42px; align-items: center; gap: 10px; margin: 0 auto 20px; color: #80949e; font-size: .7rem; letter-spacing: 1px; text-align: left; }
.volume-control input { width: 100%; accent-color: var(--cyan); cursor: pointer; }
.volume-control output { color: var(--cyan); text-align: right; font-weight: bold; }
.difficulty-picker { margin: 0 0 24px; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; border: 0; }
.difficulty-picker legend { width: 100%; margin-bottom: 9px; color: #80949e; font-size: .7rem; letter-spacing: 2px; }
.difficulty-option { padding: 12px 8px; color: #80949e; border: 2px solid var(--line); background: #071017; cursor: pointer; }
.difficulty-option b, .difficulty-option span { display: block; }
.difficulty-option b { margin-bottom: 4px; color: var(--cream); }
.difficulty-option span { font-size: .65rem; }
.difficulty-option.selected { border-color: var(--cyan); background: #102b33; box-shadow: inset 0 -4px var(--cyan); }
.difficulty-option.selected b { color: var(--cyan); }
.primary-button { border: 0; padding: 14px 25px; color: var(--ink); background: var(--orange); box-shadow: 6px 6px 0 #7e2e15; font-weight: 900; cursor: pointer; letter-spacing: 1px; }
.primary-button:active { transform: translate(3px, 3px); box-shadow: 3px 3px 0 #7e2e15; }
.pause-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; }
.secondary-button { padding: 14px 25px; color: var(--orange); border: 2px solid var(--orange); background: transparent; font-weight: 900; cursor: pointer; }

.result-moon { width: 85px; aspect-ratio: 1; margin: 10px auto; border-radius: 50%; background: #d8d0b9; box-shadow: inset -14px -8px #8e928c; }
.result-card { width: min(760px, 100%); }
.result-card h2 { font-size: clamp(2rem, 7vw, 4rem); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); margin: 22px 0 18px; border-block: 1px solid var(--line); }
.result-grid div { padding: 15px 5px; display: flex; flex-direction: column; gap: 5px; }
.result-grid span { color: #80949e; font-size: .65rem; }
.result-grid strong { color: var(--yellow); font-size: 1.35rem; }
.achievements { margin: 0 0 20px; }
.achievements-heading { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px; }
.achievements-heading h3 { margin: 0; color: var(--cyan); font-size: .72rem; letter-spacing: 2px; }
.achievements-heading span { color: #80949e; font-size: .62rem; }
.achievements-list { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(10px, 2vw, 18px); }
.achievement { position: relative; width: 92px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 7px; outline: none; }
.achievement-icon { width: 54px; aspect-ratio: 1; display: grid; place-items: center; color: #62747c; border: 2px solid #314650; border-radius: 50%; background: #071017; font-size: 1.35rem; font-weight: bold; }
.achievement div { min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: center; }
.achievement strong { color: #71848c; font-size: .6rem; letter-spacing: .5px; }
.achievement div span {
  position: absolute; z-index: 10; left: 50%; top: calc(100% + 8px); width: 180px; padding: 8px 10px;
  color: var(--cream); border: 1px solid var(--cyan); background: #071017f5; box-shadow: 4px 4px 0 #020508;
  font-size: .58rem; line-height: 1.35; text-align: center; opacity: 0; visibility: hidden;
  transform: translate(-50%, -4px); transition: opacity .15s, transform .15s, visibility .15s; pointer-events: none;
}
.achievement div span::before {
  content: ""; position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  border: 5px solid transparent; border-bottom-color: var(--cyan);
}
.achievement:hover div span, .achievement:focus-visible div span { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.achievement:first-child div span { left: 0; transform: translate(0, -4px); }
.achievement:first-child:hover div span, .achievement:first-child:focus-visible div span { transform: translate(0, 0); }
.achievement:first-child div span::before { left: 27px; }
.achievement:last-child div span { right: 0; left: auto; transform: translate(0, -4px); }
.achievement:last-child:hover div span, .achievement:last-child:focus-visible div span { transform: translate(0, 0); }
.achievement:last-child div span::before { right: 27px; left: auto; }
.achievement:focus-visible .achievement-icon { outline: 2px solid var(--cyan); outline-offset: 3px; }
.achievement.earned .achievement-icon { color: var(--ink); border-color: var(--yellow); background: var(--yellow); box-shadow: 3px 3px 0 #6f5723, 0 0 16px #ffd16633; }
.achievement.earned strong { color: var(--yellow); }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; }
.lost .result-moon { border-radius: 0; background: var(--red); clip-path: polygon(0 20%,40% 35%,50% 0,62% 38%,100% 22%,75% 55%,100% 90%,58% 70%,45% 100%,35% 65%,0 85%,22% 52%); box-shadow: none; }

@keyframes drift { to { transform: translate(-12%, 30%); } }
@keyframes blink { 50% { opacity: .25; } }
@keyframes warningPulse { 50% { border-color: var(--yellow); color: var(--yellow); } }
@keyframes cameraSwitch { 0%,100% { transform: scaleY(0); } 25%,75% { transform: scaleY(1); } }
@keyframes explode { 50% { filter: brightness(3); transform: translate(-50%,-50%) scale(1.5) rotate(20deg); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(2); } }
@keyframes blastFlash { 0% { transform: scale(.2); opacity: 1; } 55% { transform: scale(1.25); } 100% { transform: scale(0); opacity: 0; } }
@keyframes pixelFragment { from { transform: rotate(var(--angle)) translateX(4px); opacity: 1; } to { transform: rotate(var(--angle)) translateX(var(--distance)); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes hullBlink { 50% { opacity: .5; } }

@media (max-width: 620px) {
  .game-shell { padding: 8px; grid-template-rows: auto auto minmax(380px, 1fr) auto; }
  .brand { font-size: .8rem; }
  .icon-button { font-size: .65rem; }
  .topbar { flex-wrap: wrap; gap: 6px; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .stat { padding: 7px 10px; }
  .stat strong { font-size: 1.1rem; }
  .hull-display { width: 42px; }
  .controls { flex-direction: column; justify-content: center; gap: 9px; }
  #startScreen .briefing { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  #startScreen .difficulty-picker { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  #startScreen .instructions ol { grid-template-columns: 1fr 1fr; column-gap: 12px; padding-left: 18px; font-size: clamp(.52rem, 1.35vh, .65rem); line-height: 1.25; }
  #startScreen .difficulty-option span { font-size: .52rem; }
  #startScreen .difficulty-option b { font-size: .66rem; }
  .result-card { padding: 22px 16px; }
  .achievements-list { gap: 6px; }
  .achievement { width: 72px; }
  .achievement-icon { width: 44px; }
  .warning { top: auto; bottom: 16px; transform: none; }
}

@media (max-height: 600px) {
  #startScreen .hero-shuttle { width: 28px; height: 28px; }
  #startScreen h1 { font-size: 1.7rem; }
  #startScreen .instructions ol { font-size: .5rem; line-height: 1.1; }
  #startScreen .briefing span { padding: 2px; font-size: .52rem; }
  #startScreen .difficulty-option { padding: 3px; }
  #startScreen .primary-button { padding: 7px 16px; }
  .result-card { padding-block: 14px; }
  .result-moon { width: 42px; margin: 4px auto; }
  .result-card h2 { margin-bottom: 8px; }
  .result-grid { margin: 10px 0; }
  .result-grid div { padding: 7px 4px; }
  .achievement { gap: 3px; }
  .achievement-icon { width: 34px; font-size: .9rem; }
  .achievement strong { font-size: .48rem; }
  .achievements { margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
