@charset "UTF-8";

:root {
  color-scheme: dark;
  --black: #020607;
  --bg: #03080a;
  --bg-soft: #061113;
  --panel: #040d0f;
  --panel-soft: rgba(8, 21, 23, 0.9);
  --line: rgba(166, 198, 191, 0.16);
  --line-strong: rgba(186, 218, 210, 0.34);
  --line-bright: rgba(214, 236, 228, 0.56);
  --ink: #e8efeb;
  --ink-soft: #c3d2cc;
  --muted: #8ba29c;
  --dim: #617873;
  --jade: #b8d4c8;
  --jade-bright: #dce9e2;
  --amber: #d7b582;
  --amber-soft: #e6cba6;
  --danger: #df8b76;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--black);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

button {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 1px solid var(--jade-bright);
  outline-offset: 3px;
}

::selection {
  background: rgba(184, 212, 200, 0.28);
  color: #fff;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  background: var(--black);
}

#world {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #010506;
  touch-action: none;
}

#world:focus {
  outline: none;
}

#water,
#mask,
.grain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#water {
  z-index: 1;
  background: radial-gradient(ellipse at 50% 58%, rgba(57, 55, 35, 0.34), rgba(24, 25, 17, 0.2) 64%, transparent 100%);
  opacity: 1;
  transition: opacity 0.6s ease;
}

#mask {
  z-index: 2;
  background:
    radial-gradient(ellipse at 50% 47%, transparent 34%, rgba(0, 5, 6, 0.25) 70%, rgba(0, 3, 4, 0.88) 100%);
  box-shadow: inset 0 0 18vw 5vw rgba(0, 3, 4, 0.55);
  transition: opacity 0.5s ease;
}

.grain {
  z-index: 3;
  display: none;
}

/* ---------- instrument chrome ---------- */

.masthead {
  position: absolute;
  top: calc(14px + var(--safe-top));
  left: calc(18px + var(--safe-left));
  right: calc(18px + var(--safe-right));
  z-index: 12;
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

body.playing .masthead {
  display: flex;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.24em;
  white-space: nowrap;
  text-shadow: 0 1px 8px #000;
}

.wordmark-mark {
  position: relative;
  width: 14px;
  height: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.wordmark-mark::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid var(--jade);
  border-radius: 50%;
  opacity: 0.65;
}

.wordmark-mark::after {
  content: "";
  position: absolute;
  top: -4px;
  bottom: -4px;
  left: 50%;
  width: 1px;
  background: var(--line-strong);
  transform: translateX(-50%);
}

#heading {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-shadow: 0 1px 6px #000;
  isolation: isolate;
}

#heading::before {
  content: "";
  position: absolute;
  top: 50%;
  right: -22px;
  left: -22px;
  z-index: -1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
}

#heading i {
  width: 1px;
  height: 6px;
  background: var(--line-strong);
}

#heading b {
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.11em;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  margin-left: auto;
  white-space: nowrap;
  pointer-events: auto;
}

.top-actions button {
  position: relative;
  min-width: 42px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(4, 13, 15, 0.74);
  color: var(--ink-soft);
  font-size: 10px;
  letter-spacing: 0.06em;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.top-actions button:hover {
  border-color: var(--line-strong);
  background: rgba(13, 29, 30, 0.92);
}

.top-actions button[aria-expanded="true"] {
  border-color: var(--line-bright);
  color: var(--jade-bright);
}

.top-actions button.warning {
  border-color: rgba(215, 181, 130, 0.58);
  color: var(--amber-soft);
}

#sound span {
  margin-left: 3px;
  color: var(--jade);
  font-size: 9px;
}

#sound span::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-right: 3px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: 1px;
}

#pause {
  min-width: 38px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(2, 7, 8, 0.58) 0, rgba(2, 7, 8, 0.08) 16%, transparent 32%, transparent 66%, rgba(2, 7, 8, 0.72) 100%);
}

.mission {
  position: absolute;
  top: calc(88px + var(--safe-top));
  left: calc(18px + var(--safe-left));
  max-width: min(340px, 56vw);
  pointer-events: none;
  text-shadow: 0 1px 8px #000, 0 1px 2px #000;
}

.mission::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: -11px;
  width: 1px;
  background: linear-gradient(180deg, var(--jade), rgba(184, 212, 200, 0.04));
  opacity: 0.7;
}

#phase {
  max-width: 100%;
  margin: 0 0 7px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.1em;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#mission-title {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.05em;
  line-height: 1.35;
}

#mission-sub {
  max-width: 280px;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.72;
  letter-spacing: 0.02em;
}

#equipment-hud {
  position: absolute;
  top: calc(164px + var(--safe-top));
  left: calc(18px + var(--safe-left));
  z-index: 1;
  max-width: 250px;
  color: var(--dim);
  font-size: 8px;
  letter-spacing: 0.04em;
  line-height: 1.8;
  white-space: pre-line;
  pointer-events: none;
  text-shadow: 0 1px 6px #000;
}

#event {
  position: absolute;
  top: calc(84px + var(--safe-top));
  left: 50%;
  z-index: 3;
  width: max-content;
  max-width: min(430px, 40vw);
  padding: 8px 13px;
  border: 1px solid rgba(215, 181, 130, 0.3);
  border-left: 2px solid var(--amber);
  background: rgba(18, 15, 9, 0.82);
  color: var(--amber-soft);
  font-size: 10px;
  line-height: 1.65;
  letter-spacing: 0.03em;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
  text-shadow: 0 1px 4px #000;
}

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  opacity: 0.55;
  pointer-events: none;
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: var(--jade-bright);
  opacity: 0.6;
}

#crosshair::before {
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
}

#crosshair::after {
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
}

#crosshair i {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  border: 1px solid var(--jade-bright);
  border-radius: 50%;
  background: rgba(2, 7, 8, 0.55);
  transform: translate(-50%, -50%);
}

