:root {
  --field-ivory: #eee8d7;
  --field-amber: #ffc05c;
  --field-steel: #839184;
  --field-edge: #65756a;
  --field-dark: #111b19;
  --field-mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}

#menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: safe center;
  justify-content: flex-start;
  padding: clamp(32px, 7vh, 85px) clamp(28px, 7.5vw, 150px);
  overflow: auto;
  isolation: isolate;
  color: var(--field-ivory);
  background: #19201d;
}
#menu[hidden] { display: none; }
#menu::before, #menu::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
#menu::before {
  background: #29312d url("/art/ringfall/ui/title.webp") center center / cover no-repeat;
  filter: saturate(1.26) contrast(1.04);
}
#menu::after {
  background:
    linear-gradient(90deg, #0b130fbd 0%, #0c140f88 27%, #10160f30 48%, transparent 68%),
    linear-gradient(0deg, #111714c7, transparent 22%);
}
.rf-title-station {
  width: min(460px, 43vw);
  min-width: 290px;
  position: relative;
  padding: 18px 0 16px;
  filter: drop-shadow(0 3px 8px #11171166);
}
#menu h1 {
  width: min(41vw, 600px);
  margin: 0 0 clamp(25px, 4vh, 48px);
  font-size: 0;
}
#menu h1 img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 2px 0 #343629) drop-shadow(0 6px 7px #14160f94);
}
.rf-launches, .rf-invite, .rf-settings, #menu #status {
  width: min(100%, 362px);
}
.rf-launches {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}
#menu button, #menu input, .rf-settings summary,
#pause-menu button, #debrief button, #pause, #leave-room {
  color: var(--field-ivory);
  border: 1px solid #6f7868;
  border-radius: 0;
  padding: 10px 13px;
  min-height: 42px;
  background: linear-gradient(110deg, #313a32f5, #222b24f7);
  box-shadow: inset 0 1px #cdd1bd1c, 0 2px 2px #10161052;
  font: 650 14px/1.26 system-ui, sans-serif;
  text-align: left;
}
#menu button, #menu summary, #pause-menu button, #debrief button, #pause, #leave-room { cursor: pointer; }
#menu button:hover, #menu summary:hover, #pause-menu button:hover, #debrief button:hover, #pause:hover, #leave-room:hover {
  border-color: #e4b16f;
  background: #424a3c;
}
#menu :is(button,input,summary,a):focus-visible, #pause-menu button:focus-visible,
#debrief button:focus-visible, #pause:focus-visible, #leave-room:focus-visible {
  outline: 2px solid #ffe6a9;
  outline-offset: 3px;
}
#menu #solo, #menu #resume { grid-column: 1 / -1; }
#menu button[hidden] { display: none; }
#menu #solo, #pause-menu #continue-mission, #debrief #debriefReturn {
  color: #24271e;
  border-color: #e6bd77;
  background:
    repeating-linear-gradient(169deg, transparent 0 19px, #896b3211 20px 21px, transparent 22px 33px),
    linear-gradient(105deg, #e4bb79, #d0a35f);
}
#menu #solo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  min-height: 55px;
  font-size: 19px;
  font-weight: 750;
}
#menu #solo:hover, #pause-menu #continue-mission:hover, #debrief #debriefReturn:hover { background-color: #eac480; filter: brightness(1.09); }
.rf-arrow { font: 400 26px/1 system-ui,sans-serif; }
.rf-invite {
  margin: 17px 0 0;
  padding: 12px 14px 14px;
  background: linear-gradient(105deg, #1d2721f5, #1b2420e6);
  border: 1px solid #71827685;
  border-left: 3px solid #8e9b86;
}
.rf-invite label, .rf-settings-body label {
  display: block;
  margin-bottom: 7px;
  color: #d3d9c6;
  font: 700 10px/1.3 var(--field-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.rf-invite > div {
  display: grid;
  grid-template-columns: minmax(86px, 1fr) auto;
  gap: 5px;
}
#menu input {
  width: 100%;
  min-width: 0;
  background: #101914f5;
  color: #f0e9ce;
  font: 500 13px/1.3 var(--field-mono);
  box-shadow: inset 0 2px 5px #0e120f66;
}
#menu input::placeholder { color: #adb6a6; opacity: 1; }
#menu #code { text-transform: uppercase; letter-spacing: .08em; }
#menu #join { padding-inline: 12px; }
#menu #join span { margin-left: 5px; }
#menu #status {
  margin: 8px 0 2px;
  padding: 7px 10px;
  border-left: 2px solid var(--field-amber);
  background: #15201bdf;
  font: 600 12px/1.4 var(--field-mono);
}
#menu #status:empty { display: none; }
.rf-settings { margin-top: 10px; }
.rf-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  border-color: transparent;
  background: #111b15b0;
  color: #d5dacb;
  box-shadow: none;
  padding-inline: 12px;
}
.rf-settings summary::-webkit-details-marker { display: none; }
.rf-settings summary::after { content: "+"; color: var(--field-amber); font: 20px/1 var(--field-mono); }
.rf-settings[open] summary::after { content: "−"; }
.rf-settings-body {
  padding: 12px;
  background: #1b261ff7;
  border: 1px solid #627361;
}
.rf-options { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 15px; }
#menu .rf-options button { min-height: 32px; padding: 5px 8px; font-size: 12px; }
.rf-settings-body p { margin: 12px 0 0; color: #c5ccbe; font: 12px/1.45 system-ui,sans-serif; }
#menu .rf-vanguard { display: inline-flex; gap: .65em; align-items:center; margin: 17px 0 0; color: #ecebda; font: 650 13px/1.45 system-ui,sans-serif; text-decoration-color: #a7ad93; text-underline-offset: 4px; }
.rf-vanguard span { color: var(--field-amber); }

#hud.rf-hud, #hud2.rf-hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 3;
  max-width: min(calc(100vw - 120px), 510px);
  background: none;
  border: 0;
  padding: 0;
  font: 500 12px/1.35 var(--field-mono);
  color: #eeeede;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#hud2.rf-hud { left: calc(50% + 12px); max-width: calc(50% - 115px); }
body:has(#hud2:not([hidden])) #hud.rf-hud { max-width: calc(50% - 24px); }
.rf-vitals {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  flex-wrap: wrap;
  gap: 1px;
  background: #20302cc2;
  border-left: 2px solid #e8b477;
}
.rf-vitals > * { padding: 4px 8px 5px; background: #17241fef; }
.rf-vitals > div { display: grid; align-content: center; position: relative; }
.rf-vitals span { color: #c0c6b7; font: 650 9px/1.3 var(--field-mono); letter-spacing: .04em; text-transform: uppercase; }
.rf-vitals strong { color: #f0ead8; font: 650 13px/1.35 var(--field-mono); }
.rf-vitals .rf-player { display: grid; place-content: center; color: #e5bd84; font-size: 13px; }
.rf-vitals .rf-shield { padding-bottom: 7px; }
.rf-vitals progress {
  position: absolute; bottom: 3px; left: 8px; width: calc(100% - 16px); height: 2px;
  appearance: none; border: 0; background: #455148; accent-color: #b6d2a6;
}
.rf-vitals progress::-webkit-progress-bar { background: #455148; }
.rf-vitals progress::-webkit-progress-value { background: #b6d2a6; }
.rf-vitals progress::-moz-progress-bar { background: #b6d2a6; }
#rf-objective, #rf-room {
  display: table;
  margin: 4px 0 0; padding: 5px 9px;
  border-left: 2px solid #dcb277;
  background: #131f1adf; color: #ebe8d8;
}
#rf-objective:empty, #rf-room:empty { display: none; }
body:has(#menu:not([hidden])) :is(#hud,#hud2,#help),
body:has(#pause-menu:not([hidden])) :is(#hud,#hud2,#help),
body:has(#debrief:not([hidden])) :is(#hud,#hud2,#help) { visibility: hidden; }

#help {
  left: max(12px,env(safe-area-inset-left)); bottom: max(12px,env(safe-area-inset-bottom));
  max-width: min(870px,calc(100vw - 230px)); padding: 5px 9px; border-left: 2px solid #788778;
  background: #18251ed5; color: #e2e2cf; font: 10px/1.5 var(--field-mono);
}
#build { border: 1px solid #7d82716e; background: #17201cde; color: #d2d4c2; font: 10px/1.25 var(--field-mono); }
#pause,#leave-room { top: max(12px,env(safe-area-inset-top)); right: max(14px,env(safe-area-inset-right)); min-height: 36px; padding: 6px 12px; }
#pause-menu {
  position: fixed;
  inset: 0;
  overflow: auto;
  display: grid; justify-content: center; align-content: safe center;
  padding: 24px;
  background: linear-gradient(105deg,#0b1713c4,#152018b5);
}
#pause-menu[hidden],#debrief[hidden],#hud2[hidden] { display: none; }
.rf-pause-plate, #debrief {
  width: min(420px,calc(100vw - 32px)); padding: 25px 26px; border: 1px solid #899081;
  border-top: 3px solid var(--field-amber); color: var(--field-ivory);
  background:
    repeating-linear-gradient(167deg, transparent 0 26px, #b3b39708 27px 28px, transparent 29px 64px),
    linear-gradient(120deg,#303a31fa,#17241ffa 65%);
  box-shadow: 0 15px 40px #09110dc2,inset 0 1px #c8c0a431;
}
#pause-menu h2,#debrief h2 { margin: 0 0 16px; color: #f0ebd9; font: 750 clamp(25px,4vw,36px)/1.08 system-ui,sans-serif; letter-spacing: -.035em; }
.rf-pause-plate { display: grid; gap: 7px; }
#pause-menu #restart { margin-top: 8px; }
#debrief { position: absolute; left: 50%; top: 50%; bottom: auto; transform: translate(-50%,-50%); min-width: 0; z-index: 7; }
#debrief p { margin: 0 0 16px; color: #d2d5c6; font-size: 14px; line-height: 1.5; }
#debrief button { width: 100%; }

@media (max-width: 710px) {
  #menu { padding: max(20px,env(safe-area-inset-top)) 6vw max(77px,env(safe-area-inset-bottom)); }
  #menu::before { background-position: 86% center; }
  #menu::after { background: linear-gradient(0deg,#101912f5 4%,#111c15de 35%,#111b1570 62%,#111b1500 90%); }
  .rf-title-station { width: min(100%,395px); min-width: 0; margin-top: auto; padding: 0; }
  #menu h1 { width: min(86vw,440px); margin-bottom: 18px; }
  .rf-launches,.rf-invite,.rf-settings,#menu #status { width: 100%; }
  #menu #solo { min-height: 46px; }
  .rf-invite { margin-top: 9px; padding: 8px 10px; }
  .rf-settings { margin-top: 6px; }
  #menu .rf-vanguard { margin-top: 7px; }
  #build { right: 5px; bottom: 5px; max-width: 64vw; font-size: 9px; }
  #hud.rf-hud,#hud2.rf-hud { top: 5px; left: 5px; max-width: calc(100vw - 82px); }
  #hud2.rf-hud { left: calc(50% + 3px); max-width: calc(50% - 45px); }
  .rf-vitals > * { padding: 3px 5px 4px; }
  .rf-vitals strong { font-size: 11px; }
  .rf-vitals span { font-size: 8px; }
  #rf-objective,#rf-room { padding: 3px 5px; font-size: 10px; }
  #pause,#leave-room { top: 5px; right: 5px; min-height: 28px; padding: 4px 8px; font-size: 12px; }
  #help { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #menu { align-items: flex-start; padding: 12px 4vw 28px; }
  .rf-title-station { width: min(42vw,390px); }
  #menu h1 { width: min(33vw,320px); margin-bottom: 7px; }
  #menu #solo { min-height: 36px; font-size: 16px;padding:6px 12px; }
  .rf-invite { margin-top: 6px; padding: 5px 8px; }
  #menu button,#menu input,.rf-settings summary { min-height: 32px;padding:5px 8px; }
  .rf-settings { margin-top: 3px; }
  #menu .rf-vanguard { margin-top: 6px; }
}
/* The boot error replaces the HUD contents before a mission can start. */
#hud.rf-hud:not(:has(.rf-vitals)):not(:empty) {
  visibility: visible;
  z-index: 24;
  padding: 8px 12px;
  color: #fee1aa;
  background: #281e18f2;
  border-left: 3px solid #d09157;
}
.rf-vanguard span {
  position: relative; display: inline-block; width: 7px; height: 7px; font-size: 0;
  border-top: 1.5px solid var(--field-amber); border-right: 1.5px solid var(--field-amber);
}
.rf-vanguard span::before {
  content: ""; position: absolute; width: 9px; height: 1.5px; background: var(--field-amber);
  right: -1px; top: -1px; transform-origin: right center; transform: rotate(-45deg);
}
#help { z-index: 3; pointer-events: auto; padding: 0; max-width: min(390px,calc(100vw - 120px)); }
#help summary { padding: 5px 9px; cursor: pointer; color: #e6e5d7; font: 600 11px/1.35 var(--field-mono); }
#help summary:focus-visible { outline: 2px solid #e8ba7a; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; padding: 5px 11px 10px; font-size: 11px; }
#help dt { color: #ddbd86; } #help dd { margin: 0; color: #e4e6d9; }
body:has(#debrief:not([hidden])) :is(#pause,#touch),
body:has(#pause-menu:not([hidden])) #touch { visibility: hidden; }

/* When virtual controls are active, keep both thumb zones free of telemetry. */
body:has(#menu[hidden]):has(#touch[style*="block"]) #performance-tools {
  top: max(54px,calc(env(safe-area-inset-top) + 52px));
  bottom: auto;
  right: max(8px,env(safe-area-inset-right));
  pointer-events: none;
}
body:has(#menu[hidden]):has(#touch[style*="block"]) #fps-toggle,
body:has(#menu[hidden]):has(#touch[style*="block"]) #performance-panel { pointer-events: auto; }
body:has(#menu[hidden]):has(#touch[style*="block"]) #performance-panel {
  position: fixed;
  top: max(91px,calc(env(safe-area-inset-top) + 91px));
  left: max(8px,env(safe-area-inset-left));
  width: min(355px,calc(100vw - 16px));
  max-height: max(112px,calc(100dvh - 363px));
  overflow: auto;
}
body:has(#menu[hidden]):has(#touch[style*="block"]) #build {
  left: max(5px,env(safe-area-inset-left));
  right: auto; bottom: 1px;
  max-width: calc(100vw - 10px);
  height: 15px; padding: 1px 5px;
  font: 9px/11px var(--field-mono);
  pointer-events: none;
}
@media (orientation: landscape) {
  body:has(#menu[hidden]):has(#touch[style*="block"]) #performance-panel {
    top: max(48px,calc(env(safe-area-inset-top) + 45px));
    width: min(355px,calc(100vw - 280px));
    max-height: max(105px,calc(100dvh - 205px));
  }
}
@media (max-height: 340px) and (orientation: landscape) {
  body:has(#menu[hidden]):has(#touch[style*="block"]) #performance-tools {
    top: max(6px,env(safe-area-inset-top)); right: max(86px,env(safe-area-inset-right));
  }
}

.rf-hud .supply-cue, .rf-hud .supply-use {
  color: #ffe3a3;
  background: #102124f5;
  border: 1px solid #d19b54;
  border-radius: 2px;
  padding: 4px 8px;
  font: 700 12px/1.2 system-ui,sans-serif;
}
.rf-hud .supply-use { pointer-events: auto; cursor: pointer; }
.rf-hud .supply-cue[hidden], .rf-hud .supply-use[hidden] { display: none; }
.rf-hud .field-readouts:has(:is(.supply-cue,.supply-use):not([hidden])) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

/* Keep both thumb zones on the bottom edge and all telemetry above the controls. */
#touch {
  --stick-size: clamp(72px, 18vmin, 106px);
  --control-base: max(20px, calc(env(safe-area-inset-bottom) + 10px));
}
#touch .stick {
  width: var(--stick-size); height: var(--stick-size); bottom: var(--control-base);
  border: 2px solid #6d928d;
  background: radial-gradient(circle, #29403fd9 0 42%, #14282be0 43% 66%, #425a54df 67%);
  box-shadow: 0 2px 6px #0007;
}
#touch #left { left: max(12px,env(safe-area-inset-left)); }
#touch #right { right: max(12px,env(safe-area-inset-right)); border-color: #b88d55; }
#touch .nub { width: 40%; height: 40%; left: 30%; top: 30%; border: 2px solid #a6c6b8; background: #47675f; }
#touch #right .nub { border-color: #f0c687; background: #84603c; }
#touch .stick span { position: absolute; bottom: 3px; width: 100%; text-align: center; text-transform: uppercase; font: 800 10px system-ui; color: #f2ecdb; pointer-events: none; }
.rf-actions {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: var(--control-base);
  display: grid; grid-template-columns: repeat(4, minmax(52px,1fr)); gap: 4px;
}
#touch .rf-actions button {
  position: static; pointer-events: auto; touch-action: none; user-select: none;
  min-height: 44px; padding: 4px 8px; border: 1px solid #708881; border-bottom: 2px solid #41675f;
  border-radius: 2px; background: linear-gradient(165deg,#273e3ef2,#0e2024f2); color: #f1ecda;
  font: 750 12px system-ui; box-shadow: 0 2px 4px #0005;
}
#touch .rf-actions button:active { background: #46675c; border-color: #92dec9; }
#touch #crateTouch { grid-column: span 2; color: #ffd99c; border-color: #a18355; }
#touch button:disabled { opacity: .59; }
body.ringfall:has(#touch[style*="block"]) #field-map {
  top: max(8px,env(safe-area-inset-top)); right: max(126px,calc(env(safe-area-inset-right) + 124px));
  bottom: auto; width: clamp(56px,17vmin,88px);
}
@media (max-width: 560px) {
  .rf-actions { bottom: calc(var(--control-base) + var(--stick-size) + 8px); }
  body.ringfall:has(#touch[style*="block"]) #field-map { top: 144px; right: max(8px,env(safe-area-inset-right)); }
}
