/*
  SULFUR Loadout Planner — game-parity UI. Flat warm-black + amber chrome; paperdoll slot
  shapes from the game's Paperdoll_* sprites (CSS masks). Mobile-first; scale up in min-width blocks.
*/
:root {
  --bg:#14100a; --bg2:#0f0c07; --panel:#1c160d; --panel-2:#241d10; --edge:#3a2f1c;
  --amber:#e0a91b; --amber-2:#b9861a; --slot-line:#6b5526; --grid-line:#40331c;
  --text:#e8dcc4; --muted:#9a8a6a; --good:#8bbf3a; --bad:#c0532f; --scroll:#7a5cc0;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; overflow-x: hidden; -webkit-text-size-adjust: 100%;
  background: radial-gradient(120% 80% at 50% -10%, #221a0f 0%, var(--bg) 55%, var(--bg2) 100%);
  color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.4;
}
img { max-width: 100%; }

.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--edge);
  background: linear-gradient(180deg, #1c160d, rgba(28,22,13,0));
}
.app-header h1 { font-size: 1.05rem; margin: 0; letter-spacing: 0.03em; }
.app-header .accent { color: var(--amber); }
.header-actions { display: flex; gap: 0.4rem; }

.planner { display: flex; flex-direction: column; gap: 0.7rem; padding: 0.7rem; max-width: 900px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 0.8rem; box-shadow: inset 0 0 0 1px rgba(224,169,27,0.04), 0 2px 8px rgba(0,0,0,0.4); }
.panel > h2 { font-size: 0.7rem; margin: 0 0 0.7rem; color: var(--amber); text-transform: uppercase; letter-spacing: 0.12em; }

/* ---------- paperdoll ---------- */
.paperdoll { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 0.5rem 0 1.7rem; }
.pd-row { display: flex; align-items: center; justify-content: center; gap: clamp(0.4rem, 2.5vw, 1rem); }
.pd-mid { gap: clamp(0.4rem, 2.5vw, 1.2rem); }
.pd-feet { gap: clamp(0.4rem, 2vw, 0.8rem); }
/* passive row sits below the feet with a little breathing room */
.pd-passives { gap: clamp(0.35rem, 2vw, 0.7rem); margin-top: clamp(0.7rem, 3vw, 1.1rem); }
.slot { position: relative; padding: 0; border: none; background: none; cursor: pointer; display: block; flex: none; }
.slot::before { content: ""; position: absolute; inset: 0; background-color: var(--slot-line);
  -webkit-mask: var(--shape) center/contain no-repeat; mask: var(--shape) center/contain no-repeat; transition: background-color 0.15s; }
.slot:hover::before, .slot.filled::before { background-color: var(--amber); }
.slot:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 6px; }
.slot .slot-icon { position: absolute; inset: 0; margin: auto; width: 58%; height: 58%; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); }
.slot .slot-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 0.56rem; line-height: 1.1; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; pointer-events: none; padding: 0 0.25rem; }
.slot.filled .slot-label { display: none; }
.slot-head { width: clamp(84px, 28vw, 122px); aspect-ratio: 164/136; --shape: url("assets/ui/paperdoll/Head_outline.png"); }
.slot-torso { width: clamp(116px, 40vw, 168px); aspect-ratio: 192/184; --shape: url("assets/ui/paperdoll/Torso_outline.png"); }
/* paperdoll silhouette (game-UI ::before mask) stays untouched; only the equipped equipment png
   sits larger on top (base .slot-icon is 58%) so it fills more of the head/torso slot */
.slot-head .slot-icon, .slot-torso .slot-icon { width: 82%; height: 82%; }
.slot-foot { width: clamp(64px, 23vw, 92px); aspect-ratio: 100/76; --shape: url("assets/ui/paperdoll/Shoe_outline.png"); }
.slot-foot-l::before { transform: scaleX(-1); }
/* equipped foot icon mirrors its label's inner-bottom alignment + offset (18px in, 6px up): left
   foot hugs its right/inner edge, right foot its left/inner edge; right icon flipped so they mirror */
