/* ---------- Rift Haven UI kit (GAME_BIBLE.md §25) ----------
   One design language for every screen. Tokens first, then the shared components every window is
   built from. Window code composes these. A window's own CSS only places them: it never restyles a
   component and never introduces new colours, radii, type sizes or spacing values.
   Loaded after style/mobile/touch and before glass.css (glass supplies the material). */

/* Typeface: ModeNine (Andrew C. Bulhak / Graham H Freeman, after the BBC Micro; freely distributable,
   see client/assets/CREDITS.md). Every UI word uses it; system monospace is the fallback. */
@font-face { font-family: 'ModeNine'; src: url('/client/assets/fonts/modenine.ttf') format('truetype'); font-display: block; size-adjust: 84%; } /* preloaded in index.html; no flash of the fallback face */
:root {
  --font: 'ModeNine', ui-monospace, 'SF Mono', Menlo, monospace;
  /* Spacing: a 4px grid. */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  /* Radii: small for controls inside panels, medium for cards and tiles, large for panels. */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  /* Type: one family, five sizes, three weights (500 body, 650 emphasis, 800 numbers and titles). */
  --f-xs: 12px; --f-sm: 13.5px; --f-md: 15px; --f-lg: 18px; --f-xl: 26px;
  /* Text: primary, secondary, tertiary (disabled or placeholder). Never pure white body text. */
  --t1: #eef1ff; --t2: #aab3d6; --t3: #6c7599;
  /* Surfaces inside a panel: inset (cards, tiles, inputs), hover, selected. Hairline dividers. */
  --inset: rgba(8, 10, 22, .42); --hover: rgba(255, 255, 255, .06); --hair: rgba(255, 255, 255, .09);
  /* One accent, for selection and the single primary action on a screen. */
  --accent: #b77bff; --accent-soft: rgba(183, 123, 255, .16); --accent-line: rgba(183, 123, 255, .6); --accent-ink: #14081f;
  /* Semantic colours for data only (never decoration). */
  --pos: #6ff0a8; --neg: #ff6b81; --warn: #ffcc5c; --gold: #ffd23f;
  /* Control heights: compact, default, touch. */
  --h-sm: 28px; --h-md: 34px; --h-touch: 44px;
}
html.touch { --f-xs: 12.5px; --f-sm: 14.5px; --f-md: 16px; --f-lg: 19px; }

html, body, button, input, select, textarea, kbd { font-family: var(--font); }

/* ---------- Window shell ---------- */
/* Desktop windows live in the band between the top HUD and the bottom bar, never over the hotbar,
   vitals or menu. --hud-t / --hud-b are measured by client/ui.js measureHud(). */
html:not(.touch) .win {
  top: calc((var(--hud-t, 64px) + 100vh - var(--hud-b, 96px)) / 2);
  max-height: calc(100vh - var(--hud-t, 64px) - var(--hud-b, 96px) - var(--s5));
  border-radius: var(--r-lg);
}
.win-head { min-height: 48px; padding: 0 var(--s2) 0 var(--s4); gap: var(--s2); }
.win-head h3 { font-size: var(--f-md); font-weight: 800; font-variant: normal; text-transform: uppercase; letter-spacing: .09em; color: var(--t1); }
.win-body { padding: var(--s4); color: var(--t1); font-size: var(--f-sm); line-height: 1.45; }
.win-body > * + * { margin-top: var(--s4); }
.win-body > .win-tabs + * { margin-top: 0; }

