/* Parchment and ink in light mode, candlelit stone in dark mode. */
:root {
  --bg: #f6f1e6;
  --surface: #fffdf7;
  --surface-2: #efe7d6;
  --ink: #2a2420;
  --ink-soft: #5d544b;
  --rule: #d9cdb5;
  --accent: #7a2e1f;       /* oxblood */
  --accent-ink: #fffdf7;
  --gold: #9a7420;
  --ok: #3d6b3a;
  --warn: #8a5a00;
  --error: #a3281b;
  --info: #3d5a80;
  --note-bg: #f3ead2;
  --example-bg: #ece9f3;
  --shadow: 0 1px 2px rgb(60 40 20 / 0.08), 0 2px 8px rgb(60 40 20 / 0.06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f;
    --surface: #211d17;
    --surface-2: #2b261e;
    --ink: #ece4d4;
    --ink-soft: #b3a892;
    --rule: #3d362b;
    --accent: #d8806a;
    --accent-ink: #17140f;
    --gold: #d6b25e;
    --ok: #8cc084;
    --warn: #e0b04f;
    --error: #ef8a7a;
    --info: #8fb0dd;
    --note-bg: #2e2818;
    --example-bg: #262433;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f; --surface: #211d17; --surface-2: #2b261e; --ink: #ece4d4; --ink-soft: #b3a892;
  --rule: #3d362b; --accent: #d8806a; --accent-ink: #17140f; --gold: #d6b25e; --ok: #8cc084;
  --warn: #e0b04f; --error: #ef8a7a; --info: #8fb0dd; --note-bg: #2e2818; --example-bg: #262433;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 var(--serif);
  overflow-wrap: anywhere;
}
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 120px; }
/* The character sheet and editor hold three columns of traits, so they get
   more room than the reading pages. */
body.wide main, body.wide .budget-bar .inner { max-width: 1100px; }
h1, h2, h3, h4 { line-height: 1.2; margin: 1.4em 0 0.5em; }
h1 { font-size: 1.8rem; margin-top: 0.4em; }
h2 { font-size: 1.35rem; color: var(--accent); }
h3 { font-size: 1.12rem; }
a { color: var(--accent); }
p { margin: 0.6em 0; }
ul { padding-left: 1.3em; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 1.5em 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }

/* header */
header.site {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.95rem;
}
header.site .brand { font-family: var(--serif); font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.1rem; }
header.site nav { display: flex; gap: 14px; overflow-x: auto; }
header.site nav a { color: var(--ink-soft); text-decoration: none; padding: 4px 0; white-space: nowrap; }
header.site nav a[aria-current="page"] { color: var(--accent); border-bottom: 2px solid var(--accent); }
header.site .menu { margin-left: auto; position: relative; font-size: 0.85rem; }
header.site .menu > summary { list-style: none; cursor: pointer; color: var(--accent); padding: 4px 0; }
header.site .menu > summary::-webkit-details-marker { display: none; }
header.site .menu-panel {
  position: absolute; right: 0; top: 100%; z-index: 40; min-width: 240px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column;
}
header.site .menu-item {
  display: flex; align-items: center; gap: 8px; min-height: 40px; margin: 0; padding: 6px 10px;
  border: 0; border-radius: 6px; background: none; color: var(--ink);
  font-size: 0.9rem; text-align: left; justify-content: flex-start; cursor: pointer;
}
header.site .menu-item:hover { background: var(--surface-2); }

/* controls */
button, .button, input, select, textarea { font: inherit; font-family: var(--sans); font-size: 0.95rem; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 6px 14px;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { border-color: var(--ink-soft); }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--error); }
button.linkish { min-height: 0; padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; }
button:disabled { opacity: 0.5; cursor: default; }
input[type="text"], input[type="search"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; min-height: 40px; padding: 6px 10px;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
textarea { min-height: 120px; line-height: 1.45; }
label { display: block; font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft); margin: 10px 0 3px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grow { flex: 1 1 auto; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }
/* Double-wide field; only once the grid surely has two columns, since a
   span in a one-column grid would add a column and overflow. */
@media (min-width: 600px) { .field-grid > .span-2 { grid-column: span 2; } }
.field-hint { margin: 4px 0 0; padding-left: 10px; font-size: 0.82rem; color: var(--ink-soft); line-height: 1.35; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin: 12px 0;
}
.roster { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.roster .card { margin: 0; display: block; color: inherit; text-decoration: none; }
.roster .card:hover { border-color: var(--accent); }
.roster h3 { margin: 0 0 2px; }
.roster .meta { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft); }
.roster .stats { margin-top: 8px; font-family: var(--sans); font-size: 0.85rem; }

/* badges */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-family: var(--sans); font-size: 0.72rem; line-height: 1.6; vertical-align: middle;
  border: 1px solid currentColor;
}
.badge.optional { color: var(--info); }
.badge.advice { color: var(--gold); }
.badge.setting { color: var(--ok); }
.badge.review, .badge.check { color: var(--warn); }
.badge.removed { color: var(--error); }

