* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #d8f3ff;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

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

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.panel {
  position: absolute;
  background: rgba(4, 14, 24, 0.62);
  border: 2px solid rgba(120, 210, 255, 0.35);
  padding: 12px 14px;
  line-height: 1.7;
}

#status {
  left: 20px;
  bottom: 20px;
  width: 300px;
}

#help {
  right: 20px;
  bottom: 20px;
  color: #9fc3d6;
}

#help b {
  color: #e8fbff;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.label {
  width: 112px;
  color: #7fb4cc;
  letter-spacing: 0.08em;
  font-size: 11px;
}

.value {
  font-size: 15px;
  color: #f1fcff;
}

.value.small {
  font-size: 12px;
  width: 40px;
  text-align: right;
}

.bar {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.12);
}

.fill {
  height: 100%;
  width: 100%;
  background: #6fe3a5;
}

.fill.warn {
  background: #ffc857;
}

.fill.crit {
  background: #ff5d5d;
}

#objective {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(4, 14, 24, 0.62);
  border: 2px solid rgba(120, 210, 255, 0.35);
  padding: 8px 16px;
  font-size: 14px;
  max-width: 90vw;
  text-align: center;
}

.marker {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 22px;
  line-height: 1;
  color: #7dffb0;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
  will-change: transform;
}

/* A target that is out of view: an arrow on the screen edge pointing towards it, with the distance */
.marker.edge {
  display: none;
  text-align: center;
  color: #ffd45c;
}

#beacon-arrow {
  width: 40px;
  height: 40px;
  margin: 0 auto;
}

#beacon-arrow svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 5;
  stroke-linecap: square;
  filter: drop-shadow(0 0 5px rgba(255, 212, 92, 0.9));
  animation: nudge 0.9s ease-in-out infinite;
}

@keyframes nudge {
  0%,
  100% {
    transform: translateX(-5px);
    opacity: 0.55;
  }
  50% {
    transform: translateX(5px);
    opacity: 1;
  }
}

.marker.edge span {
  display: inline-block;
  padding: 1px 7px;
  font-size: 14px;
  font-weight: 700;
  background: rgba(4, 18, 28, 0.75);
  text-shadow: none;
  white-space: nowrap;
}

#flash {
  position: absolute;
  inset: 0;
  background: #ff3b3b;
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 4, 10, 0.55);
}

.overlay.hidden {
  display: none;
}

.card {
  text-align: center;
  background: rgba(4, 14, 24, 0.85);
  border: 2px solid rgba(120, 210, 255, 0.45);
  padding: 28px 40px;
  max-width: 460px;
}

.card h1 {
  margin: 0 0 12px;
  letter-spacing: 0.3em;
  font-size: 26px;
}

.card p {
  margin: 8px 0;
  line-height: 1.5;
}

.dim {
  color: #8fb3c6;
}

#prompt {
  position: absolute;
  left: 50%;
  bottom: 32%;
  transform: translateX(-50%);
  text-align: center;
  font-size: 14px;
  line-height: 1.8;
  text-shadow: 0 0 6px #000, 0 0 2px #000;
  white-space: nowrap;
}

#prompt b {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  margin-right: 4px;
  color: #04121c;
  background: #7dd8ff;
  text-shadow: none; /* the prompt's dark outline would smear the dark letter on its light key */
}

/* An action that has just become possible gently grows and shrinks */
#prompt .pulse {
  display: inline-block;
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.14);
  }
}

/* Film bars, shown only with the cinematic camera */
#letterbox::before,
#letterbox::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  background: #000;
  transition: height 0.4s ease;
}

#letterbox::before {
  top: 0;
}

#letterbox::after {
  bottom: 0;
}

body.cinematic #letterbox::before,
body.cinematic #letterbox::after {
  height: 9vh;
}

body.cinematic #help,
body.cinematic .marker {
  opacity: 0;
}

body.cinematic #objective {
  top: calc(9vh + 12px);
}

body.cinematic #status {
  bottom: calc(9vh + 12px);
}

