* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  background: #0c101c;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  font-family: "Courier New", Courier, ui-monospace, monospace;
  color: #f2e2c4;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  background: #0c101c;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #070910;
}

#crt, #vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#crt {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.12;
}

#hurt {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 30, 60, 0.55) 100%);
  opacity: 0;
  transition: opacity 80ms linear;
}
#hurt.on { opacity: 1; }

#vignette {
  box-shadow: inset 0 0 140px 36px #070910, inset 0 0 48px 8px rgba(90, 42, 16, 0.35);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

.hidden { display: none !important; }

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 24px;
  overflow: auto;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.55) 0%,
    rgba(0, 0, 0, 0.12) 38%,
    rgba(0, 0, 0, 0.12) 62%,
    rgba(0, 0, 0, 0.6) 100%
  );
  pointer-events: auto;
}

h1 {
  font-size: clamp(42px, 12vw, 96px);
  letter-spacing: 0.18em;
  font-weight: 700;
  color: #f6e6cc;
  text-shadow: 0 0 16px #c45c26, 0 0 42px rgba(196, 92, 38, 0.55);
}

h2 {
  font-size: clamp(22px, 5vw, 42px);
  letter-spacing: 0.14em;
  color: #f6e6cc;
  text-shadow: 0 0 12px #c45c26;
}

.eyebrow {
  letter-spacing: 0.35em;
  font-size: 11px;
  color: #c9a227;
}

.tag {
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: #f36;
  text-shadow: 0 0 8px #f36;
}

.crawl, #brief-body, #end-body {
  max-width: 520px;
  line-height: 1.5;
  color: #9ad;
  font-size: 14px;
}

.hi { color: #c9a227; letter-spacing: 0.2em; }

.hint {
  margin-top: 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: #467;
}

button {
  pointer-events: auto;
  font-family: inherit;
  letter-spacing: 0.2em;
  color: #7fe9ff;
  background: rgba(0, 40, 50, 0.7);
  border: 1px solid #7fe9ff;
  padding: 12px 22px;
  cursor: pointer;
  text-shadow: 0 0 6px #3cf;
  box-shadow: 0 0 12px rgba(80, 220, 255, 0.25);
}

button:active { background: #7fe9ff; color: #000; }

#btn-scores {
  min-width: 180px;
  font-size: 12px;
  padding: 8px 16px;
}

#hud { display: none; }
body.playing #hud { display: block; }
body.playing #title { display: none; }

#hud-top, #hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 13px;
  letter-spacing: 0.16em;
  text-shadow: 1px 0 #f36, -1px 0 #0ff, 0 0 8px #3cf;
  pointer-events: none;
}

#hud-top { top: max(8px, env(safe-area-inset-top)); padding-right: 120px; }
#hud-bottom { bottom: max(8px, env(safe-area-inset-bottom)); }

body.touch.playing #hud-top {
  top: max(6px, env(safe-area-inset-top));
  padding: 4px 16px;
  padding-right: 120px;
  font-size: 11px;
}
body.touch.playing #hud-bottom {
  bottom: auto;
  top: max(26px, calc(env(safe-area-inset-top) + 20px));
  padding: 0 16px 4px;
  padding-right: 120px;
  font-size: 11px;
}

#reticle {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  pointer-events: none;
}
#reticle i {
  position: absolute;
  background: #7fe9ff;
  box-shadow: 0 0 6px #3cf;
}
#reticle i:nth-child(1), #reticle i:nth-child(2) {
  width: 8px; height: 2px; top: 13px;
}
#reticle i:nth-child(1) { left: 0; }
#reticle i:nth-child(2) { right: 0; }
#reticle i:nth-child(3), #reticle i:nth-child(4) {
  width: 2px; height: 8px; left: 13px;
}
#reticle i:nth-child(3) { top: 0; }
#reticle i:nth-child(4) { bottom: 0; }

#banner {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 4vw, 32px);
  letter-spacing: 0.28em;
  text-shadow: 0 0 16px #3cf;
  background: linear-gradient(to bottom, rgba(0,0,0,0.0), rgba(0,0,0,0.35), rgba(0,0,0,0.0));
}

#radio {
  position: absolute;
  left: 50%;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 72px));
  transform: translateX(-50%);
  width: min(94vw, 720px);
  z-index: 14;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(0, 8, 12, 0.72);
  border: 1px solid rgba(127, 233, 255, 0.28);
  text-shadow: 0 0 10px #3cf;
}
#radio.hidden { display: none; }
#radio.no-port { justify-content: center; text-align: center; }
#radio-port {
  width: 108px;
  height: 108px;
  object-fit: cover;
  flex: 0 0 108px;
  border: 1px solid rgba(201, 162, 39, 0.55);
  box-shadow: 0 0 12px rgba(80, 220, 255, 0.25);
  image-rendering: auto;
}
#radio.no-port #radio-port { display: none; }
#radio.close #radio-port { border-color: #f36; box-shadow: 0 0 14px rgba(255, 60, 90, 0.45); }
#radio-text { flex: 1; min-width: 0; text-align: left; }
#radio.no-port #radio-text { text-align: center; }
#radio-who {
  display: block;
  font-size: 11px;
  letter-spacing: 0.32em;
  color: #c9a227;
  margin-bottom: 4px;
}
#radio-line {
  display: block;
  font-size: clamp(13px, 2.4vw, 18px);
  letter-spacing: 0.04em;
  color: #b8f4ff;
}

