/* main.css — game-mirror layout + components.
   Metaphor: the whole app is one game modal window. Title bar, tab row,
   persistent "Current stats" rail (equipment-column metaphor), content pane,
   white-framed nested modal for formula traces. */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--backdrop);
  color: var(--text-1);
  font: 440 var(--text-body)/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-tint); }

/* themed thin scrollbars everywhere — chunky OS scrollbars break the game look */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--line); }

a { color: var(--accent); text-decoration: none; font-weight: 560; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

button { font: inherit; color: inherit; }

/* numerals: Inter tabular for data; mono reserved for math/formula blocks */
.num, td.num { font-family: var(--font-sans); font-variant-numeric: tabular-nums; font-weight: 500; letter-spacing: -0.01em; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- game window ---------- */

/* the app IS a game modal window: bounded, rounded, floating on the backdrop */
.app {
  max-width: 1560px;
  min-height: calc(100vh - 2 * var(--sp-4));
  margin: var(--sp-4) auto;
  display: flex;
  flex-direction: column;
  background: var(--surface-0);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-window);
}
@media (max-width: 1600px) {
  .app { margin: var(--sp-4); }
}
@media (max-width: 900px) {
  .app { margin: 0; min-height: 100vh; border-radius: 0; border: 0; }
}

/* title bar — brand left, controls right */
.titlebar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--line-soft);
}
.titlebar-spacer { flex: 1; }
.titlebar-right { display: flex; align-items: center; gap: var(--sp-2); justify-content: flex-end; flex-wrap: wrap; }
.title-brand { display: flex; align-items: center; gap: 10px; }
.title-brand img { border-radius: 50%; flex: none; }
.title-brand h1 { margin: 0; font-size: 1.125rem; font-weight: 650; letter-spacing: -0.01em; }

.titlebar label { font-size: var(--text-micro); color: var(--text-3); display: flex; align-items: center; gap: 6px; font-weight: 560; letter-spacing: var(--tracking-label); text-transform: uppercase; }

/* ---------- segmented tab bar ---------- */

.tab-row {
  display: flex;
  gap: 2px;
  margin: var(--sp-3) var(--sp-4) 0;
  padding: 4px;
  width: fit-content;
  max-width: calc(100% - 2 * var(--sp-4));
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-row::-webkit-scrollbar { display: none; }

.tab {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  font-size: var(--text-small);
  padding: 7px 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}
.tab:hover { color: var(--text-1); background: var(--surface-2); }
.tab[aria-current="page"] {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

/* ---------- body: rail + content ---------- */

.body {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: var(--sp-4);
  padding: var(--sp-4);
  align-items: start;
  flex: 1;
}

/* Current-stats rail — the game's persistent left equipment column */
.rail {
  position: sticky;
  top: var(--sp-4);
  max-height: calc(100vh - 2 * var(--sp-4));
  overflow-y: auto;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-card);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-head {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  margin-bottom: var(--sp-2);
  font-size: var(--text-micro);
  font-weight: 650;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-2);
}

.rail-hero {
  background: var(--lite-bg-sky);
  color: var(--lite-text);
  border-radius: calc(var(--radius-card) - 4px);
  padding: 10px 12px;
  margin-bottom: var(--sp-2);
}
.rail-hero .lbl { font-size: var(--text-micro); font-weight: 650; letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--lite-text-2); }
.rail-hero .val { font-family: var(--font-sans); font-weight: 650; font-size: 1.3rem; letter-spacing: var(--tracking-display); font-variant-numeric: tabular-nums; }
.rail-hero .bar { height: 5px; border-radius: 3px; margin-top: 6px; background: oklch(0% 0 0 / 0.12); overflow: hidden; }
.rail-hero .bar i { display: block; height: 100%; width: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }

.rail-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  width: 100%;
  border: 0;
  border-left: 3px solid transparent;
  background: none;
  border-radius: 6px;
  padding: 4px 8px 4px 9px;
  cursor: pointer;
  text-align: left;
  transition: background var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out);
}
.rail-row:hover { background: var(--surface-2); }
.rail-row .lbl { color: var(--text-2); font-size: var(--text-small); font-weight: 480; }
.rail-row .val { font-weight: 650; font-size: var(--text-small); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* colored glow when an open trace uses this stat — each involved stat gets its
   own color (--hc set inline), matching the trace legend and math numbers */
.rail-row.hot {
  --hc: var(--gold);
  border-left-color: var(--hc);
  background: color-mix(in oklab, var(--hc) 13%, transparent);
}
.rail-row.hot .lbl { color: var(--hc); }
.rail-row.hot .val { color: var(--hc); }

/* overridden (or override-chain-affected) stats — cyan dashed underline,
   a different channel from the trace highlight so both can show at once */
.rail-row.ov .val {
  color: var(--accent-num);
  border-bottom: 1px dashed var(--accent);
}
.rail-row.hot.ov .val { color: var(--hc); border-bottom-color: var(--hc); }

.rail-foot {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line-soft);
  font-size: var(--text-micro);
  color: var(--text-3);
  font-weight: 480;
}
.rail-foot .verified { display: flex; align-items: center; gap: 6px; color: var(--lime); font-weight: 650; letter-spacing: var(--tracking-label); margin-bottom: 4px; }

/* content pane — fills the window column; reading measure is enforced per
   prose element (max-width in ch below), not by starving tables of width */
.content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.view[hidden] { display: none; }
.view { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ---------- primitives ---------- */

.card {
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--sp-4);
}
.card > h2 { font-size: 0.9375rem; font-weight: 650; margin: 0 0 var(--sp-3); }
.card-sub { color: var(--text-2); font-size: var(--text-body); font-weight: 460; margin: -8px 0 var(--sp-3); max-width: 76ch; }

.label {
  font-size: var(--text-micro);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 650;
}

.input, select.input {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-input);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-weight: 480;
  font-size: var(--text-small);
  padding: 6px 10px;
  width: 110px;
  transition: border-color var(--motion-fast) var(--ease-out), background var(--motion-fast) var(--ease-out);
}
.input:hover { border-color: var(--text-3); }
.input:focus { border-color: var(--accent); outline: none; }
.input::placeholder { color: var(--text-3); }
select.input { font-family: var(--font-sans); font-weight: 500; width: auto; cursor: pointer; border-radius: var(--radius-input); padding: 6px 12px; }

input[type="checkbox"] { accent-color: var(--gold); width: 15px; height: 15px; }

/* game-style buttons: rounded, vertical sheen, bold */
/* flat modern buttons — no gradients, no bevels */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-1);
  padding: 7px 15px;
  font-size: var(--text-small);
  font-weight: 550;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out), transform var(--motion-fast) var(--ease-out);
}
.btn:hover { background: var(--surface-3); border-color: var(--text-3); }
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hover); border-color: transparent; }
.btn.commit {
  background: var(--lime);
  border-color: transparent;
  color: var(--on-lime);
  font-weight: 600;
}
.btn.commit:hover { background: var(--lime-deep); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); font-weight: 500; }
.btn.ghost:hover { background: var(--surface-2); color: var(--text-1); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* segmented control (game tab-pair like Option/Scroll) */
.seg { display: inline-flex; background: var(--surface-inset); border: 1px solid var(--line-soft); border-radius: var(--radius-btn); padding: 3px; gap: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2);
  padding: 5px 14px; border-radius: calc(var(--radius-btn) - 3px);
  font-size: var(--text-small); font-weight: 560; cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}
.seg button:hover { color: var(--text-1); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* rarity pills — game colors, white bold text */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  font-size: var(--text-micro);
  font-weight: 650;
  color: #fff;
}
.pill.epic { background: var(--rar-epic); }
.pill.unique { background: var(--rar-unique); color: var(--on-gold); text-shadow: none; }
.pill.legendary { background: var(--rar-legendary); }
.pill.mystic { background: var(--rar-mystic); }

