/* Character creation site: parchment and ink, with a dark mode. */
:root {
  --bg: #f4efe4;
  --surface: #fbf8f1;
  --surface-2: #efe7d6;
  --line: #d8ccb2;
  --line-strong: #b9a883;
  --ink: #2a2119;
  --ink-soft: #5d5143;
  --ink-faint: #8a7c68;
  --accent: #8b2e1f;
  --accent-ink: #fff8ee;
  --accent-soft: #f3dcd3;
  --gold: #a7802b;
  --ok: #2f6b3a;
  --ok-soft: #dbead9;
  --warn: #9a5b00;
  --warn-soft: #f6e5c4;
  --bad: #a22a2a;
  --bad-soft: #f5d9d6;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 4px 16px rgba(60, 40, 10, .06);
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Book Antiqua", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120e; --surface: #1d1914; --surface-2: #26211a; --line: #3a3228; --line-strong: #56493a;
    --ink: #ece4d4; --ink-soft: #c1b5a1; --ink-faint: #8f836f; --accent: #d9774f; --accent-ink: #1b120c; --accent-soft: #3b231a;
    --gold: #d2aa55; --ok: #7fbf87; --ok-soft: #1f3322; --warn: #e0a64a; --warn-soft: #3a2d15; --bad: #e27d73; --bad-soft: #3d1f1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15120e; --surface: #1d1914; --surface-2: #26211a; --line: #3a3228; --line-strong: #56493a;
  --ink: #ece4d4; --ink-soft: #c1b5a1; --ink-faint: #8f836f; --accent: #d9774f; --accent-ink: #1b120c; --accent-soft: #3b231a;
  --gold: #d2aa55; --ok: #7fbf87; --ok-soft: #1f3322; --warn: #e0a64a; --warn-soft: #3a2d15; --bad: #e27d73; --bad-soft: #3d1f1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); min-height: 100vh; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; letter-spacing: .01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.12rem; } h4 { font-size: 1rem; }
p { margin: 0 0 .7em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); font-size: .88em; }
.nowrap { white-space: nowrap; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-size: 1.15rem; font-weight: 600; }
.brand-icon { width: 26px; height: 26px; color: var(--accent); }
.topnav { display: flex; align-items: center; gap: 10px; font-size: .92rem; }
.app { max-width: 1400px; margin: 0 auto; padding: 20px; }
.loading { color: var(--ink-faint); text-align: center; padding: 60px 0; }

/* Buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 500; text-decoration: none; min-height: 36px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.small { padding: 3px 9px; min-height: 28px; font-size: .88rem; }
.btn.danger { color: var(--bad); }
.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 8px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; min-height: 36px; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 120px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .92rem; }
label.field > span { color: var(--ink-soft); font-weight: 500; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

/* Cards and layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 14px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--surface-2); border-left: 3px solid var(--gold); }
.notice.error { background: var(--bad-soft); border-color: var(--bad); }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: .8rem; color: var(--ink-soft); white-space: nowrap; }
.tag.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag.book { background: transparent; border-style: dashed; font-size: .72rem; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* Login */
.login { max-width: 380px; margin: 8vh auto; }
.login h1 { text-align: center; }

/* Character list */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.char-card { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; }
.char-card:hover { border-color: var(--accent); }
.avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: var(--surface-2); border: 2px solid var(--line-strong); flex: none;
  display: grid; place-items: center; font-family: var(--serif); font-size: 1.4rem; color: var(--ink-faint); }

