:root {
  --bg: #07090c;
  --panel: rgba(13, 18, 24, 0.92);
  --line: rgba(255, 176, 87, 0.55);
  --amber: #ffb057;
  --amber-bright: #ffd9a8;
  --cyan: #6ce6ff;
  --text: #dfe6ee;
  --muted: #8e9baa;
  --danger: #ff5a5a;
  --mono: 'Consolas', 'Menlo', 'Roboto Mono', 'Liberation Mono', 'Courier New', monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app,
#app canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- landing overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(ellipse 70% 60% at 50% 35%, rgba(255, 138, 60, 0.13), transparent 70%),
    repeating-linear-gradient(0deg, transparent 0 47px, rgba(108, 230, 255, 0.045) 47px 48px),
    repeating-linear-gradient(90deg, transparent 0 47px, rgba(108, 230, 255, 0.045) 47px 48px),
    linear-gradient(180deg, #0b0f14 0%, #07090c 100%);
  transition: opacity 0.35s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.frame {
  min-height: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: clamp(12px, 3vh, 36px) clamp(14px, 4vw, 40px) 12px;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2.2vh, 26px);
}

.masthead {
  text-align: center;
}

.kicker {
  font-size: clamp(10px, 1.5vh, 13px);
  letter-spacing: 0.32em;
  color: var(--muted);
  margin-bottom: 6px;
}

.title {
  margin: 0;
  font-size: clamp(38px, 11vh, 104px);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.16em;
  margin-left: 0.16em; /* balances the trailing letter-spacing */
  color: var(--amber-bright);
  text-shadow:
    0 0 24px rgba(255, 138, 60, 0.55),
    0 0 2px rgba(255, 217, 168, 0.9),
    0 2px 0 #5a2d0c,
    0 4px 12px rgba(0, 0, 0, 0.8);
}

.tagline {
  margin-top: 8px;
  font-size: clamp(12px, 1.9vh, 17px);
  color: var(--text);
  letter-spacing: 0.06em;
}

.launch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: clamp(12px, 2.4vh, 24px);
  border: 1px solid var(--line);
  background: var(--panel);
  clip-path: polygon(18px 0, 100% 0, 100% calc(100% - 18px), calc(100% - 18px) 100%, 0 100%, 0 18px);
}