.slot-foot .slot-icon { inset: auto; bottom: 12px; margin: 0; }
.slot-foot-l .slot-icon { right: 10px; }
.slot-foot-r .slot-icon { left: 10px; transform: scaleX(-1); }
/* Foot labels live INSIDE each slot's invisible square container, anchored to the
   bottom (small offset off the border) and pushed to the inner edge: left foot's label
   right-aligned, right foot's label left-aligned, each 10px off that edge. */
.slot-foot .slot-label { inset: 0; align-items: flex-end; padding: 0 18px 6px; transform: none; white-space: nowrap; }
.slot-foot-l .slot-label { justify-content: flex-end; text-align: right; }
.slot-foot-r .slot-label { justify-content: flex-start; text-align: left; }
/* passive-item slots: reuse the square slot silhouette; four across, smaller than the gear slots */
.slot-passive { width: clamp(50px, 16vw, 68px); aspect-ratio: 1; --shape: url("assets/ui/paperdoll/GadgetSlot_outline.png"); }
.slot-passive .slot-label { font-size: 0.48rem; }

/* ---------- weapon cards ---------- */
.weapon-slots { display: flex; flex-direction: column; gap: 0.8rem; }
.weapon-slot { border: 1px solid var(--edge); border-radius: 6px; padding: 0.6rem; background: rgba(0,0,0,0.18); }
.ws-head { cursor: pointer; margin-bottom: 0.5rem; }
.ws-name { font-weight: 600; font-size: 0.95rem; }
.ws-sub { color: var(--muted); font-size: 0.74rem; }
/* full-width weapon container — CSS-drawn (vector-crisp at any width), no sprite mask */
.ws-weapon { position: relative; width: 100%; aspect-ratio: 156/54; cursor: pointer; padding: 0;
  background: rgba(0,0,0,0.16); border: 2px solid var(--slot-line); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  transition: border-color 0.15s, background-color 0.15s; }
.ws-weapon:hover, .ws-weapon.filled { border-color: var(--amber); }
.ws-weapon.filled { background: rgba(224,169,27,0.06); }
.ws-weapon .slot-icon { max-width: 72%; max-height: 80%; object-fit: contain; }
.ws-hint { color: var(--slot-line); font-size: 0.85rem; letter-spacing: 0.04em; }

.ws-mods, .ws-ench { margin-top: 0.7rem; }
.mg-label { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.3rem; }
.mg-note { color: var(--slot-line); letter-spacing: 0; text-transform: none; }
.acells { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }
.acell { position: relative; width: clamp(54px, 16vw, 64px); flex: none; cursor: pointer; padding: 0.25rem 0.15rem 0.15rem;
  border: 1px solid var(--grid-line); border-radius: 5px; background: var(--panel-2);
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem; transition: border-color 0.15s; color: var(--text); }
.acell:hover:not(:disabled) { border-color: var(--amber); }
.acell.filled { border-color: var(--amber); }
.acell img { width: clamp(26px, 8vw, 34px); height: clamp(26px, 8vw, 34px); object-fit: contain; }
.acell.add::before { content: "+"; color: var(--slot-line); font-size: 1.05rem; line-height: 1; height: clamp(26px,8vw,34px); display: flex; align-items: center; }
.acell.invalid { border-color: rgba(192,83,47,0.5); background: rgba(192,83,47,0.08); cursor: not-allowed; opacity: 0.6; }
.acell.invalid::before { content: "✕"; color: var(--bad); font-size: 0.9rem; height: clamp(26px,8vw,34px); display: flex; align-items: center; }
.acell.invalid .acell-label { color: var(--bad); }
.acell-label { font-size: 0.54rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.acell.filled .acell-label { color: var(--amber); }
/* caliber cell: always shows the round's ammo icon (never a "+"); dim when locked */
.acell.caliber { justify-content: center; }
.acell.caliber.base { border-color: var(--slot-line); }
.acell.caliber.locked { opacity: 0.55; cursor: not-allowed; }
.acell.caliber .cal-txt { font-size: 0.68rem; font-weight: 700; color: var(--amber); height: clamp(26px,8vw,34px); display: flex; align-items: center; }
.acell.caliber.locked .cal-txt { color: var(--bad); }

/* subtle ✕ clear badge on filled containers */
.cell-x { position: absolute; top: -4px; right: -4px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--edge); color: var(--muted); font-size: 0.6rem; line-height: 13px;
  text-align: center; opacity: 0.75; transition: color 0.12s, border-color 0.12s, opacity 0.12s; }