.seg.rarity button[aria-pressed="true"].epic { background: var(--rar-epic); color: #fff; }
.seg.rarity button[aria-pressed="true"].unique { background: var(--rar-unique); color: var(--on-gold); }
.seg.rarity button[aria-pressed="true"].legendary { background: var(--rar-legendary); color: #fff; }
.seg.rarity button[aria-pressed="true"].mystic { background: var(--rar-mystic); color: #fff; }

.check { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-small); font-weight: 560; color: var(--text-2); cursor: pointer; }

/* ---------- tables ---------- */

.table-scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: var(--text-small); }
th {
  text-align: left;
  font-weight: 650;
  color: var(--text-3);
  font-size: var(--text-micro);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 7px 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; font-weight: 480; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--motion-fast) var(--ease-out); }
tbody tr:hover { background: oklch(100% 0 0 / 0.03); }
td.num, th.num { text-align: right; }
td .input { width: 96px; }
.stat-note { color: var(--text-3); font-size: var(--text-small); font-weight: 480; }
.na { color: var(--text-3); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* clickable computed value — the formula-trace affordance */
.val-btn {
  background: none;
  border: 0;
  padding: 1px 2px;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-weight: 480;
  font-size: inherit;
  color: var(--accent-num);
  cursor: pointer;
  border-bottom: 1px dotted var(--accent);
  border-radius: 2px;
  transition: color var(--motion-fast) var(--ease-out), background var(--motion-fast) var(--ease-out);
}
.val-btn:hover { color: var(--accent-hover); background: var(--accent-tint); }
.val-btn.pos { color: var(--pos); border-bottom-color: var(--gold-deep); }
.val-btn.neg { color: var(--neg); border-bottom-color: var(--danger); }
.val-btn.pos:hover { background: var(--gold-tint); }
.val-btn.neg:hover { background: var(--danger-tint); }
.val-btn.na { color: var(--text-3); border-bottom-color: var(--line); }

/* overridden effective values + chain-affected clickable cells */
.ov-val { color: var(--accent-num); border-bottom: 1px dashed var(--accent); padding-bottom: 1px; }
.val-btn.ov-chain { color: var(--accent-num); border-bottom-style: dashed; }
.input-active-ov { border-color: var(--accent); background: var(--accent-tint); }

/* relative-weight bar — gold game progress bar */
.relbar { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.relbar .track { flex: 1; height: 7px; border-radius: 4px; background: oklch(0% 0 0 / 0.35); border: 1px solid oklch(0% 0 0 / 0.2); overflow: hidden; }
.relbar .fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }

/* ---------- metric cards — white game showcase cards ---------- */

/* flex, not grid: the wide hero + equal secondaries wrap cleanly at any width */
.metrics { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.metrics .metric { flex: 1 1 150px; min-width: 150px; }
.metrics .metric.hero { flex: 2 1 280px; min-width: 260px; }
.metric {
  background: var(--lite-bg);
  color: var(--lite-text);
  border-radius: var(--radius-card);
  box-shadow: 0 2px 6px oklch(0% 0 0 / 0.3);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.metric.hero { background: var(--lite-bg-sky); }
.metric .metric-label { font-size: var(--text-micro); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--lite-text-2); font-weight: 650; }
.metric .metric-value { font-weight: 650; font-size: 1.25rem; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }
.metric.hero .metric-value { font-size: var(--text-display); }
.metric .metric-value .val-btn { font-size: inherit; font-family: inherit; font-weight: 650; color: var(--lite-text); border-bottom-color: var(--gold-deep); }
.metric .metric-value .val-btn:hover { color: var(--gold-deep); background: var(--gold-tint); }
.metric .metric-sub { font-size: var(--text-micro); color: var(--lite-text-2); font-weight: 480; }
.metric .bar { height: 5px; border-radius: 3px; margin-top: 4px; background: oklch(0% 0 0 / 0.1); overflow: hidden; }
.metric .bar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }

/* net-gain hero (gain planner) */
.net-hero { display: flex; align-items: baseline; gap: var(--sp-4); flex-wrap: wrap; }
.net-hero .metric-value { font-size: var(--text-hero); font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- capture / dropzone — game empty-slot ---------- */

/* game "select a scroll" empty slot: solid panel, dashed gold slot inside */
.dropzone {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-panel);
  background: var(--surface-inset);
  box-shadow: var(--shadow-card);
  padding: var(--sp-6) var(--sp-5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  text-align: center;
  cursor: pointer;
  transition: background var(--motion-base) var(--ease-out);
}
.dropzone { cursor: default; }
.dropzone .plus:hover, .dropzone.dragover .plus { border-color: var(--gold); background: var(--gold-tint); }
.dropzone .plus { background: transparent; cursor: pointer; }
.dropzone.dragover { background: var(--gold-tint); }
.dropzone h2 { margin: 0; font-size: 1.125rem; font-weight: 650; }
/* icon + heading stay centered; multi-line instructions read left-aligned
   (centered paragraphs give the eye no anchor on the return sweep) */
.dropzone p { margin: 0; color: var(--text-2); font-size: var(--text-body); font-weight: 460; width: 100%; max-width: 520px; text-align: left; }
.dropzone .hint { color: var(--text-3); font-size: var(--text-small); font-weight: 520; }
.dropzone .plus {
  width: 76px; height: 76px;
  border-radius: 16px;
  border: 2px dashed var(--gold-deep);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold);
  font-size: 38px; font-weight: 650; line-height: 1;
  transition: border-color var(--motion-base) var(--ease-out), background var(--motion-base) var(--ease-out);
}

/* compact "paste more" strip shown once stats are captured */
.dropzone.strip {
  flex-direction: row;
  align-items: center;
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  gap: var(--sp-4);
}
.dropzone.strip .plus.small {
  width: 42px; height: 42px;
  border-radius: 12px;
  font-size: 24px;
  flex: none;
}
.strip-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.strip-text strong { font-size: var(--text-body); font-weight: 650; }
.chip-count {
  margin-left: auto;
  flex: none;
  background: var(--gold-tint);
  color: var(--gold);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: var(--text-micro);
  font-weight: 650;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

/* editable last-column target in the equivalency header */
.th-edit { color: var(--accent); display: inline-flex; align-items: center; gap: 2px; }
.th-edit .input { width: 52px; padding: 2px 6px; font-size: var(--text-micro); font-weight: 650; color: var(--accent-num); text-align: right; }

/* capture coverage — which stats are in, on file, or still expected */
.cov-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.cov-head h2 { margin-bottom: var(--sp-2); }
.cov-count { font-size: var(--text-micro); font-weight: 560; color: var(--text-3); letter-spacing: var(--tracking-label); text-transform: uppercase; white-space: nowrap; }
.cov-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.cov-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: default;
}
.cov-chip.captured {
  background: var(--gold-tint);
  color: var(--gold);
  border-color: color-mix(in oklab, var(--gold) 35%, transparent);
}
.cov-chip.onfile {
  background: var(--surface-2);
  color: var(--text-2);
}
.cov-chip.missing {
  color: var(--text-3);
  border: 1px dashed var(--line);
  opacity: 0.85;
}
.cov-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.cov-dash { width: 8px; height: 2px; border-radius: 1px; background: var(--text-3); opacity: 0.7; }

kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 560;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 1px;
  border-radius: 6px;
  padding: 1px 6px;
}