.btn {
  font-family: var(--mono);
  font-size: clamp(15px, 2.6vh, 22px);
  font-weight: 700;
  letter-spacing: 0.18em;
  padding: 0.7em 2.2em;
  min-width: min(420px, 86vw);
  color: var(--text);
  background: linear-gradient(180deg, #18222c, #10161d);
  border: 1px solid rgba(140, 170, 195, 0.45);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.btn[hidden] {
  display: none;
}

.btn:hover,
.btn:focus-visible {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px rgba(108, 230, 255, 0.35), 0 0 22px rgba(108, 230, 255, 0.25);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  color: #1a0f04;
  background: linear-gradient(180deg, #ffd9a8, #ff9a3c 60%, #e0731c);
  border-color: #ffd9a8;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn-primary:hover,
.btn-primary:focus-visible {
  border-color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 217, 168, 0.6), 0 0 30px rgba(255, 154, 60, 0.55);
}

.btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.status {
  margin: 0;
  min-height: 1.5em;
  font-size: clamp(12px, 1.8vh, 15px);
  text-align: center;
  color: var(--muted);
  line-height: 1.45;
}

.status.error {
  color: var(--danger);
}

.status code {
  color: var(--cyan);
  background: rgba(108, 230, 255, 0.08);
  padding: 1px 6px;
  border-radius: 3px;
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- controls ---------- */

.help {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(10px, 2vw, 24px);
}

.help-col {
  border: 1px solid rgba(140, 170, 195, 0.2);
  background: rgba(8, 12, 16, 0.72);
  padding: clamp(10px, 1.8vh, 18px) clamp(12px, 1.8vw, 20px);
}

.help-col h2 {
  margin: 0 0 8px;
  font-size: clamp(11px, 1.7vh, 14px);
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--amber);
}

.keys {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(11px, 1.7vh, 14px);
  line-height: 1.4;
}

.keys td {
  padding: 3px 0;
  vertical-align: top;
  color: var(--muted);
}

.keys td:first-child {
  width: 46%;
  padding-right: 10px;
  color: var(--text);
  white-space: nowrap;
}

.keys b {
  color: var(--amber-bright);
  font-weight: 700;
}

/* No keyboard attached (the headset's browser window): only the controller table matters. */
@media (pointer: coarse) {
  .help {
    grid-template-columns: 1fr;
  }

  .help-desktop {
    display: none;
  }
}

@media (max-width: 640px) {
  .help {
    grid-template-columns: 1fr;
  }
}

.foot {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: auto;
  font-size: clamp(10px, 1.5vh, 12px);
  color: var(--muted);
}

.foot-right {
  opacity: 0.7;
}

/* ---------- desktop toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 7vh;
  transform: translateX(-50%);
  z-index: 15;
  max-width: min(92vw, 760px);
  padding: 10px 22px;
  font-size: 15px;
  letter-spacing: 0.1em;
  text-align: center;
  color: var(--amber-bright);
  background: rgba(8, 12, 16, 0.85);
  border: 1px solid var(--line);
  pointer-events: none;
}

.noscript {
  position: fixed;
  inset: 40% 10% auto;
  text-align: center;
  color: var(--danger);
  font-size: 18px;
}

/* ---------- phone and tablet ---------- */

/* The mine is not a document: none of the browser's own gestures over the view. */
#app canvas {
  touch-action: none;
  overscroll-behavior: none;
}

body.touch .help {
  grid-template-columns: 1fr;
}

.help-touch {
  display: none;
}

body.touch .help-touch {
  display: block;
}

body.touch .help-quest,
body.touch .help-desktop {
  display: none;
}

/* On-screen controls (built by src/ship/touch.js into #touch). Layout, left to right:
   left stick | thrust slider ......... fire + missile (stacked) | right stick.
   Without a tilt sensor the right stick aims; with one it is hidden and the two buttons
   move under the right thumb. In portrait the right group sits higher so nothing overlaps. */
.tc {
  --stick: clamp(100px, 30vh, 124px); /* base diameter (touch.js measures the real one) */
  --zone: calc(var(--stick) + 72px); /* invisible hit area around a stick */
  --slider-h: clamp(128px, 47vh, 184px);
  --pad: 12px; /* gap between the outer controls and the screen edge */
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  position: fixed;
  inset: 0;
  z-index: 12;
  touch-action: none;
  -webkit-touch-callout: none;
}

.tc.hidden {
  display: none;
}

@media (orientation: portrait) {
  .tc {
    --pad: 10px;
  }
}

.tc-stick {
  position: absolute;
  width: var(--zone);
  height: var(--zone);
  touch-action: none;
}

.tc-left {
  left: calc(var(--pad) + var(--safe-l));
  bottom: calc(10px + var(--safe-b));
}

.tc-right {
  right: calc(var(--pad) + var(--safe-r));
  bottom: calc(10px + var(--safe-b));
}

.tc-base {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--stick);
  height: var(--stick);
  margin: calc(var(--stick) / -2) 0 0 calc(var(--stick) / -2);
  border-radius: 50%;
  border: 1px solid rgba(108, 230, 255, 0.5);
  background: radial-gradient(circle, rgba(108, 230, 255, 0.05) 0%, rgba(8, 12, 16, 0.4) 60%, rgba(108, 230, 255, 0.12) 100%);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.45), inset 0 0 22px rgba(108, 230, 255, 0.1);
  transition: transform 0.06s ease-out;
}

.tc-stick.on .tc-base {
  border-color: rgba(150, 242, 255, 0.95);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.45), 0 0 18px rgba(108, 230, 255, 0.4), inset 0 0 22px rgba(108, 230, 255, 0.16);
}

.tc-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 50% 38%, #dcfcff 0%, #49c9ee 46%, #0e6f8f 100%);
  box-shadow: 0 0 14px rgba(108, 230, 255, 0.55), 0 3px 8px rgba(0, 0, 0, 0.5);
}

.tc-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.26em;
  color: rgba(223, 230, 238, 0.74);
  pointer-events: none;
}

/* thrust slider: up = forward (amber), down = back (cyan); springs to the centre */
.tc-slider {
  position: absolute;
  left: calc(var(--pad) + var(--zone) + var(--safe-l));
  bottom: calc(16px + var(--safe-b));
  width: 70px;
  height: var(--slider-h);
  touch-action: none;
}