#message {
  position: absolute;
  bottom: calc(184px + var(--safe-bottom));
  left: 50%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(620px, 82vw);
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

#message i {
  display: block;
  width: 20px;
  height: 1px;
  background: var(--amber);
  opacity: 0.7;
}

#message span {
  color: var(--ink);
  font-size: 11px;
  line-height: 1.8;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 3px #000, 0 0 12px #000;
}

#message:has(span:empty) {
  visibility: hidden;
}

.gauges {
  position: absolute;
  right: calc(18px + var(--safe-right));
  bottom: calc(18px + var(--safe-bottom));
  left: calc(18px + var(--safe-left));
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 28px;
  min-width: 0;
  padding-top: 14px;
  pointer-events: none;
  text-shadow: 0 1px 6px #000;
}

.gauges::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  background: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 14px);
  opacity: 0.5;
}

.air {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.air-number {
  display: flex;
  align-items: baseline;
  gap: 2px;
  color: var(--jade-bright);
  font-family: var(--mono);
  line-height: 0.8;
  font-variant-numeric: tabular-nums;
}

.air-number > span {
  font-size: 44px;
  font-weight: 300;
  letter-spacing: -0.06em;
}

.air-number small {
  color: var(--muted);
  font-size: 10px;
}

.air-detail {
  min-width: 118px;
}

.gauge-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

#air-state {
  color: var(--jade);
}

.air-track {
  position: relative;
  width: 132px;
  max-width: 22vw;
  height: 3px;
  background: rgba(190, 216, 208, 0.14);
}

.air-track > i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--jade), var(--jade-bright));
  transition: width 0.25s linear;
}

#return-tick {
  position: absolute;
  top: -4px;
  left: 0;
  width: 1px;
  height: 10px;
  background: var(--amber);
  opacity: 0.9;
  transition: left 0.3s ease;
}

#air-time {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--dim);
  font-size: 8px;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.power-gauge {
  flex: 0 0 auto;
  min-width: 64px;
}

.power-number {
  display: flex;
  align-items: baseline;
  gap: 2px;
  color: var(--ink-soft);
  font-family: var(--mono);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.power-number b {
  font-size: 24px;
  font-weight: 300;
}

.power-number small {
  color: var(--dim);
  font-size: 8px;
}

.power-gauge > span {
  display: block;
  margin: 5px 0 7px;
  color: var(--dim);
  font-size: 8px;
  letter-spacing: 0.12em;
}

.power-track {
  width: 80px;
  height: 2px;
  background: rgba(190, 216, 208, 0.14);
}

.power-track i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--jade);
  transition: width 0.25s linear;
}

.telemetry {
  display: flex;
  align-items: flex-end;
  gap: 22px;
  margin-left: auto;
  padding-left: 20px;
  border-left: 1px solid var(--line);
}

.telemetry > span {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  column-gap: 2px;
  min-width: 42px;
}

.telemetry small {
  grid-column: 1 / -1;
  margin-bottom: 5px;
  color: var(--dim);
  font-size: 7px;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.telemetry b {
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.telemetry em {
  color: var(--dim);
  font-size: 8px;
  font-style: normal;
}

.low-air #air,
.low-air #air-state {
  color: var(--danger);
}

.low-air #air-bar {
  background: linear-gradient(90deg, #b96d5d, var(--danger));
}

.low-air .air-number {
  animation: air-pulse 1.6s ease-in-out infinite;
}

.low-power #battery {
  color: var(--amber);
}

.low-power #battery-bar {
  background: var(--amber);
}

@keyframes air-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.62; }
}

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

#joystick {
  position: absolute;
  bottom: calc(84px + var(--safe-bottom));
  left: calc(16px + var(--safe-left));
  z-index: 4;
  display: none;
  width: 104px;
  height: 104px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(7, 18, 19, 0.32) 0 30%, rgba(4, 12, 13, 0.68) 31% 64%, rgba(3, 10, 11, 0.88) 65% 100%);
  box-shadow: 0 0 34px rgba(0, 0, 0, 0.36);
  pointer-events: auto;
  touch-action: none;
}

#joystick::before,
#joystick::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: var(--line);
  pointer-events: none;
}

#joystick::before {
  width: 62%;
  height: 1px;
  transform: translate(-50%, -50%);
}

#joystick::after {
  width: 1px;
  height: 62%;
  transform: translate(-50%, -50%);
}

#stick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 1px solid var(--line-bright);
  border-radius: 50%;
  background: rgba(18, 37, 34, 0.86);
  box-shadow: 0 0 22px rgba(184, 212, 200, 0.08);
  will-change: transform;
}

#joystick small {
  position: absolute;
  bottom: 7px;
  left: 50%;
  color: var(--dim);
  font-size: 6px;
  letter-spacing: 0.12em;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.actions {
  position: absolute;
  right: calc(18px + var(--safe-right));
  bottom: calc(108px + var(--safe-bottom));
  z-index: 4;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 68px;
  height: 62px;
  padding: 5px 4px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(4, 13, 15, 0.8);
  color: var(--ink-soft);
  touch-action: none;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.2s ease;
}

.actions button:hover {
  border-color: var(--line-strong);
  background: rgba(13, 29, 30, 0.92);
}

.actions button > span {
  color: var(--jade);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1;
}

.actions button > b {
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: nowrap;
}

.actions button > small {
  color: var(--dim);
  font-size: 7px;
  line-height: 1.2;
  white-space: nowrap;
}

.actions button.held {
  border-color: var(--line-bright);
  background: rgba(45, 70, 62, 0.9);
}

#marker b i {
  color: var(--amber);
  font-style: normal;
  font-family: var(--mono);
  font-size: 9px;
}

#interact {
  border-color: rgba(215, 181, 130, 0.42);
  background: rgba(30, 24, 13, 0.88);
}

#interact > span {
  color: var(--amber-soft);
}

#interact > b {
  color: var(--amber-soft);
}

.control-hint {
  display: none;
}