.progress { width: 100%; max-width: 360px; height: 10px; border-radius: 6px; background: oklch(0% 0 0 / 0.35); border: 1px solid oklch(0% 0 0 / 0.2); overflow: hidden; }
.progress .fill { height: 100%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); border-radius: 5px; transition: width var(--motion-base) var(--ease-out); }

.ocr-preview { max-width: 200px; max-height: 120px; border-radius: var(--radius-input); border: 1px solid var(--line); object-fit: contain; }

details.unmatched { font-size: var(--text-small); color: var(--text-2); font-weight: 480; }
details.unmatched summary { cursor: pointer; }
details.unmatched li { font-family: var(--font-mono); }

.input-warn { border-color: var(--warning); }
.warn-note {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: 4px;
  color: var(--warning);
  font-family: var(--font-sans);
  font-size: var(--text-small);
  font-weight: 560;
  white-space: normal;
  text-align: left;
  max-width: 280px;
}
.btn.warn-fix {
  padding: 2px 10px;
  font-size: var(--text-micro);
  font-family: var(--font-sans);
  background: transparent;
  background-image: none;
  border: 1px solid var(--gold-deep);
  color: var(--gold);
  box-shadow: none;
  flex: none;
}
.btn.warn-fix:hover { background: var(--gold-tint); filter: none; }

