/* ---------------------------------------------------------------- tokens
 * Kaos shipped dark-only; `:root`/`[data-theme="dark"]` is that original
 * palette unchanged, `[data-theme="light"]` below is the new addition. */
:root,
[data-theme="dark"] {
  --bg: #14161a;
  --bg-2: #1b1e24;
  --bg-3: #22262e;
  --bg-4: #2b303a;
  --line: #333945;
  --line-2: #444c5b;
  --ink: #e6e8ec;
  --ink-2: #a8b0be;
  --ink-3: #737d8d;
  --accent: #c9a227;
  --accent-2: #e0bd4a;
  --accent-ink: #1a1508;
  --red: #c2513f;
  --green: #5b9c6a;
  --blue: #5b86c4;
  /* Tells the browser to draw its own widgets (dropdown lists, scrollbars,
     checkboxes, date pickers) for this theme, not the OS default. */
  color-scheme: dark;
  --radius: 6px;
  /* One page edge for the top bar and every screen under it, so the brand, the
     title and the cards all start on the same line. */
  --gutter: 24px;
  --sans: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

[data-theme="light"] {
  /* Warm parchment, not stark white - keeps the serif/gold branding feeling
     like the same app rather than a generic light-mode repaint. */
  --bg: #f6f2e8;
  --bg-2: #ffffff;
  --bg-3: #eee7d5;
  --bg-4: #e3d9bf;
  --line: #d9cdab;
  --line-2: #c2b489;
  --ink: #24201a;
  --ink-2: #55503f;
  --ink-3: #766e56;
  --accent: #8a6d1d;
  --accent-2: #6f5714;
  --accent-ink: #fffaf0;
  --red: #a3392a;
  --green: #3f7a4d;
  --blue: #3a5f96;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

/**
 * iOS measures 100% against the *large* viewport - the one behind Safari's
 * own toolbars - so the shell comes out taller than what you can actually
 * see, the page itself scrolls, and the top bar slides away with it. That is
 * not what `overflow: hidden` was asked for. `dvh` is the visible height, so
 * the shell fits it and the panels inside do the scrolling, which is how this
 * behaves everywhere else.
 */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  overflow: hidden;
  /* and no rubber-banding the whole app when a panel reaches its end */
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--line-2); }

/* ---------------------------------------------------------------- layout */
#app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--gutter);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .02em;
  white-space: nowrap;
}

.brand small {
  display: block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 400;
  color: var(--ink-3);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.topbar .name-input {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  min-width: 200px;
  font-family: var(--serif);
  font-size: 15px;
}

.topbar .spacer { flex: 1; }

.main {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 320px;
  min-height: 0;
}

@media (max-width: 1100px) {
  .main { grid-template-columns: 160px minmax(0, 1fr); }
  .sheet-rail { display: none; }
}

/* ------------------------------------------------------------------ steps */
.steps {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 8px 0;
}

.step {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: 0;
  border-left: 3px solid transparent;
  text-align: left;
  cursor: pointer;
  color: var(--ink-2);
}

.step:hover { background: var(--bg-3); color: var(--ink); }

.step.active {
  background: var(--bg-3);
  border-left-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}

.step .sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-3);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step .badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  border-radius: 9px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
}

.step-body { flex: 1; min-width: 0; }

/* ------------------------------------------------------------------ panel */
.panel {
  overflow-y: auto;
  padding: 24px var(--gutter) 64px;
  min-width: 0;
}

.panel h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 2px;
  color: var(--accent);
}

.panel .hint {
  color: var(--ink-3);
  margin: 0 0 16px;
  font-size: 13px;
}

/* ----------------------------------------------------------------- picker */
.picker { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; }

@media (max-width: 820px) { .picker { grid-template-columns: 1fr; } }

.search {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.search:focus, .name-input:focus, select:focus, textarea:focus, input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 62vh;
  overflow-y: auto;
  background: var(--bg-2);
}

.list-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
  color: var(--ink-2);
}

.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--bg-3); color: var(--ink); }

