/* Nusa Island UI: stenciled survival field kit. */

@font-face { font-family: 'Big Shoulders Stencil Display'; font-weight: 700; font-style: normal; font-display: swap; src: url('../../assets/fonts/big-shoulders-stencil-display-700.6cdc32d2.woff2') format('woff2'); }
@font-face { font-family: 'Big Shoulders Stencil Display'; font-weight: 800; font-style: normal; font-display: swap; src: url('../../assets/fonts/big-shoulders-stencil-display-800.b7a60bc1.woff2') format('woff2'); }
@font-face { font-family: 'Big Shoulders Stencil Display'; font-weight: 900; font-style: normal; font-display: swap; src: url('../../assets/fonts/big-shoulders-stencil-display-900.d071c3ae.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 500; font-style: normal; font-display: swap; src: url('../../assets/fonts/barlow-condensed-500.460f141e.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-style: normal; font-display: swap; src: url('../../assets/fonts/barlow-condensed-600.215a93c6.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-style: normal; font-display: swap; src: url('../../assets/fonts/barlow-condensed-700.3787a5a4.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 400; font-style: normal; font-display: swap; src: url('../../assets/fonts/barlow-400.b0a8ad37.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 500; font-style: normal; font-display: swap; src: url('../../assets/fonts/barlow-500.cd759df8.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-weight: 600; font-style: normal; font-display: swap; src: url('../../assets/fonts/barlow-600.4b52ddd4.woff2') format('woff2'); }

#ui {
  --canvas: #E8E0CC;
  --canvas-shade: #D6CCB4;
  --ink: #17140F;
  --ink-soft: #4A4236;
  --signal: #FF5B1F;
  --signal-ink: #1B0E06;
  --hud: #F4EFE3;
  --hud-shadow: 0 1px 2px rgba(0, 0, 0, .55);
  --hairline: rgba(23, 20, 15, .18);
  --stitch: rgba(23, 20, 15, .38);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --f-display: 'Big Shoulders Stencil Display', 'Impact', 'Arial Narrow', sans-serif;
  --f-label: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --f-body: 'Barlow', system-ui, sans-serif;

  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-family: var(--f-body);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
#ui *, #ui *::before, #ui *::after { box-sizing: border-box; }
#ui [hidden] { display: none !important; }
#ui ::selection { background: var(--signal); color: var(--signal-ink); }
#ui h1, #ui h2, #ui h3, #ui p, #ui ul { margin: 0; padding: 0; }
#ui ul { list-style: none; }
#ui .ic { display: block; flex: none; }
#ui button { font: inherit; color: inherit; cursor: pointer; }
#ui :focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* ---------- Shared: canvas tag panel ---------- */
#ui .tag {
  position: relative;
  background: var(--canvas);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px var(--hairline), 0 10px 30px rgba(0, 0, 0, .35);
  pointer-events: auto;
}
#ui .tag::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1.5px dashed var(--stitch);
  border-radius: 1px;
  pointer-events: none;
}

/* Key chip */
#ui .key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  background: var(--ink);
  color: var(--canvas);
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .06em;
  text-transform: uppercase;
  line-height: 1;
  flex: none;
}

/* ---------- Loading ---------- */
#ui .loading {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: auto;
  display: grid;
  place-items: center;
  padding: 24px;
  background-color: var(--canvas);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .09  0 0 0 0 .08  0 0 0 0 .06  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  transition: opacity .6s ease, visibility 0s linear .6s;
}
#ui .loading.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
#ui .loading-inner { width: min(1100px, 100%); }
#ui .loading-title {
  font-family: var(--f-display);
  font-weight: 900;
  font-size: clamp(48px, 10.5vw, 188px);
  line-height: .9;
  letter-spacing: .01em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
}
#ui .loading-line {
  margin-top: clamp(10px, 1.6vw, 22px);
  font-size: clamp(16px, 1.6vw, 24px);
  color: var(--ink-soft);
}
#ui .tape {
  position: relative;
  margin-top: clamp(28px, 4vw, 56px);
  height: 22px;
  border-radius: 2px;
  background: var(--canvas-shade);
  box-shadow: inset 0 0 0 1px var(--hairline);
  overflow: hidden;
}
#ui .tape::after { /* stitched track */
  content: '';
  position: absolute;
  left: 4px; right: 4px; top: 50%;
  border-top: 1.5px dashed var(--stitch);
  transform: translateY(-50%);
}
#ui .tape-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  background: var(--signal);
  box-shadow: inset 0 -3px 0 rgba(27, 14, 6, .18);
  transition: transform .35s var(--ease);
  z-index: 1;
}
#ui .loading-label {
  margin-top: 14px;
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink);
}