/* rules text */
.table-wrap { overflow-x: auto; margin: 0.8em 0; }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 0.88rem; }
th, td {
  border-bottom: 1px solid var(--rule); padding: 6px 8px; text-align: left; vertical-align: top;
  overflow-wrap: normal; min-width: 3.5em;
}
section.rule, details.entry, [id] { scroll-margin-top: 96px; }
th { background: var(--surface-2); }
caption { text-align: left; font-weight: 600; padding: 4px 0; }
dl { margin: 0.6em 0; }
dt { font-weight: 700; margin-top: 0.5em; }
dd { margin: 0 0 0 1em; }
aside.note, aside.example, .check-note {
  margin: 0.8em 0; padding: 10px 12px; border-radius: 8px; border-left: 4px solid var(--gold);
  background: var(--note-bg);
}
aside.example { border-left-color: var(--info); background: var(--example-bg); font-style: italic; }
.check-note { border-left-color: var(--warn); font-family: var(--sans); font-size: 0.85rem; }
.source { font-family: var(--sans); font-size: 0.78rem; color: var(--ink-soft); }
section.rule { border-top: 1px solid var(--rule); padding-top: 4px; }
section.rule > h2 { margin-top: 0.8em; }
.toc { columns: 2 220px; font-family: var(--sans); font-size: 0.9rem; padding-left: 1.1em; }
.toc li { break-inside: avoid; }

details.entry {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  margin: 8px 0; padding: 0;
}
details.entry > summary {
  list-style: none; cursor: pointer; padding: 10px 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: baseline;
}
details.entry > summary::-webkit-details-marker { display: none; }
details.entry > summary .name { font-weight: 700; }
details.entry > summary .cost { font-family: var(--sans); font-size: 0.85rem; color: var(--ink-soft); }
details.entry > summary .sum { grid-column: 1 / -1; font-size: 0.92rem; color: var(--ink-soft); }
details.entry[open] > summary { border-bottom: 1px solid var(--rule); }
details.entry .body { padding: 4px 14px 12px; }
details.entry.removed { opacity: 0.7; }
.group-intro { color: var(--ink-soft); margin: -0.2em 0 0.6em; }
.group-intro p { margin: 0.3em 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chips button { min-height: 32px; padding: 2px 12px; border-radius: 999px; font-size: 0.85rem; }
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.search-results .hit { padding: 10px 0; border-bottom: 1px solid var(--rule); }
.search-results .hit a { font-weight: 700; }
mark { background: color-mix(in srgb, var(--gold) 35%, transparent); color: inherit; }

/* character sheet */
.sheet-head h1 { margin-bottom: 0; }
.sheet-head .sub { color: var(--ink-soft); }
/* Name, then concept and player on the same line; wraps under on phones. */
.sheet-head .title-line { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 14px; }
/* Rules check, Edit, Version history, Archive: one row of matching buttons. */
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.sheet-actions .button, .sheet-actions button { min-height: 36px; padding: 4px 12px; font-size: 0.9rem; }
.sheet-actions button.has-errors { color: var(--error); }
.trait-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 4px 20px; }
.trait-group h3 { margin: 0.8em 0 0.2em; font-size: 1rem; display: flex; justify-content: space-between; gap: 8px; }
.trait-group h3 .tally { font-family: var(--sans); font-size: 0.78rem; font-weight: 400; color: var(--ink-soft); }
.trait { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 3px 0; border-bottom: 1px dotted var(--rule); }
.trait .tname { min-width: 0; }
.trait > .small { white-space: nowrap; }
.trait .spec { font-size: 0.82rem; color: var(--ink-soft); font-style: italic; }
.trait .note { display: block; font-size: 0.82rem; color: var(--ink-soft); }
/* Merit and Flaw details follow the name on its line, without the label. */
.trait .note.inline { display: inline; margin-left: 6px; }
.dots { font-family: var(--sans); letter-spacing: 1px; color: var(--accent); white-space: nowrap; }
/* Five dots per line, so 6-10 dot traits (Resources, Library...) take two. */
.dotpick { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 0; flex: none; max-width: calc(5 * 20px); }
.dotpick button {
  min-height: 32px; min-width: 20px; padding: 0; border: 0; background: none;
  color: var(--accent); font-size: 1.1rem; line-height: 1;
}
/* A trait row is two independent columns: name, summary and fields on the
   left; controls on the right. Each stacks on its own, so neither stretches
   the other. Names never wrap. */