/* ---------- Text ---------- */
.k-h { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); margin: 0 0 var(--s2); font-size: var(--f-xs); font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--t2); }
.k-h .k-meta { margin-left: auto; font-size: var(--f-xs); font-weight: 650; letter-spacing: 0; text-transform: none; color: var(--t2); }
.k-h .k-info { margin-left: var(--s1); }
.k-h .k-meta + .k-info { margin-left: var(--s2); }
.k-title { margin: 0; font-size: var(--f-lg); font-weight: 800; color: var(--t1); }
.k-big { font-size: var(--f-xl); font-weight: 800; font-variant-numeric: tabular-nums; color: var(--t1); line-height: 1.1; }
.muted, .k-dim { color: var(--t2); font-size: var(--f-sm); }
.k-faint { color: var(--t3); }
.k-num { font-variant-numeric: tabular-nums; }
.k-pos { color: var(--pos); } .k-neg { color: var(--neg); } .k-gold { color: var(--gold); }
/* Explanations live in a tip on a small ⓘ, never as paragraphs on screen. */
.k-info { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: var(--s1); border-radius: 50%; border: 1px solid var(--hair); color: var(--t3); font-size: 10px; font-weight: 800; font-style: normal; line-height: 1; cursor: help; vertical-align: 1px; }
.k-info::before { content: 'i'; }
.k-info:hover { color: var(--t1); border-color: var(--t3); }
html.touch .k-info { width: 22px; height: 22px; font-size: 12px; }

/* ---------- Layout ---------- */
.k-stack { display: flex; flex-direction: column; gap: var(--s3); }
.k-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.k-row.k-end { justify-content: flex-end; } .k-row.k-between { justify-content: space-between; }
.k-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.k-cols.k-side { grid-template-columns: minmax(0, 1fr) 300px; }
@media (max-width: 760px) { .k-cols, .k-cols.k-side { grid-template-columns: minmax(0, 1fr); } }
html.touch .k-cols, html.touch .k-cols.k-side { grid-template-columns: minmax(0, 1fr); }
@media (orientation: landscape) { html.touch .k-cols, html.touch .k-cols.k-side { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* ---------- Card: the one inset container ---------- */
.card, .k-card { background: var(--inset); border: 1px solid var(--hair); border-radius: var(--r-md); padding: var(--s3); }
.card h4 { margin: 0 0 var(--s2); font-size: var(--f-xs); font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--t2); }

/* ---------- Lists: rows separated by hairlines, not boxed ---------- */
.list, .k-list { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--hair); border-radius: var(--r-md); background: var(--inset); overflow: hidden; }
.li, .k-li { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 40px; padding: var(--s2) var(--s3); border: 0; border-radius: 0; background: transparent; font-size: var(--f-sm); color: var(--t1); }
.li + .li, .k-li + .k-li { border-top: 1px solid var(--hair); }
.li:hover, .k-li:hover { background: var(--hover); }
.li.done, .k-li.done { color: var(--t3); }
html.touch .li, html.touch .k-li { min-height: var(--h-touch); }

/* ---------- Stat rows: label left, value right ---------- */
.kv, .k-kv { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding: 3px 0; font-size: var(--f-sm); }
.kv > :first-child, .k-kv > :first-child { color: var(--t2); }
.kv > :last-child, .k-kv > :last-child { color: var(--t1); font-weight: 650; font-variant-numeric: tabular-nums; }

/* A group of stat rows reads as one column: label and value never sit more than ~360px apart. */
.k-kvs { display: flex; flex-direction: column; max-width: 360px; }
/* Key → action rows (controls), name → role rows (NPCs): a fixed first column, text left-aligned. */
/* Each pair is one row: both cells share a single hairline above them (a horizontal gradient line
   on the grid itself would break at the gap, so the line is drawn by both cells at the same y). */
.k-pairs { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 0; row-gap: 0; align-items: stretch; }
.k-pairs > * { display: flex; align-items: center; min-height: 36px; padding: var(--s2) 0; border-top: 1px solid var(--hair); box-sizing: border-box; }
.k-pairs > :nth-child(-n+2) { border-top: 0; }
.k-pairs > :nth-child(odd) { white-space: nowrap; font-weight: 650; color: var(--t1); }
.k-pairs > :nth-child(even) { color: var(--t2); }