.list-item.selected {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.list-item .src {
  display: block;
  font-size: 11px;
  color: var(--ink-3);
}

.list-item.selected .src { color: rgba(26, 21, 8, .7); }

.list-empty { padding: 16px; color: var(--ink-3); font-style: italic; }

/* ----------------------------------------------------------------- detail */
.detail {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  max-height: 62vh;
  overflow-y: auto;
}

.detail h3 {
  font-family: var(--serif);
  font-size: 20px;
  margin: 0 0 2px;
}

.detail .meta { color: var(--ink-3); font-size: 12px; margin-bottom: 12px; }

.rich { font-size: 13.5px; color: var(--ink-2); }
.rich p { margin: 0 0 8px; }
.rich h3, .rich h4, .rich h5 {
  font-family: var(--serif);
  color: var(--accent-2);
  margin: 16px 0 5px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.rich .flavor { font-style: italic; color: var(--ink-3); }
.rich ul, .rich ol { margin: 0 0 8px; padding-left: 20px; }
.rich li { margin-bottom: 3px; }
.rich .unstyled { list-style: none; padding-left: 0; }
.rich strong, .rich b { color: var(--ink); }
.rich table { border-collapse: collapse; width: 100%; margin: 8px 0 12px; font-size: 12px; }
.rich table td, .rich table th { border: 1px solid var(--line); padding: 3px 6px; text-align: center; }
.rich table thead td { background: var(--bg-4); font-weight: 700; color: var(--ink); }
.rich table td.left { text-align: left; }
.rich .feature { font-weight: 700; color: var(--ink); margin-right: 4px; }
.rich .indent { padding-left: 12px; }
.rich [element] { display: none; }

.table-wrap { overflow-x: auto; }

/* ---------------------------------------------------------------- buttons */
.btn {
  padding: 6px 12px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
}

.btn:hover { background: var(--bg-4); border-color: var(--accent); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn.primary:hover { background: var(--accent-2); }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 3px 8px; font-size: 12px; }

/* the light/dark switch: two icons, CSS picks the one that describes what
   clicking it does next; line-height: 0 keeps the bigger icon from growing
   the button past a plain .btn's height. */
.theme-toggle .ti-dark, .theme-toggle .ti-light { font-size: 15px; line-height: 0; }
.theme-toggle .ti-light { display: none; }
[data-theme="light"] .theme-toggle .ti-dark { display: none; }
[data-theme="light"] .theme-toggle .ti-light { display: inline; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.card > h3 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 16px;
  color: var(--accent-2);
}

.card.warn { border-color: var(--red); }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row + .row { margin-top: 12px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-3); }

select, textarea, input[type=text], input[type=number], input[type=password],
input[type=search], input[type=email] {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
}

/* The open list of a <select> is drawn by the OS and ignores the field's own
   colours unless the options carry them; without this a light-on-light or
   dark-on-dark list is possible. */
select option, select optgroup { background: var(--bg-2); color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: 1; }

textarea { resize: vertical; min-height: 70px; font-family: var(--sans); }

/* -------------------------------------------------------------- abilities */
.ability-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }

@media (max-width: 700px) { .ability-grid { grid-template-columns: repeat(3, 1fr); } }

.ability {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 6px;
  text-align: center;
}

.ability .ab-name {
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.ability .ab-total { font-size: 26px; font-weight: 700; font-family: var(--serif); line-height: 1.1; }
.ability .ab-mod { font-size: 13px; color: var(--accent-2); }
.ability .ab-base { display: flex; align-items: center; justify-content: center; gap: 5px; margin-top: 7px; }
.ability .ab-base input { width: 48px; text-align: center; padding: 3px; }
.ability .ab-bonus { font-size: 11px; color: var(--green); min-height: 15px; }

/* Rolled scores: the six rolls in a row, and a picker on each ability. A roll
   already placed dims and says where it went; an ability still waiting for
   one is drawn dashed. */
.roll-pool { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.roll-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 3px 12px;
}
.roll-chip b { font-family: var(--serif); font-size: 16px; color: var(--ink); }
.roll-chip .roll-dice { font-size: 11px; color: var(--ink-3); }
.roll-chip .roll-on { font-size: 10px; letter-spacing: .08em; color: var(--accent-2); }
.roll-chip.used { border-color: var(--line); opacity: .7; }
.ability.unplaced { border-style: dashed; border-color: var(--line-2); }
.ability.unplaced .ab-total { color: var(--ink-3); }
.ability .ab-roll-pick { width: 100%; max-width: 112px; padding: 3px; text-align: center; }

/* ------------------------------------------------------------ hit points */
.hp-grid { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

.hp-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 74px 40px 46px 40px;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--line);
}

.hp-row:last-child { border-bottom: 0; }
.hp-row:nth-child(even) { background: var(--bg-3); }

.hp-row.head {
  background: var(--bg-4);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-3);
}