.tc-track {
  position: absolute;
  left: 50%;
  top: 10px;
  bottom: 10px;
  width: 8px;
  transform: translateX(-50%);
  border-radius: 4px;
  background: rgba(108, 230, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(108, 230, 255, 0.22);
}

.tc-tick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 2px;
  transform: translate(-50%, -50%);
  background: rgba(223, 230, 238, 0.6);
}

.tc-fill {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 0;
  transform: translate(-50%, 0);
  border-radius: 7px;
  background: linear-gradient(180deg, #ffd9a8, #ff9a3c);
  box-shadow: 0 0 12px rgba(255, 154, 60, 0.6);
}

.tc-fill.back {
  background: linear-gradient(180deg, #6ce6ff, #1f8fb5);
  box-shadow: 0 0 12px rgba(108, 230, 255, 0.6);
}

.tc-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60px;
  height: 32px;
  border-radius: 9px;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #2b343f, #161b21);
  border: 1px solid rgba(255, 217, 168, 0.8);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
}

.tc-slider.on .tc-thumb {
  border-color: #fff;
  box-shadow: 0 0 14px rgba(255, 154, 60, 0.55), 0 3px 10px rgba(0, 0, 0, 0.55);
}

.tc-slider .tc-label {
  bottom: -6px;
}

/* fire below, missile above, to the left of the right stick */
.tc-btn {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  letter-spacing: 0.12em;
  touch-action: none;
  transition: transform 0.05s ease-out, filter 0.05s ease-out;
}

.tc-fire {
  right: calc(var(--pad) + var(--zone) + 14px + var(--safe-r));
  bottom: calc(22px + var(--safe-b));
  width: 86px;
  height: 86px;
  font-size: 15px;
  color: #1a0f04;
  background: radial-gradient(circle at 50% 36%, #ffe7c6 0%, #ffa64d 48%, #c9621a 100%);
  border: 2px solid rgba(255, 217, 168, 0.9);
  box-shadow: 0 0 18px rgba(255, 154, 60, 0.45), 0 4px 12px rgba(0, 0, 0, 0.5);
}

.tc-missile {
  right: calc(var(--pad) + var(--zone) + 19px + var(--safe-r));
  bottom: calc(126px + var(--safe-b));
  width: 76px;
  height: 76px;
  font-size: 12px;
  color: #dff8ff;
  background: radial-gradient(circle at 50% 36%, #1f8fb5 0%, #0f4f6a 55%, #082836 100%);
  border: 2px solid rgba(108, 230, 255, 0.85);
  box-shadow: 0 0 16px rgba(108, 230, 255, 0.35), 0 4px 12px rgba(0, 0, 0, 0.5);
}

.tc-btn.on {
  filter: brightness(1.4);
  transform: scale(0.94);
}

/* tilt steering: the device aims, so one stick is enough and the buttons take its place */
.tc-tilt .tc-right {
  display: none;
}

.tc-tilt .tc-fire {
  right: calc(32px + var(--safe-r));
}

.tc-tilt .tc-missile {
  right: calc(37px + var(--safe-r));
}

.tc-menu {
  position: absolute;
  right: calc(var(--pad) + var(--safe-r));
  top: calc(10px + env(safe-area-inset-top, 0px));
  padding: 12px 18px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--cyan);
  background: rgba(8, 12, 16, 0.6);
  border: 1px solid rgba(108, 230, 255, 0.5);
  border-radius: 8px;
}

body.touch {
  -webkit-tap-highlight-color: transparent;
}

/* Out of the thumbs' way, above the reticle */
body.touch .toast {
  bottom: 62vh;
  font-size: 13px;
}

/* Tall and narrow: no room side by side, so the right-hand group becomes a column
   (right stick over the two buttons) and the buttons move out to the screen edge.
   Last in the file on purpose: it overrides the landscape rules of the same weight. */
@media (orientation: portrait) {
  .tc .tc-right {
    bottom: calc(204px + var(--safe-b)); /* clear of the slider's corner as well as of MISSILE */
  }

  .tc .tc-fire {
    right: calc(var(--pad) + var(--safe-r));
    bottom: calc(16px + var(--safe-b));
    width: 80px;
    height: 80px;
  }

  .tc .tc-missile {
    right: calc(var(--pad) + 5px + var(--safe-r));
    bottom: calc(112px + var(--safe-b));
  }
}