/* ---------- panels ---------- */

#lamp-panel,
#graphics-panel {
  position: absolute;
  top: calc(66px + var(--safe-top));
  right: calc(18px + var(--safe-right));
  z-index: 24;
  width: min(312px, calc(100vw - 24px));
  max-height: calc(100% - 84px - var(--safe-top) - var(--safe-bottom));
  padding: 18px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  color: var(--ink-soft);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
  overscroll-behavior: contain;
}

#lamp-panel::before,
#graphics-panel::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--jade), transparent);
  opacity: 0.6;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head b {
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
}

.panel-head button {
  width: 30px;
  height: 30px;
  margin: -4px -4px -4px 0;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.panel-head button:hover {
  color: var(--ink);
}

#lamp-panel label,
#graphics-panel label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 15px;
  color: var(--ink-soft);
  font-size: 10px;
  letter-spacing: 0.04em;
}

#lamp-panel output,
#graphics-panel output {
  color: var(--jade);
  font-family: var(--mono);
  font-size: 9px;
}

#lamp-panel input,
#graphics-panel input {
  display: block;
  width: 100%;
  height: 24px;
  margin: 7px 0 0;
  padding: 0;
  accent-color: var(--jade);
  cursor: pointer;
}

#lamp-panel input[type="range"],
#graphics-panel input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  height: 22px;
  background: transparent;
}

#lamp-panel input[type="range"]::-webkit-slider-runnable-track,
#graphics-panel input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--line-strong);
}

#lamp-panel input[type="range"]::-webkit-slider-thumb,
#graphics-panel input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  background: var(--jade-bright);
}

#lamp-panel input[type="range"]::-moz-range-track,
#graphics-panel input[type="range"]::-moz-range-track {
  height: 2px;
  background: var(--line-strong);
}

#lamp-panel input[type="range"]::-moz-range-thumb,
#graphics-panel input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  background: var(--jade-bright);
}

#lamp-panel p,
#graphics-panel p {
  margin: 11px 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.8;
}

#lamp-panel small {
  display: block;
  margin-top: 12px;
  color: var(--dim);
  font-size: 9px;
  line-height: 1.8;
}

.lamp-actions,
.panel-actions {
  display: flex;
  gap: 7px;
  margin: 14px 0 2px;
}

.panel-actions button {
  flex: 1;
  min-height: 38px;
  padding: 7px 6px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(25, 46, 42, 0.58);
  color: var(--ink-soft);
  font-size: 9px;
  line-height: 1.5;
}

.panel-actions button:hover {
  border-color: var(--line-strong);
}

#lamp-backup {
  color: var(--jade);
}

.quality-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.quality-row button {
  min-height: 48px;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(12, 27, 29, 0.66);
  color: var(--muted);
  font-size: 10px;
}

.quality-row button small {
  display: block;
  margin-top: 5px;
  color: var(--dim);
  font-size: 7px;
}

.quality-row button.selected {
  border-color: var(--line-bright);
  background: rgba(39, 61, 55, 0.78);
  color: var(--jade-bright);
}

.quality-row button.selected small {
  color: var(--jade);
}

#graphics-info {
  min-height: 18px;
  margin-top: 12px !important;
  color: var(--dim) !important;
  font-family: var(--mono);
  font-size: 8px !important;
  line-height: 1.7 !important;
}

.panel-note {
  padding-top: 3px;
  border-top: 1px solid var(--line);
}

.panel-reset {
  width: 100%;
  min-height: 38px;
  margin-top: 2px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--muted);
  font-size: 9px;
}

.panel-reset:hover {
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

/* ---------- entry ---------- */

#intro {
  position: absolute;
  inset: 0;
  z-index: 20;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background-color: var(--bg);
  background-image:
    linear-gradient(90deg, #03080a 0%, rgba(3, 8, 10, 0.98) 25%, rgba(3, 8, 10, 0.84) 42%, rgba(3, 8, 10, 0.26) 66%, rgba(3, 8, 10, 0.08) 100%),
    radial-gradient(ellipse at 73% 44%, rgba(37, 70, 68, 0.28), transparent 61%),
    url("./assets/cave-cover.webp");
  background-position: center, center, 72% center;
  background-size: cover, cover, cover;
  background-repeat: no-repeat;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

#intro::-webkit-scrollbar {
  width: 6px;
}

#intro::-webkit-scrollbar-track {
  background: transparent;
}

#intro::-webkit-scrollbar-thumb {
  background: var(--line-strong);
}

.intro-scroll {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  min-height: 100%;
  padding: 8vh 6vw calc(8vh + var(--safe-bottom));
}

.intro-copy {
  width: min(440px, 44vw);
  max-width: 440px;
  color: var(--ink);
}

.intro-copy::before {
  content: "";
  display: block;
  width: 36px;
  height: 1px;
  margin-bottom: 22px;
  background: var(--amber);
  opacity: 0.85;
}

.intro-copy h1 {
  margin: 0 0 18px;
  color: var(--ink);
  font-size: clamp(48px, 6.1vw, 78px);
  font-weight: 500;
  letter-spacing: 0.1em;
  line-height: 1.04;
  text-shadow: 0 2px 32px rgba(0, 0, 0, 0.52);
}

.intro-copy .lead {
  max-width: 28em;
  margin: 0 0 32px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.95;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.9);
}

.setup {
  display: grid;
  gap: 21px;
  width: 100%;
  max-width: 440px;
  margin-bottom: 28px;
}

.choice-group {
  min-width: 0;
}

.choice-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.18em;
}

.choice-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.level-nav,
.game-difficulties {
  display: grid;
  gap: 6px;
}