.acell:hover .cell-x, .ecell:hover .cell-x, .ws-weapon:hover .cell-x { opacity: 1; }
.ws-weapon .cell-x { top: 4px; right: 4px; }   /* inside the CSS container, not on a corner edge */
.cell-x:hover { color: var(--bad); border-color: var(--bad); opacity: 1; }

/* all 5 enchant cells in a single row (grid keeps them from overflowing) */
.ecells { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.35rem; max-width: 360px; margin: 0 auto; }
.ecell { position: relative; width: 100%; aspect-ratio: 1; cursor: pointer; border: 1px solid var(--grid-line);
  border-radius: 5px; background: var(--panel-2); display: flex; align-items: center; justify-content: center; color: var(--slot-line); font-size: 1.2rem; transition: border-color 0.15s; }
.ecell:hover { border-color: var(--amber); }
.ecell img { width: 78%; height: 78%; object-fit: contain; }
.acell.caliber img { width: clamp(26px, 8vw, 34px); height: clamp(26px, 8vw, 34px); object-fit: contain; }
.ecell.filled.oil { border-color: var(--amber); }
.ecell.filled.scroll { border-color: var(--scroll); }
.ecell .ench-glyph { color: var(--amber); }

.ws-live { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.1rem 0.9rem; margin-top: 0.7rem; padding-top: 0.6rem; border-top: 1px solid var(--edge); }
.lv { display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.76rem; padding: 0.08rem 0; }
.lv .lk { color: var(--muted); }
.lv .lvv { font-variant-numeric: tabular-nums; font-weight: 600; }
.lv .lvv.pos { color: var(--good); } .lv .lvv.neg { color: var(--bad); }

/* ---------- weapon info: centered modal, sized to its content ---------- */
.overlay.wd-overlay { align-items: center; }
.overlay-box.wd-box { max-width: 560px; height: auto; max-height: 86dvh; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.6); }
.wd-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0.7rem 0.9rem; }
.wd-sub-h { font-size: 0.64rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.5rem; }
.wd-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.wd-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.2rem 0.4rem; border-bottom: 1px solid var(--edge); }
.wd-table td { padding: 0.2rem 0.4rem; border-bottom: 1px solid rgba(58,47,28,0.4); font-variant-numeric: tabular-nums; }
.wd-table td:first-child { color: var(--muted); }
.wd-base { color: var(--text); } .wd-mod.pos { color: var(--good); } .wd-mod.neg { color: var(--bad); }
.wd-delta { font-size: 0.7rem; }
.wd-other { margin-top: 0.5rem; font-size: 0.72rem; color: var(--muted); }