/* ---------- Buttons: one shape, four kinds, three heights ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--h-md); padding: 0 var(--s4); border-radius: var(--r-sm);
  border: 1px solid var(--hair); background: rgba(255, 255, 255, .06); color: var(--t1);
  font: inherit; font-size: var(--f-sm); font-weight: 650; line-height: 1.2; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, .11); border-color: rgba(255, 255, 255, .16); }
.btn.primary, .btn.good { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 800; }
.btn.primary:hover, .btn.good:hover { background: #c592ff; border-color: #c592ff; filter: none; }
.btn.bad { background: rgba(255, 107, 129, .14); border-color: rgba(255, 107, 129, .5); color: #ffd6dd; }
.btn.bad:hover { background: rgba(255, 107, 129, .24); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--t2); }
.btn.ghost:hover { background: var(--hover); color: var(--t1); }
.btn.small { min-height: var(--h-sm); padding: 0 var(--s3); font-size: var(--f-xs); border-radius: var(--r-sm); }
.btn:disabled, .btn[disabled] { opacity: .38; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
html.touch .btn, html.touch .btn.small { min-height: var(--h-touch); padding: 0 var(--s4); font-size: var(--f-sm); }
/* The many window-specific overrides of .btn colour collapse into the four kinds above. */
.win:not([data-kind=wardrobe]):not([data-kind=boutique]) .btn { border-radius: var(--r-sm); }
.win:not([data-kind=wardrobe]):not([data-kind=boutique]) .btn.good { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.win:not([data-kind=wardrobe]):not([data-kind=boutique]) .btn.bad { background: rgba(255, 107, 129, .14); border-color: rgba(255, 107, 129, .5); color: #ffd6dd; }

/* ---------- Tabs: one style everywhere (underline segments) ---------- */
.win-tabs, .av-tabs, .k-tabs { display: flex; align-items: stretch; gap: var(--s1); flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 0 var(--s4); border-bottom: 1px solid var(--hair); }
.win-tabs::-webkit-scrollbar, .av-tabs::-webkit-scrollbar, .k-tabs::-webkit-scrollbar { display: none; }
.win-tabs button, .av-tabs button, .k-tabs button {
  position: relative; flex: none; min-height: 38px; padding: 0 var(--s3); margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent;
  color: var(--t2); font: inherit; font-size: var(--f-xs); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; cursor: pointer;
}
.win-tabs button:hover, .av-tabs button:hover, .k-tabs button:hover { color: var(--t1); border-color: var(--hair); background: transparent; }
.win-tabs button.on, .av-tabs button.on, .k-tabs button.on { color: var(--t1); border-bottom-color: var(--accent); background: transparent; }
html.touch .win-tabs button, html.touch .av-tabs button, html.touch .k-tabs button { min-height: var(--h-touch); font-size: var(--f-xs); }

/* ---------- Filters / segmented toggles (not pills) ---------- */
.k-seg { display: inline-flex; flex-wrap: wrap; gap: var(--s1); }
.k-seg button, .k-chip {
  min-height: var(--h-sm); padding: 0 var(--s3); border-radius: var(--r-sm); border: 1px solid var(--hair);
  background: transparent; color: var(--t2); font: inherit; font-size: var(--f-xs); font-weight: 650; cursor: pointer; white-space: nowrap;
}
.k-seg button:hover, .k-chip:hover { color: var(--t1); background: var(--hover); }
.k-seg button.on, .k-chip.on { color: var(--t1); background: var(--accent-soft); border-color: var(--accent-line); }
html.touch .k-seg button, html.touch .k-chip { min-height: 36px; }
/* A data colour (a discipline, a rarity) is a small dot, not a border or a fill. */
.k-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- Badges and pills (small, quiet labels) ---------- */
.pill, .k-badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--hair); background: rgba(255, 255, 255, .04); font-size: var(--f-xs); font-weight: 650; color: var(--t2); margin: 0; }

/* ---------- Progress ---------- */
.k-bar { position: relative; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, .45); overflow: hidden; }
.k-bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--accent); }