.level-nav,
.game-difficulties {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.level-nav button,
.game-difficulties button {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-height: 57px;
  padding: 10px 11px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(5, 15, 17, 0.68);
  color: var(--ink-soft);
  text-align: left;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.level-nav button:hover,
.game-difficulties button:hover {
  border-color: var(--line-strong);
  background: rgba(14, 30, 31, 0.82);
}

.level-nav button b,
.game-difficulties button b {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.level-nav button small,
.game-difficulties button small {
  color: var(--dim);
  font-size: 8px;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.5;
}

.level-nav button.selected,
.game-difficulties button.selected {
  border-color: rgba(214, 236, 228, 0.5);
  background: rgba(30, 53, 49, 0.76);
  color: var(--jade-bright);
}

.level-nav button.selected small,
.game-difficulties button.selected small {
  color: var(--jade);
}

.level-nav button.selected::before,
.game-difficulties button.selected::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: var(--amber);
}

.level-nav button:disabled,
.game-difficulties button:disabled {
  opacity: 0.55;
}

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 0 20px;
  border: 1px solid rgba(235, 243, 238, 0.85);
  border-radius: 2px;
  background: linear-gradient(180deg, #e2ece6 0%, #bad0c5 100%);
  color: #06100f;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.16em;
  transition: filter 0.18s ease, transform 0.12s ease, opacity 0.18s ease;
}

.primary:hover {
  filter: brightness(1.07);
}

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

.primary:disabled {
  border-color: var(--line);
  background: rgba(16, 28, 28, 0.9);
  color: var(--muted);
  filter: none;
}

.primary.secondary {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  font-weight: 400;
}

.start {
  position: relative;
  max-width: 440px;
  min-height: 60px;
  justify-content: center;
  padding-right: 52px;
  padding-left: 52px;
}

.start::after {
  content: "→";
  position: absolute;
  right: 22px;
  color: currentColor;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0;
  opacity: 0.72;
  transition: transform 0.18s ease;
}

.start:not(:disabled):hover::after {
  transform: translateX(3px);
}

.start:disabled::after {
  opacity: 0.3;
}

.help-panel {
  width: 100%;
  max-width: 440px;
  margin-top: 20px;
  border-top: 1px solid var(--line);
}

.help-panel summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 0;
  list-style: none;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.14em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.help-panel summary::-webkit-details-marker {
  display: none;
}

.help-panel summary::before {
  content: "＋";
  color: var(--jade);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
}

.help-panel[open] summary::before {
  content: "−";
}

.help-panel summary::after {
  content: "展开";
  margin-left: auto;
  color: var(--dim);
  font-size: 8px;
  letter-spacing: 0.08em;
}

.help-panel[open] summary::after {
  content: "收起";
}

.help-body {
  padding-bottom: 6px;
}

.help-keys {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.help-keys > div {
  min-width: 0;
  padding: 9px 0 10px;
  border-bottom: 1px solid rgba(166, 198, 191, 0.1);
}

.help-keys dt {
  margin: 0 0 3px;
  color: var(--dim);
  font-size: 8px;
  letter-spacing: 0.12em;
}

.help-keys dd {
  margin: 0;
  color: var(--ink-soft);
  font-size: 9px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.help-touch {
  margin: 11px 0 0;
  color: var(--dim);
  font-size: 9px;
  line-height: 1.75;
}

.help-meta {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 8px;
  line-height: 1.8;
}

.help-meta p {
  margin: 0 0 4px;
}

.help-meta-line {
  color: var(--muted);
}

.help-meta-line > span {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--amber);
  vertical-align: 1px;
}

.cave-label {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.intro-note {
  color: var(--dim);
  font-size: 8px;
  line-height: 1.8;
}

body[data-level="1"] .intro-copy::before {
  background: var(--jade);
}

body[data-level="2"] .intro-copy::before {
  background: var(--danger);
}

/* ---------- modals ---------- */

.modal {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: calc(22px + var(--safe-top)) calc(22px + var(--safe-right)) calc(22px + var(--safe-bottom)) calc(22px + var(--safe-left));
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(24, 47, 47, 0.3), transparent 62%),
    rgba(2, 6, 7, 0.9);
  overscroll-behavior: contain;
}

.modal-card {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100vh - 44px - var(--safe-top) - var(--safe-bottom));
  padding: 27px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(8, 21, 23, 0.98), rgba(3, 9, 11, 0.99));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.72);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.modal-card::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--jade), transparent);
  opacity: 0.65;
}

.modal .eyebrow,
.preparing-screen .eyebrow,
.review-kicker {
  margin: 0 0 9px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  line-height: 1.5;
}

.modal h2 {
  margin: 0 0 14px;
  color: var(--ink);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 0.08em;
  line-height: 1.25;
}

.modal p:not(.eyebrow):not(.result-tip) {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.85;
}

.modal .primary {
  margin-top: 22px;
}

.text-button {
  display: block;
  width: 100%;
  min-height: 42px;
  margin-top: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  transition: border-color 0.18s ease, color 0.18s ease;
}

