:root {
  --ui-small: 14px;
  --ui-body: 16px;
  --ui-title: 20px;
  --ui-display: 22px;
  --hud-label: 13px;
  --hud-meta: 11px;
  --ink: #14121F;
  --cream: #FAF3E1;
  --red: #FF3B5C;
  --yellow: #F5B82E;
  --blue: #38BDF8;
  --green: #34D399;
  --orange: #FF7A2F;
  --panel: rgba(18, 22, 34, 0.94);
  --panel-soft: rgba(28, 33, 50, 0.88);
  --border: #475569;
  --font-display: "Bahnschrift", "DIN Alternate", "Arial Black", "Impact", sans-serif;
  --font-ui: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, -apple-system, sans-serif;
  --bg-metal-top: #232736;
  --bg-metal-bot: #121520;
  --bg-plate: linear-gradient(180deg, rgba(30, 34, 48, 0.94) 0%, rgba(15, 18, 28, 0.96) 100%);
  --amber: #F5B82E;
  --cyan: #38BDF8;
  --crimson: #FF3B5C;
  --emerald: #34D399;
  --steel-line: rgba(148, 163, 184, 0.34);
  --cut-xs: polygon(4px 0,calc(100% - 4px) 0,100% 4px,100% calc(100% - 4px),calc(100% - 4px) 100%,4px 100%,0 calc(100% - 4px),0 4px);
  --cut-sm: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  --cut-md: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(245, 184, 46, 0.65) rgba(15, 18, 28, 0.8);
}

*:focus { outline: none; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #10131D; }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, #F5B82E, #D97706); border: 1px solid #10131D; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0A0C12;
  color: var(--cream);
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
}

#app {
  position: relative;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at center, rgba(30, 38, 60, 0.55) 0%, #090B10 75%),
    repeating-linear-gradient(0deg, rgba(148, 163, 184, 0.04) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, rgba(148, 163, 184, 0.04) 0 1px, transparent 1px 24px);
}

#stage-frame {
  position: relative;
  width: min(100%, calc((100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9));
  width: min(100%, calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9));
  container-type: size;
  aspect-ratio: 16 / 9;
  background: #121520;
  overflow: hidden;
  border: 1.5px solid rgba(148, 163, 184, 0.28);
  box-shadow:
    inset 0 0 0 1px rgba(245, 184, 46, 0.12),
    inset 0 0 28px rgba(0, 0, 0, 0.55),
    0 18px 56px rgba(0, 0, 0, 0.85);
}

#game-canvas {
  touch-action: none;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
}
#game-canvas.playing-cursor { cursor: none; }

.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.overlay-layer.hidden,
.hidden {
  display: none !important;
}

.overlay-layer.interactive {
  pointer-events: auto;
}

#toast-container {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 60;
}

.toast-msg {
  background: rgba(26, 22, 37, 0.92);
  color: var(--cream);
  border: 2px solid var(--yellow);
  border-radius: 0;
  padding: 5px 14px;
  font-size: clamp(11px, 1.8vw, 15px);
  font-weight: 700;
  text-shadow: 0 1px 0 #000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  animation: toastPop 0.2s ease-out;
}