/* ---------- Menu ---------- */
#ui .menu {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: auto;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  animation: slide-left .38s var(--ease);
}
#ui .slab {
  position: relative;
  flex: none;
  width: min(460px, 92vw);
  min-height: 100%;
  padding: clamp(24px, 5vh, 52px) 40px 32px;
  background-color: var(--canvas);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .09  0 0 0 0 .08  0 0 0 0 .06  0 0 0 .08 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  box-shadow: inset -1px 0 0 var(--hairline), 10px 0 30px rgba(0, 0, 0, .35);
  display: flex;
  flex-direction: column;
}
#ui .slab::after { /* stitched right edge */
  content: '';
  position: absolute;
  top: 6px; bottom: 6px; right: 6px;
  border-right: 1.5px dashed var(--stitch);
  pointer-events: none;
}
#ui .slab-title {
  display: flex;
  flex-direction: column;
  font-family: var(--f-display);
  font-weight: 900;
  font-size: clamp(60px, 9vh, 92px);
  line-height: .88;
  text-transform: uppercase;
  letter-spacing: .01em;
}
#ui .slab-variant {
  margin-top: 16px;
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
#ui .btn-primary {
  margin-top: 22px;
  align-self: stretch;
  height: 56px;
  border: 0;
  border-radius: 3px;
  background: var(--signal);
  color: var(--signal-ink);
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 30px;
  letter-spacing: .08em;
  text-transform: uppercase;
  box-shadow: 0 2px 4px rgba(23, 20, 15, .35), 0 10px 22px rgba(0, 0, 0, .28);
  transition: transform .12s var(--ease), box-shadow .12s var(--ease), filter .12s;
}
#ui .btn-primary:hover { filter: brightness(1.06); }
#ui .btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 3px rgba(23, 20, 15, .35); }
/* Stage 17: New game under Continue - quiet outline, same width */
#ui .btn-secondary {
  margin-top: 10px;
  align-self: stretch;
  height: 40px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .1em;
  text-transform: uppercase;
  transition: background .12s var(--ease);
}
#ui .btn-secondary:hover { background: rgba(23, 20, 15, .06); }
#ui .btn-secondary[hidden] { display: none; }
html.is-touch #ui .btn-secondary { min-height: 44px; }
#ui .legend-head {
  margin-top: clamp(22px, 4vh, 40px);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hairline);
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
#ui .legend {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 14px;
}
#ui .legend li { display: flex; align-items: center; gap: 4px; min-width: 0; }
#ui .legend li .key { min-width: 22px; height: 22px; font-size: 13px; padding: 0 5px; }
#ui .legend li span:last-child {
  margin-left: 4px;
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Settings tag */
#ui .settings {
  flex: 0 1 420px;
  align-self: center;
  margin: 16px clamp(16px, 3vw, 56px) 16px 0;
  padding: 22px 26px 24px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ink) transparent;
}
#ui .set-sec + .set-sec { margin-top: 18px; }
#ui .set-title {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: .03em;
  text-transform: uppercase;
  line-height: 1;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
}
#ui .field { margin-top: 10px; }
#ui .field-label {
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
#ui .field--slider {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  row-gap: 2px;
}
#ui .field-value {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 22px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
#ui .field--slider .rng { grid-column: 1 / -1; }