.text-button:hover {
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.text-button:disabled {
  opacity: 0.38;
}

.help-panel-pause {
  width: 100%;
  margin-top: 16px;
}

.pause-card h2 {
  font-size: 28px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 22px 0 18px;
  border: 1px solid var(--line);
  background: var(--line);
}

.result-stats > span {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  padding: 13px 10px;
  background: rgba(4, 12, 14, 0.95);
}

.result-stats small {
  color: var(--dim);
  font-size: 8px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.result-stats b {
  color: var(--jade-bright);
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.result-tip {
  margin: 0 0 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 9px;
  line-height: 1.75;
}

.result-actions {
  display: grid;
  gap: 0;
}

.result-actions .primary {
  margin-top: 0;
}

.result-actions .primary + .primary,
.result-actions .primary + .text-button {
  margin-top: 8px;
}

/* ---------- route review ---------- */

.route-review-screen {
  position: absolute;
  inset: 0;
  z-index: 45;
  padding: calc(28px + var(--safe-top)) 6vw calc(28px + var(--safe-bottom));
  overflow-y: auto;
  background:
    radial-gradient(ellipse at 50% 28%, rgba(21, 44, 45, 0.26), transparent 65%),
    var(--bg);
  color: var(--ink);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.route-review-inner {
  max-width: 1020px;
  margin: 0 auto;
}

.route-review-inner > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.route-review-inner h2 {
  margin: 0;
  font-size: 30px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

#review-close {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(7, 18, 20, 0.75);
  color: var(--ink-soft);
  font-size: 10px;
}

.review-toolbar {
  display: flex;
  gap: 7px;
  margin: 16px 0;
}

.review-toolbar button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(9, 23, 25, 0.8);
  color: var(--muted);
  font-size: 10px;
}

.review-toolbar button[aria-pressed="true"] {
  border-color: var(--line-bright);
  background: rgba(38, 61, 55, 0.82);
  color: var(--jade-bright);
}

#review-canvas {
  display: block;
  width: 100%;
  height: min(52vh, 480px);
  min-height: 260px;
  border: 1px solid var(--line);
  background: #061012;
  touch-action: pan-y;
}

#review-summary {
  margin: 16px 0 0;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.8;
}

.review-note {
  margin: 8px 0 0;
  color: var(--dim);
  font-size: 9px;
  line-height: 1.75;
}

/* ---------- cave atlas ---------- */

.cave-atlas {
  position: absolute;
  inset: 0;
  z-index: 40;
  padding: calc(22px + var(--safe-top)) 22px calc(22px + var(--safe-bottom));
  overflow-y: auto;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.atlas-showing .cave-atlas {
  background: transparent;
}

.atlas-showing #world {
  z-index: 31;
}

.atlas-showing #water,
.atlas-showing #mask,
.atlas-showing .grain {
  visibility: hidden;
}

.atlas-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1480px;
  min-height: 100%;
  margin: 0 auto;
}

.atlas-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  background: rgba(3, 11, 13, 0.92);
}

.atlas-heading {
  min-width: 0;
}

.atlas-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.09em;
  line-height: 1.5;
}

.atlas-head h2 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: 24px;
  font-weight: 500;
  letter-spacing: 0.06em;
  line-height: 1.3;
}

.atlas-head p:not(.atlas-kicker) {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.7;
}

.atlas-close {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(12, 27, 29, 0.82);
  color: var(--ink-soft);
  font-size: 10px;
}

.atlas-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  background: rgba(3, 11, 13, 0.92);
}

.atlas-toolbar button {
  min-width: 38px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(15, 32, 34, 0.8);
  color: var(--ink-soft);
  font-size: 9px;
}

.atlas-toolbar button:hover {
  border-color: var(--line-strong);
}

.atlas-spacer {
  flex: 1;
}

.atlas-viewport {
  position: relative;
  width: 100%;
  height: clamp(300px, 60vh, 760px);
  overflow: hidden;
  border: 1px solid var(--line);
  background: transparent;
  cursor: grab;
  touch-action: none;
}

.atlas-viewport:active {
  cursor: grabbing;
}

.atlas-viewport canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.atlas-labels {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.atlas-3d-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 3px 6px;
  border: 1px solid rgba(186, 218, 210, 0.24);
  background: rgba(3, 11, 13, 0.8);
  color: var(--jade-bright);
  font-size: 9px;
  line-height: 1.45;
  white-space: nowrap;
  will-change: transform;
}

.atlas-gesture {
  position: absolute;
  bottom: 10px;
  left: 12px;
  z-index: 3;
  margin: 0;
  padding: 5px 8px;
  background: rgba(3, 11, 13, 0.72);
  color: var(--muted);
  font-size: 8px;
  line-height: 1.5;
  pointer-events: none;
}

.atlas-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 19px;
  padding: 4px 2px;
  color: var(--muted);
  font-size: 9px;
}

.atlas-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.atlas-legend i {
  display: inline-block;
  width: 14px;
  height: 2px;
}

.atlas-note {
  margin: 0;
  padding: 7px 2px 0;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 9px;
  line-height: 1.7;
}

/* ---------- loading and error ---------- */

.preparing-screen {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(31, 61, 61, 0.32), transparent 62%),
    var(--bg);
  text-align: center;
}

.preparing-card {
  width: min(360px, 100%);
}

.preparing-ring {
  position: relative;
  display: block;
  width: 46px;
  height: 46px;
  margin: 0 auto 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.preparing-ring::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.preparing-ring::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid transparent;
  border-top-color: var(--jade);
  border-radius: 50%;
  animation: preparing-spin 1.8s linear infinite;
}

@keyframes preparing-spin {
  to { transform: rotate(360deg); }
}

.preparing-screen h2 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.1em;
}

.preparing-screen p:not(.eyebrow) {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.8;
}

.preparing-screen small {
  display: block;
  margin-top: 20px;
  color: var(--dim);
  font-size: 9px;
  line-height: 1.8;
}

#error {
  position: absolute;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 22px;
  overflow-y: auto;
  background: rgba(2, 6, 7, 0.97);
}

.error-card {
  width: min(480px, 100%);
  padding: 27px;
  border: 1px solid rgba(223, 139, 118, 0.34);
  background: rgba(8, 17, 18, 0.98);
}

.error-card h2 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 24px;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.error-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.8;
}

.error-card pre {
  max-height: 32vh;
  margin: 0 0 18px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(2, 7, 8, 0.9);
  color: var(--amber-soft);
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.error-card button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: rgba(24, 45, 41, 0.7);
  color: var(--ink-soft);
  font-size: 10px;
}

/* ---------- responsive: compact desktop and phone portrait ---------- */

@media (max-width: 1100px) {
  .gauges {
    gap: 20px;
  }

  .telemetry {
    gap: 16px;
    padding-left: 16px;
  }

  .air-detail {
    min-width: 104px;
  }

  .air-track {
    width: 112px;
  }

  .actions button {
    width: 62px;
  }

  .intro-copy {
    width: min(430px, 48vw);
  }
}

