*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --ds-plate-hi: #2a2e34;
  --ds-edge: #4a5058;
  --ds-edge-dim: #2c3036;
  --ds-ink: #f2f2f2;
  --ds-ink-dim: #b8b8b8;
  --ds-red: #e01820;
  --ds-green: #0f0;
  --ds-green-dim: #8f8;
  --ds-green-mute: #3a6a3a;
  --ds-font: "Arial Narrow", "Helvetica Neue Condensed", "Franklin Gothic Medium",
    "Segoe UI", sans-serif;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ds-green);
  font-family: "Courier New", Courier, monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  cursor: none;
  object-fit: contain;
}

/* WebGL HUD overlay — shown only when RendererWebGL mounts it */
#gameHud {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 1;
  background: transparent;
}

#overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(ellipse at center, rgba(20, 24, 28, 0.35) 0%, rgba(0, 0, 0, 0.72) 70%);
}

#overlay.hidden {
  display: none;
}

#overlay .ds-menu {
  pointer-events: auto;
}

/* ── Shared Death Star menu frame (1672×941 art) ── */
.ds-menu {
  position: relative;
  pointer-events: auto;
  width: min(1672px, 96vw, calc(92vh * 1672 / 941));
  max-width: 1672px;
  aspect-ratio: 1672 / 941;
  height: auto;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 14px;
  background-color: transparent;
  background-image: url("images/trench-run-pause-menu-transparent.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  box-shadow:
    0 22px 56px rgba(0, 0, 0, 0.72),
    0 0 0 1px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  text-align: left;
}

.ds-menu.hidden {
  display: none;
}

/* Left gutter status — left edge matches the red indicator squares (art x≈434) */
.ds-side-status {
  position: absolute;
  left: 26%;
  top: 24.5%;
  width: 12.5%;
  height: 16%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.15em;
  padding: 0;
  background: transparent;
  pointer-events: none;
}

.ds-side-kicker {
  color: var(--ds-ink-dim);
  font-family: var(--ds-font);
  font-size: clamp(7px, 0.85vw, 12px);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  line-height: 1.2;
}

.ds-side-label {
  color: var(--ds-ink);
  font-family: var(--ds-font);
  font-size: clamp(16px, 2.4vw, 36px);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 0.95;
}

/**
 * Middle column — 6 equal rows (title + 5 actions).
 * Geometry from art column dividers on the 1672×941 plate.
 */
.ds-menu-rows {
  position: absolute;
  left: 38.1%;
  top: 22.4%;
  width: 25.2%;
  height: 53.9%;
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  align-items: stretch;
  gap: 0;
  margin: 0;
  padding: 0;
  z-index: 1;
}

.ds-menu-rows--panel {
  grid-template-rows: 1fr 5fr;
}

.ds-menu-rows--inline {
  position: static;
  left: auto;
  top: auto;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  grid-template-rows: none;
  margin-top: 8px;
}

.ds-menu-title {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 0.2em;
  box-sizing: border-box;
  /* Match gutter top inset so the title isn't flush with the plate edge */
  padding: 12% 3% 4% 5.5%;
  color: var(--ds-ink);
  font-family: var(--ds-font);
  font-size: clamp(12px, 1.7vw, 24px);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.05;
  pointer-events: none;
}

.ds-menu-title small {
  color: var(--ds-ink-dim);
  font-size: 0.48em;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.ds-menu-slot {
  pointer-events: none;
}

.ds-menu-rows > button,
.ds-menu-rows > .ds-menu-link,
.ds-menu-rows--inline > button {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  margin: 0;
  /* Text inset only — red hover border spans the full middle column */
  padding: 0 3% 0 5.5%;
  border: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  clip-path: none;
  color: var(--ds-ink);
  font-family: var(--ds-font);
  font-size: clamp(11px, 1.55vw, 22px);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.14em;
  line-height: 1;
  text-transform: uppercase;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

.ds-menu-rows--inline > button {
  height: auto;
  min-height: 2.2em;
  padding: 0.45em 0.8em;
  justify-content: center;
  border: 1px solid rgba(242, 242, 242, 0.35);
}

.ds-menu-rows > button:hover,
.ds-menu-rows > button:focus-visible,
.ds-menu-rows > .ds-menu-link:hover,
.ds-menu-rows > .ds-menu-link:focus-visible,
.ds-menu-rows--inline > button:hover,
.ds-menu-rows--inline > button:focus-visible {
  background: transparent;
  border-color: var(--ds-red);
  color: #fff;
  outline: none;
  box-shadow: none;
}

/* Keep row alignment when Debug is locked */
.ds-menu-rows > .hidden {
  display: flex !important;
  visibility: hidden;
  pointer-events: none;
}

/* Secret PIN entry — sits on the ALERT / grill art */
.ds-alert-hotspot {
  position: absolute;
  left: 68.1%;
  top: 55.3%;
  width: 8.2%;
  height: 17.5%;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  appearance: none;
}

.ds-alert-hotspot:focus-visible {
  outline: 1px solid rgba(224, 24, 32, 0.45);
  outline-offset: 1px;
}

/* Dense content under the title row (settings / pin / debug) */
.ds-menu-body {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.45em;
  min-height: 0;
  overflow: auto;
  padding: 2% 8% 3% 4%;
  color: var(--ds-ink-dim);
  font-family: var(--ds-font);
  font-stretch: condensed;
  scrollbar-width: thin;
}

.ds-menu-body::-webkit-scrollbar {
  width: 4px;
}
.ds-menu-body::-webkit-scrollbar-thumb {
  background: rgba(242, 242, 242, 0.25);
}

/* Pause / settings shell */
.menu-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 6;
  background: rgba(4, 6, 8, 0.72);
  pointer-events: auto;
}

.menu-overlay.hidden {
  display: none !important;
  pointer-events: none !important;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 0.55em;
  text-align: left;
}

.settings-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--ds-ink-dim);
  font-size: clamp(10px, 1.1vw, 14px);
  letter-spacing: 0.06em;
  line-height: 1.3;
  cursor: pointer;
  text-transform: uppercase;
}