/* ---------- Tiles: items and equipment slots ---------- */
.cell, .k-tile {
  position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-md); border: 1px solid var(--hair); background: var(--inset); cursor: pointer;
}
.cell:hover, .k-tile:hover { border-color: rgba(255, 255, 255, .2); filter: none; background: rgba(255, 255, 255, .05); }
.cell.sel, .k-tile.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.k-tile.k-empty { border-style: dashed; cursor: default; }
.k-tile-label { margin-top: var(--s1); font-size: var(--f-xs); color: var(--t2); text-align: center; }

/* ---------- Empty state ---------- */
.k-empty-state { display: grid; place-items: center; min-height: 96px; padding: var(--s4); border: 1px dashed var(--hair); border-radius: var(--r-md); color: var(--t3); font-size: var(--f-sm); text-align: center; }

/* ---------- Inputs ---------- */
.win input:not([type=checkbox]):not([type=radio]):not([type=range]), .win select, .win textarea {
  min-height: var(--h-md); padding: 0 var(--s3); border-radius: var(--r-sm); border: 1px solid var(--hair);
  background: var(--inset); color: var(--t1); font: inherit; font-size: var(--f-sm);
}
.win textarea { padding: var(--s2) var(--s3); }
.win input:focus, .win select:focus, .win textarea:focus { outline: none; border-color: var(--accent-line); }
html.touch .win input:not([type=checkbox]):not([type=radio]):not([type=range]), html.touch .win select { min-height: var(--h-touch); font-size: 16px; }

/* ---------- Keycaps ---------- */
kbd, .k-key { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--hair); border-bottom-width: 2px; background: rgba(255, 255, 255, .05); color: var(--t1); font: inherit; font-size: var(--f-xs); font-weight: 800; }
.menu-btns kbd { display: block; min-width: 0; height: auto; border: 0; border-radius: 0; }

/* ---------- Tooltip ---------- */
#tip { max-width: 280px; padding: var(--s2) var(--s3); border-radius: var(--r-md); border: 1px solid var(--hair); font-size: var(--f-sm); line-height: 1.45; color: var(--t1); }

/* ---------- Top-right HUD column ----------
   The wallet row, the Rift box and the status row are one column of one width: every chip in a row
   is the same width and the rows' edges line up exactly with the box under them. */
:root { --tr-col: 252px; }
@media (max-width: 980px) { :root { --tr-col: 228px; } }
html.touch { --tr-col: 192px; }
.chip-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--s1); width: var(--tr-col); justify-content: stretch; }
.chip-row[hidden] { display: none; }
.chip-row .chip { justify-content: center; min-width: 0; overflow: hidden; }
.rankbox { width: var(--tr-col); box-sizing: border-box; }
html:not(.touch) .hud-tr { display: flex; flex-direction: column; align-items: flex-end; gap: var(--s2); }
html.touch .chip-row .chip { padding-inline: 4px; }
html.touch .rankbox { width: var(--tr-col); }


/* A section header that follows content always gets a full step of air above it. */
:is(.kv, .k-kv, .li, .k-list, .k-kvs, .card, .k-bar, .k-row, .k-pairs) + .k-h { margin-top: var(--s4); }

