/* STAR IMPACT - UI read from the reference sheet.
   Palette: deep space #05060f to #0b1024, panels #0d1730/#101a33 on #2a4a7a/#35558c,
   buttons blue #16294d/#4a7ac0 and green #1c7a45/#56e08a, gold #f5c542/#d99b1f,
   magenta #ff3fa4, cyan #35d0ff, red #e8323c, health #3fd07a/#2aa85f.
   Shapes: near-square corners (2-4px), 2px lighter border, top-edge bevel, dark fill. */
@font-face {
  font-family: 'Press Start 2P';
  src: url('fonts/PressStart2P.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'VT323';
  src: url('fonts/VT323.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg0: #05060f;
  --bg1: #0b1024;
  --nebula1: #2a1745;
  --nebula2: #3a1f5c;
  --panel: #0d1730;
  --panel2: #101a33;
  --border: #2a4a7a;
  --border2: #35558c;
  --btn: #16294d;
  --btnb: #4a7ac0;
  --green: #1c7a45;
  --greenb: #56e08a;
  --gold: #f5c542;
  --gold2: #ffd24a;
  --golddeep: #d99b1f;
  --magenta: #ff3fa4;
  --cyan: #35d0ff;
  --red: #e8323c;
  --hp: #3fd07a;
  --hp2: #2aa85f;
  --text: #ffffff;
  --dim: #8fa6c8;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg0);
  color: var(--text);
  font-family: 'VT323', monospace;
  font-size: 18px;
  user-select: none;
  touch-action: none;
}
#app { position: fixed; inset: 0; }
#stage {
  position: absolute; inset: 0;
  overflow: hidden;
  background: radial-gradient(circle at 62% 30%, var(--nebula1) 0%, var(--bg1) 55%, var(--bg0) 100%);
}

/* the game surface */
#game {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--bg0);
  box-shadow: 0 0 0 2px #0e1c3a;
}
.crt {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0.16) 0 1px, rgba(0,0,0,0) 1px 3px);
  opacity: .28;
  mix-blend-mode: multiply;
}
.crt.off { display: none; }