/* Controls panel: lines appear one at a time as the tutorial introduces them */
#help:empty {
  display: none;
}

#help div.new {
  animation: reveal 2.4s ease-out;
}

@keyframes reveal {
  0% {
    background: rgba(125, 216, 255, 0.55);
    color: #fff;
  }
  100% {
    background: transparent;
  }
}

/* Hidden until the astronaut is outside */
body.airlock:not(.helmet) #status,
body.airlock .marker {
  display: none !important;
}

#title {
  position: absolute;
  left: 0;
  right: 0;
  top: 34%;
  text-align: center;
  font-size: 30px;
  letter-spacing: 0.3em;
  color: #fff;
  text-shadow: 0 0 14px #000, 0 0 4px #000;
  opacity: 0;
  transition: opacity 1s;
}

#title.show {
  opacity: 1;
}

#title small {
  display: block;
  margin-top: 10px;
  font-size: 14px;
  letter-spacing: 0.2em;
  color: #9fd8f5;
}

#help {
  font-size: 12px;
  line-height: 1.6;
}

/* The picture of a button, used in instructions in place of a key name */
.ico {
  display: inline-flex;
  width: 24px;
  height: 24px;
  padding: 3px;
  margin: 0 2px;
  border-radius: 50%;
  vertical-align: middle;
  color: #04121c;
  background: #7dd8ff;
}

.ico svg,
.tbtn svg {
  width: 100%;
  height: 100%;
  display: block;
}

#prompt b.ico {
  min-width: 0;
  padding: 3px;
}

.card button {
  margin: 14px 5px 0;
  font: inherit;
  font-size: 14px;
  padding: 10px 22px;
  color: #04121c;
  background: #7dd8ff;
  border: 1px solid #7dd8ff;
  cursor: pointer;
}

/* The lesser choice of two: an outline only */
.card button.second {
  color: #7dd8ff;
  background: none;
}

.card button.hidden {
  display: none;
}

.card {
  max-width: min(460px, 92vw);
}

/* --- Touch screens: a look stick on the left, icon buttons on the right --- */
#touch {
  display: none;
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  left: env(safe-area-inset-left, 0px);
  pointer-events: none;
}

body.touch #touch {
  display: block;
}

body.touch,
body.touch canvas {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stick,
.tbtn {
  position: absolute;
  display: none;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  color: #e8fbff;
  background: rgba(4, 14, 24, 0.45);
  border: 2px solid rgba(125, 216, 255, 0.55);
}

#stick.on,
.tbtn.on {
  display: block;
}

#stick {
  left: 18px;
  bottom: 22px;
  width: 132px;
  height: 132px;
}

#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(125, 216, 255, 0.5);
  border: 2px solid rgba(232, 251, 255, 0.8);
}

.tbtn {
  width: 64px;
  height: 64px;
  padding: 15px;
}

.tbtn.down {
  background: rgba(125, 216, 255, 0.6);
  color: #04121c;
}

.tbtn.ready {
  border-color: #ffd45c;
  box-shadow: 0 0 14px rgba(255, 212, 92, 0.8);
  animation: pulse 0.9s ease-in-out infinite;
}

#t-thrust {
  right: 18px;
  bottom: 22px;
  width: 88px;
  height: 88px;
  padding: 20px;
}

#t-stop {
  right: 120px;
  bottom: 20px;
}

#t-grab {
  right: 112px;
  bottom: 98px;
}

#t-hook {
  right: 24px;
  bottom: 124px;
}

#t-camera,
#t-restart {
  right: 10px;
  width: 46px;
  height: 46px;
  padding: 10px;
}

#t-camera {
  top: 40px;
}

#t-restart {
  top: 96px;
}

/* The status panel becomes one thin strip along the top, out of the way of the thumbs */
body.touch #help,
body.touch .keys {
  display: none;
}

body.touch #status {
  top: calc(6px + env(safe-area-inset-top, 0px));
  left: 6px;
  right: 6px;
  bottom: auto;
  width: auto;
  display: flex;
  gap: 10px;
  padding: 3px 8px;
  border-width: 1px;
  line-height: 1.4;
}