@media (max-width: 900px) {
  #heading > span,
  #heading i {
    display: none;
  }

  #heading {
    gap: 0;
  }

  #event {
    top: calc(198px + var(--safe-top));
    max-width: min(430px, 68vw);
  }

  .intro-copy {
    width: min(430px, 56vw);
  }
}

@media (max-width: 760px) {
  .masthead {
    top: calc(8px + var(--safe-top));
    left: calc(12px + var(--safe-left));
    right: calc(12px + var(--safe-right));
  }

  .wordmark {
    display: none;
  }

  #heading {
    top: calc(100% + 9px);
    transform: translateX(-50%);
  }

  #heading b {
    font-size: 8px;
  }

  .top-actions {
    gap: 4px;
  }

  .top-actions button {
    min-width: 38px;
    height: 34px;
    padding: 0 6px;
    font-size: 8px;
    letter-spacing: 0;
  }

  #sound span {
    margin-left: 2px;
    font-size: 8px;
  }

  #sound span::before {
    width: 3px;
    height: 3px;
    margin-right: 2px;
  }

  #pause {
    min-width: 33px;
    font-size: 11px;
  }

  .mission {
    top: calc(78px + var(--safe-top));
    left: calc(14px + var(--safe-left));
    max-width: 58vw;
  }

  .mission::before {
    left: -9px;
  }

  #phase {
    font-size: 7px;
    letter-spacing: 0.06em;
  }

  #mission-title {
    margin-bottom: 5px;
    font-size: 16px;
  }

  #mission-sub {
    max-width: 220px;
    font-size: 9px;
    line-height: 1.65;
  }

  #equipment-hud {
    top: calc(156px + var(--safe-top));
    left: calc(14px + var(--safe-left));
    max-width: 215px;
    font-size: 8px;
  }

  #event {
    top: calc(190px + var(--safe-top));
    max-width: calc(100vw - 28px);
    font-size: 9px;
  }

  #message {
    bottom: calc(292px + var(--safe-bottom));
    max-width: 84vw;
  }

  #message span {
    font-size: 10px;
  }

  .gauges {
    right: calc(14px + var(--safe-right));
    bottom: calc(18px + var(--safe-bottom));
    left: calc(14px + var(--safe-left));
    gap: 14px;
  }

  .air {
    gap: 10px;
  }

  .air-number > span {
    font-size: 34px;
  }

  .air-number small {
    font-size: 8px;
  }

  .air-detail {
    min-width: 88px;
  }

  .gauge-label {
    gap: 8px;
    margin-bottom: 6px;
    font-size: 7px;
  }

  .air-track {
    width: 88px;
    max-width: 24vw;
  }

  #air-time {
    margin-top: 5px;
    font-size: 7px;
  }

  .power-gauge {
    min-width: 48px;
  }

  .power-number b {
    font-size: 20px;
  }

  .power-gauge > span {
    margin: 4px 0 6px;
    font-size: 7px;
  }

  .power-track {
    width: 52px;
  }

  .telemetry {
    gap: 10px;
    padding-left: 12px;
  }

  .telemetry > span {
    min-width: 36px;
  }

  .telemetry small {
    margin-bottom: 4px;
    font-size: 6.5px;
  }

  .telemetry b {
    font-size: 12px;
  }

  .telemetry em {
    font-size: 7px;
  }

  #joystick {
    display: block;
  }

  .actions {
    right: calc(12px + var(--safe-right));
    bottom: calc(84px + var(--safe-bottom));
    display: grid;
    grid-template-columns: repeat(2, 64px);
    gap: 7px;
  }

  .actions button {
    width: 64px;
    height: 58px;
  }

  .actions button > small {
    display: none;
  }

  .actions button > b {
    font-size: 8px;
  }

  #interact {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    flex-direction: row;
    gap: 8px;
    width: auto;
    height: 48px;
  }

  #interact > span {
    font-size: 16px;
  }

  .actions #marker b i {
    font-size: 8px;
  }

  #lamp-panel,
  #graphics-panel {
    top: calc(84px + var(--safe-top));
    right: calc(12px + var(--safe-right));
    width: min(312px, calc(100vw - 24px));
    max-height: calc(100% - 96px - var(--safe-top) - var(--safe-bottom));
  }

  .intro-scroll {
    display: block;
    min-height: 100%;
    padding: calc(43vh) 20px calc(38px + var(--safe-bottom));
  }

  .intro-copy {
    width: 100%;
    max-width: 430px;
  }

  .intro-copy::before {
    width: 30px;
    margin-bottom: 17px;
  }

  .intro-copy h1 {
    margin-bottom: 13px;
    font-size: clamp(40px, 11vw, 54px);
    letter-spacing: 0.08em;
  }

  .intro-copy .lead {
    margin-bottom: 24px;
    font-size: 12px;
    line-height: 1.85;
  }

  .setup {
    gap: 17px;
    margin-bottom: 22px;
  }

  .choice-label {
    margin-bottom: 7px;
    font-size: 8px;
  }

  .level-nav button,
  .game-difficulties button {
    min-height: 53px;
    padding: 8px 9px;
  }

  .level-nav button b,
  .game-difficulties button b {
    font-size: 11px;
  }

  .level-nav button small,
  .game-difficulties button small {
    font-size: 7.5px;
  }

  .start {
    min-height: 56px;
    font-size: 13px;
  }

  .help-panel {
    margin-top: 15px;
  }

  #intro {
    background-image:
      linear-gradient(180deg, rgba(3, 8, 10, 0.03) 0%, rgba(3, 8, 10, 0.08) 24%, rgba(3, 8, 10, 0.42) 35%, rgba(3, 8, 10, 0.88) 44%, #03080a 51%, #03080a 100%),
      radial-gradient(ellipse at 68% 18%, rgba(37, 70, 68, 0.26), transparent 58%),
      url("./assets/cave-cover.webp");
    background-position: center, center, 80% 40%;
    background-size: cover, cover, cover;
  }

  .modal {
    padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left));
  }

  .modal-card {
    max-height: calc(100vh - 28px - var(--safe-top) - var(--safe-bottom));
    padding: 22px;
  }

  .modal h2 {
    font-size: 26px;
  }

  .route-review-screen {
    padding: calc(20px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
  }

  .route-review-inner h2 {
    font-size: 25px;
  }

  #review-canvas {
    height: 44vh;
    min-height: 240px;
  }

  .cave-atlas {
    padding: calc(12px + var(--safe-top)) 12px calc(14px + var(--safe-bottom));
  }

  .atlas-head {
    padding: 11px 12px;
  }

  .atlas-head h2 {
    font-size: 21px;
  }

  .atlas-close {
    min-height: 34px;
    padding: 0 10px;
  }

  .atlas-toolbar {
    gap: 5px;
    padding: 6px;
  }

  .atlas-toolbar button {
    min-height: 32px;
    padding: 0 9px;
  }

  .atlas-viewport {
    height: 54vh;
    min-height: 280px;
  }

  .atlas-legend {
    gap: 7px 14px;
  }
}