/* ---------- equipment matrix ---------- */
.equip-matrix { overflow-x: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.em-table { width: 100%; border-collapse: collapse; font-size: 0.74rem; }
.em-table th, .em-table td { padding: 0.2rem 0.35rem; border-bottom: 1px solid rgba(58,47,28,0.4); text-align: center; font-variant-numeric: tabular-nums; }
.em-table th:first-child, .em-table td.em-attr { text-align: left; color: var(--muted); white-space: nowrap; }
.em-col { font-size: 0.6rem; color: var(--muted); text-transform: uppercase; line-height: 1.05; }
.em-col.on { color: var(--amber); }
.em-table td.pos { color: var(--good); } .em-table td.neg { color: var(--bad); }
.em-empty { color: var(--grid-line); }

/* ---------- overlays (static size; top-anchored) ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(6,5,3,0.82); display: flex; align-items: flex-start; justify-content: center; padding: 2vh 0.5rem; }
.overlay[hidden] { display: none; }
.overlay-box { width: 100%; max-width: 820px; height: 92dvh; max-height: 92dvh; background: var(--panel); border: 1px solid var(--amber); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 8px 30px rgba(0,0,0,0.6); }
.overlay-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--edge); flex: none; }
.overlay-head h3 { margin: 0; font-size: 0.9rem; color: var(--amber); flex: none; }
.overlay-head .search { flex: 1 1 140px; margin: 0; min-width: 0; }
.overlay-head .btn-ghost { flex: none; }
.overlay-filters { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0.5rem 0.8rem 0; flex: none; }
.overlay-filters[hidden] { display: none; }
.fchip { padding: 0.2rem 0.55rem; font-size: 0.7rem; cursor: pointer; background: var(--panel-2); color: var(--muted); border: 1px solid var(--grid-line); border-radius: 999px; }
.fchip.on { color: #17130a; background: var(--amber); border-color: var(--amber); font-weight: 600; }
.overlay-body { flex: 1; min-height: 0; display: flex; gap: 0.6rem; padding: 0.6rem; }
.overlay-list { flex: 1 1 60%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.4rem; align-content: start; }
/* detail = scrolling head+stats with a PINNED Equip footer (never scrolled out of reach) */
.overlay-detail { flex: 1 1 40%; min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--edge); padding-left: 0.6rem; }
.od-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.od-empty { padding: 1rem 0; }
/* image-forward tile: big image on top, name below, no superfluous sub-text */
.opt { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 0.3rem; padding: 0.5rem 0.3rem; background: var(--panel-2); border: 1px solid var(--grid-line); border-radius: 5px; cursor: pointer; text-align: center; color: var(--text); }
.opt:hover:not(.disabled) { border-color: var(--amber); }
.opt.disabled { opacity: 0.4; cursor: not-allowed; }
.opt.dupe { opacity: 1; border-color: var(--amber); background: rgba(224,169,27,0.14); cursor: not-allowed; }   /* already on this weapon */
.opt.selected { border-color: var(--amber); box-shadow: inset 0 0 0 2px var(--amber); background: rgba(224,169,27,0.12); }  /* currently equipped — re-pick to remove */
.opt img, .opt .opt-noimg { width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; }
.opt .opt-noimg { border: 1px dashed var(--grid-line); border-radius: 4px; }
.opt .opt-name { font-size: 0.74rem; line-height: 1.15; overflow-wrap: anywhere; max-width: 100%; }
.opt.clear-opt { flex-direction: row; justify-content: center; color: var(--bad); border-style: dashed; grid-column: 1 / -1; }
/* group header spanning the grid (weapon type sections) */
.opt-group { grid-column: 1 / -1; font-size: 0.64rem; color: var(--amber); text-transform: uppercase; letter-spacing: 0.09em; padding: 0.5rem 0.1rem 0.15rem; border-bottom: 1px solid var(--edge); }
.opt-group:first-child { padding-top: 0.1rem; }
/* info panel: centered image on top (larger), text + stats below */
.od-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.4rem; margin-bottom: 0.7rem; }
.od-head img { width: 62%; max-width: 170px; height: auto; aspect-ratio: 1; object-fit: contain; }
.od-name { font-weight: 600; font-size: 0.95rem; } .od-sub { font-size: 0.72rem; color: var(--muted); }
/* stats: a centered two-column block so values aren't flung to the screen edge */
.od-stats { display: flex; flex-direction: column; gap: 0.12rem; margin: 0 auto 0.6rem; max-width: 300px; }
.od-stat { display: grid; grid-template-columns: 1fr 1fr; column-gap: 1rem; font-size: 0.8rem; }
.od-stat span:first-child { color: var(--muted); text-align: right; }
.od-stat span:last-child { text-align: left; font-variant-numeric: tabular-nums; }
.od-stat .pos { color: var(--good); } .od-stat .neg { color: var(--bad); }
.od-equip { flex-shrink: 0; width: 100%; margin: 0.5rem 0 0; padding: 0.5rem; background: var(--amber); color: #17130a; border: none; border-radius: 5px; font-weight: 700; cursor: pointer; }
.od-equip:hover:not(:disabled) { background: var(--amber-2); }
.od-equip:disabled { background: var(--grid-line); color: var(--muted); cursor: not-allowed; }

/* DPS overlay body */
.dps-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0.8rem; }