.settings-check input {
  margin-top: 2px;
  accent-color: var(--ds-red);
  flex: 0 0 auto;
}

.settings-slider {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ds-ink-dim);
  font-size: clamp(10px, 1.1vw, 14px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.settings-slider-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.settings-slider-head span:last-child {
  color: var(--ds-ink);
  min-width: 2.6em;
  text-align: right;
}

.settings-slider input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--ds-red);
  cursor: pointer;
}

/* TEMP: nose Z debug slider — kept in DOM but hidden */
#noseTune {
  display: none !important;
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid #0a0;
  background: rgba(0, 0, 0, 0.8);
  color: #0f0;
  font: 12px/1.3 "Courier New", Courier, monospace;
  letter-spacing: 0.06em;
  pointer-events: none;
  cursor: default;
}

#noseTune label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

#noseTune #noseZVal,
#noseTune #gunRelZVal,
#noseTune #gunYVal {
  color: #8f8;
  min-width: 3.2em;
  text-align: right;
}

#noseTune input[type="range"] {
  width: 180px;
  margin: 0;
  accent-color: #0f0;
  cursor: pointer;
}

/* Mobile steer thumbstick — aim/fire is drag-anywhere on the canvas */
.stick {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  z-index: 4;
  width: 118px;
  height: 118px;
  touch-action: none;
  pointer-events: auto;
}

.stick.hidden {
  display: none;
}

#stickLeft {
  left: max(16px, env(safe-area-inset-left, 0px));
}

#stickRight {
  right: max(16px, env(safe-area-inset-right, 0px));
}

.stick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(0, 255, 0, 0.45);
  background: rgba(0, 40, 0, 0.35);
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  border: 2px solid rgba(0, 255, 0, 0.85);
  background: rgba(0, 180, 0, 0.35);
  will-change: transform;
}

@media (pointer: fine) {
  .stick {
    opacity: 0.85;
  }
}

@media (pointer: coarse) {
  #noseTune {
    display: none;
  }
}

/* Dev unlock UI removed — Alert grill is the secret PIN hotspot */

.pin-screen,
.debug-screen {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 8, 0.88);
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
}

.pin-screen.open,
.debug-screen.open {
  display: flex;
}

.pin-panel,
.debug-panel {
  width: min(1672px, 96vw, calc(92vh * 1672 / 941));
  max-width: 1672px;
}

.pin-msg {
  min-height: 1.1em;
  margin: 0;
  font-size: clamp(9px, 1vw, 12px);
  letter-spacing: 0.12em;
  color: var(--ds-red);
  text-transform: uppercase;
}

.pin-display {
  font-size: clamp(16px, 2vw, 26px);
  letter-spacing: 0.35em;
  text-align: center;
  color: var(--ds-ink);
  margin: 0 0 6px;
  padding: 0.35em 0.4em;
  border: 1px solid rgba(242, 242, 242, 0.28);
  background: rgba(0, 0, 0, 0.45);
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 6px;
}

.pin-grid button,
#pinCancel {
  appearance: none;
  border: 1px solid rgba(242, 242, 242, 0.35);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ds-ink);
  font-family: var(--ds-font);
  font-size: clamp(12px, 1.4vw, 18px);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.08em;
  padding: 0.45em 0;
  cursor: pointer;
  text-transform: uppercase;
}

.pin-grid button:hover,
.pin-grid button:focus-visible,
#pinCancel:hover,
#pinCancel:focus-visible {
  border-color: var(--ds-red);
  color: #fff;
  outline: none;
  background: rgba(224, 24, 32, 0.12);
}

#pinCancel {
  width: 100%;
}

.debug-hint {
  margin: 0 0 4px;
  color: var(--ds-ink-dim);
  font-size: clamp(9px, 1vw, 12px);
  letter-spacing: 0.06em;
  line-height: 1.35;
  text-transform: uppercase;
}

.debug-levels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 4px;
}

.debug-levels button {
  appearance: none;
  border: 1px solid rgba(242, 242, 242, 0.35);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ds-ink);
  font-family: var(--ds-font);
  font-size: clamp(10px, 1.15vw, 14px);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.1em;
  padding: 0.5em 0.4em;
  cursor: pointer;
  text-transform: uppercase;
}

.debug-levels button:hover,
.debug-levels button:focus-visible,
.debug-levels button.on {
  border-color: var(--ds-red);
  color: #fff;
  outline: none;
  background: rgba(224, 24, 32, 0.12);
}

.debug-stepper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 2px 0 4px;
}

.debug-stepper-label {
  color: var(--ds-ink-dim);
  font-size: clamp(9px, 1vw, 12px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.debug-stepper-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.debug-stepper-controls button {
  appearance: none;
  width: 30px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(242, 242, 242, 0.35);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ds-ink);
  font-family: var(--ds-font);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.debug-stepper-controls button:hover,
.debug-stepper-controls button:focus-visible {
  border-color: var(--ds-red);
  outline: none;
}

.debug-stepper-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

.debug-stepper-value {
  min-width: 2.2em;
  text-align: center;
  font-size: clamp(14px, 1.6vw, 20px);
  letter-spacing: 0.08em;
  color: var(--ds-ink);
  font-family: var(--ds-font);
  font-weight: 700;
}

.debug-infinite {
  margin-bottom: 2px;
  justify-content: flex-start;
}