.error-banner {
  background: var(--danger-tint);
  border: 1px solid var(--danger);
  border-radius: var(--radius-card);
  color: var(--text-1);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-small);
  font-weight: 560;
  display: flex;
  gap: var(--sp-3);
  align-items: center;
}

/* ---------- trace panel — the game's white-framed nested modal ---------- */

.trace-panel {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  max-height: calc(100vh - 2 * var(--sp-4));
  width: min(420px, calc(100vw - 300px));
  background: var(--lite-bg);
  border-radius: var(--radius-panel);
  box-shadow: 0 16px 48px oklch(0% 0 0 / 0.55);
  padding: 8px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + var(--sp-5)));
  visibility: hidden;
  transition: transform var(--motion-slow) var(--ease-out), visibility 0s var(--motion-slow);
}
.trace-panel.open { transform: translateX(0); visibility: visible; transition: transform var(--motion-slow) var(--ease-out); }

.trace-head {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 4px 2px 8px;
  touch-action: none;
}
.trace-head h2 { margin: 0; grid-column: 2; text-align: center; font-size: 1rem; font-weight: 650; color: var(--lite-text); }
.trace-close {
  grid-column: 3;
  background: none; border: 0; color: var(--lite-text-2); cursor: pointer;
  width: 44px; height: 44px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.trace-close svg { width: 22px; height: 22px; }
.trace-close:hover { color: var(--lite-text); background: oklch(0% 0 0 / 0.08); }

.trace-inner {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--surface-inset);
  border-radius: calc(var(--radius-panel) - 6px);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* legend: which color is which stat, shown when a trace involves several */
.trace-legend { display: flex; flex-wrap: wrap; gap: 6px; }
.trace-legend[hidden] { display: none; }
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-micro);
  font-weight: 650;
  color: var(--hc);
  background: color-mix(in oklab, var(--hc) 14%, transparent);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
}
.legend-chip::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hc);
}

.trace-lines { display: flex; flex-direction: column; gap: var(--sp-3); }
.trace-line .trace-label { font-size: var(--text-micro); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-3); font-weight: 650; margin-bottom: 3px; }
.trace-line .trace-math {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-small);
  font-weight: 480;
  background: var(--surface-2);
  border-radius: var(--radius-input);
  padding: var(--sp-2) var(--sp-3);
  white-space: pre-wrap;
  word-break: break-word;
}
/* numbers used in the calculation — gold, like the game's option values */
.trace-math .gnum { color: var(--gold); font-weight: 560; }

/* collapsible full derivation inside a trace */
.trace-more { margin-top: var(--sp-2); }
.trace-more summary {
  cursor: pointer;
  font-size: var(--text-small);
  font-weight: 650;
  color: var(--accent);
  padding: 4px 0;
  list-style-position: inside;
}
.trace-more summary:hover { color: var(--accent-hover); }
.trace-more[open] summary { margin-bottom: var(--sp-2); }
.trace-more .trace-line { margin-bottom: var(--sp-3); }