#brief-stills {
  width: min(92vw, 640px);
  max-height: min(46vh, 400px);
  margin: 4px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #05080a;
  border: 1px solid rgba(201, 162, 39, 0.5);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
#brief-stills.hidden { display: none; }
#brief-still {
  display: block;
  max-width: 100%;
  max-height: min(42vh, 360px);
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
}
#brief-caption {
  margin-top: 8px;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: #c9a227;
  max-width: none;
}
#briefing {
  justify-content: flex-start;
  padding-top: max(28px, env(safe-area-inset-top));
  overflow: auto;
}
#btn-brief { min-width: 200px; margin-top: 8px; }

#attract {
  z-index: 9;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.62);
  padding: 16px;
}
#attract.hidden { display: none !important; }
#attract-card {
  width: min(92vw, 720px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#attract-card.char {
  flex-direction: row;
  align-items: stretch;
  justify-content: flex-start;
  width: min(96vw, 860px);
  gap: 18px;
}
#attract-img {
  width: 100%;
  max-height: min(62vh, 520px);
  object-fit: contain;
  border: 1px solid rgba(201, 162, 39, 0.45);
  box-shadow: 0 0 40px rgba(0, 40, 60, 0.5);
}
#attract-card.char #attract-img {
  width: 42%;
  max-height: min(70vh, 560px);
  object-fit: contain;
  object-position: left center;
  flex-shrink: 0;
}
#attract-copy {
  text-align: center;
  max-width: 560px;
}
#attract-card.char #attract-copy {
  text-align: left;
  max-width: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
@media (max-width: 560px) {
  #attract-card.char {
    flex-direction: column;
    align-items: flex-start;
  }
  #attract-card.char #attract-img {
    width: min(72vw, 280px);
    max-height: 42vh;
  }
  #attract-card.char #attract-copy { text-align: left; }
}
#attract-title {
  font-size: clamp(18px, 3.6vw, 28px);
  letter-spacing: 0.16em;
  margin: 4px 0;
}
#attract-body {
  color: #9ad;
  line-height: 1.45;
  font-size: 14px;
  white-space: pre-line;
}
#attract-hint {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  letter-spacing: 0.32em;
  font-size: 12px;
  color: #7fe9ff;
  text-shadow: 0 0 10px #3cf;
}

#hud-shields.hit {
  color: #f36;
  text-shadow: 0 0 12px #f36, 1px 0 #fff;
}

#touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
}

#joystick-zone,
#action-buttons {
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#joystick-zone {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 120px;
  height: 120px;
  border: 1px solid rgba(127, 233, 255, 0.45);
  border-radius: 50%;
  background: rgba(0, 30, 40, 0.35);
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(127, 233, 255, 0.8);
  box-shadow: 0 0 12px #3cf;
}

#action-buttons {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

#action-buttons button {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  padding: 0;
  font-size: 12px;
}

#btn-fire {
  width: 96px;
  height: 96px;
  background: rgba(80, 20, 30, 0.7);
  border-color: #f36;
  color: #f99;
}

#top-chrome {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 14;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

#top-chrome button {
  width: 48px;
  height: 44px;
  padding: 0;
  border-radius: 4px;
  font-size: 11px;
  letter-spacing: 0.12em;
}

body:not(.playing) #btn-pause { visibility: hidden; }
body.standalone #btn-fs { display: none; }

#pause {
  z-index: 16;
  gap: 10px;
  overflow: auto;
  background: radial-gradient(ellipse at center, rgba(0, 16, 24, 0.88) 0%, rgba(0, 0, 0, 0.82) 70%);
}

#pause button {
  min-width: 240px;
}

#pause .opt.on {
  background: #7fe9ff;
  color: #000;
  text-shadow: none;
}

#pause .hint {
  max-width: 420px;
  margin-top: 0;
}

#scores {
  overflow: hidden;
  gap: 8px;
}
#end {
  overflow: hidden;
  gap: 8px;
}

.score-wrap {
  width: min(420px, 92vw);
  flex: 0 0 auto;
  overflow: hidden;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(10px, 1.65vh, 13px);
  letter-spacing: 0.14em;
  line-height: 1.15;
}

.score-table th,
.score-table td {
  padding: 0.28vh 8px;
  text-align: left;
}
.score-table tr.empty td {
  color: #345;
  text-shadow: none;
}

