@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --space: #080d0f;
  --ink: #111719;
  --panel: #e6e3d9;
  --paper: #f1eee4;
  --line: #a8aaa3;
  --muted: #656c69;
  --orange: #f05a36;
  --amber: #ffb234;
  --cyan: #77d6cc;
  --green: #72c9a1;
  --danger: #d7432f;
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background: var(--space);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 8% 17%, #95c9c8 0 1px, transparent 1.5px),
    radial-gradient(circle at 79% 9%, #d7d6bb 0 1px, transparent 1.5px),
    radial-gradient(circle at 67% 73%, #779a9a 0 1px, transparent 1.5px),
    radial-gradient(circle at 22% 86%, #dad8c4 0 1px, transparent 1.5px),
    #080d0f;
  background-size: 190px 190px, 270px 270px, 220px 220px, 310px 310px, auto;
  overflow-x: hidden;
}
button { font: inherit; }

.game-shell {
  width: min(1440px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(380px, 1fr) auto;
  background: #101719;
  border-inline: 1px solid #263235;
  box-shadow: 0 0 90px #000;
}

.masthead {
  min-height: 68px;
  padding: 10px clamp(12px, 2.5vw, 30px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--panel);
  border-bottom: 1px solid #3b4648;
  background: #131b1d;
}
.identity { display: flex; align-items: center; gap: 13px; }
.identity p, .kicker {
  margin: 0 0 3px;
  font: 500 8px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: .17em;
  color: #8f9c9b;
}
.identity h1 { margin: 0; font-size: clamp(20px, 3vw, 29px); line-height: .95; letter-spacing: .1em; }
.identity-mark { width: 42px; height: 42px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 6px; border: 1px solid #516061; transform: rotate(-8deg); }
.identity-mark i { background: var(--orange); }
.identity-mark i:nth-child(2) { height: 65%; background: var(--amber); }
.identity-mark i:nth-child(3) { height: 35%; background: var(--cyan); }
.utility-button, .icon-button, .seed-panel button {
  border: 1px solid #596668;
  color: #dcdad1;
  background: transparent;
  cursor: pointer;
  font: 600 9px "IBM Plex Mono", monospace;
  letter-spacing: .12em;
}
.utility-button { min-height: 34px; padding: 0 12px; }
.utility-button:hover, .icon-button:hover, .seed-panel button:hover { color: var(--ink); background: var(--cyan); border-color: var(--cyan); }

.hud { display: grid; grid-template-columns: minmax(210px, 1.15fr) .85fr 1.25fr auto; background: var(--panel); border-bottom: 5px solid var(--orange); }
.hud-block { min-height: 74px; padding: 10px clamp(10px, 2vw, 22px); border-right: 1px solid var(--line); }
.hud-block > span, .seed-panel > span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font: 600 8px "IBM Plex Mono", monospace;
  letter-spacing: .15em;
}
.hud-block > span b { color: var(--orange); font: inherit; }
.hud-block strong { font: 700 clamp(20px, 2.3vw, 28px)/1 "Space Grotesk", sans-serif; }
.hud-block small { display: block; margin-top: 4px; color: var(--muted); font: 500 9px "IBM Plex Mono", monospace; }
.hud-block small.alien-alert { color: #47753c; font-weight: 600; }
.reactor-block { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 10px; }
.reactor-block > span { margin: 0; }
.reactor-block strong { color: var(--danger); font-family: "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }
.timer-bar { grid-column: 1 / -1; height: 5px; background: #c0c1b9; overflow: hidden; }
.timer-bar b { display: block; width: 100%; height: 100%; background: var(--orange); transform-origin: left; }
.pod-readout > div { display: flex; gap: clamp(8px, 2vw, 20px); }
.pod-chip { min-width: 54px; display: grid; grid-template-columns: auto auto; gap: 1px 5px; align-items: end; font: 600 10px "IBM Plex Mono", monospace; }
.pod-chip b { font-size: 14px; }
.pod-chip i { grid-column: 1 / -1; height: 3px; background: #bec1ba; }
.pod-chip i::after { content: ""; display: block; width: var(--fill); height: 100%; background: var(--cyan); transition: width .2s; }
.pod-chip.launched { color: #8b8e89; text-decoration: line-through; }
.pod-chip.launched i::after { background: var(--orange); }
.hud-actions { display: flex; padding: 10px; gap: 5px; align-items: center; }
.icon-button { width: 34px; height: 34px; color: #3a4546; border-color: #9b9e99; font-size: 14px; }

.playfield-wrap { min-height: 0; position: relative; background: var(--space); overflow: hidden; isolation: isolate; }
#game-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.scanlines { position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: .05; background: repeating-linear-gradient(0deg, transparent 0 3px, #a5dad6 4px); }
.alarm-flash { position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; box-shadow: inset 0 0 80px 18px var(--danger); }
.game-shell.urgent .alarm-flash { animation: alarm-flash 1.2s ease-in-out infinite; }
.game-shell.critical .alarm-flash { animation-duration: .55s; }
.game-shell.critical .playfield-wrap { animation: ship-shake .18s steps(2) infinite; }
.status-toast { position: absolute; z-index: 4; top: 13px; left: 50%; margin: 0; transform: translate(-50%, -8px); padding: 7px 11px; color: var(--ink); background: var(--amber); font: 600 10px "IBM Plex Mono"; letter-spacing: .12em; opacity: 0; pointer-events: none; transition: .18s; }
.status-toast.show { opacity: 1; transform: translate(-50%, 0); }

.control-deck { min-height: 76px; display: grid; grid-template-columns: 1fr 1fr minmax(185px, .7fr); color: var(--panel); background: #151d1f; border-top: 1px solid #475254; }
.instruction { padding: 12px clamp(10px, 2vw, 20px); display: flex; gap: 12px; align-items: center; border-right: 1px solid #394446; }
.instruction-number { color: var(--orange); font: 600 22px "IBM Plex Mono", monospace; }
.instruction strong { display: block; font-size: 11px; letter-spacing: .07em; }
.instruction small { display: block; margin-top: 3px; color: #899493; font: 400 9px/1.25 "IBM Plex Mono", monospace; }
.seed-panel { padding: 10px 14px; display: grid; grid-template-columns: 1fr auto; align-content: center; }
.seed-panel > span { color: #899493; }
.seed-panel > strong { color: var(--cyan); font: 600 12px "IBM Plex Mono", monospace; }
.seed-panel button { grid-column: 2; grid-row: 1 / span 2; padding: 0 12px; margin-left: 12px; }

dialog { border: 0; padding: 0; background: transparent; color: var(--ink); max-width: none; max-height: none; }
dialog::backdrop { background: #040708dc; backdrop-filter: blur(5px); }
.briefing-card, .result-card { position: relative; width: min(570px, calc(100vw - 28px)); max-height: calc(100dvh - 30px); overflow: auto; padding: clamp(25px, 5vw, 48px); background: var(--paper); border-top: 9px solid var(--orange); box-shadow: 18px 18px 0 #f05a3630; }
.dialog-x { position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border: 0; background: transparent; font-size: 26px; cursor: pointer; }
.briefing-symbol { margin: 22px 0 18px; width: 94px; height: 54px; display: flex; gap: 3px; align-items: stretch; }
.briefing-symbol span { display: grid; place-items: center; width: 54px; color: white; background: var(--orange); font: 700 32px "IBM Plex Mono"; }
.briefing-symbol i { flex: 1; background: var(--ink); }
.briefing-symbol i:nth-of-type(2) { height: 72%; }
.briefing-symbol i:nth-of-type(3) { height: 44%; }
.briefing-card h2, .result-card h2 { margin: 0; font-size: clamp(22px, 5vw, 38px); line-height: 1.02; letter-spacing: -.035em; }
.bang { margin: 4px 0 10px; color: var(--orange); font: 700 clamp(44px, 12vw, 78px)/.95 "Space Grotesk"; letter-spacing: -.05em; }
.lead { max-width: 450px; margin: 0; color: #565d5b; font-size: 14px; line-height: 1.45; }
.briefing-card ol { list-style: none; padding: 0; margin: 23px 0; border-top: 1px solid #b8b9b2; }
.briefing-card li { display: flex; gap: 13px; padding: 10px 0; border-bottom: 1px solid #c5c5be; }
.briefing-card li > span { color: var(--orange); font: 600 11px "IBM Plex Mono"; }
.briefing-card li p { margin: 0; font-size: 12px; }
.primary-button, .secondary-button { min-height: 48px; padding: 0 18px; border: 1px solid var(--ink); cursor: pointer; font: 700 11px "IBM Plex Mono"; letter-spacing: .12em; }
.primary-button { color: var(--paper); background: var(--ink); }
.primary-button:hover { background: var(--orange); border-color: var(--orange); }
.secondary-button { color: var(--ink); background: transparent; }
.secondary-button:hover { background: #d7d4ca; }
.briefing-card .primary-button { width: 100%; }
.briefing-card > small { display: block; margin-top: 12px; text-align: center; color: #767b78; font: 500 9px "IBM Plex Mono"; }

.threat-card { border-top-color: #76b85f; box-shadow: 18px 18px 0 #76b85f2b; }
.alien-portrait { width: 98px; height: 72px; margin: 20px 0 18px; display: flex; align-items: center; justify-content: center; gap: 5px; background: #192220; }
.alien-portrait > span { position: relative; width: 45px; height: 50px; display: block; background: #7fbe68; border-radius: 48% 48% 54% 54% / 38% 38% 65% 65%; clip-path: polygon(20% 0, 80% 0, 100% 42%, 76% 90%, 50% 100%, 24% 90%, 0 42%); }
.alien-portrait > span b { position: absolute; top: 19px; width: 10px; height: 6px; background: #14201b; border-radius: 60% 15%; transform: rotate(12deg); }
.alien-portrait > span b:first-child { left: 7px; }
.alien-portrait > span b:last-child { right: 7px; transform: rotate(-12deg); }
.alien-portrait > i { width: 8px; height: 35px; background: var(--orange); }
.alien-portrait > i:last-child { height: 20px; background: var(--cyan); }
.threat-card h2 { margin-bottom: 10px; }
.containment-note { margin: -10px 0 20px; padding: 10px; color: #35552f; background: #dce8d5; border-left: 4px solid #76b85f; font: 600 10px/1.4 "IBM Plex Mono", monospace; }
.threat-card .primary-button { width: 100%; background: #263b2b; border-color: #263b2b; }
.threat-card .primary-button:hover { background: #5a9448; border-color: #5a9448; }

.result-card { width: min(520px, calc(100vw - 28px)); text-align: center; }
.result-card h2 { margin-top: 18px; font-size: clamp(38px, 8vw, 64px); }
.result-score { margin: 12px 0 0; color: var(--orange); font: 700 clamp(30px, 7vw, 48px) "IBM Plex Mono"; }
.result-copy { margin: 4px 0 22px; letter-spacing: .12em; font-size: 11px; }
.result-card dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); margin: 0 0 24px; border-block: 1px solid #b8b9b2; }
.result-card dl div { padding: 12px 5px; border-right: 1px solid #b8b9b2; }
.result-card dl div:last-child { border-right: 0; }
.result-card dt { color: #707673; font: 500 8px "IBM Plex Mono"; letter-spacing: .1em; }
.result-card dd { margin: 5px 0 0; font-size: 20px; font-weight: 700; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@keyframes alarm-flash { 0%, 100% { opacity: 0; } 50% { opacity: .17; } }
@keyframes ship-shake { 0% { transform: translate(0); } 25% { transform: translate(1px, -1px); } 75% { transform: translate(-1px, 1px); } }

@media (max-width: 760px) {
  .game-shell { grid-template-rows: auto auto minmax(360px, 1fr) auto; }
  .masthead { min-height: 58px; }
  .identity-mark { width: 34px; height: 34px; padding: 5px; }
  .identity p { display: none; }
  .identity h1 { font-size: 19px; }
  .utility-button { min-height: 30px; }
  .hud { grid-template-columns: 1.2fr .8fr auto; }
  .hud-block { min-height: 62px; padding: 8px 10px; }
  .hud-block strong { font-size: 20px; }
  .hud-block small { display: none; }
  .pod-readout { grid-column: 1 / -1; grid-row: 2; min-height: 42px; display: flex; align-items: center; gap: 15px; border-top: 1px solid var(--line); }
  .pod-readout > span { margin: 0; }
  .hud-actions { padding: 6px; }
  .icon-button { width: 30px; height: 30px; }
  .control-deck { grid-template-columns: 1fr 1fr; }
  .instruction { padding: 9px; gap: 7px; }
  .instruction-number { font-size: 15px; }
  .instruction strong { font-size: 9px; }
  .instruction small { display: none; }
  .seed-panel { grid-column: 1 / -1; min-height: 48px; border-top: 1px solid #394446; }
}

@media (max-width: 430px) {
  .game-shell { grid-template-rows: auto auto minmax(355px, 1fr) auto; }
  .hud { grid-template-columns: 1fr .72fr auto; }
  .reactor-block { min-width: 0; }
  .reactor-block > span { font-size: 7px; }
  .hud-actions .icon-button:first-child { display: none; }
  .pod-chip { min-width: 48px; }
  .control-deck { min-height: 98px; }
  .briefing-card, .result-card { padding: 25px 22px; }
}

@media (pointer: coarse) {
  html, body { height: 100%; overflow: hidden; }
  .game-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }
  .playfield-wrap {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }
  .playfield-wrap::-webkit-scrollbar { display: none; }
  #game-canvas {
    width: max(100%, 680px);
    height: max(100%, 500px);
    min-width: 680px;
    min-height: 500px;
    touch-action: pan-x pan-y;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 650px) {
  .masthead { min-height: 46px; padding-block: 5px; }
  .identity p { display: none; }
  .identity-mark { width: 32px; height: 32px; padding: 4px; }
  .identity h1 { font-size: 18px; }
  .hud-block { min-height: 54px; padding-block: 7px; }
  .hud-block small { display: none; }
  .control-deck { min-height: 50px; }
  .instruction { padding-block: 7px; }
  .instruction small { display: none; }
  .seed-panel { padding-block: 6px; }
}

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