/* ---------- screens ---------- */
#screens { position: absolute; inset: 0; pointer-events: none; z-index: 8; }
.screen {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  pointer-events: auto;
  overflow: auto;
}
.screen.active { display: flex; }
.screen::before {
  content: ''; position: absolute; inset: 0;
  background: rgba(3, 5, 15, 0.8);
}
#scr-menu::before { background: rgba(3, 5, 15, 0.45); }
#scr-menu .panel { width: min(430px, 94%); }
.panel {
  position: relative;
  width: min(560px, 94%);
  max-height: 96%;
  overflow: auto;
  background: linear-gradient(180deg, var(--panel2) 0%, var(--panel) 100%);
  border: 2px solid var(--border2);
  border-radius: 3px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.07), inset 0 0 0 4px rgba(6,10,22,.5);
  padding: 16px 16px 16px;
  display: flex; flex-direction: column; gap: 12px;
  align-items: stretch;
  text-align: center;
}
.panel-narrow { width: min(340px, 92%); }
.panel::after {
  content: ''; position: absolute; inset: 4px;
  border: 1px solid rgba(53,208,255,.12);
  pointer-events: none;
}
.title {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px; line-height: 1.5;
  color: var(--text);
  text-shadow: 2px 2px 0 #0a1024;
  letter-spacing: 1px;
}
.title.danger {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(22px, 6vw, 34px);
  line-height: 1.3;
  background: linear-gradient(180deg, #ff9a44 0%, #e8323c 52%, #a81c26 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(3px 0 0 #2a0a0c) drop-shadow(-3px 0 0 #2a0a0c) drop-shadow(0 3px 0 #2a0a0c) drop-shadow(0 -3px 0 #2a0a0c);
}
.title.gold {
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--golddeep), 2px 2px 0 #6a4a08;
}
.flash-pulse { animation: pulse 1s steps(2, end) infinite; }
@keyframes pulse { 50% { filter: brightness(1.3); } }
.trophy { color: var(--gold); }
.trophy-ico { width: 15px; height: auto; image-rendering: pixelated; vertical-align: middle; margin-right: 3px; }
.big-trophy { align-self: center; }
.head-row { display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ---------- logo: one wide chrome wordmark, rocket and stars above ---------- */
.logo { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; margin-top: 2px; }
.logo-flank { display: flex; align-items: flex-end; gap: 8px; }
.logo-star { width: 14px; height: 12px; image-rendering: pixelated; }
.logo-rocket { width: 30px; height: 42px; image-rendering: pixelated; image-rendering: crisp-edges; }
.logo-text {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(19px, 5.6vw, 35px);
  line-height: 1;
  letter-spacing: 3px;
  white-space: nowrap;
  padding: 3px 4px 5px;
  background: linear-gradient(180deg,
    #ffffff 0%, #e8effc 10%, #9fb0cf 24%, #f7fAff 34%,
    #dbe6f7 42%, #ffffff 50%, #8b9cbb 60%, #cfdbf0 72%,
    #5e6c8c 88%, #39435c 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(2px 3px 0 #05060f) drop-shadow(-1px -1px 0 #2a3350);
}
.tagline {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px; color: #cfe0ff;
  letter-spacing: 2px; text-shadow: 1px 1px 0 #05060f;
}
.brand {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px; color: var(--dim);
  letter-spacing: 2px; margin-top: 3px;
}

/* ---------- buttons ---------- */
.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: #dce9ff;
  background: linear-gradient(180deg, #1d3560 0%, var(--btn) 55%, #101f3d 100%);
  border: 2px solid var(--btnb);
  border-radius: 3px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.12), 0 3px 0 rgba(0,0,0,.4);
  padding: 9px 14px;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.btn:hover, .btn:focus-visible {
  border-color: #7fb0f0;
  color: #ffffff;
  outline: none;
}
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn:active { transform: translateY(2px); box-shadow: inset 0 2px 0 rgba(255,255,255,.08); }
.btn:disabled, .btn.disabled {
  color: #4a5a7a; border-color: #24406e;
  background: linear-gradient(180deg, #101f3d 0%, #0b1528 100%);
  box-shadow: none; cursor: not-allowed; transform: none;
}
.btn-primary {
  color: #eafff2;
  background: linear-gradient(180deg, #25995a 0%, var(--green) 58%, #146034 100%);
  border-color: var(--greenb);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.18), 0 3px 0 rgba(0,0,0,.4);
}
.btn-primary:hover, .btn-primary:focus-visible { border-color: #9dffbe; }
.btn-danger { border-color: var(--red); color: #ffd9df; }
.btn-small { font-size: 9px; padding: 8px 10px; width: auto; align-self: center; }
.menu-buttons { display: flex; flex-direction: column; gap: 9px; width: min(252px, 100%); align-self: center; }
.menu-buttons .btn { min-height: 34px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn-row .btn { flex: 1 1 40%; }
.hidden { display: none !important; }

/* ---------- high score plate ---------- */
.hs-panel {
  border: 2px solid var(--border2);
  background: linear-gradient(180deg, #121b36 0%, #0b1328 100%);
  border-radius: 3px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.06);
  padding: 9px 12px;
  display: flex; align-items: center; gap: 10px;
  width: min(252px, 100%); align-self: center; cursor: pointer; text-align: left;
  font-family: 'Press Start 2P', monospace;
}
.hs-panel:hover, .hs-panel:focus-visible { border-color: var(--gold); outline: none; }
.hs-trophy { flex: 0 0 auto; }
.hs-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.hs-title { font-size: 10px; color: var(--gold); letter-spacing: 1px; }
.hs-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hs-name { color: #ffffff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.hs-score { color: var(--gold); font-size: 12px; }
.version { align-self: flex-end; font-family: 'Press Start 2P', monospace; font-size: 8px; color: var(--dim); letter-spacing: 1px; margin-top: 2px; }
.btn-play { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; }
.play-glyph { width: 12px; height: 12px; image-rendering: pixelated; }
.caption { font-family: 'Press Start 2P', monospace; font-size: 8px; line-height: 1.9; color: var(--dim); letter-spacing: 1px; }
.caption.small { font-size: 8px; margin-top: -4px; }
.plate {
  border: 2px solid #6a5a14; background: linear-gradient(180deg, #1a1606 0%, #0d0b04 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.06);
  padding: 12px; display: flex; flex-direction: column; gap: 6px; align-items: center;
  font-family: 'Press Start 2P', monospace;
}
.plate-name { color: #ffffff; font-size: 15px; }
.plate-score { color: var(--gold); font-size: 17px; }
.name-input.underscore { background: #0a1226; border: none; border-bottom: 3px solid var(--cyan); box-shadow: none; }
.name-input.underscore:focus { border-bottom-color: var(--gold); box-shadow: none; }

/* ---------- how to play ---------- */
.cols { display: flex; gap: 12px; text-align: left; flex-wrap: wrap; align-items: flex-start; }
.col { flex: 1 1 210px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.sub { font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--cyan); }
.keyrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.keycluster { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.keyline { display: flex; gap: 4px; }
.key {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 6px;
  border: 2px solid var(--btnb); background: var(--btn); color: #eaf2ff;
  border-radius: 4px; font-family: 'Press Start 2P', monospace; font-size: 10px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.12);
}
.key.wide { min-width: 86px; }
.keylbl { font-family: 'Press Start 2P', monospace; font-size: 8px; color: var(--dim); line-height: 1.5; }
.boxed { border: 2px solid var(--border2); border-radius: 3px; padding: 10px; background: rgba(9,16,34,.6); }
.mobrow { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.mob-joy { position: relative; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--btnb); background: var(--panel); flex: 0 0 auto; }
.mob-joy i { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--cyan); opacity: .8; }
.mob-fire { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; background: var(--red); border: 2px solid #ff9a9a; color: #fff; font-family: 'Press Start 2P', monospace; font-size: 6px; flex: 0 0 auto; }
.mob-spec { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; background: var(--btn); border: 2px solid var(--btnb); color: #dce9ff; font-family: 'Press Start 2P', monospace; font-size: 12px; flex: 0 0 auto; }
.asset-rows { display: flex; flex-direction: column; gap: 10px; }
.asset-block { border: 2px solid var(--border2); border-radius: 3px; padding: 8px 10px; background: rgba(9,16,34,.55); text-align: left; }
.asset-block .sub { margin-bottom: 7px; }
.pulist { display: flex; flex-wrap: wrap; gap: 6px; }
.pu-item { display: flex; align-items: center; gap: 6px; font-family: 'Press Start 2P', monospace; font-size: 8px; color: #ffffff; border: 1px solid var(--border); border-radius: 3px; padding: 4px 6px; background: #0a1330; }
.pu-item canvas { image-rendering: pixelated; width: auto; height: 22px; }
.pu-item canvas.boss-ico { height: 46px; }

/* ---------- leaderboard ---------- */
.board-status {
  font-family: 'Press Start 2P', monospace; font-size: 8px; letter-spacing: 1px;
  color: var(--dim); text-align: center; margin-top: -4px; line-height: 1.6;
}
.board-status.online { color: var(--greenb); }
.board-status.local { color: var(--cyan); }
.board-status.loading { color: var(--dim); animation: boardpulse 1s steps(2, end) infinite; }
@keyframes boardpulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.board { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.board-row {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center;
  font-family: 'Press Start 2P', monospace; font-size: 11px;
  border: 1px solid var(--border); border-radius: 3px; background: #0a1330; padding: 8px 10px;
}
.board-row .rk { color: var(--cyan); }
.board-row .nm { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.board-row .nm .who { color: #ffffff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .bd-meta { font-size: 8px; color: var(--dim); letter-spacing: .5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .sc { color: var(--gold); text-align: right; }
.board-row.top1 { border-color: var(--gold); }
.board-row.top1 .rk { color: var(--gold); }
.board-row.mine { border-color: var(--greenb); }
.board-empty { color: var(--dim); font-family: 'Press Start 2P', monospace; font-size: 10px; padding: 18px 0; }
.board-edit { display: flex; flex-direction: column; gap: 8px; }
.board-edit .name-input { font-size: 13px; padding: 9px; letter-spacing: 2px; }
.board-actions .btn { flex: 1 1 100%; }

/* ---------- settings ---------- */
.setting { display: flex; align-items: center; gap: 10px; }
.setting label { font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--dim); flex: 1; text-align: left; }
.setting .val { font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--text); width: 40px; text-align: right; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 140px; height: 12px; background: var(--btn); border: 2px solid var(--btnb); border-radius: 7px; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--cyan); border: 2px solid #eaf2ff; margin-top: -4px;
}
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--cyan); border: 2px solid #eaf2ff; }
.toggle {
  position: relative; width: 76px; height: 30px; border-radius: 15px;
  border: 2px solid var(--border); background: var(--btn); color: var(--dim);
  font-family: 'Press Start 2P', monospace; font-size: 8px; cursor: pointer;
  text-align: right; padding-right: 9px;
}
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #dfe9ff; }
.toggle.on { background: var(--green); border-color: var(--greenb); color: #eafff2; text-align: left; padding-right: 0; padding-left: 9px; }
.toggle.on::after { left: auto; right: 2px; }
.toggle:active { transform: translateY(1px); }

/* ---------- stats ---------- */
.stats { display: flex; flex-direction: column; gap: 8px; border: 2px solid var(--border2); border-radius: 3px; padding: 10px 12px; background: rgba(9,16,34,.55); }
.stat { display: flex; justify-content: space-between; font-family: 'Press Start 2P', monospace; font-size: 10px; border-bottom: 1px dashed #24406e; padding-bottom: 6px; }
.stat:last-child { border-bottom: none; padding-bottom: 0; }
.stat .k { color: var(--dim); }
.stat .v { color: #ffffff; }
.stat .v.gold { color: var(--gold); }
.bigscore { font-family: 'Press Start 2P', monospace; font-size: 26px; color: var(--gold); text-shadow: 3px 3px 0 var(--golddeep); }
.entry-label { font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--dim); letter-spacing: 1px; }
.name-input {
  font-family: 'Press Start 2P', monospace; font-size: 15px; text-align: center; letter-spacing: 3px;
  background: #0a1226; color: #ffffff; border: 2px solid var(--border2);
  border-radius: 3px; padding: 11px; width: 100%; text-transform: uppercase;
}
.name-input:focus { outline: none; border-color: var(--cyan); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.chips button {
  font-family: 'Press Start 2P', monospace; font-size: 10px; width: 30px; height: 30px;
  background: #0a1330; border: 1px solid var(--border); border-radius: 3px; color: var(--text); cursor: pointer;
}
.chips button:hover { border-color: var(--cyan); color: #fff; }
.owner-note { font-family: 'Press Start 2P', monospace; font-size: 9px; color: var(--greenb); line-height: 1.6; }
.confetti-cv { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- tutorial hint ---------- */
#tutorial-hint {
  position: absolute; left: 50%; bottom: 14%;
  transform: translateX(-50%);
  font-family: 'Press Start 2P', monospace; font-size: 10px; text-align: center; line-height: 2;
  color: #ffffff; background: rgba(5,6,15,.78); border: 2px solid var(--border2);
  border-radius: 3px; padding: 10px 14px; pointer-events: none; z-index: 6;
}
#tutorial-hint.fade { opacity: 0; transition: opacity .6s; }
#tutorial-hint b { color: var(--cyan); }

/* ---------- touch controls ---------- */
.touch-ui { display: none; position: absolute; inset: 0; z-index: 5; pointer-events: none; }
body.touch.ingame .touch-ui { display: block; }
#joystick {
  position: absolute; left: calc(16px + env(safe-area-inset-left)); bottom: calc(16px + env(safe-area-inset-bottom));
  width: 132px; height: 132px; border-radius: 50%;
  background: rgba(13,23,48,.45); border: 3px solid rgba(74,122,192,.55);
  pointer-events: auto; touch-action: none;
}
#joystick.active { border-color: rgba(53,208,255,.85); }
#stick {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%; background: rgba(53,208,255,.30); border: 2px solid rgba(191,230,255,.8);
}
.touch-right { position: absolute; inset: 0; pointer-events: none; }
.tbtn {
  pointer-events: auto; touch-action: none;
  font-family: 'Press Start 2P', monospace; color: #ffffff;
  display: flex; align-items: center; justify-content: center; position: absolute;
}
#btn-fire {
  right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 112px; height: 112px; border-radius: 50%; font-size: 13px;
  background: var(--red); border: 3px solid #ff9a9a; color: #ffffff;
}
#btn-fire:active, #btn-fire.down { background: #ff4a52; }
#btn-special {
  right: calc(38px + env(safe-area-inset-right)); bottom: calc(146px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 50%; font-size: 20px;
  background: var(--btn); border: 3px solid var(--btnb); color: #dce9ff;
}
#btn-special:active, #btn-special.down { background: #24406e; }
#btn-special.disabled { opacity: .4; }
.tbtn-pause {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  width: 40px; height: 40px; font-size: 10px; border-radius: 6px;
  background: #ffffff; border: 2px solid #cdd8ee; color: #0d1730;
}

/* ---------- portrait phones: game sits in the upper half, thumbs own the lower half ---------- */
body.portrait #game { top: 34%; }
body.portrait .crt { top: 34%; }
body.portrait #tutorial-hint { bottom: auto; top: calc(36px + env(safe-area-inset-top)); font-size: 9px; }
body.portrait #joystick { width: 148px; height: 148px; }
body.portrait #stick { width: 62px; height: 62px; margin: -31px 0 0 -31px; }
body.portrait #btn-fire { width: 124px; height: 124px; bottom: calc(22px + env(safe-area-inset-bottom)); }
body.portrait #btn-special { width: 72px; height: 72px; bottom: calc(158px + env(safe-area-inset-bottom)); }

/* ---------- small screens ---------- */
@media (max-width: 620px), (max-height: 520px) {
  body { font-size: 16px; }
  .panel { padding: 12px; gap: 9px; width: min(520px, 96%); }
  .title { font-size: 13px; }
  .btn { font-size: 10px; padding: 8px 10px; }
  .bigscore { font-size: 20px; }
  .stat { font-size: 9px; }
  .board-row { font-size: 9px; }
  .board-row .bd-date { display: none; }
  input[type=range] { width: 104px; }
  .logo-text { font-size: clamp(18px, 6.6vw, 26px); }
  .name-input { font-size: 13px; }
}
@media (max-height: 420px) {
  .panel { padding: 10px; gap: 7px; }
  .title { font-size: 12px; }
  .logo-rocket { width: 24px; height: 34px; }
}
/* short landscape phones: keep the whole menu on one screen */
@media (max-height: 460px) {
  #scr-menu .panel { gap: 5px; padding: 7px 10px; }
  #scr-menu .logo-rocket { width: 22px; height: 32px; }
  #scr-menu .logo-text { font-size: clamp(15px, 4.6vh, 25px); letter-spacing: 2px; }
  #scr-menu .tagline { font-size: 8px; }
  #scr-menu .btn { padding: 6px 10px; font-size: 9px; min-height: 28px; }
  #scr-menu .hs-panel { padding: 6px 10px; }
  #scr-menu .version { font-size: 7px; }
  #scr-menu .brand { font-size: 6px; }
}