/* Wizard layout */
.wizard { display: grid; grid-template-columns: 250px minmax(0, 1fr) 290px; gap: 18px; align-items: start; }
.steps { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; padding: 12px; }
.steps h3 { font-size: .95rem; margin: 10px 0 4px; color: var(--ink-soft); }
.steps ol { list-style: none; margin: 0; padding: 0; }
.steps li button { width: 100%; text-align: left; border: 0; background: none; padding: 4px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; font-size: .88rem; color: var(--ink-soft); }
.steps li button:hover { background: var(--surface-2); color: var(--ink); }
.steps li.done button::before { content: "✓"; color: var(--ok); font-weight: 700; }
.steps li.current button { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.steps li.current button::before { content: "›"; color: var(--accent); font-weight: 700; }
.steps li .sum { display: block; font-size: .78rem; color: var(--ink-faint); font-weight: 400; }
.summary { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
.step-card h2 { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.step-card .step-origin { font-family: var(--sans); font-size: .85rem; font-weight: 500; color: var(--ink-faint); }
.step-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.hint { color: var(--ink-soft); font-size: .92rem; }
.hint p:last-child { margin-bottom: 0; }

/* Ability tiles */
.abilities { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.ability { text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; background: var(--surface); }
.ability .abbr { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.ability .score { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.ability .mod { font-size: .85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.summary .abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 6px; text-align: center; }
.stat b { display: block; font-family: var(--serif); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--ink-soft); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: .88rem; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }

/* Point buy rows */
.pb-table { width: 100%; border-collapse: collapse; }
.pb-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper output { min-width: 2.2em; text-align: center; font-family: var(--serif); font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.budget { font-weight: 600; font-size: 1.05rem; }
.budget.bad { color: var(--bad); }
.dice-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 8px 0 14px; }
.die { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 10px; border: 2px solid var(--line-strong); font-family: var(--serif); font-size: 1.4rem; font-weight: 600; }
.die.used { opacity: .35; }
.michel-sets { display: grid; gap: 10px; }
.michel-set { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 10px; padding: 10px 12px; border: 2px solid var(--line-strong); border-radius: 10px; cursor: pointer; }
.michel-set.selected { border-color: var(--accent); }
.michel-set .dice-row { grid-column: 1 / -1; justify-content: flex-start; margin: 0; gap: 6px; }
.michel-set .die { width: 36px; height: 36px; font-size: 1.1rem; }

/* Browser (list + details) */
.browser { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 14px; min-height: 420px; }
.browser-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.browser-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.browser-tools input[type="search"] { flex: 1 1 180px; width: auto; }
.browser-tools select { flex: 0 1 200px; width: auto; }
.options { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: auto; max-height: 560px; background: var(--surface); }
.options li { border-bottom: 1px solid var(--line); }
.options li:last-child { border-bottom: 0; }
.option { display: flex; align-items: center; gap: 10px; padding: 7px 10px; cursor: pointer; }
.option:hover { background: var(--surface-2); }
.option.active { background: var(--accent-soft); }
.option.selected .opt-name { font-weight: 650; }
.option.invalid { opacity: .55; }
.option img { width: 32px; height: 32px; border-radius: 6px; flex: none; object-fit: cover; background: var(--surface-2); }
.option .opt-main { flex: 1; min-width: 0; }
.option .opt-name { display: block; }
.option .opt-sub { display: block; font-size: .8rem; color: var(--ink-faint); overflow-wrap: anywhere; }
.option input[type="checkbox"], .option input[type="radio"] { accent-color: var(--accent); width: 17px; height: 17px; flex: none; }
.group-title { padding: 6px 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); background: var(--surface-2); position: sticky; top: 0; }
.details { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: var(--surface); max-height: 620px; overflow: auto; min-width: 0; }
.details h3 { margin-bottom: 4px; }
.details .en { color: var(--ink-faint); font-size: .85rem; margin-bottom: 8px; }
.details img.item-art, .modal img.item-art { float: right; width: 72px; height: 72px; object-fit: cover; border-radius: 8px; margin: 0 0 8px 10px; }
.details table { border-collapse: collapse; margin: 8px 0; font-size: .88rem; width: 100%; }
.details th, .details td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; vertical-align: top; }
.details blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--gold); color: var(--ink-soft); font-style: italic; }
.details aside { background: var(--surface-2); padding: 8px 10px; border-radius: 8px; margin: 8px 0; }
.details .ref { color: var(--accent); text-decoration: underline dotted; cursor: pointer; }
.details .stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.details .prereq { margin: 8px 0; }
.empty { color: var(--ink-faint); text-align: center; padding: 30px 10px; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 8px 10px; border: 1px dashed var(--line-strong); border-radius: 10px; font-size: .9rem; }
.filters label { display: inline-flex; gap: 5px; align-items: center; }

/* Slots / counters */
.counter { font-weight: 600; }
.counter.ok { color: var(--ok); }
.counter.bad { color: var(--bad); }

/* Equipment */
.equip-section { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.equip-section + .equip-section { margin-top: 12px; }
.equip-section ul { margin: 4px 0 8px 26px; padding: 0; }
.equip-section li { margin: 3px 0; }

/* Shop */
.shop-row { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 6px 10px; }
.shop-row .price { color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qty { display: inline-flex; align-items: center; gap: 3px; }
.qty output { min-width: 1.8em; text-align: center; font-variant-numeric: tabular-nums; }
.shop-total { position: sticky; bottom: 0; background: var(--surface); padding: 10px; border-top: 1px solid var(--line); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 14, 6, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; max-width: 720px; width: 100%; max-height: 85vh; overflow: auto; padding: 18px 20px; box-shadow: var(--shadow); }

/* Sheet (screen) */
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.sheet { background: #fffdf8; color: #1f1811; border: 1px solid #d9cdb3; border-radius: 6px; padding: 26px 30px; font-size: 13px; line-height: 1.4; }
.sheet h1 { font-size: 26px; margin: 0; }
.sheet h2 { font-size: 15px; border-bottom: 2px solid #8b2e1f; color: #8b2e1f; padding-bottom: 2px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.sheet h3 { font-size: 13.5px; margin: 8px 0 2px; }
.sheet .sheet-head { display: grid; grid-template-columns: 90px 1fr auto; gap: 16px; align-items: center; border-bottom: 3px double #8b2e1f; padding-bottom: 10px; }
.sheet .portrait { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; border: 2px solid #8b2e1f; background: #efe7d6; }
.sheet .identity { display: grid; grid-template-columns: repeat(3, auto); gap: 2px 18px; font-size: 12.5px; }
.sheet .identity b { color: #6b5d49; font-weight: 500; margin-right: 4px; }
.sheet .cols { display: grid; grid-template-columns: 200px 1fr 1fr; gap: 18px; }
.sheet .ab { display: grid; grid-template-columns: 1fr; gap: 6px; }
.sheet .ab .a { display: grid; grid-template-columns: 54px 1fr; border: 1px solid #cdbf9f; border-radius: 8px; overflow: hidden; }
.sheet .ab .a .big { background: #f3ead6; text-align: center; padding: 4px 0; }
.sheet .ab .a .big .n { font-size: 20px; font-weight: 700; font-family: var(--serif); display: block; }
.sheet .ab .a .big .l { font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; }
.sheet .ab .a .list { padding: 3px 8px; font-size: 11.5px; }
.sheet .ab .a .list div { display: flex; justify-content: space-between; gap: 6px; }
.sheet .prof::before { content: "●"; color: #8b2e1f; margin-right: 3px; font-size: 9px; }
.sheet .noprof::before { content: "○"; color: #b9a883; margin-right: 3px; font-size: 9px; }
.sheet .boxes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.sheet .box { border: 1px solid #cdbf9f; border-radius: 8px; text-align: center; padding: 4px; }
.sheet .box b { display: block; font-size: 18px; font-family: var(--serif); }
.sheet .box span { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: #6b5d49; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sheet th { text-align: left; font-weight: 600; color: #6b5d49; border-bottom: 1px solid #cdbf9f; padding: 2px 4px; }
.sheet td { border-bottom: 1px solid #eee3cc; padding: 2px 4px; vertical-align: top; }
.sheet .feature { margin-bottom: 6px; break-inside: avoid; }
.sheet .feature .desc { font-size: 11.5px; color: #3b3025; }
.sheet .feature .desc p { margin: 0 0 3px; }
.sheet .feature .desc table { font-size: 10.5px; }
.sheet .two { columns: 2; column-gap: 20px; }
.sheet .page { break-after: page; }
.sheet .page:last-child { break-after: auto; }
.sheet .slots span { display: inline-block; border: 1px solid #cdbf9f; border-radius: 6px; padding: 1px 6px; margin: 0 4px 4px 0; font-size: 11.5px; }
.sheet .muted { color: #6b5d49; }

/* Responsive */
@media (max-width: 1180px) {
  .wizard { grid-template-columns: 220px minmax(0, 1fr); }
  .summary { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 820px) {
  .app { padding: 12px 16px; }
  .wizard { grid-template-columns: minmax(0, 1fr); }
  .steps { position: static; max-height: 220px; }
  .browser { grid-template-columns: minmax(0, 1fr); }
  .abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sheet { padding: 14px; }
  .sheet .cols { grid-template-columns: 1fr; }
  .sheet .sheet-head { grid-template-columns: 60px 1fr; }
  .sheet .identity { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 8px 16px; }
  .brand span { font-size: 1rem; }
}

/* Print: only the sheet, on A4 */
@page { size: A4; margin: 12mm; }
@media print {
  body { background: #fff; }
  .topbar, .sheet-actions, .no-print, #modal-root { display: none !important; }
  .app { max-width: none; padding: 0; }
  .sheet { border: 0; border-radius: 0; padding: 0; font-size: 11.5px; }
  .sheet .cols { grid-template-columns: 180px 1fr 1fr; }
  a { color: inherit; text-decoration: none; }
}

/* Background: book cover art (served only after login), cross-fading every 20 s, behind a parchment or night veil */
.art-layer { position: fixed; inset: 0; z-index: -2; background: center / cover no-repeat; opacity: 0; transition: opacity 2.5s ease; }
.art-layer.on { opacity: 1; }
.art-veil { position: fixed; inset: 0; z-index: -1; background: var(--veil); pointer-events: none; }
:root { --veil: rgba(244, 239, 228, .62); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --veil: rgba(21, 18, 14, .62); } }
:root[data-theme="dark"] { --veil: rgba(21, 18, 14, .62); }
@media (prefers-reduced-motion: reduce) { .art-layer { transition: none; } }
body.with-art { background: transparent; }
body.with-art .topbar { background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(6px); }
@media print { .art-layer, .art-veil { display: none; } }

/* Musical instrument photos */
.trait-with-photo { display: inline-flex; align-items: center; gap: 8px; }
.trait-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; flex: none; }
.instrument-photo { margin: 8px 0 12px; text-align: center; }
.instrument-photo img { max-width: 100%; max-height: 320px; border-radius: 8px; background: #fff; }
.instrument-photo figcaption { font-size: .75rem; color: var(--ink-faint); margin-top: 4px; }

/* Class and subclass features by level */
.features { margin: 10px 0 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.features h4 { margin-bottom: 6px; }
.feature-level { display: grid; grid-template-columns: 76px 1fr; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }
.feature-level:first-of-type { border-top: 0; }
.feature-level .tag { justify-self: start; align-self: start; margin-top: 2px; }
.feature-list .feature-link { font-weight: 600; }
.feature-plain { color: var(--ink-soft); font-style: italic; }