.trace-result { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: var(--sp-3); }
.trace-result .value { font-family: var(--font-sans); font-variant-numeric: tabular-nums; font-weight: 650; font-size: var(--text-display); letter-spacing: var(--tracking-display); color: var(--gold); }
.trace-note { font-size: var(--text-body); font-weight: 460; color: var(--text-2); background: var(--accent-tint); border-radius: var(--radius-input); padding: var(--sp-2) var(--sp-3); }
.trace-doclink { font-size: var(--text-small); }

/* ---------- formulas view: left subnav + one page at a time ---------- */

.formulas-layout {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: var(--sp-4);
  align-items: start;
}

.subnav {
  position: sticky;
  top: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-card);
  padding: var(--sp-2);
}

.subnav-group {
  font-size: var(--text-micro);
  font-weight: 650;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-3);
  padding: var(--sp-2) 10px 4px;
  margin-top: var(--sp-1);
}

.subnav-btn {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-weight: 560;
  font-size: var(--text-small);
  text-align: left;
  padding: 7px 10px;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}
.subnav-btn:hover { color: var(--text-1); background: var(--surface-2); }
.subnav-btn[aria-current="page"] {
  background: var(--accent-tint);
  color: var(--accent);
  font-weight: 650;
}

.subpage { display: grid; gap: var(--sp-3); max-width: 780px; }

.subpage-nav { display: flex; justify-content: space-between; gap: var(--sp-2); }
.subpage-step {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-btn);
  background: var(--surface-1);
  color: var(--text-2);
  font-weight: 560;
  font-size: var(--text-small);
  padding: 7px 12px;
  cursor: pointer;
  transition: color var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out);
}
.subpage-step:hover { color: var(--accent); border-color: var(--accent-line); }

@media (max-width: 900px) {
  .formulas-layout { grid-template-columns: 1fr; }
  .subnav { position: static; flex-direction: row; flex-wrap: wrap; }
  .subnav-group { display: none; }
}
.formula-card .applies { color: var(--gold); font-size: var(--text-micro); letter-spacing: var(--tracking-label); text-transform: uppercase; font-weight: 650; }
.formula-card h3 { margin: 4px 0 8px; font-size: var(--text-body); font-weight: 650; }
.formula-card .gain-formula {
  font-family: var(--font-mono);
  font-size: var(--text-small);
  font-weight: 480;
  background: var(--surface-2);
  border-radius: var(--radius-input);
  padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-2) 0;
  white-space: pre-wrap;
}
.formula-card p { margin: var(--sp-2) 0 0; color: var(--text-2); font-size: var(--text-body); font-weight: 460; }
.formula-card .deps { color: var(--text-3); font-size: var(--text-small); font-weight: 520; }
.formula-card.flash { animation: flash 1.2s var(--ease-out); }
@keyframes flash { 0% { border-color: var(--gold); } 100% { border-color: var(--line-soft); } }

/* ---------- controls rows ---------- */

.controls { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; }
.controls .group { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--text-small); font-weight: 560; color: var(--text-2); }
.controls .input.short { width: 64px; }

.weight-note { font-size: var(--text-small); color: var(--text-2); font-weight: 480; max-width: 76ch; }

.star { color: var(--gold); }

/* sortable tier headers (artifacts) */
th.sortable { cursor: pointer; user-select: none; transition: filter var(--motion-fast) var(--ease-out); }
th.sortable:hover { filter: brightness(1.2); }
th.sortable .sort-ind { color: var(--text-3); font-size: 0.75rem; font-weight: 650; margin-left: 2px; }
th.sortable.sorted .sort-ind { color: var(--gold); }

/* Ring of Cycles level slider */
.ring-slider { width: 140px; accent-color: var(--gold); cursor: pointer; }

/* prime cube lines — bold name in the selected rarity's color */
.prime-line { color: var(--rar, var(--gold)); font-weight: 650; }

/* rarity-scoped table (cubes): header row and prime lines take the color of
   the selected rarity so the active tier is readable at a glance */
.rar-scope { --rar: var(--gold); }
.rar-scope thead th {
  background: color-mix(in oklab, var(--rar) 16%, transparent);
  color: var(--rar);
  border-bottom-color: color-mix(in oklab, var(--rar) 45%, transparent);
}
.rar-scope thead th:first-child { border-radius: 8px 0 0 0; }
.rar-scope thead th:last-child { border-radius: 0 8px 0 0; }

