:root {
  color-scheme: dark;
  --space: #080e12;
  --ink: #f5efe5;
  --muted: #adbfbc;
  --mint: #9de4ce;
  --amber: #ffb878;
  --line: #a1c9bf38;
  --panel: #101a1ef2;
  --mono: ui-monospace, 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  --sans: system-ui, sans-serif;
  --edge: clamp(1rem, 4vw, 4.5rem);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 0;
  background: var(--space);
  color: var(--ink);
  font: 1rem/1.5 var(--sans);
}

h1, h2, p, dl, dd { margin: 0; }
button, input { font: inherit; }
button:focus-visible, input:focus-visible, #view:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.fallback-space, #view {
  display: block;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.fallback-space { pointer-events: none; }
#view { touch-action: none; }

#lobby {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(1.5rem, 5vh, 4rem);
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(1rem, 3.6vh, 2.5rem) var(--edge);
  pointer-events: none;
}

#lobby::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(90deg, #080e12ed, #080e127d 46%, #080e1220 75%),
    linear-gradient(0deg, #080e12f5, transparent 28%, transparent 77%, #080e12bf),
    repeating-linear-gradient(90deg, transparent 0 calc(8.333% - 1px), #a1c9bf13 calc(8.333% - 1px) 8.333%);
}

.masthead, .controls, .lobby-main {
  width: 100%;
  max-width: 92rem;
  margin-inline: auto;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.brand, .signal, .eyebrow, .hero-meta, .console-strip, .controls-heading,
.field label, .readout dt, .hud-hint {
  font: 700 .69rem/1.4 var(--mono);
  letter-spacing: .10em;
  text-transform: uppercase;
}

.brand, .signal { display: flex; align-items: center; gap: .65rem; }
.brand-mark { flex: none; width: 2.25rem; color: var(--mint); }
.brand small, .controls-heading small {
  display: block;
  margin-top: .25rem;
  font-size: .66rem;
  font-weight: 400;
  color: var(--muted);
}

.signal { color: var(--mint); }
.signal i, .console-strip i, .eyebrow i {
  display: inline-block;
  flex: none;
  width: .39rem;
  height: .39rem;
  background: var(--mint);
  box-shadow: 0 0 .75rem #9de4ce88;
}

.lobby-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(19rem, 25rem);
  align-items: center;
  gap: clamp(1.75rem, 6vw, 7rem);
}

.hero { container-type: inline-size; }
.hero-tag { color: var(--amber); }
.hero-tag span {
  display: inline-block;
  margin-right: .55rem;
  border: 1px solid #ffb87866;
  padding: .29rem .45rem;
}

.hero h1 {
  margin: clamp(.8rem, 2vh, 1.35rem) 0 clamp(1.1rem, 3vh, 2rem);
  font-size: min(clamp(4.5rem, 10.4vw, 11.5rem), 17.5cqi);
  font-weight: 800;
  line-height: .85;
  letter-spacing: -.085em;
  text-shadow: 0 .05em .3em #080e128c;
}

.hero h1 em { display: block; color: var(--amber); font-weight: 750; }
.hero-copy { max-width: 31ch; color: #d7e1dd; font-size: clamp(1rem, 1.6vw, 1.27rem); }
.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.25rem;
  width: fit-content;
  margin-top: clamp(1.1rem, 3.8vh, 2.5rem);
  padding-top: .65rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.hero-meta span:first-child { color: var(--mint); }

.console {
  border: 1px solid var(--line);
  background: var(--panel);
}

.lobby-console, .victory-card {
  position: relative;
  border-top-color: var(--mint);
  background: linear-gradient(145deg, #1b2c2ef5, #10191dfc 55%);
  box-shadow: 0 1.25rem 4rem #0008;
}

.lobby-console::before, .victory-card::before {
  content: '';
  position: absolute;
  inset: -1px -1px auto auto;
  width: 1.65rem;
  height: .27rem;
  background: var(--mint);
}

.console-strip {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .65rem;
  padding: .78rem clamp(.9rem, 2.4vw, 1.65rem);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.console-strip span:first-child { color: var(--mint); }
.console-strip i, .eyebrow i { margin-right: .32rem; vertical-align: .08em; }
.console-body { padding: clamp(1rem, 2.4vw, 1.65rem); }
.console-body h2 { font-size: clamp(1.65rem, 2.7vw, 2.2rem); letter-spacing: -.05em; line-height: 1.1; }
.console-intro { margin: .55rem 0 1.3rem; color: var(--muted); font-size: .9rem; }

#join-form { display: grid; gap: .85rem; pointer-events: auto; }
.field { display: grid; gap: .38rem; min-width: 0; }
.field label { color: var(--ink); }
.field label span { margin-right: .2rem; color: var(--mint); }
.field input {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: .6rem .75rem;
  background: #080e12c9;
  color: var(--ink);
  font-family: var(--mono);
}
.field input::placeholder { color: #a9bab6; opacity: 1; }
.field input:focus { border-color: var(--mint); }

.form-actions { display: grid; gap: .45rem; margin-top: .2rem; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: .66rem;
  min-height: 2.65rem;
  padding: .55rem .75rem;
  border: 1px solid transparent;
  border-radius: 0;
  font-weight: 750;
  text-align: left;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.button span { font: 1.15em var(--mono); }
.button-primary { background: var(--amber); color: #20150f; }
.button-primary:not(:disabled):hover { background: #ffd1a5; }
.button-secondary, .hud-button { border-color: var(--line); background: #151f23; color: var(--ink); }
.button-secondary:not(:disabled):hover, .hud-button:not(:disabled):hover { border-color: var(--mint); color: var(--mint); }
.button:disabled { opacity: .55; cursor: default; }
#lobby-error { color: #ffad9f; font-size: .85rem; overflow-wrap: anywhere; }
#lobby-error:empty { margin-top: -.85rem; }

.controls {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: .65rem 1.75rem;
  padding: .85rem 0 0;
  border-top: 1px solid var(--line);
}
.controls-heading { color: var(--mint); }
.key-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1.1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: #cedad7;
  font-size: .77rem;
}
kbd {
  display: inline-block;
  padding: .1rem .32rem;
  border: 1px solid var(--line);
  background: #101a1ecf;
  color: var(--ink);
  font: 700 .72rem/1.25 var(--mono);
}

#hud {
  --hud-edge: clamp(.65rem, 2vw, 1.65rem);
  position: fixed;
  z-index: 1;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1.06fr);
  grid-template-rows: auto 1fr auto;
  grid-template-areas: 'crew mission readings' '. . .' 'radio radio actions';
  align-items: start;
  gap: .65rem;
  padding: var(--hud-edge);
  pointer-events: none;
  font-size: .85rem;
}

#hud button, #hud a[href] { pointer-events: auto; }
#hud .console { box-shadow: 0 .35rem 1.2rem #0006; }
.hud-crew, .hud-mission, .hud-radio { padding: .65rem .8rem; min-width: 0; overflow-wrap: anywhere; }
#hud .eyebrow { color: var(--mint); }
.hud-crew { grid-area: crew; width: 100%; max-width: 17rem; }
.hud-room { display: flex; gap: .45rem; justify-content: space-between; align-items: center; }
.hud-room > div { min-width: 0; }
#room-label { display: block; margin-top: .15rem; color: var(--ink); font: 750 1.2rem/1.1 var(--mono); }
.hud-button { min-height: 2.1rem; padding: .38rem .53rem; font-size: .75rem; }
.crew-heading { margin-top: .6rem; padding-top: .54rem; border-top: 1px solid var(--line); }
.hud-mission { grid-area: mission; justify-self: center; width: 100%; max-width: 29rem; }
#chapter { margin-top: .2rem; font-size: clamp(1rem, 1.9vw, 1.28rem); letter-spacing: -.025em; line-height: 1.2; }
#objective, #crew, #radio { color: #d2dfdb; line-height: 1.35; }
:is(#objective, #crew, #radio):not(:empty) { margin-top: .32rem; }
:is(#objective, #crew, #radio) :is(ul, ol) { margin: 0; padding-inline-start: 1rem; }

.hud-readouts {
  grid-area: readings;
  justify-self: end;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  max-width: 24rem;
  border-top-color: var(--amber);
}
.readout { padding: .67rem .48rem; min-width: 0; overflow-wrap: anywhere; }
.readout + .readout { border-left: 1px solid var(--line); }
.readout dt { font-size: .64rem; letter-spacing: .045em; color: var(--muted); }
.readout dd { margin-top: .18rem; font: 750 clamp(.92rem, 1.9vw, 1.4rem)/1.15 var(--mono); }
.readout-wave dd { color: var(--amber); }
.readout-fuel dd { color: var(--mint); }

.crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.1rem;
  height: 1.1rem;
  transform: translate(-50%, -50%);
  color: var(--ink);
  filter: drop-shadow(0 0 2px #000) drop-shadow(0 0 2px #000);
}
.crosshair::before, .crosshair::after { content: ''; position: absolute; background: currentColor; }
.crosshair::before { inset: calc(50% - .5px) 0; }
.crosshair::after { inset: 0 calc(50% - .5px); }
.context-prompt {
  position: absolute;
  top: calc(50% + 1.3rem);
  left: 50%;
  width: max-content;
  max-width: calc(100% - 2 * var(--hud-edge));
  transform: translateX(-50%);
  padding: .34rem .7rem;
  border: 1px solid #ffb87870;
  background: #101a1ef5;
  color: var(--amber);
  font-weight: 700;
  overflow-wrap: anywhere;
  text-align: center;
  white-space: pre-line;
}
.context-prompt:empty { display: none; }

.hud-radio { grid-area: radio; align-self: end; width: 100%; max-width: 29rem; }
#radio { white-space: pre-line; }
.crew-row { display: flex; align-items: baseline; gap: .45rem; }
.crew-row i { flex: 0 0 .48rem; height: .48rem; border-radius: 50%; }
.blackout #view { filter: brightness(.025); transition: filter 1.25s ease; }
.hud-actions {
  grid-area: actions;
  align-self: end;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: .38rem;
}
.hud-hint { flex-basis: 100%; text-align: right; color: var(--ink); text-shadow: 0 1px 4px #000, 0 0 8px #000; }

#victory {
  position: fixed;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: auto;
  background: radial-gradient(ellipse at center, #172e2ed9, #080e12f5 75%);
}
.victory-card { width: min(100%, 32rem); }
.victory-card .console-body { padding: clamp(1.1rem, 4vw, 2.35rem); }
.victory-stamp {
  display: grid;
  place-items: center;
  width: 2.6rem;
  aspect-ratio: 1;
  margin-bottom: 1.1rem;
  border: 1px solid var(--mint);
  color: var(--mint);
  font: 1.45rem var(--mono);
}
.victory-card .eyebrow { margin-bottom: .4rem; color: var(--mint); }
.victory-card h2 { font-size: clamp(2.05rem, 6vw, 3.65rem); }
.victory-card p:not(.eyebrow) { margin: .7rem 0 1.45rem; color: var(--muted); }

@media (max-width: 60rem) {
  .lobby-main { gap: 1.5rem; }
  .hero h1 { font-size: min(clamp(3.75rem, 10.3vw, 6.2rem), 17.5cqi); }
  #hud { grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, 1.1fr); }
  .hud-readouts { grid-template-columns: 1fr; }
  .readout { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .2rem .45rem; padding: .38rem .55rem; }
  .readout + .readout { border-left: 0; border-top: 1px solid var(--line); }
  .readout dd { margin-top: 0; }
}

@media (max-width: 45rem) {
  #lobby { gap: 1.5rem; }
  #lobby::before { background: linear-gradient(120deg, #080e12db, #080e1255 66%), linear-gradient(0deg, #080e12f5, transparent 55%); }
  .lobby-main { grid-template-columns: minmax(0, 1fr); }
  .hero h1 { font-size: min(clamp(3rem, 14vw, 6rem), 17.5cqi); }
  .controls { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 37rem) {
  #hud {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: 'crew readings' 'mission mission' '. .' 'radio actions';
    gap: .38rem;
    font-size: .76rem;
  }
  .hud-crew, .hud-mission, .hud-radio { padding: .41rem .5rem; }
  .hud-mission { justify-self: start; }
  .hud-hint { letter-spacing: 0; }
  #room-label { font-size: .96rem; }
  #copy-invite { font-size: .65rem; }
  #radio { max-height: 14vh; max-height: 14dvh; overflow: hidden; }
}

@media (max-height: 33rem) {
  #hud .eyebrow, .hud-hint { font-size: .61rem; }
  .hud-crew, .hud-mission, .hud-radio { padding-block: .36rem; }
  #radio { max-height: 10vh; max-height: 10dvh; overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}