/* slim themed scrollbars (palette-derived) */
.overlay-list, .od-scroll, .dps-body, .wd-body, .equip-matrix, .character, .arsenal { scrollbar-width: thin; scrollbar-color: var(--edge) transparent; }
.overlay-list::-webkit-scrollbar, .od-scroll::-webkit-scrollbar, .dps-body::-webkit-scrollbar, .wd-body::-webkit-scrollbar, .equip-matrix::-webkit-scrollbar, .character::-webkit-scrollbar, .arsenal::-webkit-scrollbar { width: 8px; height: 8px; }
.overlay-list::-webkit-scrollbar-thumb, .od-scroll::-webkit-scrollbar-thumb, .dps-body::-webkit-scrollbar-thumb, .wd-body::-webkit-scrollbar-thumb, .equip-matrix::-webkit-scrollbar-thumb, .character::-webkit-scrollbar-thumb, .arsenal::-webkit-scrollbar-thumb { background: var(--edge); border-radius: 4px; }
.target-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.8rem; }
.target-label { font-size: 0.72rem; color: var(--muted); flex: none; }
.dps .dps-w { font-size: 0.68rem; color: var(--amber); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 0.6rem; }
.row { display: flex; justify-content: space-between; gap: 1rem; padding: 0.12rem 0; }
.row .k { color: var(--muted); } .row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.row.big .v { color: var(--amber); font-size: 1.1rem; } .row.ttk .v { color: var(--good); }

/* ---------- DPS target panel: hitmap + stats + aim-point selector ---------- */
.target-panel { margin-bottom: 0.8rem; padding-bottom: 0.8rem; border-bottom: 1px solid var(--edge); }
.target-panel[hidden] { display: none; }
.tp-grid { display: flex; gap: 0.9rem; align-items: stretch; }
.tp-map { flex: none; width: clamp(120px, 34vw, 176px); background: radial-gradient(90% 90% at 50% 40%, rgba(224,169,27,0.06), rgba(0,0,0,0.25));
  border: 1px solid var(--edge); border-radius: 8px; padding: 0.4rem; display: flex; align-items: center; justify-content: center; }