@media (max-width: 640px) {
  #heading {
    display: flex;
  }

  .top-actions button {
    min-width: 36px;
    padding: 0 5px;
  }

  #lamp-panel,
  #graphics-panel {
    top: calc(80px + var(--safe-top));
  }

  .help-keys {
    gap: 0 12px;
  }

  .help-keys dd {
    font-size: 8.5px;
  }

  .result-stats > span {
    padding: 11px 7px;
  }

  .result-stats b {
    font-size: 15px;
  }

  .result-stats small {
    font-size: 7px;
  }
}

@media (max-width: 420px) {
  #equipment-hud {
    display: none;
  }

  #event {
    top: calc(186px + var(--safe-top));
  }

  .telemetry > span:nth-child(3) {
    display: none;
  }

  .intro-scroll {
    padding-top: calc(41vh);
  }

  .intro-copy h1 {
    font-size: 40px;
  }

  .level-nav button small,
  .game-difficulties button small {
    font-size: 7px;
  }

  .actions {
    grid-template-columns: repeat(2, 60px);
  }

  .actions button {
    width: 60px;
    height: 56px;
  }

  #interact {
    width: auto;
    height: 46px;
  }

  .gauges {
    gap: 9px;
  }

  .air-number > span {
    font-size: 31px;
  }

  .air-track {
    width: 76px;
  }

  .power-track {
    width: 44px;
  }

  .modal {
    padding: calc(10px + var(--safe-top)) calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left));
  }

  .modal-card {
    max-height: calc(100vh - 20px - var(--safe-top) - var(--safe-bottom));
    padding: 19px;
  }

  .modal .primary {
    margin-top: 17px;
  }

  .help-panel-pause {
    margin-top: 12px;
  }

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

  .help-keys > div {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 6px 0;
  }

  .help-keys dt {
    flex: 0 0 42px;
    margin: 0;
  }

  .help-keys dd {
    font-size: 8.5px;
  }

  .review-toolbar {
    flex-wrap: wrap;
  }

  #review-canvas {
    height: 40vh;
    min-height: 220px;
  }

  .atlas-legend {
    font-size: 8px;
  }

  .atlas-viewport {
    height: 50vh;
    min-height: 250px;
  }
}

@media (max-width: 360px) {
  .telemetry > span:nth-child(2) {
    display: none;
  }

  .telemetry {
    gap: 0;
    padding-left: 10px;
  }

  .air-detail {
    min-width: 76px;
  }

  .air-track {
    width: 62px;
  }

  .power-number b {
    font-size: 18px;
  }

  .top-actions button {
    min-width: 33px;
    font-size: 7.5px;
  }

  #sound span {
    font-size: 7px;
  }

  .intro-copy h1 {
    font-size: 36px;
  }

  .level-nav button b,
  .game-difficulties button b {
    font-size: 10px;
  }

  .level-nav button small,
  .game-difficulties button small {
    font-size: 6.5px;
  }
}

@media (pointer: coarse) {
  #joystick {
    display: block;
  }

  .actions button > small {
    display: none;
  }
}

/* ---------- short screens: keep the entry scrollable and controls clear ---------- */