/* Segmented control */
#ui .seg {
  margin-top: 6px;
  display: flex;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(23, 20, 15, .4);
  overflow: hidden;
  background: var(--canvas-shade);
}
#ui .seg-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: background-color .12s, color .12s;
}
#ui .seg-btn + .seg-btn { box-shadow: inset 1px 0 0 rgba(23, 20, 15, .22); }
#ui .seg--icons .seg-btn { flex-direction: column; gap: 3px; min-height: 58px; font-size: 14px; }
#ui .seg-btn:hover { background: rgba(23, 20, 15, .08); }
#ui .seg-btn[aria-checked='true'] { background: var(--signal); color: var(--signal-ink); box-shadow: none; }
#ui .seg-btn:focus-visible { outline-offset: -4px; outline-color: var(--ink); }
#ui .seg-btn[aria-checked='true']:focus-visible { outline-color: var(--ink); }

/* Range */
#ui .rng {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --pct: 0%;
}
#ui .rng::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 1px;
  background: linear-gradient(to right, var(--ink) var(--pct), rgba(23, 20, 15, .22) var(--pct));
}
#ui .rng::-moz-range-track { height: 4px; border-radius: 1px; background: rgba(23, 20, 15, .22); }
#ui .rng::-moz-range-progress { height: 4px; border-radius: 1px; background: var(--ink); }
#ui .rng::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border: 0;
  border-radius: 2px;
  background: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: background-color .12s;
}
#ui .rng::-moz-range-thumb {
  width: 16px; height: 16px;
  border: 0;
  border-radius: 2px;
  background: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
#ui .rng.is-active::-webkit-slider-thumb, #ui .rng:active::-webkit-slider-thumb { background: var(--signal); box-shadow: 0 0 0 2px var(--ink); }
#ui .rng.is-active::-moz-range-thumb, #ui .rng:active::-moz-range-thumb { background: var(--signal); box-shadow: 0 0 0 2px var(--ink); }

/* ---------- HUD ---------- */
#ui .hud { position: absolute; inset: 0; transition: opacity .12s linear; }
#ui .hud.is-hidden { opacity: 0; visibility: hidden; }

#ui .crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 0; height: 0;
  transition: opacity .12s linear;
}
#ui .xh-dot, #ui .xh-ring {
  position: absolute;
  left: 0; top: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: opacity .12s linear, width .12s var(--ease), height .12s var(--ease);
}
#ui .xh-dot {
  width: 4px; height: 4px;
  background: var(--hud);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .4);
}
#ui .xh-ring {
  width: 14px; height: 14px;
  border: 1.5px solid var(--hud);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), inset 0 0 0 1px rgba(0, 0, 0, .3);
  opacity: 0;
}
#ui .crosshair[data-mode='interact'] .xh-ring { opacity: .95; }
#ui .crosshair[data-mode='aim'] .xh-dot { width: 2px; height: 2px; opacity: .6; }
#ui .crosshair[data-mode='hidden'] { opacity: 0; }

#ui .prompt {
  position: absolute;
  left: calc(50% + 28px);
  top: calc(50% + 28px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  pointer-events: none;
  animation: fade-in .12s linear;
}
#ui .prompt::after { inset: 3px; }
#ui .prompt .key { min-width: 28px; height: 28px; font-size: 16px; }
#ui .prompt-text { display: flex; flex-direction: column; }
#ui .prompt-line {
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
#ui .prompt-verb { color: var(--ink); }
#ui .prompt-name { color: var(--ink-soft); }
#ui .prompt-detail { font-size: 14px; color: var(--ink-soft); }