/* tier-colored gain values (artifact / hero power columns) */
.val-btn.tier-epic { color: var(--rar-epic); border-bottom-color: var(--rar-epic); }
.val-btn.tier-unique { color: var(--rar-unique); border-bottom-color: var(--rar-unique); }
.val-btn.tier-legendary { color: var(--rar-legendary); border-bottom-color: var(--rar-legendary); }
.val-btn.tier-mystic { color: var(--rar-mystic); border-bottom-color: var(--rar-mystic); }
.val-btn.tier-epic:hover, .val-btn.tier-unique:hover,
.val-btn.tier-legendary:hover, .val-btn.tier-mystic:hover {
  background: color-mix(in oklab, currentColor 14%, transparent);
}

/* encounter-split sliders — one per line, two-tone track, color-coded ends */
/* the encounter-split control — same header + slider + description treatment
   everywhere it appears (planner, equivalency, cubes, artifacts, hero power) */
.split-group { margin: var(--sp-2) 0 var(--sp-3); }
.split-head {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  margin-bottom: var(--sp-3);
  font-size: var(--text-micro);
  font-weight: 650;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-2);
}
.slider-block { margin-bottom: var(--sp-3); }
.split-group .slider-block:last-child { margin-bottom: 0; }
.slider-row {
  --c-left: var(--split-normal);
  --c-right: var(--rar-mystic);
  --pos: 50%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius-pill);
}
.slider-row .side { font-size: var(--text-small); font-weight: 650; color: var(--c-left); white-space: nowrap; min-width: 96px; }
.slider-row .side.right { text-align: right; color: var(--c-right); }
.slider-row .side b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* an open breakdown that uses a split share lights its slider up in the
   reserved weight color — ring on the track, used side's value tinted to
   match the number inside the math (--hc is set by highlightSliders) */
.slider-row.hot .split-slider { box-shadow: 0 0 0 2px var(--hc), 0 0 10px color-mix(in oklab, var(--hc) 45%, transparent); }
.slider-row.hot.wl .side:not(.right) b,
.slider-row.hot.wr .side.right b { color: var(--hc); }
.slider-desc { margin-top: 4px; max-width: 640px; }

.split-slider {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 8px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--c-left) 0 var(--pos), var(--c-right) var(--pos) 100%);
  cursor: pointer;
  outline-offset: 4px;
}
.split-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text-1);
  border: 3px solid var(--surface-0);
  box-shadow: 0 1px 3px oklch(0% 0 0 / 0.4);
}
.split-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-1);
  border: 3px solid var(--surface-0);
  box-shadow: 0 1px 3px oklch(0% 0 0 / 0.4);
}

/* override vs auto-adjusted tags */
.tag {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 0.5625rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 2px;
}
.tag-ov { background: var(--accent); color: var(--on-accent); }
.tag-auto { background: transparent; border: 1px solid var(--accent); color: var(--accent-num); }

/* formula doc modal — dimmed page, game nested-modal frame */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0% 0 0 / 0.6);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}
.modal-backdrop[hidden] { display: none; }
.doc-modal {
  background: var(--lite-bg);
  border-radius: var(--radius-panel);
  box-shadow: 0 24px 64px oklch(0% 0 0 / 0.6);
  padding: 8px;
  width: min(600px, 94vw);
  max-height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
}
.doc-modal .formula-card { border: 0; box-shadow: none; background: transparent; padding: 0; }