.score-table th { color: #c9a227; }
.score-table td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
.score-table tr.hi-row td {
  color: #fff;
  text-shadow: 0 0 8px #3cf;
}

.ace-reels {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  touch-action: none;
}
.ace-reels .reel-kicker {
  letter-spacing: 0.28em;
  font-size: 11px;
  color: #c9a227;
}
.reel-row {
  display: flex;
  gap: 10px;
}
.reel {
  width: 72px;
  min-height: 118px;
  background: rgba(0, 20, 28, 0.75);
  border: 1px solid rgba(127, 233, 255, 0.35);
  color: #7fe9ff;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.reel.active {
  border-color: #c9a227;
  box-shadow: 0 0 14px rgba(201, 162, 39, 0.45);
}
.reel.locked { opacity: 0.7; }
.reel .up, .reel .dn {
  pointer-events: auto;
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font: inherit;
  font-size: 16px;
  color: #9ad;
  letter-spacing: 0;
  line-height: 1;
  text-shadow: none;
  cursor: pointer;
}
.reel .up:active, .reel .dn:active {
  background: rgba(127, 233, 255, 0.18);
  color: #fff;
}
.reel .ch {
  font-size: 28px;
  letter-spacing: 0.08em;
  line-height: 1.2;
  pointer-events: none;
  padding: 4px 0;
  text-align: center;
}
.reel-nav {
  display: flex;
  gap: 8px;
}
.ace-reels.is-done .reel {
  pointer-events: none;
  cursor: default;
  opacity: 1;
}
.ace-reels.is-done .reel .up,
.ace-reels.is-done .reel .dn {
  visibility: hidden;
}
.reel-nav button,
#reel-confirm {
  min-width: 120px;
}

#joystick-zone,
#action-buttons,
#btn-pause,
#btn-fs,
#btn-start,
#btn-again,
#btn-resume {
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#rotate-hint {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  background: #000;
  letter-spacing: 0.3em;
  color: #7fe9ff;
}

.desktop-only { display: block; }
.mobile-only { display: none; }

body.touch .desktop-only { display: none; }
body.touch .mobile-only { display: block; }
body.touch.playing #touch-controls,
body.touch.scoring #touch-controls { display: block; }
body:not(.playing):not(.scoring) #touch-controls { display: none; }
body.touch.scoring #btn-boost,
body.touch.scoring #btn-roll { visibility: hidden; }

/* Combat/brief radio sits in the bottom eighth, scaled to that band. */
body.touch #radio {
  left: 50%;
  right: auto;
  bottom: max(4px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(52vw, 420px);
  max-height: 12.5vh;
  padding: 3px 8px;
  gap: 8px;
  align-items: center;
  background: rgba(0, 8, 12, 0.84);
}
body.touch.playing #radio {
  width: min(46vw, 360px);
}
body.touch #radio-port {
  width: 10.5vh;
  height: 10.5vh;
  flex: 0 0 10.5vh;
  max-width: 48px;
  max-height: 48px;
}
body.touch #radio-who {
  font-size: 8px;
  letter-spacing: 0.22em;
  margin-bottom: 0;
}
body.touch #radio-line {
  font-size: clamp(10px, 2.5vh, 13px);
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
body.touch #briefing {
  padding-bottom: calc(12.5vh + 20px);
}
body.touch.playing #banner {
  align-items: flex-start;
  padding-top: max(58px, calc(env(safe-area-inset-top) + 50px));
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent 60%);
  font-size: clamp(14px, 3.2vh, 22px);
}

@media (orientation: landscape) and (max-height: 480px) {
  body.touch #end {
    padding: 8px 12px;
    gap: 4px;
    justify-content: flex-start;
  }
  body.touch #end h2 { font-size: clamp(16px, 4.6vh, 28px); }
  body.touch #end-body { display: none; }
  body.touch .score-table { font-size: 10px; }
  body.touch .reel {
    width: 56px;
    min-height: 96px;
  }
  body.touch .reel .ch { font-size: 22px; }
  body.touch .reel .up,
  body.touch .reel .dn { min-height: 28px; font-size: 14px; }
}

@media (orientation: portrait) and (max-width: 900px) {
  body.touch #rotate-hint { display: flex; }
}
@media (orientation: landscape) {
  #rotate-hint { display: none !important; }
}

#cheat-flash {
  position: absolute;
  z-index: 19;
  top: 14%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  letter-spacing: 0.42em;
  font-size: clamp(20px, 5vw, 36px);
  color: #f6e6cc;
  text-shadow: 0 0 16px #c45c26, 0 0 42px rgba(196, 92, 38, 0.55);
}
#cheats {
  z-index: 18;
  gap: 8px;
  overflow: auto;
  background: radial-gradient(ellipse at center, rgba(16, 8, 4, 0.92) 0%, rgba(0, 0, 0, 0.86) 70%);
}
#cheats h2 { text-shadow: 0 0 12px #c45c26; }
#cheats button {
  min-width: min(440px, 92vw);
  font-size: 12px;
  padding: 8px 14px;
}
#cheats button.sel {
  border-color: #c45c26;
  color: #f6e6cc;
  box-shadow: 0 0 14px rgba(196, 92, 38, 0.55);
}
#cheats button.on {
  background: #c45c26;
  color: #0c101c;
  text-shadow: none;
}
#cheats .hint { max-width: 480px; margin-top: 0; }