@media (max-height: 700px) and (max-width: 760px) {
  .intro-scroll {
    padding-top: calc(33vh);
    padding-bottom: calc(26px + var(--safe-bottom));
  }

  .intro-copy::before {
    margin-bottom: 12px;
  }

  .intro-copy h1 {
    margin-bottom: 9px;
    font-size: 38px;
  }

  .intro-copy .lead {
    margin-bottom: 17px;
    font-size: 11px;
    line-height: 1.7;
  }

  .setup {
    gap: 12px;
    margin-bottom: 15px;
  }

  .choice-label {
    margin-bottom: 5px;
  }

  .level-nav button,
  .game-difficulties button {
    min-height: 45px;
    padding: 6px 8px;
    gap: 3px;
  }

  .level-nav button small {
    display: none;
  }

  .start {
    min-height: 50px;
  }

  .help-panel {
    margin-top: 9px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .masthead {
    top: calc(8px + var(--safe-top));
    left: calc(16px + var(--safe-left));
    right: calc(16px + var(--safe-right));
  }

  .wordmark {
    display: none;
  }

  .top-actions button {
    height: 30px;
    font-size: 9px;
  }

  #pause {
    min-width: 32px;
    font-size: 11px;
  }

  #heading {
    top: 50%;
    display: flex;
    transform: translate(-50%, -50%);
  }

  #heading > span,
  #heading i {
    display: none;
  }

  .mission {
    top: calc(54px + var(--safe-top));
    left: calc(16px + var(--safe-left));
    max-width: min(320px, 38vw);
  }

  #phase {
    font-size: 7px;
  }

  #mission-title {
    font-size: 15px;
  }

  #mission-sub {
    max-width: 240px;
    font-size: 9px;
  }

  #equipment-hud {
    display: none;
  }

  #event {
    top: calc(140px + var(--safe-top));
    max-width: min(320px, 36vw);
    font-size: 9px;
  }

  #message {
    bottom: calc(116px + var(--safe-bottom));
    max-width: 40vw;
  }

  #message span {
    font-size: 9px;
  }

  .gauges {
    top: calc(54px + var(--safe-top));
    right: calc(16px + var(--safe-right));
    bottom: auto;
    left: auto;
    flex-direction: column;
    align-items: flex-end;
    gap: 7px;
    width: min(250px, 31vw);
    padding-top: 0;
  }

  .gauges::before {
    display: none;
  }

  .air {
    gap: 9px;
  }

  .air-number > span {
    font-size: 31px;
  }

  .air-detail {
    min-width: 94px;
  }

  .air-track {
    width: 118px;
    max-width: 118px;
  }

  .gauge-label {
    margin-bottom: 5px;
  }

  #air-time {
    margin-top: 4px;
  }

  .power-gauge {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .power-number b {
    font-size: 18px;
  }

  .power-gauge > span {
    margin: 0;
    font-size: 7px;
  }

  .power-track {
    width: 74px;
  }

  .telemetry {
    gap: 13px;
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  .telemetry > span {
    min-width: 34px;
  }

  .telemetry small {
    margin-bottom: 3px;
  }

  .telemetry b {
    font-size: 11px;
  }

  #joystick {
    display: block;
    bottom: calc(12px + var(--safe-bottom));
    left: calc(16px + var(--safe-left));
    width: 84px;
    height: 84px;
  }

  #stick {
    width: 34px;
    height: 34px;
    margin: -17px 0 0 -17px;
  }

  #joystick small {
    bottom: 5px;
    font-size: 5.5px;
  }

  .actions {
    right: calc(16px + var(--safe-right));
    bottom: calc(12px + var(--safe-bottom));
    display: grid;
    grid-template-columns: repeat(2, 58px);
    gap: 6px;
  }

  .actions button {
    width: 58px;
    height: 52px;
  }

  .actions button > b {
    font-size: 8px;
  }

  #interact {
    height: 44px;
  }

  .intro-scroll {
    display: flex;
    align-items: center;
    min-height: 100%;
    padding: 20px 0 calc(24px + var(--safe-bottom));
  }

  .intro-copy {
    width: min(470px, 56vw);
    margin-left: 6vw;
    padding: 0;
  }

  .intro-copy::before {
    margin-bottom: 12px;
  }

  .intro-copy h1 {
    margin-bottom: 9px;
    font-size: clamp(34px, 5vw, 44px);
  }

  .intro-copy .lead {
    margin-bottom: 15px;
    font-size: 10px;
    line-height: 1.7;
  }

  .setup {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 13px;
  }

  .choice-label {
    margin-bottom: 4px;
    font-size: 7px;
  }

  .level-nav button,
  .game-difficulties button {
    min-height: 39px;
    padding: 5px 8px;
  }

  .level-nav button b,
  .game-difficulties button b {
    font-size: 9px;
  }

  .level-nav button small {
    display: none;
  }

  .start {
    min-height: 44px;
    font-size: 11px;
  }

  .help-panel {
    margin-top: 7px;
  }

  .help-panel summary {
    min-height: 32px;
    padding: 6px 0;
  }

  #intro {
    background-image:
      linear-gradient(90deg, #03080a 0%, rgba(3, 8, 10, 0.98) 28%, rgba(3, 8, 10, 0.8) 47%, rgba(3, 8, 10, 0.16) 72%, rgba(3, 8, 10, 0.04) 100%),
      radial-gradient(ellipse at 75% 46%, rgba(37, 70, 68, 0.22), transparent 60%),
      url("./assets/cave-cover.webp");
    background-position: center, center, 73% center;
    background-size: cover, cover, cover;
  }

  .modal {
    padding: calc(8px + var(--safe-top)) calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
  }

  .modal-card {
    max-height: calc(100vh - 16px - var(--safe-top) - var(--safe-bottom));
    padding: 17px;
  }

  .modal h2 {
    font-size: 23px;
  }

  .modal .primary {
    min-height: 44px;
    margin-top: 13px;
  }

  .text-button {
    min-height: 34px;
    margin-top: 5px;
  }

  .help-panel-pause {
    margin-top: 9px;
  }

  .route-review-screen {
    padding: calc(14px + var(--safe-top)) 18px calc(14px + var(--safe-bottom));
  }

  .route-review-inner > header {
    padding-bottom: 9px;
  }

  .route-review-inner h2 {
    font-size: 22px;
  }

  .review-toolbar {
    margin: 9px 0;
  }

  #review-canvas {
    height: 48vh;
    min-height: 180px;
  }

  .cave-atlas {
    padding: calc(8px + var(--safe-top)) 14px calc(9px + var(--safe-bottom));
  }

  .atlas-head {
    padding: 7px 10px;
  }

  .atlas-head h2 {
    font-size: 18px;
  }

  .atlas-viewport {
    height: calc(100vh - 184px);
    min-height: 190px;
  }

  .atlas-legend {
    padding: 0;
  }

  .atlas-note {
    display: none;
  }

  .preparing-screen h2 {
    font-size: 23px;
  }

  .preparing-ring {
    width: 36px;
    height: 36px;
    margin-bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- standalone map page ---------- */

body.map-standalone {
  position: static;
  height: auto;
  min-height: 100%;
  overflow: auto;
  background: var(--bg);
}

.map-standalone .cave-atlas {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(22px + var(--safe-top)) 22px calc(22px + var(--safe-bottom));
  background: var(--bg);
}

.map-standalone .atlas-inner {
  min-height: 0;
}

.map-standalone .atlas-viewport canvas {
  pointer-events: none;
}

.unlimited-resources .air-number small,
.unlimited-resources .power-number small {
  display: none;
}
