:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --ink: #e8eef6;
  --line: rgba(232, 238, 246, 0.55);
  --panel: rgba(8, 12, 18, 0.62);
  --red: #ff3b4e;
  --cyan: #3de2ff;
  --ok: #37e08a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #05070b;
  color: var(--ink);
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  /* Nothing on this page scrolls, bounces or pops a long-press menu. */
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

#app { position: fixed; inset: 0; }

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding:
    calc(8px + var(--safe-t))
    calc(10px + var(--safe-r))
    calc(8px + var(--safe-b))
    calc(10px + var(--safe-l));
}

.top {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(180px, 1fr) minmax(150px, 230px);
  gap: 8px;
  align-items: start;
}

.card, .pill, .btn, .fire, .joy {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  backdrop-filter: blur(6px);
}

.ghost-card, .ammo-card {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  pointer-events: none;
}

.portrait {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 38%, #6a4a34 0 18%, transparent 19%),
    linear-gradient(#1b1e24, #0c0e12);
  border: 1px solid rgba(255,255,255,0.25);
}

.name, #weapon-name, .kicker {
  font-size: 12px;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.hp-track {
  width: 108px;
  height: 8px;
  border-radius: 99px;
  background: #1b2420;
  overflow: hidden;
  margin-top: 4px;
}

#hp-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #1d9a52, #6dff9a);
}

.hp-label, #ammo-text { font-size: 11px; opacity: 0.85; margin-top: 2px; }