/* Menu icons: one line-icon family (client/ui-icons.js), same stroke and size everywhere. */
.menu-btns .mi { display: grid; place-items: center; transform: none; filter: none; line-height: 0; }
.menu-btns .ico { width: 20px; height: 20px; color: var(--t1); }
.menu-btns button:hover .ico { color: #fff; }
html.touch .menu-btns .ico { width: 26px; height: 26px; }

/* ---------- Icon glyphs ----------
   The UI font is a terminal face: its × reads as a letter X. Close and remove buttons draw a real
   cross (an SVG mask in the current text colour) and hide their text, which stays for screen readers. */
.win-head .x[data-a=close], .lo-x, .k-x { font-size: 0 !important; color: var(--t2); }
.win-head .x[data-a=close]::before, .lo-x::before, .k-x::before {
  content: ''; display: block; width: 14px; height: 14px; margin: auto; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M2 2l10 10M12 2 2 12' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M2 2l10 10M12 2 2 12' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.win-head .x:hover, .lo-x:hover { color: var(--t1); }
html.touch .win-head .x[data-a=close]::before { width: 18px; height: 18px; }
.lo-x::before { width: 10px; height: 10px; }

/* An empty state is the only box: no card around a dashed box. */
.card:has(> .k-empty-state:only-child) { background: none; border: 0; padding: 0; box-shadow: none; }

/* Pair lists: rules run unbroken across both columns. */
.k-pairs { column-gap: 0; }
.k-pairs > :nth-child(odd) { padding-right: var(--s4); }

/* A folding section header: full-width row with a chevron that turns when open. */
.ab-filter-toggle { width: 100%; padding: var(--s2) 0; border: 0; border-bottom: 1px solid var(--hair); background: none; cursor: pointer; text-align: left; }
.ab-filter-toggle::after { content: ''; width: 8px; height: 8px; margin-left: var(--s2); border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-3px); transition: transform .25s var(--spring, ease); }
.ab-filter-toggle[aria-expanded=true]::after { transform: rotate(225deg) translateY(-2px); }
.ab-filter-toggle:hover { color: var(--t1); }
.help-tips > :nth-child(odd) { align-items: flex-start; padding-right: var(--s3); }
.help-tips .k-dot { width: 5px; height: 5px; margin-top: 8px; color: var(--t3); }

/* Tabs never wrap onto a second line: they scroll sideways (the scrollbar is hidden). */
.win-tabs, .av-tabs, .k-tabs { flex-wrap: nowrap !important; }
/* Touch close: a 40px rounded square sitting inside the header with even margins (its tap area is
   the whole header corner), never touching the sheet's top edge. */
html.touch .win-head { min-height: 56px; padding-right: var(--s2); }
html.touch .win-head .x { width: 40px; height: 40px; border-radius: var(--r-md); background: rgba(255, 255, 255, .07); position: relative; }
html.touch .win-head .x::after { content: ''; position: absolute; inset: -8px; }
/* Unaffordable shop items: the card stays crisp, only the price fades. */
.bq-card.dim { opacity: 1; }
.bq-card.dim .pr { color: var(--t3) !important; }
.bq-card b { color: var(--t1); }
.win-tabs button, .av-tabs button, .k-tabs button { white-space: nowrap; }
.win-head .x .ico { width: 20px; height: 20px; display: block; margin: auto; }
/* Tab strips keep their rhythm in every window; on overflow they scroll with a soft fade at the edge. */
.win .win-tabs button, .win .av-tabs button, .win .k-tabs button { padding: 0 var(--s3); }
/* The fade shows only while the strip overflows and fades out as it is scrolled to the end (a scroll-driven
   animation; with no overflow the timeline is inactive, --tab-fade stays 0 and nothing at the edge dims). */
@property --tab-fade { syntax: '<length>'; inherits: false; initial-value: 0px; }
@keyframes tab-fade { from { --tab-fade: 24px; } to { --tab-fade: 0px; } }
.win-tabs, .av-tabs, .k-tabs { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - var(--tab-fade)), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - var(--tab-fade)), transparent); animation: tab-fade linear both; animation-timeline: scroll(self inline); }
.chip .mi { display: inline-grid; place-items: center; line-height: 0; }
.chip .ico { width: 15px; height: 15px; }
/* Phone landscape: the loadout row stays compact so the ability list is in view. */
@media (orientation: landscape) and (max-height: 520px) {
  html.touch .win[data-kind=abilities] .lo-slot { min-height: 0 !important; height: 76px; padding-top: var(--s1); padding-bottom: var(--s1); }
}
/* A keycap inside running text keeps a little air on both sides and sits on the text's middle. */
.k-pairs > span:nth-child(2n) kbd, .help-tips kbd { margin: 0 3px; vertical-align: middle; }