.trait-edit {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px;
  align-items: start; padding: 6px 0; border-bottom: 1px dotted var(--rule);
}
.te-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.te-left .te-name { white-space: nowrap; overflow-wrap: normal; min-height: 26px; line-height: 26px; display: flex; align-items: center; gap: 2px; }
.te-left input, .te-left select { min-height: 34px; font-size: 0.85rem; }
/* Name and its specialty/note box share the top line; the box drops below
   when there is less than about 8em left for it. */
.te-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.te-head input, .te-head select { flex: 1 1 8em; min-width: 0; min-height: 26px; height: 26px; padding: 0 8px; }
.te-head > div { flex: 0 1 auto; }
.te-head select { width: auto; padding: 0 4px; }
.te-left .rule-summary { font-size: 0.82rem; color: var(--ink-soft); line-height: 1.35; }
.te-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
/* The right column's top line is as tall as the name's line, and starts at
   the same top, so cost, dots and remove sit level with the name. */
.te-line { display: flex; align-items: flex-start; gap: 6px; min-height: 26px; line-height: 26px; }
.te-line .icon-btn, .te-line .dotpick button { min-height: 26px; height: 26px; }
.te-line .icon-btn { min-width: 28px; }
.te-right select { width: auto; min-height: 26px; height: 26px; padding: 0 4px; font-size: 0.85rem; }
/* An instrument's personal / unique / discarded boxes, one line under its name. */
.te-checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.te-check { display: flex; align-items: center; gap: 4px; margin: 0; font-size: 0.8rem; color: var(--ink); }
.icon-btn { min-height: 32px; min-width: 32px; padding: 0 6px; font-size: 0.9rem; }
.prose h3, .prose h4 { color: var(--ink); }

.warnings { list-style: none; padding: 0; margin: 8px 0; font-family: var(--sans); font-size: 0.88rem; }
.warnings li { padding: 4px 0 4px 22px; position: relative; }
.warnings li::before { position: absolute; left: 0; }
.warnings li.error { color: var(--error); }
.warnings li.error::before { content: "✕"; }
.warnings li.warn { color: var(--warn); }
.warnings li.warn::before { content: "!"; font-weight: 700; left: 6px; }
.warnings li.info { color: var(--info); }
.warnings li.info::before { content: "i"; font-weight: 700; left: 6px; font-style: italic; }

/* budget bar (editing) */
.budget-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--rule); box-shadow: 0 -2px 10px rgb(0 0 0 / 0.08);
  font-family: var(--sans); font-size: 0.82rem;
}
.budget-bar .inner { max-width: 760px; margin: 0 auto; padding: 8px 16px; }
.budget-bar .pills { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.pill { white-space: nowrap; }
.pill.over { color: var(--error); font-weight: 700; }
.pill.under { color: var(--info); }
.pill.spill { color: var(--gold); }
.pill.done { color: var(--ok); }
.budget-bar .actions { display: flex; gap: 8px; margin-top: 6px; }
.budget-bar .actions button { flex: 1; }
.budget-bar details > summary { cursor: pointer; color: var(--ink-soft); }
.budget-bar details[open] > ul { max-height: 35vh; overflow-y: auto; }

.banner { padding: 10px 14px; border-radius: 8px; margin: 12px 0; font-family: var(--sans); font-size: 0.9rem; }
.banner.info { background: var(--note-bg); }
.banner.error { background: color-mix(in srgb, var(--error) 15%, var(--surface)); color: var(--ink); }

.versions li { margin: 6px 0; font-family: var(--sans); font-size: 0.88rem; }
.xplog td:last-child { text-align: right; }

.login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { text-align: center; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  h1 { font-size: 1.5rem; }
  header.site .menu { margin-left: 0; }
  header.site .menu-panel { position: fixed; top: auto; left: 16px; right: 16px; min-width: 0; }
}