.hitmap-svg { width: 100%; height: auto; max-height: 220px; display: block; }
.hitmap-svg polygon { transition: fill-opacity 0.1s; }
.tp-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.tp-name { font-weight: 700; font-size: 1rem; color: var(--text); }
.tp-sub { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.3rem; }
.tp-stat { display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.8rem; padding: 0.06rem 0; }
.tp-stat .k { color: var(--muted); } .tp-stat .v { font-variant-numeric: tabular-nums; text-align: right; }
.tp-note { font-size: 0.7rem; margin-top: 0.2rem; }
.tp-note.bad { color: var(--bad); } .tp-note.muted { color: var(--muted); }
.aim-row { display: flex; align-items: baseline; gap: 0.5rem; margin-top: 0.7rem; flex-wrap: wrap; }
.aim-label { font-size: 0.66rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; flex: none; }
.aim-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.aim-chip { padding: 0.2rem 0.55rem; font-size: 0.72rem; cursor: pointer; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--grid-line); border-radius: 999px; }
.aim-chip:hover { border-color: var(--amber); }
.aim-chip.on { color: #17130a; background: var(--amber); border-color: var(--amber); font-weight: 600; }
.aim-chip .am-mult { opacity: 0.75; font-variant-numeric: tabular-nums; }
.aim-chip.on .am-mult { opacity: 0.9; }

.select, .search { width: 100%; padding: 0.4rem 0.55rem; font-size: 0.85rem; background: var(--bg); color: var(--text); border: 1px solid var(--edge); border-radius: 5px; }
.select:focus, .search:focus { outline: none; border-color: var(--amber); }
.btn-ghost { background: none; color: var(--muted); border: 1px solid var(--edge); border-radius: 5px; padding: 0.3rem 0.7rem; font-size: 0.8rem; cursor: pointer; }
.btn-ghost:hover { color: var(--amber); border-color: var(--amber); }
/* glossary tooltips: dotted-underline cue on labels + a floating note (tap on mobile / hover on desktop) */
.tip-label { cursor: help; text-decoration: underline dotted rgba(154,138,106,0.55); text-underline-offset: 2px; }
.tooltip { position: fixed; z-index: 120; max-width: 260px; background: var(--panel-2); border: 1px solid var(--amber);
  border-radius: 6px; padding: 0.45rem 0.6rem; font-size: 0.72rem; line-height: 1.35; color: var(--text);
  box-shadow: 0 6px 20px rgba(0,0,0,0.55); pointer-events: none; }
.tooltip[hidden] { display: none; }

.muted { color: var(--muted); } .small { font-size: 0.72rem; }

@media (min-width: 780px) { .app-header h1 { font-size: 1.35rem; } }

/* ---------- desktop: fill the viewport height, no page scroll ----------
   Not a scaled-up phone: the planner becomes a grid that occupies exactly the space below
   the pinned header. The paperdoll + equipment matrix stack on the LEFT; weapons sit
   side-by-side on the right. Panels only scroll INTERNALLY if a dense build overflows,
   so the page itself never scrolls. */
@media (min-width: 900px) {
  html { height: 100%; }
  body { height: 100dvh; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
  .app-header { flex: none; }

  .planner {
    flex: 1; min-height: 0; max-width: none; width: 100%; margin: 0;
    display: grid; gap: 0.7rem; overflow: hidden;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.55fr);
    /* minmax(0,auto) (not auto) so a tall arsenal spanning both rows can't force the top
       track past the viewport — the grid stays viewport-bounded and panels scroll internally */
    grid-template-rows: minmax(0, auto) minmax(0, 1fr);
    grid-template-areas: "character arsenal" "equip arsenal";
  }
  .arsenal { grid-area: arsenal; }
  .character { grid-area: character; overflow-y: auto; overscroll-behavior: contain; }
  .equip-detail { grid-area: equip; }

  /* every panel: header pinned, body free to scroll only if it must */
  .planner .panel { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .planner .panel > h2 { flex: none; }

  /* arsenal scrolls as one region; keep its heading in view while scrolling.
     NOTE: needs the .planner descendant selector to out-specify `.planner .panel { overflow: hidden }`
     above — a bare `.arsenal` loses the cascade and the panel never scrolls. */
  .planner .arsenal { overflow-y: auto; overscroll-behavior: contain; }
  .arsenal > h2 { position: sticky; top: 0; z-index: 1; background: var(--panel); padding-bottom: 0.4rem; }
  #weapon-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; align-items: start; }
  #melee-slot { margin-top: 0.8rem; }
  .ws-live { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

  /* melee has no mods/enchants, so it wastes a full row: shrink the weapon box to one
     gun-slot's width (left) and float its live stats into the freed space to the right */
  #melee-slot .weapon-slot.melee {
    display: grid; column-gap: 0.9rem; align-items: center;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "mhead mhead" "mweapon mlive";
  }
  #melee-slot .melee .ws-head { grid-area: mhead; }
  #melee-slot .melee .ws-weapon { grid-area: mweapon; align-self: center; }
  #melee-slot .melee .ws-live { grid-area: mlive; margin-top: 0; padding-top: 0; border-top: none; }

  /* paperdoll centred in its cell, no oversized dead space */
  .paperdoll { flex: 1; justify-content: center; padding: 0.3rem 0 1.2rem; }

  /* equipment matrix scrolls inside its panel (both axes) */
  .equip-matrix { flex: 1; min-height: 0; overflow: auto; }
}

@media (max-width: 779px) {
  .overlay { padding: 0; align-items: stretch; }
  .overlay-box { height: 100dvh; max-height: 100dvh; border-radius: 0; border-left: none; border-right: none; }
  .overlay-body { flex-direction: column; }
  .overlay-list { flex: 1 1 auto; }
  .overlay-detail { flex: none; max-height: 42dvh; border-left: none; border-top: 1px solid var(--edge); padding-left: 0; padding-top: 0.5rem; }
  /* appendix detail gets more room than the equip selector's (richer content) */
  #appendix-overlay .overlay-detail { max-height: 50dvh; }
}

/* ---------- appendix (full-screen item compendium) ---------- */
.ax-box { max-width: 1120px; }
.ax-list { grid-template-columns: repeat(3, minmax(0, 1fr)); flex: 1 1 58%; }
.ax-detail { flex: 1 1 42%; }
.ax-context { font-size: 0.82rem; color: var(--amber); line-height: 1.4; margin: 0 0 0.5rem; }
.ax-desc { font-size: 0.8rem; color: var(--text); line-height: 1.45; margin: 0 0 0.5rem; }
.ax-flavor { font-size: 0.76rem; color: var(--muted); font-style: italic; line-height: 1.4; margin: 0 0 0.6rem; }
.ax-section { margin: 0.6rem 0; }
.ax-section h4 { margin: 0 0 0.35rem; font-size: 0.64rem; color: var(--amber); text-transform: uppercase; letter-spacing: 0.09em; border-bottom: 1px solid var(--edge); padding-bottom: 0.2rem; }
.ax-section .od-stats { max-width: none; margin: 0; }                    /* stat rows span the panel here */
.ax-section .od-stat { grid-template-columns: 1.3fr 1fr; column-gap: 0.8rem; }
.ax-section .od-stat span:first-child { text-align: left; }
.ax-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; margin: 0.25rem 0; }
.ax-chip-lbl { font-size: 0.6rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-right: 0.15rem; }
.ax-chip { padding: 0.15rem 0.5rem; font-size: 0.7rem; background: var(--panel-2); color: var(--text); border: 1px solid var(--grid-line); border-radius: 999px; }
.ax-chip.ax-nav { cursor: pointer; font: inherit; font-size: 0.7rem; }              /* drills to that item */
.ax-chip.ax-nav:hover { border-color: var(--amber); color: var(--amber); }
.ax-chip.ax-nav::after { content: " ›"; opacity: 0.5; }
.ax-chip.ax-grp { background: rgba(224,169,27,0.12); border-color: var(--amber-2); color: var(--amber); }  /* interchangeable category */
.ax-note { font-size: 0.72rem; color: var(--text); line-height: 1.4; margin: 0.3rem 0 0; }
.ax-note.muted { color: var(--muted); }
/* back button for drill-through navigation */
.ax-back { background: none; border: 1px solid var(--edge); color: var(--muted); border-radius: 5px; padding: 0.2rem 0.55rem; font-size: 0.72rem; cursor: pointer; margin-bottom: 0.5rem; }
.ax-back:hover { color: var(--amber); border-color: var(--amber); }
/* inventory-size footprint: n×n grid of little rounded amber squares */
.ax-sizeline { display: flex; align-items: center; gap: 0.45rem; margin: 0 0 0.5rem; font-size: 0.72rem; color: var(--muted); }
.ax-size { display: inline-grid; grid-template-columns: repeat(var(--sw), 1fr); gap: 1.5px; }
.ax-size i { width: 7px; height: 7px; background: var(--amber); border-radius: 2px; opacity: 0.85; }
@media (min-width: 780px) {
  .ax-box { width: 96vw; }
  .ax-list { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