#ui .weapon {
  position: absolute;
  right: clamp(20px, 3vw, 44px);
  bottom: clamp(18px, 3vh, 36px);
  text-align: right;
  color: var(--hud);
  text-shadow: var(--hud-shadow);
}
/* compact corner readout: the count is glanceable, the world stays the picture */
#ui .weapon-name {
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .8;
  margin-bottom: 1px;
}
#ui .weapon-count {
  font-family: var(--f-display);
  font-weight: 900;
  font-size: 34px;
  line-height: .95;
  font-variant-numeric: tabular-nums;
}
#ui .w-sep, #ui .w-res { font-size: 18px; font-weight: 800; opacity: .7; }
#ui .weapon-count.is-low .w-mag { color: var(--signal); }

#ui .toasts {
  position: absolute;
  left: 0;
  top: clamp(16px, 3vh, 32px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
#ui .toast {
  padding: 6px 16px 6px 20px;
  background: var(--ink);
  color: var(--canvas);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: .05em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  animation: slide-left .32s var(--ease);
  transition: opacity .25s ease, transform .25s var(--ease);
}
#ui .toast.is-out { opacity: 0; transform: translateX(-24px); }

#ui .announce {
  position: absolute;
  left: 50%;
  top: clamp(20px, 5vh, 56px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px 12px 18px;
  pointer-events: none;
}
#ui .announce.is-in { animation: drop-in .34s var(--ease); }
#ui .announce-text { display: flex; flex-direction: column; }
#ui .announce-title {
  font-family: var(--f-display);
  font-weight: 900;
  font-size: 30px;
  line-height: 1;
  letter-spacing: .05em;
  text-transform: uppercase;
}
#ui .announce-sub { margin-top: 3px; font-size: 15px; color: var(--ink-soft); }

#ui .hint {
  position: absolute;
  left: 50%;
  bottom: clamp(96px, 16vh, 170px);
  transform: translateX(-50%);
  max-width: min(90vw, 640px);
  text-align: center;
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--hud);
  text-shadow: var(--hud-shadow);
}
#ui .hint.is-in { animation: fade-in .2s linear; }