.hp-row .hp-lvl { font-variant-numeric: tabular-nums; color: var(--ink-3); }
.hp-row .hp-cls { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.hp-row .hp-in { width: 100%; padding: 3px 6px; text-align: center; }
.hp-row .hp-in.fixed {
  display: block;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  color: var(--accent-2);
  font-weight: 600;
}
.hp-row .hp-con, .hp-row .hp-tot { text-align: right; font-variant-numeric: tabular-nums; }
.hp-row .hp-tot { font-weight: 700; }
.hp-row.head .hp-in, .hp-row.head .hp-con, .hp-row.head .hp-tot { text-align: center; }

/* ------------------------------------------------------- starting gear   */
.gear-src { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.gear-src:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.gear-src > h4 { margin: 0 0 8px; font-size: 14px; font-family: var(--serif); }
.gear-src > h4 .muted { font-family: var(--sans); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

.gear-group { border-left: 3px solid var(--line-2); padding-left: 12px; margin-bottom: 12px; }
.gear-group.unfilled { border-left-color: var(--red); }
.gear-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 4px; }

.gear-items { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.gear-items .tag.ok { border-color: var(--green); color: var(--ink); }
.gear-items .tag.unmatched { border-style: dashed; color: var(--ink-3); }
.gear-slot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.gear-slot select { padding: 3px 6px; }

/* ------------------------------------------------------------- inventory */
.inv { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

.inv-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto 30px;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--line);
}

.inv-row:last-child { border-bottom: 0; }
.inv-row:nth-child(even) { background: var(--bg-3); }
.inv-row.on .inv-name { color: var(--ink); font-weight: 600; }
.inv-row:not(.on) .inv-name { color: var(--ink-3); }

.inv-eq { display: grid; place-items: center; }
.inv-eq input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.inv-name { overflow: hidden; text-overflow: ellipsis; }
.inv-note { font-size: 11px; margin-left: 7px; font-weight: 400; }
.inv-qty { display: flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }

.inv-contents {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 6px 12px 8px 36px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  font-size: 11px;
}

.inv-contents .muted { text-transform: uppercase; letter-spacing: .06em; font-size: 10px; }
.inv-contents .tag { font-size: 11px; padding: 0 6px; }

/* --------------------------------------------------------------- choices */
.choice { border-left: 3px solid var(--accent); padding-left: 12px; margin-bottom: 16px; }
.choice.unfilled { border-left-color: var(--red); }
.choice h4 { margin: 0 0 3px; font-size: 14px; }
.choice .of { font-size: 11px; color: var(--ink-3); font-weight: 400; }
.choice-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 5px; margin-top: 7px; }

/* sentence-length options (traits, ideals, bonds, flaws) read as a list */
.choice-opts.stacked { grid-template-columns: 1fr; }
.choice-opts.stacked .opt { align-items: flex-start; line-height: 1.45; }
.choice-opts.stacked .opt input { margin-top: 3px; flex: none; }

.opt {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

.opt:hover { border-color: var(--line-2); }
.opt.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.opt input { accent-color: var(--accent); }
.opt.disabled { opacity: .4; cursor: not-allowed; }

/* ----------------------------------------------------------- sheet (rail) */
.sheet-rail {
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px;
  font-size: 13px;
}

.sheet-rail h3 {
  font-family: var(--serif);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-3);
  margin: 16px 0 7px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

.sheet-rail h3:first-child { margin-top: 0; }

.vitals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }

.vital {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 4px;
}

.vital .v { font-size: 20px; font-weight: 700; font-family: var(--serif); }
.vital .k { font-size: 9px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); }

.kv { display: flex; justify-content: space-between; padding: 2px 0; }
.kv .k { color: var(--ink-2); }
.kv .v { font-variant-numeric: tabular-nums; }
.kv.prof .k { color: var(--ink); font-weight: 600; }
.kv.prof .k::before { content: "● "; color: var(--accent); }
.kv:not(.prof) .k::before { content: "○ "; color: var(--ink-3); }

.slot-row { display: flex; flex-wrap: wrap; gap: 4px; }
.slot-pill {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 12px;
}
.slot-pill b { color: var(--accent-2); }

.prof-groups {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 6px 12px;
  margin: 0;
  align-items: baseline;
}

.prof-groups dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-3);
  text-align: right;
}

.prof-groups dd {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

@media (max-width: 620px) {
  .prof-groups { grid-template-columns: 1fr; }
  .prof-groups dt { text-align: left; }
}

.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--ink-2);
}

/* ---------------------------------------------------------- feature lists */
.feature-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 7px;
  background: var(--bg-2);
  overflow: hidden;
}

.feature-item > summary {
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.feature-item > summary::-webkit-details-marker { display: none; }
.feature-item > summary::before { content: "▸"; color: var(--accent); font-size: 11px; }
.feature-item[open] > summary::before { content: "▾"; }
.feature-item > summary:hover { background: var(--bg-3); }
.feature-item > summary .from { margin-left: auto; font-size: 11px; color: var(--ink-3); font-weight: 400; }
.feature-body { padding: 4px 16px 12px; border-top: 1px solid var(--line); }

/* -------------------------------------------------------------- portraits */
.portrait-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; max-height: 50vh; overflow-y: auto; }
.portrait-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); border: 2px solid transparent; cursor: pointer; display: block; }
.portrait-grid img:hover { border-color: var(--line-2); }
.portrait-grid img.on { border-color: var(--accent); }
.portrait-preview { width: 110px; height: 110px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); }
.portrait-tools { margin-bottom: 12px; }