/* Build 48: energy armor over health; the alter ego runs it red. */
.armor-track {
  width: 108px;
  height: 4px;
  border-radius: 99px;
  background: #142026;
  overflow: hidden;
  margin-top: 3px;
}
#armor-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #1a8fb8, #7ff0ff);
  box-shadow: 0 0 8px rgba(95, 228, 255, 0.6);
  transition: width 0.08s linear;
}
.armor-track.down { background: #2a1416; }
#hud.ego #armor-fill { background: linear-gradient(90deg, #b3123f, #ff6b98); box-shadow: 0 0 8px rgba(255, 45, 106, 0.7); }
#hud.ego .ghost-card { border-color: rgba(255, 45, 106, 0.75); box-shadow: 0 0 16px rgba(255, 45, 106, 0.28); }
#hud.ego .ghost-card .name { color: #ff6b98; }

#btn-emp { color: #c9f6ff; border-color: #3aa9c4; background: rgba(12, 32, 40, 0.88); }
#btn-emp.empty { opacity: 0.5; }

/* Charged shot: a ring that fills round the crosshair. */
#reticle .charge {
  --charge: 0;
  position: absolute;
  left: -15px;
  top: -15px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  opacity: 0;
  background: conic-gradient(#7ff0ff calc(var(--charge) * 360deg), rgba(255,255,255,0.12) 0);
  -webkit-mask: radial-gradient(circle, transparent 11px, #000 12px);
  mask: radial-gradient(circle, transparent 11px, #000 12px);
  transition: opacity 0.1s linear;
}
#reticle.charging .charge { opacity: 1; }
#reticle.charged .charge { background: #7ff0ff; box-shadow: 0 0 14px rgba(127, 240, 255, 0.9); }
#hud.ego #reticle .charge { background: conic-gradient(#ff6b98 calc(var(--charge) * 360deg), rgba(255,255,255,0.12) 0); }
#hud.ego #reticle.charged .charge { background: #ff6b98; box-shadow: 0 0 14px rgba(255, 45, 106, 0.9); }

/* Agency trust / street cred */
.meters { display: grid; gap: 2px; margin-top: 4px; }
.meter { display: flex; align-items: center; gap: 5px; font-size: 8px; letter-spacing: 0.14em; font-weight: 700; opacity: 0.9; }
.meter span { width: 40px; }
.meter i { display: block; width: 64px; height: 4px; border-radius: 99px; background: rgba(255,255,255,0.12); overflow: hidden; }
.meter b { display: block; height: 100%; width: 50%; transition: width 0.4s ease; }
.meter.agency b { background: linear-gradient(90deg, #2c6fd6, #7cc3ff); }
.meter.street b { background: linear-gradient(90deg, #b8322b, #ffb347); }
.meter.agency span { color: #9cc9ff; }
.meter.street span { color: #ffb37a; }
#meter-note {
  position: absolute; left: max(12px, env(safe-area-inset-left)); top: 96px;
  font-size: 10px; letter-spacing: 0.14em; font-weight: 700; color: #e9edf2;
  background: rgba(8, 10, 14, 0.7); border-left: 2px solid #ffb347; padding: 4px 8px;
  opacity: 0; pointer-events: none;
}
#meter-note.show { animation: meterNote 2.4s ease forwards; }
@keyframes meterNote { 0% { opacity: 0; transform: translateY(-4px); } 10%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.mission-card {
  text-align: center;
  padding: 8px 12px;
  pointer-events: none;
}

#objective {
  font-size: 13px;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.top-right { display: flex; justify-content: flex-end; gap: 8px; align-items: flex-start; }

.gun {
  width: 28px;
  height: 16px;
  background: linear-gradient(#d7dde6, #8d97a6);
  clip-path: polygon(0 30%, 70% 30%, 78% 0, 100% 0, 100% 100%, 78% 100%, 70% 70%, 0 70%);
}

.mid-left {
  position: absolute;
  left: calc(12px + var(--safe-l));
  top: calc(85px + var(--safe-t));
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.pill { padding: 6px 10px; font-size: 11px; letter-spacing: 0.08em; width: max-content; }

/* Crosshair: four ticks that open with weapon spread, plus a centre dot. */
#reticle {
  --gap: 6px;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  color: #fff;
  transition: opacity 0.12s linear;
}
#reticle.off { opacity: 0.25; }
#reticle.on-target { color: #ff5a64; }
#reticle.on-civ { color: #7fd0ff; }
#reticle i {
  position: absolute;
  background: currentColor;
  box-shadow: 0 0 2px rgba(0,0,0,0.9);
}
#reticle .dot { width: 2px; height: 2px; left: -1px; top: -1px; border-radius: 50%; }
#reticle .t { width: 2px; height: 8px; left: -1px; bottom: var(--gap); }
#reticle .b { width: 2px; height: 8px; left: -1px; top: var(--gap); }
#reticle .l { width: 8px; height: 2px; top: -1px; right: var(--gap); }
#reticle .r { width: 8px; height: 2px; top: -1px; left: var(--gap); }

/* Aim lock: four corners that sit on the locked target. */
#lock {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
#lock i {
  position: absolute;
  left: -19px;
  top: -19px;
  width: 38px;
  height: 38px;
  background:
    linear-gradient(#ff5a64, #ff5a64) left top / 10px 2px,
    linear-gradient(#ff5a64, #ff5a64) left top / 2px 10px,
    linear-gradient(#ff5a64, #ff5a64) right top / 10px 2px,
    linear-gradient(#ff5a64, #ff5a64) right top / 2px 10px,
    linear-gradient(#ff5a64, #ff5a64) left bottom / 10px 2px,
    linear-gradient(#ff5a64, #ff5a64) left bottom / 2px 10px,
    linear-gradient(#ff5a64, #ff5a64) right bottom / 10px 2px,
    linear-gradient(#ff5a64, #ff5a64) right bottom / 2px 10px;
  background-repeat: no-repeat;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.9));
  animation: lock-in 0.16s ease-out;
}
@keyframes lock-in {
  from { transform: scale(1.9) rotate(45deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* Hit confirm: an X that snaps in on every round that lands. */
#hitmarker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  pointer-events: none;
  opacity: 0;
  color: #fff;
}
#hitmarker.crit { color: #ffd34d; }
#hitmarker.kill { color: #ff4350; }
#hitmarker::before, #hitmarker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  margin-left: -1px;
  background: linear-gradient(currentColor 0 32%, transparent 32% 68%, currentColor 68%);
  box-shadow: 0 0 3px rgba(0,0,0,0.8);
}
#hitmarker::before { transform: rotate(45deg); }
#hitmarker::after { transform: rotate(-45deg); }
#hitmarker.show { animation: hit-pop 0.24s ease-out; }
#hitmarker.kill.show { animation: hit-pop 0.34s ease-out; }
@keyframes hit-pop {
  0% { opacity: 1; transform: scale(1.7); }
  30% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.1); }
}

/* Damage numbers that rise off the enemy. */
#floaters { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floater {
  position: absolute;
  left: 0;
  top: 0;
  font: 800 17px/1 ui-sans-serif, system-ui, sans-serif;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 2px rgba(0,0,0,0.9);
  will-change: transform, opacity;
}
.floater.crit { color: #ffd34d; font-size: 22px; }

#ammo-text.low { color: #ff5a64; }

.floater.callout {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: #ffd9a8;
  background: rgba(10, 12, 16, 0.6);
  padding: 3px 6px;
  border-radius: 4px;
}

/* Damage direction: a red arc on the ring around the crosshair, pointing at the shooter. */
#hurt-dir {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(56vh, 340px);
  height: min(56vh, 340px);
  margin: calc(min(56vh, 340px) / -2) 0 0 calc(min(56vh, 340px) / -2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease-out;
}
#hurt-dir.on { opacity: 1; transition: opacity 0.05s linear; }
#hurt-dir i {
  position: absolute;
  left: 50%;
  top: 0;
  width: 44%;
  height: 14%;
  transform: translateX(-50%);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  border-top: 5px solid rgba(255, 50, 60, 0.9);
  filter: drop-shadow(0 0 6px rgba(255, 30, 40, 0.8));
}

/* Build 49: danger arcs. One per attacker off the middle of the view,
   rotated to where it is coming from (top = straight ahead). */
#threats {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(82vh, 470px);
  height: min(82vh, 470px);
  margin: calc(min(82vh, 470px) / -2) 0 0 calc(min(82vh, 470px) / -2);
  pointer-events: none;
}
#threats i { position: absolute; inset: 0; display: none; --c: rgba(255, 60, 70, 0.95); }
#threats i.on { display: block; }
#threats i::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 40%;
  height: 13%;
  transform: translateX(-50%);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  border-top: 9px solid var(--c);
  filter: drop-shadow(0 0 7px var(--c));
  animation: threat-pulse 0.32s ease-in-out infinite alternate;
}
#threats i::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 2.5%;
  margin-left: -10px;
  border: 10px solid transparent;
  border-bottom: 13px solid var(--c);
  transform: translateY(-100%);
}
#threats i.ready { --c: rgba(255, 214, 120, 1); }
#threats i.charge { --c: rgba(255, 128, 32, 0.95); }
#threats i.shot { --c: rgba(255, 176, 64, 0.85); }
#threats i.shot::before { border-top-width: 5px; animation-duration: 0.5s; }
@keyframes threat-pulse { from { transform: translateX(-50%) scale(0.92); opacity: 0.65; } to { transform: translateX(-50%) scale(1.06); opacity: 1; } }

#btn-turn { color: #ffd7c2; border-color: #c46a3a; background: rgba(40, 20, 12, 0.88); }

#marker {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px;
  border: 2px solid var(--cyan);
  border-radius: 3px;
  transform: rotate(45deg);
  pointer-events: none;
  box-shadow: 0 0 10px var(--cyan);
}

#banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  padding: 8px 14px;
  background: rgba(0,0,0,0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
  letter-spacing: 0.14em;
  font-size: 13px;
  pointer-events: none;
}

#dmg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle, transparent 40%, rgba(180, 20, 30, 0.0) 75%);
  opacity: 0;
  transition: opacity 0.12s linear;
}
#dmg.on { opacity: 1; background: radial-gradient(circle, transparent 35%, rgba(180, 20, 30, 0.45) 78%); }

#fps {
  position: absolute;
  right: calc(12px + var(--safe-r));
  top: calc(86px + var(--safe-t));
  font: 12px/1.2 ui-monospace, monospace;
  pointer-events: none;
  background: rgba(0,0,0,0.45);
  padding: 4px 6px;
  border-radius: 6px;
}

.controls {
  position: absolute;
  left: calc(8px + var(--safe-l));
  right: calc(8px + var(--safe-r));
  bottom: calc(6px + var(--safe-b));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.left-controls, .right-controls { pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.right-controls { align-items: flex-end; }

.btn, .fire, .joy { pointer-events: auto; touch-action: none; color: var(--ink); }

.btn {
  min-width: 64px;
  min-height: 48px;
  padding: 8px 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.btn.small { min-width: 72px; }
.btn.icon { width: 48px; height: 48px; min-width: 48px; border-radius: 14px; font-weight: 800; }
.btn.pressed, .fire.pressed, .btn.ready { background: rgba(61, 226, 255, 0.22); border-color: var(--cyan); }
.btn.on { background: rgba(255, 59, 78, 0.28); border-color: var(--red); }

.joy {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  position: relative;
  background: rgba(8, 12, 18, 0.45);
}
.joy-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #8d97a6, #2c333d 60%, #15191f);
  border: 1px solid rgba(255,255,255,0.35);
}
.hint { font-size: 10px; letter-spacing: 0.14em; opacity: 0.8; pointer-events: none; }

.cluster { display: flex; gap: 8px; }

.fire {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 800;
  letter-spacing: 0.12em;
}
.fire small { font-size: 8px; letter-spacing: 0.04em; font-weight: 600; opacity: 0.8; text-align: center; width: 84px; }

[hidden] { display: none !important; }

.util-row { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

/* Full-screen toggle, next to pause. Shows the icon for what a tap will do. */
#btn-full { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0; color: #c9f6ff; border-color: #69c9dd; }
#btn-full svg { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#btn-full .full-label { font-size: 8px; line-height: 9px; letter-spacing: 0.04em; text-align: center; }
#btn-full .i-exit { display: none; }
#btn-full.is-full .i-enter { display: none; }
#btn-full.is-full .i-exit { display: block; }

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 6, 10, 0.72);
  padding: calc(24px + var(--safe-t)) calc(24px + var(--safe-r)) calc(24px + var(--safe-b)) calc(24px + var(--safe-l));
  z-index: 20;
  /* A menu taller than the screen scrolls instead of hiding its button. */
  overflow-y: auto;
  touch-action: pan-y;
}
.screen * { touch-action: pan-y; }
.panel {
  width: min(520px, 100%);
  background: rgba(10, 14, 20, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
}
.brand { letter-spacing: 0.18em; font-size: 12px; color: var(--cyan); }
h1 { margin: 8px 0 10px; font-size: 28px; }
.brief { padding-left: 18px; }
.fine, .error { font-size: 12px; opacity: 0.75; }
.error { color: #ff8d8d; opacity: 1; }
.primary, .ghost-btn {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 10px 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: white;
  background: #12384a;
}
.ghost-btn { background: transparent; }
.row { display: flex; gap: 8px; margin-top: 12px; }
label { display: block; margin: 10px 0; font-size: 14px; }
input[type="range"], select { width: 100%; margin-top: 4px; }
.check { display: flex; gap: 8px; align-items: center; }

#build-stamp {
  position: absolute;
  z-index: 30;
  top: auto;
  bottom: calc(8px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  font: 700 11px/1 ui-monospace, monospace;
  letter-spacing: 0.08em;
  color: #9fffe8;
  background: rgba(0,0,0,0.55);
  padding: 4px 6px;
  border-radius: 6px;
  pointer-events: none;
}

#portrait, #resume-lock {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #07090d;
  text-align: center;
  padding: 24px;
}
#portrait[hidden], #resume-lock[hidden], .screen[hidden] { display: none !important; }

@media (max-width: 740px) {
  .top { grid-template-columns: 1fr auto; }
  .mission-card { grid-column: 1 / -1; order: -1; }
  .joy { width: 112px; height: 112px; }
  .fire { width: 104px; height: 104px; }
  .btn { min-width: 56px; font-size: 10px; }
  #objective { font-size: 12px; }
}

@media (min-width: 900px) and (min-height: 700px) {
  .joy { width: 150px; height: 150px; }
  .fire { width: 136px; height: 136px; }
  .mid-left { top: calc(103px + var(--safe-t)); }
}

/* Short screens (phones in landscape, iPad Safari with its toolbars): the right
   thumb's buttons sit in two rows beside FIRE, and the pills go side by side,
   so nothing stacks into the top bar. */
@media (max-height: 520px) {
  .right-controls {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    align-items: end;
    justify-items: end;
    gap: 8px;
  }
  .util-row { flex-direction: row; grid-column: 1; grid-row: 1; }
  .cluster { grid-column: 1; grid-row: 2; }
  .fire { grid-column: 2; grid-row: 1 / span 2; align-self: end; }
  .mid-left { flex-direction: row; top: calc(73px + var(--safe-t)); }
  .left-controls { flex-direction: row; align-items: flex-end; }
  .left-controls .hint { display: none; }
  .left-controls #btn-sprint { order: 2; }
  .joy { width: 112px; height: 112px; }
  .fire { width: 104px; height: 104px; }
}
@media (max-height: 380px) {
  .joy { width: 100px; height: 100px; }
  .fire { width: 92px; height: 92px; }
  .btn { min-height: 42px; }
  .btn.icon { width: 42px; height: 42px; min-width: 42px; }
}

/* Phones in landscape are short. Menus go wide and tight so the button is on screen. */
@media (max-height: 520px) {
  .screen { padding-top: calc(10px + var(--safe-t)); padding-bottom: calc(10px + var(--safe-b)); }
  .panel { width: min(780px, 100%); padding: 12px 18px; }
  .panel h1 { font-size: 19px; margin: 3px 0 5px; }
  .panel p { margin: 5px 0; font-size: 12.5px; line-height: 1.3; }
  .panel .brand { font-size: 10.5px; }
  .brief { margin: 5px 0; font-size: 12px; line-height: 1.3; columns: 2; column-gap: 28px; }
  .brief li { break-inside: avoid; margin-bottom: 3px; }
  .panel label { margin: 5px 0; font-size: 13px; }
  .primary, .ghost-btn { min-height: 42px; padding: 8px 16px; }
  .panel .fine { font-size: 10.5px; margin-top: 5px; }
  .row { margin-top: 6px; }
}

/* Combat actions have distinct colours and generous touch targets. */
#btn-melee { border-color: #d8b477; background: rgba(69, 48, 22, 0.8); }
#btn-dodge { border-color: #73b9df; background: rgba(17, 43, 66, 0.8); }
#btn-counter { color: #f1d7a8; border-color: #ab8550; background: rgba(34, 27, 19, 0.88); }
#btn-counter.ready { color: #17120b; border-color: #ffe6ac; background: #e5bc71; box-shadow: 0 0 18px rgba(229,188,113,0.45); }
#btn-counter.cooldown { opacity: 0.55; }
#btn-counter.grab { color: #ffd9dc; border-color: #d0485a; background: rgba(48, 16, 22, 0.9); }
#btn-melee, #btn-dodge, #btn-counter { min-height: 52px; font-size: 11px; }
.util-row { display: flex; gap: 8px; }
#counter-cue {
  position: absolute; transform: translate(-50%, -100%);
  padding: 7px 12px; border: 1px solid #9caab9; border-radius: 8px;
  background: rgba(7, 12, 20, 0.9); color: #d7e3f0;
  font-size: 12px; font-weight: 800; letter-spacing: 0.08em; white-space: nowrap;
  pointer-events: none;
}
#counter-cue.ready { border-color: #ffe6ac; color: #ffe6ac; box-shadow: 0 0 16px rgba(229,188,113,0.35); }
@media (max-height: 520px) {
  #btn-melee, #btn-dodge, #btn-counter { min-height: 48px; }
  .util-row .btn.small { min-width: 64px; padding: 8px; font-size: 10px; }
}
@media (max-width: 660px) {
  .controls { left: calc(6px + var(--safe-l)); right: calc(6px + var(--safe-r)); }
  .cluster, .util-row { gap: 5px; }
  .right-controls { gap: 5px; }
  .util-row .btn.small { min-width: 56px; }
  .left-controls { gap: 5px; }
  #btn-sprint { min-width: 56px; }
  .joy { width: 92px; height: 92px; }
  .fire { width: 92px; height: 92px; }
}

/* Identity switch stays near the status pills, clear of the combat cluster. */
#btn-transform { min-height: 44px; min-width: 96px; padding: 8px 10px; font-size: 10px; color: #f1d7a8; border-color: #ab8550; align-self: flex-start; }
#btn-transform[aria-pressed="true"] { background: rgba(72, 49, 24, 0.9); }


/* --- Story: dialogue cards, chapter titles, radio lines ------------------- */
#story {
  position: fixed; inset: 0; z-index: 15;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 calc(16px + var(--safe-r, 0px)) calc(18px + var(--safe-b, 0px)) calc(16px + var(--safe-l, 0px));
  background: linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,0.62) 100%);
  cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
}
#story[hidden], #story-chapter[hidden], #story-radio[hidden] { display: none; }
.story-card {
  --side: #e9edf2;
  position: relative; width: min(680px, 100%);
  background: rgba(7, 9, 12, 0.9); border: 1px solid rgba(255,255,255,0.08); border-left: 3px solid var(--side);
  padding: 12px 18px 12px 16px; color: #e9edf2;
  box-shadow: 0 10px 40px rgba(0,0,0,0.55);
}
#story[data-side="agency"] .story-card { --side: #5aa8ff; }
#story[data-side="street"] .story-card { --side: #e8a54b; }
#story[data-side="crew"] .story-card { --side: #ff4a4a; }
#story[data-side="ghost"] .story-card { --side: #c9ced6; }
.story-who { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.story-name { font-size: 12px; font-weight: 800; letter-spacing: 0.22em; color: var(--side); }
.story-role { font-size: 9px; letter-spacing: 0.2em; opacity: 0.55; }
.story-text { margin: 0; font-size: 16px; line-height: 1.45; min-height: 2.9em; }
.story-next { position: absolute; right: 12px; bottom: 8px; font-size: 9px; letter-spacing: 0.2em; opacity: 0.5; animation: storyBlink 1.2s ease-in-out infinite; }
@keyframes storyBlink { 50% { opacity: 0.15; } }
#story-chapter {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 14;
  text-align: center; color: #f2f4f7; pointer-events: none; opacity: 0;
  text-shadow: 0 4px 30px rgba(0,0,0,0.8);
}
#story-chapter.show { animation: storyChapter 3.2s ease forwards; }
.story-kicker { font-size: 12px; letter-spacing: 0.5em; opacity: 0.75; }
.story-title { font-size: clamp(34px, 7vw, 64px); font-weight: 900; letter-spacing: 0.18em; margin-top: 4px; }
.story-title::after { content: ""; display: block; height: 2px; width: 60%; margin: 10px auto 0; background: linear-gradient(90deg, transparent, #ff4a4a, transparent); }
@keyframes storyChapter { 0% { opacity: 0; letter-spacing: 0.3em; } 15%, 75% { opacity: 1; } 100% { opacity: 0; } }
#story-radio {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-b, 0px)); z-index: 14;
  max-width: min(560px, 62vw); padding: 7px 12px; font-size: 12px; line-height: 1.35; color: #e9edf2;
  background: rgba(7, 9, 12, 0.78); border-left: 2px solid #c9ced6; pointer-events: none;
  animation: storyRadio 4.2s ease forwards;
}
#story-radio b { letter-spacing: 0.18em; font-size: 10px; margin-right: 4px; }
#story-radio[data-side="agency"] { border-color: #5aa8ff; } #story-radio[data-side="agency"] b { color: #5aa8ff; }
#story-radio[data-side="street"] { border-color: #e8a54b; } #story-radio[data-side="street"] b { color: #e8a54b; }
#story-radio[data-side="crew"] { border-color: #ff4a4a; } #story-radio[data-side="crew"] b { color: #ff4a4a; }
@keyframes storyRadio { 0% { opacity: 0; } 8%, 85% { opacity: 1; } 100% { opacity: 0; } }
@media (max-height: 430px) {
  .story-text { font-size: 14px; min-height: 2.8em; }
  .story-card { padding: 9px 14px 9px 12px; }
  #story-radio { bottom: calc(70px + var(--safe-b, 0px)); font-size: 11px; }
}

@media (max-height: 520px) {
  .meters { grid-template-columns: auto auto; gap: 8px; margin-top: 3px; }
  .meter { gap: 3px; font-size: 7px; }
  .meter span { width: auto; }
  .meter i { width: 38px; }
  .mid-left { top: calc(80px + var(--safe-t)); }
  #meter-note { top: calc(122px + var(--safe-t)); }
}

/* The machines: a boss bar at the top centre for whichever one is on Ghost,
   hull on top, shield underneath in its glow colour. */
#machine-bar {
  --mb: #ff2a14;
  position: absolute;
  left: 50%;
  top: calc(68px + var(--safe-t));
  width: min(360px, 46vw);
  transform: translateX(-50%);
  pointer-events: none;
  font-family: inherit;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
#machine-bar .mb-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: #fff;
  margin-bottom: 4px;
}
#machine-bar .mb-name { color: var(--mb); font-weight: 700; }
#machine-bar .mb-state { font-size: 10px; color: #fff; opacity: 0.85; }
#machine-bar .mb-track {
  height: 7px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  overflow: hidden;
}
#machine-bar .mb-track.shield { height: 4px; margin-top: 3px; }
#machine-bar .mb-track b { display: block; height: 100%; width: 100%; transition: width 0.12s linear; }
#machine-bar .mb-hull { background: linear-gradient(90deg, #8a0f0a, var(--mb)); }
#machine-bar .mb-shield { background: #9fe8ff; box-shadow: 0 0 6px #5fe4ff; }
#machine-bar.stunned .mb-state { color: #ffd34d; }
#machine-pill { color: #ff6a50; }
.floater.shield { color: #9fe8ff; }

/* --- Briefing: gamer tag + difficulty (Build 52). */
#screen-start .panel { width: min(700px, 100%); }
.start-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin-top: 12px; }
.tag-field { display: grid; gap: 4px; flex: 1 1 180px; font-size: 11px; letter-spacing: 0.16em; color: var(--cyan); margin: 0; }
.tag-field input {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font: 600 16px/1 inherit;
  letter-spacing: 0.04em;
}
.tag-field input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(61, 226, 255, 0.25); }
.tag-field.bad input { border-color: #ff6b78; box-shadow: 0 0 0 2px rgba(255, 90, 100, 0.25); }
.diff-pick { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.diff-pick button {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: #c7d0da;
  font: 700 12px/1 inherit;
  letter-spacing: 0.12em;
  cursor: pointer;
}
.diff-pick button + button { border-left: 1px solid var(--line); }
.diff-pick button[aria-checked="true"][data-diff="easy"] { background: rgba(70, 220, 130, 0.22); color: #9dffbe; }
.diff-pick button[aria-checked="true"][data-diff="medium"] { background: rgba(61, 226, 255, 0.2); color: #b4f6ff; }
.diff-pick button[aria-checked="true"][data-diff="hard"] { background: rgba(255, 70, 90, 0.24); color: #ffb3bb; }
.start-row #btn-start { flex: 0 0 auto; }
.tag-note { margin: 6px 0 0; min-height: 1.2em; font-size: 12px; color: #aeb8c4; }
.tag-note.bad { color: #ff8d8d; }
@media (max-height: 520px) {
  .start-row { margin-top: 6px; gap: 6px 8px; }
  .tag-field input, .diff-pick button { min-height: 38px; }
  .tag-field { font-size: 10px; }
  .tag-note { margin-top: 3px; font-size: 11px; }
}
@media (max-height: 760px) and (min-height: 521px) {
  #screen-start .panel { width: min(820px, 100%); }
  #screen-start .brief { columns: 2; column-gap: 26px; font-size: 13px; line-height: 1.3; margin: 8px 0; }
  #screen-start .brief li { break-inside: avoid; margin-bottom: 4px; }
}

/* --- iPhone full screen help (Build 53). */
#full-help { z-index: 40; }
#full-help .panel { width: min(560px, 100%); }
.full-steps { padding-left: 22px; margin: 10px 0; line-height: 1.45; }
.full-steps li { margin-bottom: 6px; }
.share-icon { display: inline-block; position: relative; width: 12px; height: 14px; margin: 0 3px -2px; border: 2px solid currentColor; border-top: 0; border-radius: 0 0 2px 2px; }
.share-icon::before { content: ""; position: absolute; left: 50%; top: -8px; width: 2px; height: 12px; background: currentColor; transform: translateX(-50%); }
.share-icon::after { content: ""; position: absolute; left: 50%; top: -9px; width: 6px; height: 6px; border-left: 2px solid currentColor; border-top: 2px solid currentColor; transform: translateX(-50%) rotate(45deg); }
@media (max-height: 520px) {
  .full-steps { margin: 5px 0; font-size: 13px; line-height: 1.35; }
  .full-steps li { margin-bottom: 3px; }
}

/* --- Ratings (Build 54). */
.rate { margin: 10px 0 12px; padding: 10px 12px; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 4px; background: rgba(255, 255, 255, 0.03); }
.rate-head { font-size: 11px; letter-spacing: 0.2em; color: #ffd27a; font-weight: 700; }
.rate-word { color: #fff; letter-spacing: 0.14em; }
.rate-stars { display: flex; gap: 6px; margin: 6px 0 2px; }
.rate-stars button {
  width: 46px; height: 46px; border-radius: 8px; border: 1px solid rgba(255, 210, 122, 0.35);
  background: rgba(255, 210, 122, 0.06); color: rgba(255, 255, 255, 0.28); font-size: 26px; line-height: 1; cursor: pointer;
  transition: transform 0.08s ease, color 0.1s linear, background 0.1s linear;
}
.rate-stars button.on { color: #ffd27a; background: rgba(255, 210, 122, 0.18); text-shadow: 0 0 10px rgba(255, 210, 122, 0.7); }
.rate-stars button:active { transform: scale(0.92); }
.rate-more { display: flex; gap: 8px; margin-top: 8px; }
.rate-more[hidden] { display: none; }
.rate-comment { flex: 1; min-width: 0; min-height: 42px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: #fff; font: 500 15px/1 inherit; }
.rate-comment:focus { outline: none; border-color: #ffd27a; }
.rate-send { min-height: 42px; padding: 0 18px; border-radius: 8px; border: 1px solid #ffd27a; background: rgba(255, 210, 122, 0.2); color: #ffe7b0; font: 700 13px/1 inherit; letter-spacing: 0.18em; cursor: pointer; }
.rate-send:disabled { opacity: 0.5; }
.rate-note { margin: 6px 0 0; min-height: 1.1em; font-size: 12px; color: #c7d0da; }
.rate.done .rate-stars button { pointer-events: none; }
.rate.done .rate-more { display: none; }
.rate.done .rate-note { color: #9dffbe; }
#pause-rate-host:empty { display: none; }
@media (max-height: 520px) {
  .rate { margin: 6px 0 8px; padding: 7px 10px; }
  .rate-stars button { width: 40px; height: 40px; font-size: 22px; }
  .rate-more { margin-top: 5px; }
  .rate-comment, .rate-send { min-height: 38px; }
}