body.touch #status .row {
  flex: 1;
  gap: 5px;
  min-width: 0;
  white-space: nowrap;
}

body.touch #status .row:nth-child(4),
body.touch #status .row:nth-child(6),
body.touch #status .value.small {
  display: none;
}

body.touch #status .label[data-short] {
  width: auto;
  font-size: 0;
}

body.touch #status .label[data-short]::before {
  content: attr(data-short);
  font-size: 9px;
}

body.touch #status .value {
  font-size: 11px;
}

body.touch #objective,
body.touch.cinematic #objective {
  top: calc(36px + env(safe-area-inset-top, 0px));
  max-width: calc(100vw - 130px);
  padding: 5px 10px;
  font-size: 13px;
  border-width: 1px;
}

body.touch #title {
  font-size: 22px;
}

body.touch.cinematic #status {
  bottom: auto;
}

body.touch #prompt {
  bottom: 44%;
  font-size: 13px;
}

/* --- Fitting the frame the game is shown in ---
   Small frames (the smallest portal embed is 821 x 462) get tighter panels and a two-column
   controls list, so the astronaut stays in view. Large and fullscreen frames get everything
   scaled up by --ui, which the game sets from the frame's height. Text never drops below 11px. */
.panel,
#objective,
#title,
#prompt,
.card {
  zoom: var(--ui, 1);
}

@media (max-height: 700px) {
  body:not(.touch) .panel {
    padding: 7px 10px;
    line-height: 1.45;
  }

  body:not(.touch) #status {
    left: 12px;
    bottom: 12px;
    width: 236px;
  }

  body:not(.touch) #status .label {
    width: 98px;
    font-size: 11px;
    letter-spacing: 0.04em;
  }

  body:not(.touch) #status .value {
    font-size: 13px;
  }

  body:not(.touch) #status .value.small {
    font-size: 11px;
    width: 34px;
  }

  #help {
    right: 12px;
    bottom: 12px;
    font-size: 11px;
    line-height: 1.45;
    columns: 2;
    column-gap: 16px;
    max-width: calc(100vw - 272px);
  }

  #help div {
    break-inside: avoid;
  }

  #objective {
    top: 12px;
    padding: 5px 12px;
    font-size: 13px;
  }

  #title {
    top: 30%;
    font-size: 22px;
  }

  #title small {
    margin-top: 6px;
    font-size: 12px;
  }

  #prompt {
    font-size: 13px;
  }

  .card {
    padding: 18px 28px;
  }

  .card h1 {
    font-size: 22px;
  }
}

/* Controls that share a line stay whole when the line has to wrap */
#help span {
  white-space: nowrap;
  margin-right: 8px;
}

/* --- A key named in the instruction: drawn as a keycap that presses itself until the player does --- */
kbd {
  display: inline-block;
  min-width: 24px;
  padding: 1px 7px 2px;
  margin: 0 2px 4px;
  font: inherit;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  color: #04121c;
  background: #cfeeff;
  border-radius: 4px;
  box-shadow: 0 4px 0 #4f8fb0;
  vertical-align: middle;
}

kbd.ask {
  background: #ffd45c;
  box-shadow: 0 4px 0 #a9781a;
  animation: keypress 0.9s ease-in-out infinite;
  animation-delay: var(--phase, 0s);
}

@keyframes keypress {
  0%,
  45%,
  100% {
    transform: translateY(0);
    box-shadow: 0 4px 0 #a9781a;
  }
  60%,
  80% {
    transform: translateY(4px);
    box-shadow: 0 0 0 #a9781a;
  }
}

/* --- First person: the inside of the helmet, with the suit's readouts on the faceplate --- */
#visor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}

#visor .pad {
  filter: drop-shadow(0 0 26px rgba(0, 0, 0, 0.85));
}

#visor.blocky {
  shape-rendering: crispEdges;
}

#visor.blocky .pad {
  filter: none;
}

/* The readouts are projected on the curved glass: no box, tilted to follow the faceplate, and each
   line set a little further in than the one above, the way the rim closes in towards the bottom. */