/* profiles modal */
.profiles-modal { width: min(700px, 94vw); }
.prof-toolbar { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.prof-notice {
  background: var(--lime-tint);
  color: var(--lime);
  border-radius: var(--radius-input);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-small);
  font-weight: 560;
  margin-bottom: var(--sp-3);
}
.prof-notice.err { background: var(--danger-tint); color: var(--danger); }
.prof-import {
  background: var(--surface-2);
  border-radius: var(--radius-card);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.prof-import input[type="file"] { color: var(--text-2); font-size: var(--text-small); margin-bottom: var(--sp-2); }
.prof-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-3); max-height: 46vh; overflow-y: auto; }
.prof-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-card);
  padding: 6px 8px;
  transition: border-color var(--motion-fast) var(--ease-out), background var(--motion-fast) var(--ease-out);
}
.prof-row:hover { border-color: var(--line); background: var(--surface-3); }
.prof-row.active { border-color: var(--accent-line, var(--accent)); background: var(--accent-tint); }
.prof-row.active:hover { border-color: var(--accent); }
.prof-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 6px 4px;
  cursor: pointer;
  text-align: left;
  border-radius: var(--radius-input);
}
.prof-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.prof-row.active .prof-dot { background: var(--accent); }
.prof-name { font-weight: 650; font-size: var(--text-body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prof-meta { margin-left: auto; color: var(--text-3); font-size: var(--text-micro); font-weight: 560; white-space: nowrap; }
.prof-rename { width: 180px; font-family: var(--font-sans); font-weight: 560; }
.prof-actions { display: flex; gap: 4px; flex: none; }
.iconbtn-sm {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}
.iconbtn-sm:hover { background: var(--surface-3); color: var(--text-1); }
.iconbtn-sm.danger:hover { color: var(--danger); background: var(--danger-tint); }
.iconbtn-sm.confirming {
  width: auto;
  padding: 0 10px;
  background: var(--danger);
  color: #fff;
  font-size: var(--text-micro);
  font-weight: 650;
}
.iconbtn-sm:disabled { opacity: 0.35; cursor: not-allowed; }

/* first-run welcome */
.card.welcome {
  border-color: var(--accent-line, var(--accent));
  background: var(--accent-tint);
  display: flex;
  gap: var(--sp-4);
  align-items: flex-start;
}
.welcome-mascot { flex: none; border-radius: 50%; }
.welcome-body { min-width: 0; }
.welcome-body h2 { margin-top: 2px; }

/* worked examples (formulas page + doc modal) */
.example {
  margin-top: var(--sp-3);
  border-top: 1px solid var(--line-soft);
  padding-top: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.example-title { font-size: var(--text-micro); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--accent); font-weight: 650; }
.example .trace-label { font-size: var(--text-micro); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-3); font-weight: 650; margin-bottom: 3px; }
.example .trace-math {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-small);
  font-weight: 480;
  background: var(--surface-2);
  border-radius: var(--radius-input);
  padding: var(--sp-2) var(--sp-3);
  white-space: pre-wrap;
  word-break: break-word;
}
.example .gnum { color: var(--gold); font-weight: 560; }
.example-result { font-size: var(--text-small); font-weight: 560; color: var(--text-2); }
.example-result span { color: var(--gold); font-weight: 650; font-size: 1rem; font-variant-numeric: tabular-nums; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .body { grid-template-columns: 1fr; }
  .rail {
    position: sticky;
    top: 0;
    z-index: 6;
    max-height: none;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-card);
  }
  .rail-head { margin-bottom: 0; flex: none; }
  .rail-hero { margin-bottom: 0; flex: none; padding: 6px 10px; }
  .rail-hero .bar { display: none; }
  .rail-row { flex: none; flex-direction: column; align-items: flex-start; gap: 0; border-left: 0; border-bottom: 3px solid transparent; }
  .rail-row.hot { border-bottom-color: var(--gold); }
  .rail-foot { display: none; }
  .titlebar-right { justify-content: flex-start; }

  /* trace becomes a bottom sheet so the sticky rail strip stays visible */
  .trace-panel {
    top: auto;
    left: var(--sp-2);
    right: var(--sp-2);
    bottom: var(--sp-2);
    width: auto;
    max-height: 58vh;
    transform: translateY(calc(100% + var(--sp-5)));
  }
  .trace-panel.open { transform: translateY(0); }
}
