/* Decathlon Galaxy: Asteroid Run — Sports Planet palette: deep navy + cyan */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #04070f;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color: #eaf6ff; touch-action: none; user-select: none; -webkit-user-select: none;
}
#game-wrap { position: fixed; inset: 0; }
#game-canvas { display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(8px, env(safe-area-inset-top)) 10px 0 10px; gap: 8px;
}
.hud-box { min-width: 86px; }
.hud-center { text-align: center; flex: 1; }
.hud-right { text-align: right; min-width: 86px; }
.hud-label { font-size: 10px; letter-spacing: 2px; color: #7fd8ff; font-weight: 700; }
.hud-value { font-size: 22px; font-weight: 800; line-height: 1.05; text-shadow: 0 0 12px rgba(34,211,238,.65); }
.hud-unit { font-size: 12px; color: #7fd8ff; margin-left: 3px; }
.hud-sub { font-size: 10px; letter-spacing: 1.5px; color: #bfeaff; opacity: .85; }
.hud-btn {
  pointer-events: auto; background: rgba(10,28,51,.7); color: #eaf6ff;
  border: 1px solid rgba(127,216,255,.5); border-radius: 8px;
  width: 38px; height: 38px; font-size: 15px; cursor: pointer; margin-left: 4px;
}
.hud-btn:active { background: rgba(34,211,238,.35); }
.hud-btn-wide { width: auto; padding: 0 9px; font-size: 11px; font-weight: 800; letter-spacing: 1px; }
#btn-exit-cruise {
  position: absolute; top: 128px; right: 10px; pointer-events: auto;
  background: rgba(216,165,46,.85); color: #23180a; border: 1px solid #ffe9a8;
  border-radius: 9px; padding: 9px 13px; font-size: 12px; font-weight: 900; letter-spacing: 1px;
  cursor: pointer; box-shadow: 0 0 14px rgba(216,165,46,.5);
}
.cruise-block { margin-top: 14px; }
.cruise-btn {
  background: rgba(10,28,51,.8); color: #ffe9a8; border: 1px solid rgba(216,165,46,.75);
  font-size: 14px; font-weight: 900; letter-spacing: 1.5px; padding: 11px 22px; border-radius: 12px;
  cursor: pointer; min-width: 240px;
}
.cruise-btn:active { transform: scale(.97); }
.cruise-hint { margin-top: 6px; font-size: 12px; color: #bfeaff; font-style: italic; }

#hud-bars {
  position: absolute; top: 74px; left: 10px; width: min(210px, 44vw);
  background: rgba(4,10,24,.45); border-radius: 8px; padding: 6px 8px;
}
.bar-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.bar-label { font-size: 9px; letter-spacing: 1.5px; width: 44px; color: #bfeaff; font-weight: 700; }
.bar-track { flex: 1; height: 9px; background: rgba(255,255,255,.14); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; width: 100%; border-radius: 5px; transition: width .12s linear; }
.bar-shield { background: linear-gradient(90deg, #1899c9, #4be1ff); box-shadow: 0 0 8px #22d3ee; }
.bar-shield.low { background: linear-gradient(90deg, #c92a2a, #ff7847); box-shadow: 0 0 8px #ff5030; }
.bar-hull { background: linear-gradient(90deg, #1fae5f, #7dff9a); }
.bar-hull.low { background: linear-gradient(90deg, #c92a2a, #ff7847); }
.bar-charge { background: linear-gradient(90deg, #b8860b, #ffe14b); width: 0%; }

#hud-bottom { position: absolute; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom)); display: flex; justify-content: center; }
#weapon-bar { display: flex; gap: 6px; pointer-events: auto; }
.weapon-btn {
  background: rgba(10,28,51,.72); color: #cfeeff; border: 1px solid rgba(127,216,255,.4);
  border-radius: 9px; padding: 8px 10px; font-size: 11px; font-weight: 800; letter-spacing: .5px;
  cursor: pointer; min-width: 64px;
}
.weapon-btn .wkey {
  display: inline-block; background: rgba(127,216,255,.25); border-radius: 4px;
  padding: 0 4px; margin-right: 4px; font-size: 10px;
}
.weapon-btn.active { background: rgba(34,211,238,.85); color: #04263a; border-color: #aef; box-shadow: 0 0 14px rgba(34,211,238,.7); }
.weapon-btn:active { transform: scale(.96); }

#banner {
  position: absolute; top: 30%; left: 0; right: 0; text-align: center;
  font-size: clamp(20px, 6vw, 38px); font-weight: 900; letter-spacing: 3px;
  color: #fff; text-shadow: 0 0 22px #22d3ee, 0 0 44px rgba(34,211,238,.5);
  pointer-events: none;
}
/* comet approach warning — positioned per-frame at the comet's bearing */
#comet-warn {
  position: absolute; transform: translate(-50%, -50%); z-index: 6;
  color: #ffc44d; font-size: 13px; font-weight: 900; letter-spacing: 1.5px;
  text-shadow: 0 0 10px rgba(255,160,40,.85), 0 0 22px rgba(255,120,20,.5);
  pointer-events: none; white-space: nowrap;
  animation: cometPulse .45s ease-in-out infinite alternate;
}
@keyframes cometPulse { from { opacity: .5; } to { opacity: 1; } }
#btn-fire {
  position: absolute; right: 16px; bottom: 86px; width: 84px; height: 84px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(120,230,255,.95), rgba(14,116,164,.9));
  border: 2px solid rgba(200,245,255,.8); color: #fff; font-weight: 900; letter-spacing: 1px;
  font-size: 15px; pointer-events: auto; box-shadow: 0 0 22px rgba(34,211,238,.55); cursor: pointer;
}
#btn-fire:active { transform: scale(.94); }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 10; overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 120%, rgba(14,60,110,.55), rgba(4,7,15,.88) 65%);
  padding: 18px 14px;
}
.screen-inner { max-width: 520px; width: 100%; text-align: center; margin: auto; }
.game-kicker { font-size: 11px; letter-spacing: 3.5px; color: #7fd8ff; font-weight: 800; }
.game-title {
  font-size: clamp(44px, 13vw, 76px); font-weight: 900; line-height: .95; letter-spacing: 2px;
  margin: 10px 0 12px; color: #fff;
  text-shadow: 0 0 18px rgba(34,211,238,.8), 0 0 60px rgba(34,211,238,.45), 0 4px 0 #0a3a5c;
}
.game-title.small { font-size: clamp(32px, 9vw, 52px); }
.game-tag { font-size: 14px; line-height: 1.5; color: #d5efff; margin-bottom: 14px; }
.how-to {
  text-align: left; background: rgba(10,28,51,.65); border: 1px solid rgba(127,216,255,.35);
  border-radius: 12px; padding: 12px 14px; font-size: 12.5px; line-height: 1.45; color: #cfeeff;
  display: grid; gap: 7px; margin-bottom: 16px;
}
.how-to strong { color: #7fd8ff; letter-spacing: 1px; }
.big-btn {
  background: linear-gradient(180deg, #38e0ff, #0e86c8); color: #fff; border: none;
  font-size: 20px; font-weight: 900; letter-spacing: 2px; padding: 15px 38px; border-radius: 14px;
  cursor: pointer; box-shadow: 0 0 26px rgba(34,211,238,.6), inset 0 1px 0 rgba(255,255,255,.5);
  min-width: 240px;
}
.big-btn:active { transform: scale(.97); }
.best-line { margin-top: 12px; font-size: 12px; letter-spacing: 1.5px; color: #bfeaff; min-height: 16px; }
.shop-link { display: inline-block; margin-top: 16px; color: #7fd8ff; font-size: 13px; font-weight: 700; text-decoration: none; border-bottom: 1px dotted #7fd8ff; }
.over-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.over-stat { background: rgba(10,28,51,.65); border: 1px solid rgba(127,216,255,.3); border-radius: 10px; padding: 10px; display: grid; gap: 2px; }
.over-label { font-size: 10px; letter-spacing: 2px; color: #7fd8ff; font-weight: 700; }
.over-value { font-size: 21px; font-weight: 900; }
.newbest { color: #ffe14b; font-weight: 900; letter-spacing: 2px; margin-bottom: 12px; text-shadow: 0 0 14px rgba(255,225,75,.7); }

@media (max-width: 480px) {
  .hud-value { font-size: 18px; }
  .weapon-btn { min-width: 56px; padding: 7px 6px; font-size: 10px; }
  #hud-bars { top: 66px; }
}

/* ---------- Run mode select (start screen) ---------- */
.mode-select { margin-bottom: 14px; }
.mode-row { display: flex; gap: 8px; justify-content: center; }
.mode-btn {
  flex: 1; max-width: 200px; background: rgba(10,28,51,.72); color: #cfeeff;
  border: 1px solid rgba(127,216,255,.4); border-radius: 10px; padding: 10px 8px;
  font-size: 13px; font-weight: 900; letter-spacing: 1.5px; cursor: pointer;
}
.mode-btn.active {
  background: rgba(216,165,46,.92); color: #23180a; border-color: #ffe9a8;
  box-shadow: 0 0 14px rgba(216,165,46,.55);
}
.mode-btn:active { transform: scale(.97); }
.mode-desc { margin-top: 7px; font-size: 12px; color: #bfeaff; font-style: italic; min-height: 15px; }

/* ---------- Safe areas (notches) in both orientations ---------- */
#hud-top {
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
#hud-bottom {
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
}
#hud-bars { left: max(10px, env(safe-area-inset-left)); }
#btn-exit-cruise { right: max(10px, env(safe-area-inset-right)); }
#btn-fire { right: max(16px, env(safe-area-inset-right)); }

/* ---------- Landscape: compact HUD, everything reachable ---------- */
@media (orientation: landscape) {
  #hud-bars { top: 62px; width: min(190px, 30vw); }
  #btn-exit-cruise { top: 62px; }
  #btn-fire { bottom: 74px; width: 72px; height: 72px; font-size: 13px; }
  #banner { top: 22%; }
  .screen { padding: 10px 14px; }
  .game-title { font-size: clamp(32px, 10vh, 58px); margin: 6px 0 8px; }
  .game-tag { font-size: 12.5px; margin-bottom: 9px; }
  .how-to { font-size: 11.5px; padding: 8px 12px; gap: 4px; margin-bottom: 10px; }
  .big-btn { padding: 11px 30px; font-size: 17px; }
  .mode-select { margin-bottom: 9px; }
  .cruise-block { margin-top: 9px; }
  .over-stats { gap: 7px; margin: 9px 0; }
}
@media (orientation: landscape) and (max-height: 430px) {
  .how-to { grid-template-columns: 1fr 1fr; column-gap: 16px; }
  .game-tag { display: none; }
  .hud-value { font-size: 17px; }
  .weapon-btn { min-width: 56px; padding: 6px 6px; font-size: 10px; }
}

/* ---------- Custom controls (Workstream C) ---------- */
:root {
  --ctlO: .9;          /* control opacity (settings slider) */
  --btnScale: 1;       /* button size (settings slider) */
  --fireTX: 0px; --fireTY: 0px;   /* FIRE button drag offset (edit layout) */
  --weapTX: 0px; --weapTY: 0px;   /* weapon bar drag offset (edit layout) */
}
/* All touch controls are semi-transparent and fade further when idle;
   the center play field is never covered by controls. */
.weapon-btn, #btn-fire, .hud-btn, #btn-exit-cruise { opacity: var(--ctlO); transition: opacity .35s ease; }
body.ctl-idle .weapon-btn, body.ctl-idle #btn-fire,
body.ctl-idle .hud-btn, body.ctl-idle #btn-exit-cruise { opacity: calc(var(--ctlO) * 0.45); }
#btn-fire {
  transform: translate(var(--fireTX), var(--fireTY)) scale(var(--btnScale));
  transform-origin: center;
}
#btn-fire:active { transform: translate(var(--fireTX), var(--fireTY)) scale(calc(var(--btnScale) * 0.94)); }
#weapon-bar {
  transform: translate(var(--weapTX), var(--weapTY)) scale(var(--btnScale));
  transform-origin: bottom center;
}
/* Left-handed layout flip */
body.lefty #btn-fire { left: max(16px, env(safe-area-inset-left)); right: auto; }
body.lefty #hud-bottom { justify-content: flex-start; padding-left: max(10px, env(safe-area-inset-left)); }
body.lefty #hud-bars { left: auto; right: max(10px, env(safe-area-inset-right)); }
body.lefty #btn-exit-cruise { right: auto; left: max(10px, env(safe-area-inset-left)); }

/* Settings panel */
#settings-screen { z-index: 20; }
.settings-link-btn {
  margin-top: 12px; background: none; border: none; color: #7fd8ff; cursor: pointer;
  font-size: 13px; font-weight: 800; letter-spacing: 2px; border-bottom: 1px dotted #7fd8ff; padding: 2px 0;
}
.settings-list {
  text-align: left; background: rgba(10,28,51,.65); border: 1px solid rgba(127,216,255,.35);
  border-radius: 12px; padding: 12px 14px; display: grid; gap: 12px; margin-bottom: 14px;
}
.set-row { display: flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 800; letter-spacing: 1px; color: #cfeeff; }
.set-row span { flex: 0 0 42%; }
.set-row input[type="range"] { flex: 1; accent-color: #22d3ee; height: 28px; }
.set-row input[type="checkbox"] { width: 24px; height: 24px; accent-color: #22d3ee; margin-left: auto; }
.set-row b { flex: 0 0 44px; text-align: right; color: #7fd8ff; }
.settings-btn {
  display: block; margin: 12px auto; background: rgba(10,28,51,.8); color: #ffb3a7;
  border: 1px solid rgba(255,120,90,.55); border-radius: 10px; padding: 9px 18px;
  font-size: 12px; font-weight: 900; letter-spacing: 1.5px; cursor: pointer;
}
#settings-screen .big-btn { margin-top: 6px; }

/* Edit-layout mode */
.hud-preview { z-index: 15 !important; }
.editable { outline: 2px dashed #ffe14b; outline-offset: 3px; cursor: grab; }
#edit-bar {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 30; display: flex; align-items: center; gap: 12px;
  background: rgba(10,28,51,.92); border: 1px solid #ffe14b; border-radius: 12px;
  padding: 8px 10px 8px 16px; font-size: 12.5px; font-weight: 700; color: #ffe9a8;
  max-width: 94vw; text-align: center;
}
#edit-bar button {
  background: #d8a52e; color: #23180a; border: none; border-radius: 8px;
  padding: 8px 16px; font-size: 13px; font-weight: 900; letter-spacing: 1px; cursor: pointer;
}