/* ---------- Examine ---------- */
#ui .examine {
  position: absolute;
  left: 50%;
  bottom: clamp(20px, 5vh, 56px);
  z-index: 20;
  width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 20px 28px 18px;
  pointer-events: none;
}
#ui .examine.is-in { animation: rise-in .34s var(--ease); }
/* Stage 17b field map view */
#ui .mapview {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: grid;
  place-items: center;
  background: rgba(23, 20, 15, .45);
  pointer-events: auto;
  padding: 12px;
}
#ui .mapview[hidden] { display: none; }
#ui .mapview-sheet {
  display: grid;
  gap: 8px;
  justify-items: center;
  animation: rise-in .3s var(--ease);
}
#ui .mapview-canvas {
  width: min(92vw, calc((100vh - 64px) * 1.3333));
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 3px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, .45);
}
#ui .mapview-key {
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--canvas);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}
#ui .examine-title {
  font-family: var(--f-display);
  font-weight: 900;
  font-size: 38px;
  line-height: 1;
  letter-spacing: .02em;
  text-transform: uppercase;
}
#ui .examine-text { margin-top: 8px; font-size: 17px; line-height: 1.45; color: var(--ink); }
#ui .examine-keys {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}
#ui .ek {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--f-label);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---------- Inventory ---------- */
#ui .inv {
  position: absolute;
  left: 50%;
  bottom: clamp(16px, 7vh, 72px);
  z-index: 30;
  width: min(1040px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  padding: 18px 24px 22px;
}
#ui .inv.is-in { animation: rise-in .36s var(--ease); }
#ui .inv-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
#ui .inv-title {
  font-family: var(--f-display);
  font-weight: 900;
  font-size: 34px;
  line-height: 1;
  letter-spacing: .03em;
  text-transform: uppercase;
}
#ui .btn-close {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 8px 0 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(23, 20, 15, .4);
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: background-color .12s;
}
#ui .btn-close:hover { background: rgba(23, 20, 15, .09); }
#ui .btn-close .key { min-width: 20px; height: 20px; font-size: 12px; }
#ui .inv-body { display: flex; gap: 20px; min-height: 0; flex: 1; }
#ui .inv-scroll {
  flex: 1 1 auto;
  min-width: 0;
  max-height: min(46vh, 420px);
  overflow-y: auto;
  padding: 4px 6px 6px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--ink) var(--canvas-shade);
}
#ui .inv-scroll::-webkit-scrollbar { width: 10px; }
#ui .inv-scroll::-webkit-scrollbar-track { background: var(--canvas-shade); border-radius: 2px; }
#ui .inv-scroll::-webkit-scrollbar-thumb { background: var(--ink); border-radius: 2px; border: 2px solid var(--canvas-shade); }
#ui .inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
#ui .slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px 8px;
  border: 0;
  border-radius: 3px;
  background: var(--canvas-shade);
  box-shadow: inset 0 0 0 1px var(--hairline);
  color: var(--ink);
  text-align: center;
  transition: background-color .12s, transform .16s var(--ease);
}
#ui .slot::after { /* pocket stitching */
  content: '';
  position: absolute;
  inset: 3px;
  border: 1.5px dashed var(--stitch);
  border-radius: 1px;
  pointer-events: none;
}
#ui .slot:hover, #ui .slot:focus-visible { background: #CFC4A9; transform: translateY(-2px); }
#ui .slot:active { transform: translateY(0); }
#ui .slot-img { width: 80px; height: 80px; display: grid; place-items: center; color: var(--ink-soft); }
#ui .slot-img img { width: 80px; height: 80px; object-fit: contain; pointer-events: none; }
#ui .slot-name {
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .06em;
  text-transform: uppercase;
  line-height: 1.1;
  min-height: 1.1em;
}
#ui .slot-qty {
  position: absolute;
  top: 7px; right: 7px;
  padding: 2px 6px 1px;
  background: var(--ink);
  color: var(--signal);
  border-radius: 2px;
  font-family: var(--f-display);
  font-weight: 900;
  font-size: 20px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#ui .inv-empty {
  padding: 36px 12px;
  text-align: center;
  font-size: 18px;
  color: var(--ink-soft);
}
#ui .inv-detail {
  flex: 0 0 250px;
  padding-left: 20px;
  border-left: 1.5px dashed var(--stitch);
}
#ui .inv-detail-name {
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 28px;
  line-height: 1;
  letter-spacing: .03em;
  text-transform: uppercase;
}
#ui .inv-detail-desc { margin-top: 8px; font-size: 16px; line-height: 1.45; color: var(--ink); }