.toast-msg.warn { border-color: var(--red); color: #FFD2D6; }
.toast-msg.good { border-color: var(--green); color: #D8FFE5; }

@keyframes toastPop {
  from { opacity: 0; transform: translateY(-6px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#portrait-warning {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 13, 24, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

body.mobile-portrait #portrait-warning {
  display: flex !important;
}

.portrait-card {
  background: var(--panel);
  border: 3px solid var(--yellow);
  border-radius: 16px;
  padding: 28px 22px;
  max-width: 340px;
}

.portrait-icon { font-size: 46px; margin-bottom: 10px; }
.portrait-title { margin: 0 0 8px; font-size: var(--ui-title); font-weight: 800; color: var(--yellow); }
.portrait-sub { margin: 0; font-size: var(--ui-small); color: #CFC9DC; }

.boot-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  background: radial-gradient(circle at 50% 42%, #20273B 0%, #0D1018 78%);
  pointer-events: auto;
  z-index: 50;
}
.boot-logo {
  width: min(46%, 240px);
  height: auto;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.75));
}

.boot-bar-wrap {
  width: min(72%, 340px);
  height: 16px;
  padding: 2px;
  background: #0D1018;
  border: 1.5px solid var(--steel-line);
  clip-path: var(--cut-sm);
  overflow: hidden;
  margin-top: 6px;
}

.boot-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--amber), #FF7A2F);
  -webkit-mask-image: repeating-linear-gradient(90deg, #000 0 16px, transparent 16px 20px);
  mask-image: repeating-linear-gradient(90deg, #000 0 16px, transparent 16px 20px);
  transition: width 0.08s linear;
}

.boot-label {
  margin-top: 4px;
  font-family: var(--font-display);
  letter-spacing: 0.5px;
  font-size: clamp(11px, 1.7vw, 13px);
  color: #E2E8F0;
  font-variant-numeric: tabular-nums;
}
.boot-tip {
  margin-top: 8px;
  max-width: min(86%, 440px);
  padding: 4px 12px;
  background: rgba(20, 24, 38, 0.85);
  border-left: 3px solid var(--amber);
  font-size: clamp(10px, 1.4vw, 12px);
  color: #CBD5E1;
}

.btn {
  position: relative;
  font: inherit;
  font-weight: 800;
  color: #14121F;
  background: linear-gradient(180deg, #FBD35B 0%, #D99B16 100%);
  border: 1.5px solid #14121F;
  clip-path: var(--cut-sm);
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), inset 0 -3px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.06s, filter 0.12s;
  pointer-events: auto;
}

.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.09); }
.btn:active:not(:disabled) { transform: translateY(1px); filter: brightness(0.96); }
.btn.red { background: linear-gradient(180deg, #ab2948, #80203b); color: #fff; }
.btn.blue { background: linear-gradient(180deg, #72d4ff, #43aadc); color: var(--ink); }
.btn.green { background: linear-gradient(180deg, #5EEAA8 0%, #059669 100%); color: #091812; }
.btn.dark:not(:disabled) { background: linear-gradient(180deg, #2C3246 0%, #191D2A 100%); color: var(--cream); border-color: var(--border); }

.btn:disabled, .storage-card:disabled { opacity: 1; background: #303442; color: #c4c9d4; border-color: #606775; cursor: not-allowed; }
.choice-card:disabled { color: #c4c9d4; border-style: dashed; cursor: wait; }

/* === Touch Controls === */
#touch-layer { touch-action: none; pointer-events: auto; z-index: 25; }
.touch-joy-zone { position: absolute; left: 0; top: 0; width: 52%; height: 100%; }
.touch-flipped .touch-joy-zone { left: auto; right: 0; }
.touch-joy-base {
  position: absolute; width: 112px; height: 112px; margin-left: -56px; margin-top: -56px;
  border-radius: 50%; background: rgba(26, 22, 37, 0.38); border: 2px solid rgba(250, 243, 225, 0.45);
  pointer-events: none; display: flex; align-items: center; justify-content: center;
}
.touch-joy-knob { width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 209, 71, 0.85); border: 2px solid var(--ink); }
.touch-diamond { position: absolute; right: 18px; bottom: 18px; width: 190px; height: 190px; transform-origin: bottom right; pointer-events: none; }
.touch-flipped .touch-diamond { right: auto; left: 18px; transform-origin: bottom left; }
.tbtn {
  position: absolute; width: 58px; height: 58px; border-radius: 50%; border: 3px solid var(--ink);
  color: #fff; font-weight: 800; font-size: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; pointer-events: auto;
  box-shadow: 0 3px 0 var(--ink); opacity: 1;
}
.tbtn.pressed { box-shadow: inset 0 0 0 3px #fff1bc; }
.tbtn-ico { font-size: 16px; line-height: 1; }
.tbtn-lbl { font-size: 9px; line-height: 1.05; text-shadow: 0 1px 0 #1A1625; }
.tbtn-throw { left: 66px; top: 0px; background: #D99B16; color: var(--ink); }
.tbtn-use   { left: 132px; top: 66px; background: #E13748; }
.tbtn-grab  { left: 0px; top: 66px; background: #2A82DE; }
.tbtn-jump  { left: 66px; top: 132px; background: #2FB563; color: var(--ink); }

/* === HUD === */
#hud-layer { z-index: 26; }
.hud-top-left {
  position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 5px;
  max-width: clamp(164px, 26vw, 232px);
}
.hud-time-card {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 0;
  padding: 3px 8px; font-size: clamp(10px, 1.4vw, 12px); font-weight: 800;
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
}
.hud-day-badge { background: var(--yellow); color: var(--ink); border-radius: 0; padding: 1px 5px; }
.hud-phase-txt.blood { color: var(--red); }

.hud-party-list { display: flex; flex-direction: column; gap: 4px; }
.hud-member {
  display: flex; align-items: center; gap: 6px; min-height: 38px;
  background: rgba(26, 22, 37, 0.84); border: 1.5px solid #494261; border-radius: 0;
  padding: 3px 7px; font-size: clamp(9px, 1.2vw, 11px); width: clamp(164px, 23vw, 224px);
  color: var(--cream); text-align: left; font-family: inherit; pointer-events: none;
  transition: border-color 0.12s, background 0.12s, opacity 0.12s;
}
.hud-member.is-me { border-color: var(--yellow); }
.hud-member.is-other-player { border-color: var(--blue); }
.hud-member.is-dead { opacity: 0.5; }
.hud-member.is-interactive { pointer-events: auto; cursor: pointer; }
.hud-member.is-ally.can-swap:hover,
.hud-member.is-ally.can-swap:active {
  border-color: var(--green); background: rgba(34, 62, 48, 0.90);
}
.hud-member.is-ally.too-far,
.hud-member.is-ally.diff-layer,
.hud-member.is-ally.is-escort {
  opacity: 0.78;
}
.hud-member.swap-ok {
  animation: cardSwapOk 0.25s ease-out;
}
.hud-member.swap-ng {
  animation: cardSwapNg 0.22s ease-out;
}
@keyframes cardSwapOk {
  0% { border-color: #4ADE80; box-shadow: 0 0 10px rgba(74, 222, 128, 0.85); }
  100% { box-shadow: none; }
}
@keyframes cardSwapNg {
  0%, 100% { transform: translateX(0); border-color: #FF4D5A; }
  25% { transform: translateX(-3px); border-color: #FF4D5A; }
  75% { transform: translateX(3px); border-color: #FF4D5A; }
}
.hud-item-slot {
  position: relative; flex: 0 0 32px; width: 32px; height: 32px;
  background: rgba(15, 13, 24, 0.85); border: 1.5px solid #59546D; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
}
.hud-member.is-ally.can-swap .hud-item-slot { border-color: #4ADE80; }
.hud-item-ico { width: 28px; height: 28px; image-rendering: pixelated; object-fit: contain; }
.hud-item-hand { font-size: 14px; opacity: 0.55; line-height: 1; }
.hud-item-fallback { font-size: 9px; font-weight: 900; color: var(--cream); }
.hud-swap-glyph {
  position: absolute; top: -3px; right: -3px; font-size: 9px; font-weight: 900; line-height: 1;
  background: #14532D; color: #86EFAC; border: 1px solid #4ADE80; border-radius: 3px; padding: 0 2px;
}
.hud-ico-badge {
  position: absolute; right: -3px; bottom: -3px; font-size: 8px; font-weight: 900; line-height: 1.1;
  padding: 0 3px; border-radius: 3px; font-variant-numeric: tabular-nums;
  border: 1px solid #14121F;
}
.hud-ico-badge.badge-ammo { background: #1E293B; color: var(--yellow); }
.hud-ico-badge.badge-zero { background: #a82742; color: #fff; }
.hud-ico-badge.badge-far { background: #991B1B; color: #FECACA; }
.hud-ico-badge.badge-layer { background: #475569; color: #E2E8F0; }
.hud-m-body { flex: 1; min-width: 0; }
.hud-m-row { display: flex; justify-content: space-between; gap: 4px; font-weight: 800; }
.hud-m-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-m-hp { font-variant-numeric: tabular-nums; flex-shrink: 0; }
.hud-hp-track { height: 5px; background: #2D2740; border-radius: 0; overflow: hidden; margin: 2px 0; }
.hud-hp-fill { height: 100%; background: var(--green); transition: width 0.08s; }
.hud-hp-fill.low { background: var(--red); }
.hud-hp-fill.ally { background: #38BDF8; }
.hud-hp-fill.other { background: #3B9EFF; }
.hud-m-sub { font-size: 9px; color: #CFC9DC; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-ai-tag { color: var(--yellow); font-size: 9px; flex-shrink: 0; }
.hud-ai-tag.escort { color: #38BDF8; }
.hud-ai-tag.other { color: #93C5FD; font-variant-numeric: tabular-nums; }

.hud-top-center {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: min(46%, 356px); display: flex; flex-direction: column; gap: 4px;
}
.hud-tutorial {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  gap: 2px 6px; padding: 4px 8px; background: var(--bg-plate); color: var(--cream);
  border-left: 3px solid var(--amber); font-size: clamp(10px, 1.25vw, 13px); line-height: 1.35;
}
#hud-tutorial-task small { color: var(--amber); font-weight: 800; white-space: nowrap; }
#hud-tutorial-skip { grid-column: 2; grid-row: 1; min-height: 30px; pointer-events: auto; }
#hud-tutorial-detail { grid-column: 1 / -1; font-size: .95em; }
@media (max-height: 560px) {
  .hud-top-center:has(.hud-tutorial:not(.hidden)) { z-index: 1; }
  #stage-frame:has(.hud-tutorial:not(.hidden)) #toast-container { top: max(12%, 76px); }
}
.hud-boss-card {
  background: var(--bg-plate); border: 1.5px solid var(--crimson);
  clip-path: var(--cut-sm); padding: 4px 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 4px 14px rgba(0, 0, 0, 0.65);
}
.hud-boss-card.is-phase2 {
  border-color: #FF3B5C;
  box-shadow: inset 0 0 14px rgba(255, 59, 92, 0.35), 0 0 14px rgba(255, 59, 92, 0.55);
  animation: bossP2Pulse 1.1s ease-in-out infinite alternate;
}
@keyframes bossP2Pulse {
  from { box-shadow: inset 0 0 10px rgba(255, 59, 92, 0.28), 0 0 8px rgba(255, 59, 92, 0.45); }
  to   { box-shadow: inset 0 0 18px rgba(255, 59, 92, 0.50), 0 0 18px rgba(255, 59, 92, 0.85); }
}
.hud-boss-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; font-weight: 900; color: #FFE4E8;
  text-shadow: 0 1px 0 #090B10;
}
.hud-boss-num {
  font-family: var(--font-display); font-variant-numeric: tabular-nums;
  letter-spacing: 0.4px; color: #FDA4AF;
}
.hud-boss-track {
  position: relative; height: 8px; background: #1F111A; border: 1px solid rgba(255, 59, 92, 0.35);
  overflow: hidden; margin: 3px 0;
}
.hud-boss-lag {
  position: absolute; left: 0; top: 0; bottom: 0; background: #FFF5F5; opacity: 0.78;
  transition: width 0.45s ease-out;
}
.hud-boss-fill {
  position: relative; z-index: 1; height: 100%;
  background: linear-gradient(90deg, #FF3B5C, #FF7A2F);
}
.hud-boss-hint { font-size: 9px; color: var(--amber); text-align: center; text-shadow: 0 1px 0 #090B10; }

.hud-top-right {
  position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; align-items: flex-end; gap: 5px;
}
.hud-navigation { display: flex; align-items: flex-start; gap: 5px; pointer-events: none; }
.hud-instruments { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; max-width: min(24vw, 240px); }
.hud-minimap {
  width: clamp(80px, min(13vw, 21vh), 144px); flex: none; pointer-events: none;
  background: var(--bg-plate); color: var(--cream); border: 1px solid var(--border);
  font: 800 10px/1.2 var(--font-ui); font-variant-numeric: tabular-nums;
}
.hud-minimap-caption { display: flex; justify-content: space-between; padding: 1px 3px; white-space: nowrap; }
.hud-minimap-caption > :first-child { color: var(--cyan); }
#hud-minimap-canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.hud-minimap-caption b { color: #65ffb4; }
/* Let the boss/vote panel use the space between the party and navigation on small stages. */
@media (max-width: 1024px), (max-height: 560px) {
  #hud-layer {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start; column-gap: 5px; padding: 8px;
  }
  .hud-top-left, .hud-top-center, .hud-top-right { position: static; }
  .hud-top-center { width: 100%; max-width: 356px; justify-self: center; transform: none; }
}
@media (max-height: 440px) and (orientation: landscape) {
  .hud-minimap { font-size: 9px; }
  .hud-minimap-caption { padding-block: 0; }
  .hud-instruments .compass-pill { padding-inline: 3px; }
  .hud-instruments:has(.hud-radar-frame:not(.hidden)) {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: start; max-width: min(34vw, 232px);
  }
  .hud-instruments :is(.hud-base-stock, .hud-compass-box) { grid-column: 1; }
  .hud-instruments .hud-radar-frame { grid-column: 2; grid-row: 1 / span 2; }
  #hud-radar-canvas { width: 72px; height: auto; }
}
.hud-compass-box { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; max-width: 240px; }
.compass-pill {
  background: var(--bg-plate); border: 1.5px solid var(--amber); clip-path: var(--cut-sm);
  padding: 2px 7px; font-size: 10px; font-weight: 800; display: flex; align-items: center; gap: 3px;
}
.compass-dist { color: #CBD5E1; font-size: 9px; font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.hud-radar-frame {
  position: relative; padding: 2px; background: linear-gradient(135deg, rgba(56, 189, 248, 0.55), rgba(15, 18, 28, 0.95));
  clip-path: var(--cut-sm); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.65);
}
.hud-radar-n {
  position: absolute; top: 2px; left: 5px; font-family: var(--font-display); font-size: 8px;
  font-weight: 900; color: var(--cyan); z-index: 2; text-shadow: 0 1px 0 #000;
}
.hud-radar-scan {
  position: absolute; inset: 2px; pointer-events: none; z-index: 2;
  background: repeating-linear-gradient(0deg, rgba(56, 189, 248, 0.08) 0 1px, transparent 1px 3px);
}
#hud-radar-canvas {
  display: block; background: rgba(12, 16, 26, 0.92); image-rendering: pixelated;
}

.hud-banner {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  background:
    repeating-linear-gradient(-45deg, rgba(255, 59, 92, 0.92) 0 6px, #121520 6px 12px) top / 100% 4px no-repeat,
    repeating-linear-gradient(-45deg, rgba(255, 59, 92, 0.92) 0 6px, #121520 6px 12px) bottom / 100% 4px no-repeat,
    rgba(14, 17, 26, 0.95);
  border-left: 3px solid var(--crimson); border-right: 3px solid var(--crimson);
  clip-path: var(--cut-sm); padding: 9px 22px;
  font-size: clamp(12px, 2vw, 16px); font-weight: 900; color: var(--amber);
  letter-spacing: 0.6px; text-shadow: 0 2px 0 #000;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.75);
}

.bottom-item-bar {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  background: var(--bg-plate); border: 1.5px solid var(--steel-line);
  clip-path: var(--cut-md); padding: 4px 10px;
  display: flex; align-items: center; gap: 10px;
  font-size: clamp(10px, 1.3vw, 12px); font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 4px 16px rgba(0, 0, 0, 0.72);
  white-space: nowrap;
}
.btm-slot-unit { display: flex; align-items: center; gap: 7px; }
.btm-ico-frame {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: flex; align-items: center; justify-content: center;
  background: #0D1018; border: 1.5px solid var(--amber); clip-path: var(--cut-sm);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.8);
}
.btm-ico-frame img { width: 28px; height: 28px; image-rendering: pixelated; object-fit: contain; }
.btm-ico-hand { font-size: 16px; line-height: 1; }
.btm-ico-fb { font-size: 10px; font-weight: 900; color: var(--amber); }
.btm-item-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.btm-item-name { font-size: 11px; font-weight: 900; color: var(--cream); text-shadow: 0 1px 0 #090B10; line-height: 1.1; }
.btm-dur-row { display: flex; align-items: center; gap: 5px; }
.btm-dur-track { width: 64px; height: 4px; background: #0B0D14; border: 1px solid #334155; overflow: hidden; }
.btm-dur-fill { height: 100%; transition: width 0.12s; }

.btm-right-unit { display: flex; flex-direction: column; gap: 3px; }
.btm-hp-row { display: flex; align-items: center; gap: 6px; }
.btm-hp-tag { font-family: var(--font-display); font-size: 10px; font-weight: 900; color: #94A3B8; letter-spacing: 0.5px; }
.btm-hp-track {
  position: relative; width: clamp(104px, 16vw, 152px); height: 10px;
  background: #0D1018; border: 1px solid rgba(148, 163, 184, 0.35); overflow: hidden;
}
.hud-hp-lag {
  position: absolute; left: 0; top: 0; bottom: 0; background: #FFFFFF; opacity: 0.78;
  transition: width 0.45s ease-out;
}
.btm-hp-fill {
  position: relative; z-index: 1; height: 100%;
  background: linear-gradient(90deg, #10B981, #34D399); transition: width 0.1s;
}
.btm-hp-fill.is-low { background: linear-gradient(90deg, #E11D48, #FF3B5C); animation: hpLowPulse 0.7s ease-in-out infinite alternate; }
@keyframes hpLowPulse { from { filter: brightness(0.95); } to { filter: brightness(1.3); } }
.btm-shield-fill {
  position: absolute; left: 0; top: 0; height: 3px; z-index: 2;
  background: var(--cyan); box-shadow: 0 0 6px rgba(56, 189, 248, 0.8);
}
.btm-hp-val {
  font-family: var(--font-display); font-variant-numeric: tabular-nums;
  font-size: 11px; font-weight: 900; color: var(--cream); text-shadow: 0 1px 0 #090B10;
}
.btm-hp-val.is-low { color: #FDA4AF; }
.btm-sh-txt { color: var(--cyan); font-size: 10px; }

.hud-key-hints { display: flex; align-items: center; gap: 5px; color: #CBD5E1; font-size: 9px; }
.key-pill { display: inline-flex; align-items: center; gap: 3px; color: #CBD5E1; }
.key-pill.hot { color: var(--amber); font-weight: 900; }
.key-pill.harv { color: var(--cyan); font-weight: 900; }
.gkey {
  display: inline-block; font-family: var(--font-display); font-size: 8.5px; font-weight: 900;
  color: #E2E8F0; background: linear-gradient(180deg, #334155, #1E293B);
  border: 1px solid #64748B; border-bottom-width: 2px; border-radius: 3px;
  padding: 0 4px; line-height: 1.3;
}
.key-pill.hot .gkey {
  color: #14121F; background: linear-gradient(180deg, #FBD35B, #D97706); border-color: #B45309;
}
@media (max-width: 820px) {
  .hud-key-hints { display: none; }
  .hud-key-hints:has(.harv) { display: flex; }
  .hud-key-hints .key-pill:not(.harv) { display: none; }
}

.ammo-pill {
  background: #1E293B; color: var(--amber); border: 1px solid rgba(245, 184, 46, 0.35);
  clip-path: var(--cut-sm); padding: 1px 6px; font-family: var(--font-display); font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.ammo-pill.empty { background: #a82742; color: #fff; border-color: #FDA4AF; animation: hpLowPulse 0.7s infinite alternate; }

/* === Modal & Screen UI === */
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(9, 11, 18, 0.78);
  display: flex; align-items: center; justify-content: center; padding: 14px; pointer-events: auto; z-index: 40;
}
.res-backdrop { backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.res-backdrop.after-boss-finish { animation: revealClear 0.15s var(--finish-hold) backwards; }
@keyframes revealClear {
  from { opacity: 0; visibility: hidden; }
  to { opacity: 1; visibility: visible; }
}
.modal-card {
  background: var(--bg-plate); border: 2px solid var(--amber); clip-path: var(--cut-md);
  padding: 14px 18px; width: min(92%, 560px); max-height: 100%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 14px 36px rgba(0, 0, 0, 0.78);
  animation: modalPopIn 0.18s cubic-bezier(0.2, 0.9, 0.25, 1);
}
@keyframes modalPopIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-card h2 {
  margin: 0 0 8px; font-size: clamp(15px, 2.5vw, 20px); color: var(--amber);
  letter-spacing: 0.4px; text-shadow: 0 2px 0 #090B10;
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 10px 0; }
.choice-card {
  background: linear-gradient(180deg, #23283A 0%, #171B28 100%);
  border: 1.5px solid var(--border); clip-path: var(--cut-sm); padding: 8px 10px;
  cursor: pointer; text-align: left; color: var(--cream); font: inherit;
  transition: border-color 0.12s, transform 0.08s;
}
.choice-card:hover { border-color: var(--amber); transform: translateY(-1px); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 10px; }

.res-banner-head {
  font-family: var(--font-display); font-size: clamp(18px, 3vw, 24px); font-weight: 900;
  letter-spacing: 1.2px; padding: 6px 12px; margin-bottom: 10px; text-shadow: 0 2px 0 #090B10;
}
.res-banner-head.is-gameover { background: rgba(255, 59, 92, 0.18); border-left: 4px solid var(--crimson); border-right: 4px solid var(--crimson); color: #FF5A75; }
.res-banner-head.is-clear { background: rgba(245, 184, 46, 0.18); border-left: 4px solid var(--amber); color: var(--amber); }
.res-reason { font-size: 13px; margin: 4px 0 10px; color: #E2E8F0; }
.res-unlock-pill {
  background: rgba(245, 184, 46, 0.15); border: 1.5px solid var(--amber); clip-path: var(--cut-sm);
  padding: 5px 10px; margin-bottom: 10px; font-size: 12px; font-weight: 800; color: var(--amber);
}
.res-score-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 10px; }
.res-score-tile {
  background: #141824; border: 1.5px solid var(--steel-line); clip-path: var(--cut-sm);
  padding: 7px 6px; text-align: center;
}
.res-k { font-size: 10px; color: #94A3B8; font-weight: 700; }
.res-v { font-family: var(--font-display); font-size: 16px; font-weight: 900; color: var(--amber); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* === Title, Slots, Base Bar, Facility Rows === */
.title-screen { position: absolute; inset: 0; pointer-events: auto; z-index: 45; overflow: hidden; }
.title-bg {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  animation: titleBgZoom 24s ease-in-out infinite alternate;
}
@keyframes titleBgZoom {
  from { transform: scale(1.00); }
  to   { transform: scale(1.07); }
}
.title-scrim {
  position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(12, 15, 24, 0.25) 0%, rgba(9, 11, 18, 0.84) 100%);
}
.title-embers { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.title-ember {
  position: absolute; bottom: -10px; background: var(--amber); border-radius: 50%;
  box-shadow: 0 0 6px #FF7A2F; opacity: 0;
  animation: titleEmberRise 5s linear infinite;
}
@keyframes titleEmberRise {
  0%   { transform: translateY(0) translateX(0); opacity: 0; }
  20%  { opacity: 0.75; }
  100% { transform: translateY(-280px) translateX(26px); opacity: 0; }
}
.title-content {
  position: relative; z-index: 2; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: safe center; gap: 10px; padding: 12px 12px 26px; overflow-y: auto;
}
.title-logo-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.title-logo {
  width: min(296px, 50vw, 47cqh); height: auto;
  filter: drop-shadow(0 5px 12px rgba(0, 0, 0, 0.75)) drop-shadow(0 0 12px rgba(245, 184, 46, 0.28));
  animation: titleLogoFloat 3.6s ease-in-out infinite;
}
@keyframes titleLogoFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
.title-tagline {
  font-family: var(--font-display); font-size: clamp(9px, 1.3vw, 11px);
  letter-spacing: 1.8px; color: var(--amber);
  background: rgba(12, 15, 24, 0.78); border: 1px solid rgba(245, 184, 46, 0.35);
  padding: 2px 10px; clip-path: var(--cut-sm);
}
.title-menu { flex: none; display: flex; flex-direction: column; gap: 6px; width: min(78%, 310px); }
.title-menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.title-menu .btn {
  width: 100%; font-size: clamp(10.5px, 1.5vw, 12.5px); padding: 6px 8px;
  display: flex; align-items: center; justify-content: center; gap: 4px; overflow: hidden;
}
.title-cta { font-size: clamp(12px, 1.8vw, 14px) !important; padding: 8px 12px !important; }
.title-cta::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 42px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-22deg); left: -60px;
  animation: ctaSweep 4s ease-in-out infinite;
}
@keyframes ctaSweep {
  0%, 72% { left: -60px; }
  100%    { left: 115%; }
}
.menu-arrow { opacity: 0; transform: translateX(-4px); transition: opacity 0.12s, transform 0.12s; font-size: 9px; }
.title-menu .btn:hover:not(:disabled) .menu-arrow { opacity: 1; transform: translateX(0); }
.title-footer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 12px; background: rgba(10, 12, 18, 0.82);
  border-top: 1px solid rgba(148, 163, 184, 0.22);
  font-family: var(--font-display); font-size: 9.5px; letter-spacing: 0.8px; color: #94A3B8;
}

.slot-list, .fac-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.slot-row { display: flex; gap: 6px; align-items: center; }
.slot-btn { flex: 1; }
.fac-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: rgba(24, 29, 44, 0.92); border: 1.5px solid var(--border); clip-path: var(--cut-sm);
  padding: 6px 10px; font-size: 12px;
}
.fac-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; position: relative;
  width: 42px; height: 22px; background: #1A1E2B; border: 1.5px solid #475569;
  clip-path: var(--cut-sm); cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.fac-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 3px; width: 14px; height: 14px;
  background: #94A3B8; clip-path: var(--cut-sm); transition: transform 0.15s, background 0.15s;
}
.fac-row input[type="checkbox"]:checked {
  background: rgba(5, 150, 105, 0.35); border-color: var(--emerald);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}
.fac-row input[type="checkbox"]:checked::after {
  transform: translateX(19px); background: var(--emerald);
}
.fac-row .vol-ctrl { min-width: 0; display: flex; align-items: center; gap: 8px; flex: 1; justify-content: flex-end; }
.fac-row input[type="range"] {
  appearance: none; -webkit-appearance: none; width: min(170px, 34vw); height: 24px;
  background: linear-gradient(#64748b, #64748b) center / 100% 4px no-repeat; border: 0; cursor: pointer;
}
.fac-row input[type="range"]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none; width: 12px; height: 18px;
  background: linear-gradient(180deg, #FBD35B, #D97706); border: 1px solid #14121F; cursor: pointer;
}
.fac-row input[type="range"]::-moz-range-thumb {
  width: 12px; height: 18px; background: linear-gradient(180deg, #FBD35B, #D97706);
  border: 1px solid #14121F; border-radius: 0; cursor: pointer;
}
.fac-row .vol-val {
  min-width: 38px; text-align: right; color: var(--amber); font-weight: 800;
  font-family: var(--font-display); font-variant-numeric: tabular-nums; font-size: 11px;
}
.stat-box {
  background: rgba(18, 22, 34, 0.90); border: 1.5px solid var(--border);
  clip-path: var(--cut-sm); padding: 8px 10px; font-size: 12px; line-height: 1.55;
}
.txt-inp {
  background: #0D1018; color: var(--cream); border: 1px solid #475569; border-bottom: 2px solid var(--amber);
  padding: 4px 8px; font: inherit; font-family: var(--font-display); width: 150px;
}

/* === Screen Transition Slash Wipe === */
#screen-wipe {
  position: absolute; inset: 0; z-index: 80; pointer-events: none;
  background: linear-gradient(115deg, transparent 0%, #14121F 18%, #090B10 82%, var(--amber) 83.5%, transparent 86%);
  transform: translateX(-110%);
}
#screen-wipe.active {
  animation: screenWipeAnim 0.28s cubic-bezier(0.25, 0.85, 0.35, 1) forwards;
}
@keyframes screenWipeAnim {
  0%   { transform: translateX(-105%); }
  48%  { transform: translateX(0%); }
  100% { transform: translateX(110%); }
}

.base-bar {
  position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  pointer-events: auto; z-index: 30;
}
.base-stock {
  background: var(--panel); border: 1.5px solid var(--ink); border-radius: 8px; padding: 3px 8px;
  font-size: clamp(9px, 1.3vw, 11px); font-weight: 800; color: var(--yellow);
}
.base-btns { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.base-btns .btn { font-size: 10px; padding: 4px 8px; }

/* === Rev2 / RA-1..RA-3 HUD & Facility Dock Panel === */
.hud-sys-btns {
  display: flex; gap: 4px; pointer-events: auto; align-items: center;
}
.btn.mini {
  font-size: 10px; padding: 2px 8px; border-radius: 0; box-shadow: 0 2px 0 var(--ink);
}
.hud-base-stock {
  background: var(--panel); border: 1.5px solid var(--ink); border-radius: 0;
  padding: 2px 7px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end;
  font-size: clamp(9px, 1.2vw, 11px); font-weight: 800; pointer-events: none;
}
.stock-chip { color: var(--cream); font-variant-numeric: tabular-nums; transition: color 0.15s, transform 0.15s; }
.stock-chip.zero { color: #b7b2c7; }
.stock-chip.changed { color: var(--yellow); transform: scale(1.12); text-shadow: 0 0 6px rgba(255, 209, 71, 0.7); }

.hud-base-pill {
  background: rgba(20, 83, 45, 0.9); color: #86EFAC; border: 1.5px solid #4ADE80;
  border-radius: 0; padding: 1px 5px; font-size: 9px; font-weight: 900;
}
.hud-rest-pill {
  background: rgba(120, 53, 15, 0.92); color: #FDE68A; border: 1.5px solid #FFD147;
  border-radius: 0; padding: 1px 5px; font-size: 9px; font-weight: 900;
}
.hud-layer-badge {
  background: #2C2740; color: #7DD3FC; border: 1px solid #0EA5E9;
  border-radius: 0; padding: 0 4px; font-size: 9px; font-weight: 800;
}
.hud-rest-banner {
  background: rgba(26, 22, 37, 0.92); border: 2px solid var(--yellow); border-radius: 0;
  padding: 4px 10px; font-size: 11px; font-weight: 900; color: var(--yellow); text-align: center;
}

#facility-panel-host {
  position: absolute; inset: 0; pointer-events: none; z-index: 35;
}
.facility-panel {
  position: absolute; right: 10px; top: 54px; width: min(442px, 48%);
  max-height: calc(100% - 112px); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  background: var(--bg-plate); border: 2px solid var(--amber); clip-path: var(--cut-md);
  padding: 8px 10px; pointer-events: auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 12px 30px rgba(0, 0, 0, 0.78);
  display: flex; flex-direction: column; gap: 7px;
}
.facility-panel.panel-enter {
  animation: dockSlideIn 0.16s ease-out;
}
@keyframes dockSlideIn {
  from { opacity: 0; translate: 18px 0; }
  to   { opacity: 1; translate: 0 0; }
}
body.is-touch .facility-panel {
  left: 50%; right: auto; top: 6px; transform: translateX(-50%);
  width: min(570px, 92%); max-height: calc(100% - 12px);
}
@media (max-width: 820px) {
  .facility-panel {
    left: 50%; right: auto; top: 6px; transform: translateX(-50%);
    width: min(570px, 92%); max-height: calc(100% - 12px);
  }
}
.wb-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
}
.wb-tab { padding: 4px 6px; font-size: 11px; }
.fac-panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  border-bottom: 1.5px solid #494261; padding-bottom: 5px;
}
.fac-panel-title { font-size: 13px; font-weight: 900; color: var(--yellow); }
.fac-close-btn {
  min-width: 36px; min-height: 30px; padding: 2px 8px; font-size: 12px;
}
.fac-sec {
  background: rgba(38, 33, 56, 0.78); border: 1.5px solid #494261; border-radius: 0;
  padding: 6px 8px; display: flex; flex-direction: column; gap: 5px;
}
.fac-sec-title { font-size: 11px; font-weight: 900; color: #93C5FD; }
.fac-row.selected {
  border-color: var(--yellow); border-left: 4px solid var(--yellow); background: #3A3256;
}
.fac-row.locked { border-style: dashed; }
.fac-pin-badge {
  display: inline-block; background: var(--yellow); color: var(--ink); border-radius: 4px;
  padding: 0 4px; font-size: 9px; font-weight: 900; margin-left: 4px;
}
.facility-panel .btn { min-height: 30px; font-size: 11px; padding: 4px 10px; }

.wb-mini-pill {
  position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; z-index: 28;
  background: rgba(26, 22, 37, 0.92); border: 2px solid var(--yellow); border-radius: 0;
  padding: 3px 6px; pointer-events: auto; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.65);
}
.wb-mini-pill .btn { min-height: 30px; padding: 3px 10px; font-size: 11px; border-radius: 0; }

.rest-fade-overlay {
  position: absolute; inset: 0; z-index: 55; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(14px, 2.4vw, 20px); font-weight: 900; color: var(--yellow);
  text-shadow: 0 2px 0 #1A1625;
  animation: restCrossfade 1.2s ease-out forwards;
}
@keyframes restCrossfade {
  0%   { background: rgba(14, 18, 54, 0.94); opacity: 1; }
  55%  { background: rgba(255, 178, 88, 0.42); opacity: 1; }
  100% { background: rgba(255, 220, 150, 0); opacity: 0; }
}

/* === Storage Box Panel (T7) === */
.storage-held-row {
  display: flex; align-items: center; gap: 7px;
  background: #221D33; border: 1px solid #494261; border-radius: 6px; padding: 4px 6px;
}
.storage-held-ico {
  width: 28px; height: 28px; flex: 0 0 28px; display: flex; align-items: center; justify-content: center;
  background: #14121F; border: 1px solid #59546D; border-radius: 4px;
}
.storage-held-name {
  flex: 1; min-width: 0; font-size: 11px; font-weight: 800; color: var(--cream);
  overflow-wrap: anywhere;
}
.storage-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.storage-tab { flex: 1; min-width: 58px; text-align: center; }
.storage-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px;
  padding-right: 2px;
}
.storage-empty {
  grid-column: 1 / -1; text-align: center; padding: 14px 6px; font-size: 11px; color: #94A3B8;
}
.storage-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #231E34; border: 1.5px solid #4F486A; border-radius: 0; padding: 6px 4px 4px;
  color: var(--cream); font-family: inherit; cursor: pointer; text-align: center;
  transition: border-color 0.1s, background 0.1s;
}
.storage-card:hover { border-color: var(--yellow); background: #312A48; }
.storage-count {
  position: absolute; top: 2px; right: 3px; font-size: 9px; font-weight: 900; line-height: 1.1;
  background: #334155; color: #E2E8F0; border-radius: 4px; padding: 0 4px; font-variant-numeric: tabular-nums;
}
.storage-count.multi { background: var(--yellow); color: var(--ink); }
.storage-ico { width: 32px; height: 32px; image-rendering: pixelated; object-fit: contain; }
.storage-ico-fb { width: 32px; height: 32px; line-height: 32px; font-size: 10px; font-weight: 900; color: var(--yellow); }
.storage-name {
  width: 100%; font-size: 10px; font-weight: 800; line-height: 1.15;
  overflow-wrap: anywhere;
}
.storage-dur-track {
  width: 90%; height: 3px; background: #14121F; border-radius: 2px; overflow: hidden; margin-top: 1px;
}
.storage-dur-fill { height: 100%; }
.storage-dur-lbl {
  font-size: 9px; font-weight: 800; color: #CFC9DC; font-variant-numeric: tabular-nums; line-height: 1.1;
}
.storage-dur-lbl.zero {
  background: #a82742; color: #fff; border-radius: 3px; padding: 0 4px;
}
.storage-cat-lbl {
  font-size: 9px; font-weight: 700; color: #93C5FD; background: rgba(14, 165, 233, 0.14);
  border-radius: 3px; padding: 0 5px; line-height: 1.2;
}


/* R8 plates. The inset ring has its own cut corners, including all diagonal edges. */
.ui-ico {
  --size: 16px; display: inline-block; width: var(--size); height: var(--size); flex: none;
  vertical-align: middle; background: url('../assets/textures/ui_icons.png') no-repeat;
  background-size: calc(8 * var(--size)) calc(8 * var(--size));
  background-position: calc(-1 * var(--ix) * var(--size)) calc(-1 * var(--iy) * var(--size));
  image-rendering: pixelated; pointer-events: none;
}
.btn, .modal-card, .facility-panel, .bottom-item-bar, .hud-boss-card, .compass-pill, .choice-card,
.fac-row, .hud-time-card, .hud-member, .hud-base-stock, .fac-sec, .storage-card, .wb-mini-pill, .toast-msg {
  --corner: 6px;
  --shape: polygon(var(--corner) 0,calc(100% - var(--corner)) 0,100% var(--corner),100% calc(100% - var(--corner)),calc(100% - var(--corner)) 100%,var(--corner) 100%,0 calc(100% - var(--corner)),0 var(--corner));
  clip-path: var(--shape); isolation: isolate;
}
.hud-time-card, .hud-member, .hud-base-stock, .fac-sec, .toast-msg, .compass-pill, .fac-row, .choice-card, .hud-boss-card { position: relative; }
:is(.btn,.modal-card,.facility-panel,.bottom-item-bar,.hud-boss-card,.compass-pill,.choice-card,.fac-row,.hud-time-card,.hud-member,.hud-base-stock,.fac-sec,.storage-card,.wb-mini-pill,.toast-msg)::before {
  content: ''; position: absolute; pointer-events: none; inset: -1px; z-index: 1;
  background: linear-gradient(145deg,#8994a0,#181b22 35%,#10121a 75%,#69747d);
  clip-path: polygon(0 0,100% 0,100% 100%,0 100%,0 0,
    2px var(--corner),2px calc(100% - var(--corner)),var(--corner) calc(100% - 2px),calc(100% - var(--corner)) calc(100% - 2px),
    calc(100% - 2px) calc(100% - var(--corner)),calc(100% - 2px) var(--corner),calc(100% - var(--corner)) 2px,var(--corner) 2px,2px var(--corner));
}
.hud-time-card, .fac-sec, .storage-card, .hud-base-stock, .hud-member { background: var(--bg-plate); }
.hud-time-card { display: grid; gap: 2px; align-content: center; height: 44px; border-left: 4px solid var(--amber); }
.clock-line,.location-line { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.location-line { overflow: hidden; font-size: 9px; color: #c3cddd; }
.clock-line .ui-ico { --size: 18px; }
.hud-day-badge,.hud-clock,.res-score-val,.boss-name,.hud-stock-val { font-variant-numeric: tabular-nums; letter-spacing: .06em; }
.stock-chip { display: inline-flex; align-items: center; gap: 2px; }
.stock-chip .ui-ico { --size: 14px; }
.portrait { width: 28px; height: 28px; object-fit: contain; image-rendering: pixelated; border: 2px solid #404b59; }
.is-me .portrait { border-color: var(--amber); }
.hud-member .hud-item-slot { order: 2; }
.hud-hp-track { position: relative; height: 9px; }
.hud-hp-fill { position: relative; }
.hud-hp-track::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(to right, transparent 0 calc(20% - 1px), #13182488 calc(20% - 1px) 20%); }
.hud-member .hud-hp-lag { animation: healthLoss .55s ease-out; }
@keyframes healthLoss { from { width: var(--from); } }
.is-hurt { animation: partyHit .18s ease-out; }
@keyframes partyHit { 20%, 65% { transform: translateX(-2px); background: #893344; } }
.ammo-pill.low,.ammo-pill.empty,.can-pick { animation: hpLowPulse .6s alternate infinite; }
.tbtn { background: radial-gradient(circle at 36% 25%,#ffffff88,transparent 57%), var(--pad-color,#ad7918); box-shadow: inset 0 2px 0 #ffffff88,inset 0 -4px 0 #15132288,0 3px 0 #13151d; }
.tbtn-use { --pad-color: #c04949; } .tbtn-grab { --pad-color: #2389ac; } .tbtn-jump { --pad-color: #279369; }
.tbtn.pressed { border-color: #fff1bc; } .tbtn .ui-ico { --size: 23px; }
.tbtn.can-pick { outline: 2px solid #ffc357; } .charge-ring { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; transform:rotate(-90deg); }
.charge-ring circle { fill:none; stroke:var(--amber); stroke-width:3; stroke-dasharray:100; stroke-dashoffset:calc(100 - var(--charge,0) * 100); }
.full-charge .charge-ring { filter:drop-shadow(0 0 3px #ffc82c); }
@media (prefers-reduced-motion: reduce) { .is-hurt,.can-pick,.ammo-pill,.hud-member .hud-hp-lag { animation:none; } }

.area-plate { position: absolute; pointer-events:none; top: 13%; left:50%; transform:translateX(-50%);
  clip-path: var(--cut-sm); padding: 4px 18px; font: 900 clamp(10px,1.6vw,15px) var(--font-ui);
  background: linear-gradient(105deg,#1b2632,#10141e); color:var(--cream); border-block:2px solid var(--amber);
  animation: areaSlide 1.8s both; }
.area-plate small { color:var(--amber); }
@keyframes areaSlide { 0% {opacity:0;translate:-18px 0} 12%,85% {opacity:1;translate:0} 100% {opacity:0;translate:18px 0} }
@media(prefers-reduced-motion:reduce){.area-plate{animation:none}}

#stage-frame { --pointer: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='28'%3E%3Cpath d='M2 2l18 12-8 1-4 8z' fill='%23ffce56' stroke='%23171520' stroke-width='3'/%3E%3C/svg%3E") 2 2, auto;
  --select-pointer: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26'%3E%3Ccircle cx='13' cy='13' r='8' fill='none' stroke='%23171520' stroke-width='5'/%3E%3Cpath d='M13 1v8m0 8v8M1 13h8m8 0h8' stroke='%23ffd147' stroke-width='3'/%3E%3C/svg%3E") 13 13, pointer;
  cursor:var(--pointer); }
#stage-frame :is(button,input,select,[data-sel-rec],.hud-member.is-interactive):not(:disabled) { cursor:var(--select-pointer); }
.modal-card { position:relative; }
.menu-focus { box-shadow: inset 4px 0 0 var(--amber), inset 0 0 0 2px #f5b82e !important; filter: brightness(1.12); }
.menu-focus .menu-arrow { opacity:1; transform:none; }
.menu-focus:not(input):not(:has(.menu-arrow))::after { content:""; position:absolute; top:50%; left:2px; translate:0 -50%;
  border-block:4px solid transparent; border-left:6px solid #ffcf58; pointer-events:none; animation: focusPulse .75s ease-in-out infinite alternate; }
@keyframes focusPulse { to { opacity:.55; } }
.title-embers { background-image:radial-gradient(ellipse at center,transparent 45%,#0e0c125c),repeating-linear-gradient(0deg,transparent 0 3px,#0e0c1224 3px 4px); }
.settings-tabs { display:flex; gap:5px; margin-bottom:8px; }
.guide-grid,.craft-grid,.radar-chips { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:5px; }
.guide-grid[hidden], #settings-options[hidden] {display:none;}
#btn-tutorial-replay { grid-column: 1 / -1; }
.guide-grid > div,.radar-chips > div {background:#202936; border-left:2px solid var(--amber); padding:5px; font-size:11px; }
.guide-grid > div span { display:block; margin-top:3px; } .guide-grid p {grid-column:1/-1; font-size:11px;}
.fac-level {color:var(--amber);letter-spacing:2px;} .recipe-icon {width:24px;height:24px;vertical-align:middle;image-rendering:pixelated;}
.fac-row .portrait { vertical-align:middle; } [data-srv] .portrait { width:48px;height:48px; float:left;margin-right:8px; }
.rank-stamp { display:block; width:max-content; margin:-3px 6px 0 auto; color:var(--amber); border:3px double currentColor; padding:2px 8px;
  font:900 var(--ui-display) var(--font-display); transform:rotate(-8deg); animation:stampIn .24s ease-out; }
@keyframes stampIn {from {transform:scale(1.45) rotate(-13deg);opacity:.3}}
@media(prefers-reduced-motion:reduce){.rank-stamp{animation:none}}

.facility-panel > * { flex-shrink:0; }
.fac-panel-header { position:sticky; top:0; z-index:3; background:#171624; }
.fac-header-cost { display:flex; gap:4px; align-items:center; flex-wrap:wrap; font-size:10px; color:var(--cream); }
.fac-header-cost .ui-ico,.resident-info .ui-ico { --size:13px; }
.housing-member .portrait { flex:none; width:48px; height:48px; }
.resident-info { flex:1; min-width:0; }
.survivor-stats { clear:both; display:grid; grid-template-columns:max-content minmax(24px,80px); align-items:center; gap:1px 5px; margin-top:3px; font-size:9px; font-variant-numeric:tabular-nums; }
.survivor-stats i,.hud-member-ammo { height:4px; background:linear-gradient(to right,var(--stat,#4ade80) var(--value),#273342 var(--value)); }
.stat-speed { --stat:#38bdf8; }
.hud-member-ammo { --stat:#ffd147; position:absolute; left:1px; right:1px; bottom:0; }
.hud-day-badge,.hud-clock,.res-v,.hud-boss-title,.stock-chip { font-variant-numeric:tabular-nums; letter-spacing:.06em; text-shadow:0 2px 0 #090710; }
@media(prefers-reduced-motion:reduce){ .menu-focus::after {animation:none !important;} }
.hud-layer-badge,.hud-base-pill,.hud-rest-pill,.hud-item-slot { border-radius:0; clip-path:var(--cut-xs); }
.btn.mini,.wb-mini-pill,.compass-pill,.toast-msg { --corner:4px; }
.modal-card,.facility-panel,.bottom-item-bar { --corner:10px; }

.hud-formation { align-self: flex-start; pointer-events: auto; touch-action: manipulation; }

/* Menu text and compact HUD readouts share the persisted text size preference. */
body.ui-large {
  --ui-small: 17px;
  --ui-body: 19px;
  --ui-title: 24px;
  --ui-display: 27px;
  --hud-label: 16px;
  --hud-meta: 14px;
}
body { font-size: var(--ui-body); }
.btn, .modal-card, .confirm-card { line-height: 1.4; }
.modal-card h2, .res-banner-head { font-size: var(--ui-title); }
.title-menu .btn, .btn.mini, .facility-panel .btn, .fac-row, .fac-sec-title,
.storage-held-name, .storage-name, .storage-empty, .survivor-stats, .fac-header-cost,
.storage-count, .storage-dur-lbl, .storage-cat-lbl, .fac-pin-badge, .fac-row .vol-val,
.res-k, .res-save-note, .stat-box, .guide-grid > div, .guide-grid p, .radar-chips > div,
.boot-label, .boot-tip, .res-unlock-pill, .action-reason, #slot-status {
  font-size: var(--ui-small);
}
.modal-card .txt-inp, .fac-panel-title, .title-menu .title-cta, .res-reason, .res-v {
  font-size: var(--ui-body) !important;
}
.res-save-note, .action-reason { color: #c3cedf; margin: 0; }
.material-cost { display: inline-block; font-variant-numeric: tabular-nums; }
.material-cost.shortage { color: #ffb1bb; font-weight: 800; }
.btn[aria-pressed="true"]:is(.wb-tab,.storage-tab,[data-settings-tab],[data-radar-mode],#fac-craft-filter)::after {
  content: ''; position: absolute; inset: auto 22% 3px; height: 3px; background: currentColor;
  border: 0; translate: none; animation: none;
}
#fac-craft-filter[aria-pressed="true"] { background: var(--amber); color: var(--ink); }
:is(.choice-card,.storage-card):active { background: #354056; }
.menu-focus { box-shadow: inset 0 0 0 2px #14121f, inset 0 0 0 5px #ffdf82 !important; }
.confirm-card {
  width: min(28em, 88vw); max-height: 85dvh; overflow: auto;
  color: var(--cream); font-family: var(--font-ui); font-size: var(--ui-body);
  border: 2px solid var(--amber); padding: 16px 18px; background: #191d2a;
}
.confirm-card p { margin: 0; }
.confirm-card::backdrop { background: rgba(8, 9, 16, .8); }
.invite-fallback:not([hidden]) { display: grid; gap: 5px; font-size: var(--ui-small); }
.invite-fallback input { width: 100%; user-select: text; -webkit-user-select: text; }
#slot-status:empty { display: none; }
.craft-grid { grid-template-columns: 1fr; }
.craft-grid > .fac-row > div { flex: 1; min-width: 0; }
.craft-grid > .fac-row > button { flex: none; }
.fac-panel-header { scroll-margin-block: 4px; }
.facility-panel { scroll-padding-block: 66px 5px; }
.fac-panel-title { min-width: 0; overflow-wrap: anywhere; }
.housing-member { flex-wrap: wrap; }
.housing-member .resident-info { min-width: 9em; }
.housing-member > :last-child { flex-wrap: wrap; }
.fac-row .txt-inp { max-width: 55%; }
.storage-held-name, .storage-name { white-space: normal; overflow-wrap: anywhere; }
.modal-card :is(button,input,select), .facility-panel :is(button,[data-sel-rec]) { scroll-margin-block: 4px; }
#stage-frame:has(.modal-backdrop) :is(#hud-layer,#touch-layer) { visibility: hidden; }
#stage-frame:has(.modal-backdrop) #toast-container,
#stage-frame:has(.facility-panel) #toast-container { max-width: 90%; top: 4px; }
#toast-container { width: max-content; max-width: 70%; }
.toast-msg, .hud-banner, .hud-tutorial, .hud-rest-banner, .area-plate, .hud-time-card,
.hud-member, .btm-item-name, .btm-hp-val, .hud-boss-title, .compass-pill {
  font-size: var(--hud-label);
}
.location-line, .hud-layer-badge, .hud-m-sub, .hud-ai-tag, .hud-swap-glyph,
.hud-ico-badge, .hud-boss-hint, .compass-dist, .hud-radar-n, .hud-minimap,
.ammo-pill, .btm-hp-tag, .btm-sh-txt, .hud-key-hints, .gkey, .hud-base-stock,
.title-footer, .title-tagline, .tbtn-lbl { font-size: var(--hud-meta); }
.btm-hp-val, .hud-boss-num, .compass-dist, .ammo-pill, .res-v { font-family: var(--font-ui); }
.hud-day-badge { text-shadow: none; }
.hud-top-center { min-width: 0; }
#hud-boss-bar-wrap { order: -2; }
#hud-boss-bar-wrap:empty { display: none; }
.hud-rest-banner { order: -1; }
.hud-top-center :is(.area-plate,.hud-banner,#toast-container) {
  position: static; inset: auto; transform: none; align-self: center;
  width: fit-content; max-width: 100%; overflow-wrap: anywhere; text-align: center;
}
.hud-top-center :is(.area-plate,.hud-banner,.toast-msg) { padding: 4px 8px; line-height: 1.3; }
.hud-top-center #toast-container { order: 1; }
.hud-top-center:has(.hud-banner:not(.hidden),#toast-container:not(:empty)) .area-plate { display: none; }
.hud-party-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; pointer-events: auto; touch-action: pan-y; }
.hud-party-list > * { flex-shrink: 0; }
.hud-top-left { max-height: calc(100cqh - 72px); }
.hud-time-card { height: auto; min-height: 44px; flex: none; }
.clock-line, .location-line { flex-wrap: wrap; }
.hud-hp-fill.low { background: repeating-linear-gradient(135deg,#ff5470 0 4px,#652336 4px 6px); }
.hud-m-name { min-width: 0; }
.hud-minimap-caption { flex-wrap: wrap; gap: 1px 2px; }
.tbtn-lbl { background: #171927; color: white; text-shadow: none; padding: 1px 2px; border-radius: 2px; }
.tbtn { font-family: var(--font-ui); }
body.is-touch .hud-key-hints { display: none; }
body.is-touch .hud-key-hints:has(.harv) { display: flex; }
body.is-touch .hud-key-hints .key-pill:not(.harv) { display: none; }
body.is-touch :is(.btn,.choice-card,.storage-card,.hud-member.is-interactive,.modal-card .fac-row,.modal-card .txt-inp) {
  min-width: 44px; min-height: 44px;
}
body.is-touch .fac-row input[type="range"] { height: 44px; }
body.is-touch .modal-card .fac-row { cursor: pointer; }
body.is-touch #hud-tutorial-skip, body.is-touch .facility-panel .btn { min-height: 44px; }
body.is-touch .title-content { gap: 6px; }
body.is-touch .title-menu { width: min(88%, 390px); }
body.is-touch .title-logo { max-height: 22cqh; width: auto; }
body.is-touch .hud-sys-btns .mini { padding: 2px; }
body.is-touch .touch-diamond {
  --pad-step: calc(var(--pad-size) + 6px);
  width: calc(2 * var(--pad-step) + var(--pad-size));
  height: calc(2 * var(--pad-step) + var(--pad-size));
  right: 8px; bottom: 8px;
}
body.is-touch .touch-flipped .touch-diamond { left: 8px; right: auto; }
body.is-touch .tbtn { width: var(--pad-size); height: var(--pad-size); }
body.is-touch .tbtn-throw { left: var(--pad-step); }
body.is-touch .tbtn-use { left: calc(2 * var(--pad-step)); top: var(--pad-step); }
body.is-touch .tbtn-grab { top: var(--pad-step); }
body.is-touch .tbtn-jump { top: calc(2 * var(--pad-step)); left: var(--pad-step); }
body.is-touch .wb-mini-pill { bottom: 68px; }
@container (max-width: 900px) {
  #hud-layer {
    display: grid; grid-template-columns: minmax(0, 26fr) minmax(0, 43fr) minmax(0, 31fr);
    gap: 4px; align-items: start; padding: 4px;
  }
  .hud-top-left,.hud-top-center,.hud-top-right { position: static; width: 100%; min-width: 0; transform: none; }
  .hud-top-left { max-width: none; }
  .hud-member { width: 100%; gap: 3px; padding-inline: 4px; }
  .hud-member .portrait { width: 21px; height: 21px; }
  .hud-member .hud-item-slot { flex-basis: 25px; width: 25px; height: 25px; }
  .hud-item-ico { width: 21px; height: 21px; }
  .hud-sys-btns { flex-wrap: wrap; justify-content: flex-end; }
  .hud-navigation { width: 100%; justify-content: flex-end; gap: 3px; }
  .hud-instruments, .hud-instruments:has(.hud-radar-frame:not(.hidden)) {
    display: flex; flex-direction: column; max-width: none; min-width: 0;
  }
  .compass-pill { gap: 1px; padding: 1px 4px; }
  .hud-compass-box { gap: 2px; }
  .hud-base-stock { gap: 1px 3px; padding: 2px 3px; }
  .hud-minimap { width: clamp(68px, 11cqw, 94px); }
  .hud-tutorial { gap: 2px; padding: 3px 4px; }
  .hud-tutorial small { display: block; }
  .hud-tutorial .btn { padding-inline: 3px; }
  .btm-hp-track { width: clamp(40px, 10cqw, 90px); }
  .bottom-item-bar { gap: 5px; padding-inline: 6px; }
  body.is-touch #btm-face { display: none; }
  body.is-touch .bottom-item-bar .btm-ico-frame { width: 26px; height: 26px; flex-basis: 26px; }
  body.is-touch .btm-item-meta { min-width: 0; }
  .hud-key-hints { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  #stage-frame *, #stage-frame *::after { animation: none !important; transition: none !important; }
  #screen-wipe { visibility: hidden; }
}

/* The same footprint reserves space for the pad, on either side of the stage. */
body.is-touch #stage-frame {
  --pad-size: clamp(44px, calc(clamp(48px, 14cqh, 58px) * var(--touch-scale, 1)), 66px);
  --pad-footprint: calc(3 * var(--pad-size) + 12px);
}
body.is-touch .bottom-item-bar {
  max-width: calc(100cqw - 2 * (var(--pad-footprint) + 12px));
  min-width: 0; align-items: center; flex-wrap: wrap; justify-content: center; gap: 2px 6px; white-space: normal;
}
body.is-touch .hud-top-right { min-height: 0; max-height: calc(100cqh - var(--pad-footprint) - 20px); }
body.is-touch .hud-navigation {
  pointer-events: auto; touch-action: pan-y; overflow-y: auto; min-height: 0;
  overscroll-behavior: contain;
}
body.is-touch #stage-frame:has(.touch-flipped) .hud-top-left {
  max-height: calc(100cqh - var(--pad-footprint) - 20px);
}
body.is-touch #stage-frame:has(.touch-flipped) .hud-top-right { max-height: calc(100cqh - 72px); }
@container (max-width: 900px) {
  body.is-touch .btm-ico-frame { display: none; }
  body.is-touch .btm-right-unit, body.is-touch .btm-slot-unit { max-width: 100%; min-width: 0; }
  body.is-touch .btm-dur-track { width: 38px; }
  body.is-touch .btm-hp-row { flex-wrap: wrap; gap: 3px; }
}
@container (max-width: 650px) {
  .hud-member .portrait { display: none; }
  .hud-party-list { gap: 3px; }
  .hud-top-center { max-height: 44cqh; overflow-y: auto; pointer-events: auto; touch-action: pan-y; }
  .hud-top-center > * { flex-shrink: 0; }
  .hud-minimap { width: 68px; }
  .hud-sys-btns { gap: 2px; }
  .hud-compass-box { flex-direction: column; }
}
.tbtn.context-active { border-color: #ffdd83; }
body:not(.is-touch) .hud-key-hints:has(.hot) { display: flex; }
@media (max-width: 820px) {
  body:not(.is-touch) .hud-key-hints .key-pill.hot { display: inline-flex; }
}