/* ------------------------------------------------------------------ misc  */
.loading { display: grid; place-items: center; height: 100%; gap: 12px; color: var(--ink-3); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-4);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 8px 16px;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}

dialog {
  background: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 0;
  max-width: 700px;
  width: 92vw;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog .dlg-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-family: var(--serif); font-size: 17px; color: var(--accent); }
dialog .dlg-body { padding: 16px; max-height: 66vh; overflow-y: auto; }
dialog .dlg-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.src-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.src-row .count { margin-left: auto; color: var(--ink-3); font-size: 12px; }

.src-collection {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg-3);
}

.src-collection > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
}

.src-collection > summary::-webkit-details-marker { display: none; }
.src-collection > summary::after {
  content: "▸";
  color: var(--ink-3);
  font-size: 11px;
  margin-left: 4px;
}
.src-collection[open] > summary::after { content: "▾"; }
.src-collection > summary:hover { background: var(--bg-4); border-radius: var(--radius); }

.src-collection .src-title { font-weight: 600; }
.src-collection .count { margin-left: auto; color: var(--ink-3); font-size: 12px; }

.src-master { display: grid; place-items: center; }
.src-master input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.src-books {
  padding: 4px 12px 12px 37px;
  border-top: 1px solid var(--line);
  max-height: 260px;
  overflow-y: auto;
}

.muted { color: var(--ink-3); }
.warn-text { color: var(--red); }
.ok-text { color: var(--green); }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------ print */
@media print {
  body { background: #fff; color: #000; overflow: visible; }
  .topbar, .steps, .sheet-rail, .btn, .search { display: none !important; }
  .main { display: block; }
  .panel { overflow: visible; padding: 0; }
  .card, .detail, .list { border-color: #999; background: #fff; }
  .rich, .kv .k, .muted { color: #222; }
}

/* ---------------------------------------------------------------- utilities
   A deliberately small set. These replace the handful of inline styles that
   were repeated across the views; anything one-off stays inline rather than
   growing a utility framework nobody can remember. */

.small { font-size: 12px; }
.tiny { font-size: 11px; }
.grow { flex: 1; min-width: 0; }
.flush { margin: 0; }
.between { justify-content: space-between; align-items: baseline; }
.stack-tight { display: flex; flex-direction: column; gap: 6px; }

/* vertical rhythm, so panels do not need ad-hoc margin-top everywhere */
.card > h3:first-child { margin-top: 0; }
.card > * + .row,
.card > * + form,
.card > * + .inv,
.card > * + .hp-grid { margin-top: 12px; }
.panel > .card + .card,
.panel > * + .card { margin-top: 16px; }

.gear-removed { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

/* Small screens and fingers live in tablet.css, which is loaded last: the
   rules they replace are spread across every sheet, and an override written
   beside the rule it fixes loses to whichever stylesheet comes after it. */

/* ---------------------------------------------- builder: made and unmade

   A made choice is one line (views.js choiceCard); the step rail says per
   step whether it is done or how much is left. */

.choice.done { border-left-color: var(--green); margin-bottom: 12px; }
.choice-made { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.made-ok { color: var(--green); font-weight: 700; }
.made-names { color: var(--ink); min-width: 0; }
.card.has-open { border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }

.step { align-items: center; }
.step-ic {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--line-2);
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-3);
}
.step-ic.ok { background: var(--green); border-color: var(--green); color: #0e1a11; }
.step-ic.todo { border-color: var(--red); color: #fff; background: var(--red); }

/* the +2 / +1+1 as steppers, or a feat */
.asi-modes { display: flex; gap: 4px; align-items: center; margin: 6px 0 8px; flex-wrap: wrap; }
.asi-mode {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--ink-2);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
  font: inherit;
}
.asi-mode.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.asi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.asi-row {
  display: grid;
  grid-template-columns: 40px 1fr auto 26px auto;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.asi-row.on { border-color: var(--accent); }
.asi-ab { font-size: 11px; letter-spacing: .06em; color: var(--ink-3); }
.asi-score { font-weight: 600; font-variant-numeric: tabular-nums; }
.asi-to { color: var(--accent-2); }
.asi-n { text-align: center; font-weight: 700; color: var(--accent-2); }
.asi-left { margin: 6px 0 0; }

/* the other printings of a race or background, over its description */
.versions { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
.versions .btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* an option the build already has from elsewhere (views.js choiceCard) */
.opt.had { opacity: .6; }
.had-note { font-size: 11px; }