/* ---------- Motion ---------- */
@keyframes slide-left { from { transform: translateX(-28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes drop-in { from { transform: translate(-50%, -14px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes rise-in { from { transform: translate(-50%, 18px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  #ui .menu { flex-direction: column; align-items: stretch; gap: 0; }
  #ui .slab { width: 100%; min-height: 0; flex: none; box-shadow: inset 0 -1px 0 var(--hairline), 0 10px 30px rgba(0, 0, 0, .35); padding: 28px 24px 24px; }
  #ui .slab::after { top: auto; left: 6px; right: 6px; bottom: 6px; border-right: 0; border-bottom: 1.5px dashed var(--stitch); }
  #ui .slab-title { flex-direction: row; flex-wrap: wrap; column-gap: .25em; font-size: clamp(48px, 13vw, 84px); }
  #ui .settings { flex: none; align-self: stretch; max-height: none; overflow: visible; margin: 16px; }
  #ui .inv-detail { flex-basis: 200px; }
}
@media (max-width: 640px) {
  #ui .inv { padding: 14px 14px 16px; }
  #ui .inv-body { flex-direction: column; gap: 12px; }
  #ui .inv-scroll { max-height: 34vh; }
  #ui .inv-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  #ui .slot-img, #ui .slot-img img { width: 64px; height: 64px; }
  #ui .inv-detail { flex: none; padding: 10px 0 0; border-left: 0; border-top: 1.5px dashed var(--stitch); }
  #ui .weapon-count { font-size: 28px; }
  #ui .w-sep, #ui .w-res { font-size: 16px; }
  #ui .legend { grid-template-columns: 1fr; }
  #ui .seg-btn { font-size: 14px; letter-spacing: .03em; }
  #ui .examine { padding: 16px 20px 14px; }
  #ui .examine-title { font-size: 30px; }
  #ui .prompt { left: calc(50% + 16px); top: calc(50% + 20px); }
}
@media (min-width: 2000px) {
  #ui { font-size: 18px; }
  #ui .settings { flex-basis: 480px; }
}
@media (max-height: 720px) and (min-width: 961px) {
  #ui .set-sec + .set-sec { margin-top: 12px; }
  #ui .field { margin-top: 6px; }
  #ui .seg--icons .seg-btn { min-height: 50px; }
  #ui .settings { padding-top: 16px; padding-bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  #ui *, #ui *::before, #ui *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- Mobile / touch (Stage 14) ---------- */
html, body { overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.is-touch body { touch-action: none; }

html.is-touch #ui .menu,
html.is-touch #ui .settings,
html.is-touch #ui .inv-scroll {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
html.is-touch #ui .btn-primary,
html.is-touch #ui .seg-btn,
html.is-touch #ui .btn-close,
html.is-touch #ui .slot { min-height: 44px; }
html.is-touch #ui .btn-close { height: 44px; padding: 0 14px; }
html.is-touch #ui .rng { height: 44px; }
html.is-touch #ui .rng::-webkit-slider-thumb { width: 28px; height: 28px; }
html.is-touch #ui .rng::-moz-range-thumb { width: 28px; height: 28px; }
html.is-touch #ui .legend-head,
html.is-touch #ui .legend { display: none; }
html.is-touch #ui .examine-keys { display: none; }
html.is-touch #ui .menu,
html.is-touch #ui .hud {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
html.is-touch #ui .hud { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html.is-touch #ui .toasts { left: env(safe-area-inset-left, 0px); }

/* Small landscape phones: 740x360, 844x390, 915x412 */
@media (max-height: 500px), (max-width: 900px) {
  html.is-touch #ui { font-size: 14px; }
  /* menu: slab and settings side by side, scrolling internally */
  html.is-touch #ui .menu {
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100%;
    padding-left: 0;
    padding-right: 0;
  }
  html.is-touch #ui .slab {
    width: min(300px, 42vw);
    min-height: 100%;
    padding: 14px 20px 14px max(20px, env(safe-area-inset-left, 0px));
    box-shadow: inset -1px 0 0 var(--hairline), 10px 0 30px rgba(0, 0, 0, .35);
  }
  html.is-touch #ui .slab::after { top: 6px; bottom: 6px; right: 6px; left: auto; border-bottom: 0; border-right: 1.5px dashed var(--stitch); }
  html.is-touch #ui .slab-title { flex-direction: column; flex-wrap: nowrap; font-size: clamp(36px, 11vh, 56px); }
  html.is-touch #ui .settings {
    flex: 1 1 auto;
    align-self: stretch;
    margin: 8px max(12px, env(safe-area-inset-right, 0px)) 8px 12px;
    padding: 12px 16px;
    max-height: calc(100% - 16px);
    overflow-y: auto;
  }
  html.is-touch #ui .set-sec + .set-sec { margin-top: 10px; }
  html.is-touch #ui .field { margin-top: 6px; }
  html.is-touch #ui .seg--icons .seg-btn { min-height: 48px; }
  /* HUD */
  html.is-touch #ui .prompt {
    left: 50%;
    top: calc(50% - 84px);
    transform: translateX(-50%);
    padding: 5px 10px 5px 8px;
  }
  html.is-touch #ui .prompt-detail { display: none; }
  html.is-touch #ui .weapon {
    right: auto;
    left: 50%;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    text-align: center;
  }
  html.is-touch #ui .weapon-name { font-size: 10px; letter-spacing: .1em; }
  html.is-touch #ui .weapon-count { font-size: 22px; }
  html.is-touch #ui .w-sep, html.is-touch #ui .w-res { font-size: 13px; }
  html.is-touch #ui .toasts { top: max(8px, env(safe-area-inset-top, 0px)); transform-origin: left top; transform: scale(.88); }
  html.is-touch #ui .announce { transform-origin: top center; }
  html.is-touch #ui .examine {
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    width: min(440px, calc(100vw - 340px));
    padding: 12px 16px 10px;
  }
  html.is-touch #ui .examine-title { font-size: 24px; }
  html.is-touch #ui .examine-text { font-size: 14px; margin-top: 4px; }
  /* inventory */
  html.is-touch #ui .inv {
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    width: min(1040px, calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    max-height: calc(100% - 16px);
    padding: 12px 16px;
  }
  html.is-touch #ui .inv-body { flex-direction: row; gap: 12px; }
  html.is-touch #ui .inv-scroll { max-height: none; }
  html.is-touch #ui .inv-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
  html.is-touch #ui .slot-img, html.is-touch #ui .slot-img img { width: 48px; height: 48px; }
  html.is-touch #ui .inv-detail { flex: 0 0 180px; padding: 0 0 0 12px; border-top: 0; border-left: 1.5px dashed var(--stitch); }
  html.is-touch #ui .loading { padding: 16px max(16px, env(safe-area-inset-left, 0px)); }
}

/* ---------- Stage 15: bag actions, examine actions ---------- */
#ui .slot.is-selected { background: #CFC4A9; box-shadow: inset 0 0 0 2px var(--ink); transform: translateY(-2px); }
#ui .slot.is-selected::after { border-color: var(--signal); }
#ui .slot-hb {
  position: absolute;
  top: 7px; left: 7px;
  min-width: 18px;
  padding: 2px 5px 1px;
  background: var(--signal);
  color: var(--signal-ink);
  border-radius: 2px;
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  letter-spacing: .04em;
  pointer-events: none;
}
#ui .inv-actions { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
#ui .btn-act {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(23, 20, 15, .55);
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .08em;
  text-transform: uppercase;
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  transition: background-color .12s, transform .12s var(--ease);
}
#ui .btn-act > span { position: relative; z-index: 1; }
#ui .btn-act:hover { background: rgba(23, 20, 15, .09); }
#ui .btn-act:active { transform: translateY(1px); }
#ui .btn-act--primary { background: var(--signal); color: var(--signal-ink); box-shadow: none; }
#ui .btn-act--primary:hover { background: var(--signal); filter: brightness(1.06); }
#ui .btn-act .key { height: 20px; min-width: 20px; font-size: 12px; }
#ui .btn-hold::before { /* hold-to-drop-all fill */
  content: '';
  position: absolute;
  inset: 0;
  background: var(--signal);
  transform: scaleX(0);
  transform-origin: left center;
}
#ui .btn-hold.is-holding::before { animation: hold-fill 500ms linear forwards !important; animation-duration: 500ms !important; }
#ui .btn-hold.is-armed { color: var(--signal-ink); box-shadow: inset 0 0 0 2px var(--ink); }
#ui .btn-hold.is-armed::before { transform: scaleX(1); animation: none !important; }
#ui .slot, #ui .btn-act {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#ui .btn-act:active, #ui .btn-hold.is-holding { transform: translateY(1px) scale(.98); }
/* drag-out-to-drop */
#ui .slot.is-lifted { opacity: .35; transform: scale(.94); }
#ui .inv.is-dragging { outline: 3px dashed rgba(23, 20, 15, .55); outline-offset: 2px; transition: outline-color .12s; }
#ui .inv.is-dragging.is-drag-out { outline-color: transparent; }
#ui .inv.is-dragging .inv-scroll { overflow: hidden; }
#ui.is-dragging::before, .ui-root.is-dragging::before {
  content: ''; position: absolute; inset: 0; z-index: 29; pointer-events: none;
  background: rgba(10, 8, 5, .0); transition: background .15s;
}
.ui-root.is-dragging:has(.inv.is-drag-out)::before { background: rgba(10, 8, 5, .45); }
#ui .drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 60; width: 72px; height: 72px;
  display: grid; place-items: center; pointer-events: none;
  background: #CFC4A9; border-radius: 4px; box-shadow: 0 6px 18px rgba(0, 0, 0, .4), inset 0 0 0 2px var(--ink);
  opacity: .92; will-change: transform;
}
#ui .drag-ghost img { width: 56px; height: 56px; object-fit: contain; }
#ui .drag-label {
  position: fixed; left: 0; top: 0; z-index: 61; pointer-events: none; white-space: nowrap;
  padding: 5px 10px; border-radius: 3px; background: var(--ink); color: #F1E9D2;
  font-family: var(--f-label); font-weight: 700; font-size: 14px; letter-spacing: .08em; text-transform: uppercase;
  will-change: transform;
}
#ui .drag-label.is-out { background: var(--signal); color: var(--signal-ink); }
@keyframes hold-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }

#ui .examine .examine-actions { margin-top: 12px; display: flex; gap: 10px; }
#ui .examine .examine-actions .btn-act { flex: 1 1 0; min-height: 44px; }
#ui .examine-hold-hint { margin-top: 6px; font-size: 13px; color: var(--ink-soft); }

html.is-touch #ui .btn-act { min-height: 44px; }
html.is-touch #ui .examine .examine-actions { display: flex; }
@media (max-height: 500px), (max-width: 900px) {
  html.is-touch #ui .inv-actions { margin-top: 8px; gap: 6px; }
  html.is-touch #ui .examine .examine-actions { margin-top: 8px; }
}

/* ---------- Stage 17d: touch menu fits the visible viewport ----------
   The menu used to scroll as one page while the slab / settings were stretched to the first screen,
   so on a 360-412 px tall phone the touch legend and build id ran past the slab's background and the
   settings column was cut. Now #ui follows the visual viewport (--vvh, set in ui.js), each column
   scrolls on its own, and Continue / New game stay pinned at the bottom of the slab. */
#ui .slab-actions { display: flex; flex-direction: column; }
html.is-touch #ui { bottom: auto; height: 100%; height: 100dvh; height: var(--vvh, 100dvh); }
@media (max-height: 500px), (max-width: 900px) {
  html.is-touch #ui .menu { overflow: hidden; height: 100%; }
  html.is-touch #ui .slab {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding-bottom: 0;
  }
  html.is-touch #ui .slab-title { font-size: clamp(30px, 9vh, 52px); }
  html.is-touch #ui .slab-variant { margin-top: 6px; font-size: 15px; }
  html.is-touch #ui .slab-actions {
    order: 99;
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin-top: auto;
    padding: 8px 0 max(10px, env(safe-area-inset-bottom, 0px));
    background: var(--canvas);
    box-shadow: 0 -10px 12px -8px rgba(23, 20, 15, .25);
  }
  html.is-touch #ui .slab-actions .btn-primary { margin-top: 0; height: 48px; font-size: 26px; }
  html.is-touch #ui .slab-actions .btn-secondary { margin-top: 6px; }
  html.is-touch #ui .touch-legend-head { margin-top: 10px; padding-top: 8px; }
  html.is-touch #ui .touch-legend b { min-width: 86px; }
  html.is-touch #ui .build-id { margin: 8px 0 10px; }
  html.is-touch #ui .install-help { max-width: none; }
  html.is-touch #ui .settings {
    height: calc(100% - 16px);
    max-height: none;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    overscroll-behavior: contain;
  }
  html.is-touch #ui .mapview-canvas { width: min(92vw, calc((var(--vvh, 100dvh) - 56px) * 1.3333)); }
  html.is-touch #ui .inv { max-height: calc(var(--vvh, 100dvh) - 16px); }
}