body.helmet:not(.touch) #status,
body.helmet:not(.touch) #help {
  background: none;
  border-color: transparent;
  color: #9fe6ff;
  text-shadow: 0 0 7px rgba(80, 200, 255, 0.85), 0 0 2px rgba(0, 10, 20, 0.9);
  filter: blur(calc(var(--fog, 0) * 1.3px));
  opacity: calc(1 - var(--fog, 0) * 0.4);
}

body.helmet:not(.touch) #status {
  left: 8vw;
  bottom: 12vh;
  transform-origin: 0 100%;
  transform: perspective(700px) rotateY(15deg) rotateZ(4deg);
}

body.helmet:not(.touch) #help {
  right: 8vw;
  bottom: 12vh;
  transform-origin: 100% 100%;
  transform: perspective(700px) rotateY(-15deg) rotateZ(-4deg);
}

body.helmet:not(.touch) #status .row:nth-child(2) { margin-left: 5px; }
body.helmet:not(.touch) #status .row:nth-child(3) { margin-left: 13px; }
body.helmet:not(.touch) #status .row:nth-child(4) { margin-left: 24px; }
body.helmet:not(.touch) #status .row:nth-child(5) { margin-left: 38px; }
body.helmet:not(.touch) #status .row:nth-child(6) { margin-left: 55px; }

body.helmet:not(.touch) #status .label,
body.helmet:not(.touch) #status .value,
body.helmet:not(.touch) #help b {
  color: #dff6ff;
}

body.helmet:not(.touch) #status .bar {
  background: rgba(140, 220, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(140, 220, 255, 0.4);
}

body.helmet:not(.touch) #status .fill:not(.warn):not(.crit) {
  background: #7fe0ff;
  box-shadow: 0 0 8px rgba(110, 215, 255, 0.8);
}

/* Breath on the glass: a patch of mist low in the middle that comes and goes */
#fog {
  position: absolute;
  inset: 0;
  opacity: 0;
  background:
    radial-gradient(ellipse 46% 40% at 50% 96%, rgba(226, 240, 250, 0.85), rgba(226, 240, 250, 0.3) 55%, transparent 100%),
    radial-gradient(ellipse 30% 26% at 34% 88%, rgba(226, 240, 250, 0.45), transparent 100%),
    radial-gradient(ellipse 30% 26% at 67% 90%, rgba(226, 240, 250, 0.4), transparent 100%);
  filter: blur(14px);
}

/* The power-up film plays with nothing over the picture but the film bars */
body.film #objective,
body.film #status,
body.film #prompt,
body.film #help {
  display: none !important;
}

/* --- Tutorial ghosts: a finger that slides left and right over the astronaut (touch), and a mouse that does the same when looking around is taught --- */
.ghost {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
}

.ghost > div {
  position: absolute;
  left: -26px;
  top: -18px;
  width: 52px;
  text-align: center;
  color: #ffd45c;
  animation: ghost-drag 2.6s ease-in-out infinite;
}

.ghost svg {
  width: 52px;
  height: 65px;
  display: block;
  fill: rgba(255, 255, 255, 0.28);
  stroke: #fff;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.7));
}

.ghost span {
  font-size: 15px;
  letter-spacing: 6px;
  text-shadow: 0 0 6px #000;
}

/* The mouse sits over the scene itself, so it carries its own dark backing to read against bright panels. */
#ghost-mouse svg {
  fill: rgba(8, 14, 26, 0.6);
  filter: drop-shadow(0 0 3px #000) drop-shadow(0 0 10px rgba(255, 255, 255, 0.55));
}

.ghost .wheel {
  fill: #ffd45c;
  stroke: none;
}

@keyframes ghost-drag {
  0%,
  100% {
    transform: translateX(0);
    opacity: 0.35;
  }
  12% {
    transform: translateX(0);
    opacity: 1;
  }
  35% {
    transform: translateX(-78px);
    opacity: 1;
  }
  75% {
    transform: translateX(78px);
    opacity: 1;
  }
  90% {
    transform: translateX(0);
    opacity: 1;
  }
}
