/* ============ Grundlagen ============ */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --line: #e7e4de;
  --line-strong: #d6d2ca;
  --text: #1c1b19;
  --muted: #6d6a64;
  --faint: #9a968e;
  --accent: #a3312b;
  --accent-soft: #f6e9e7;
  --accent-line: #e8c9c5;
  --ok: #2f7a4f;
  --ok-soft: #e7f3ec;
  --warn: #9a6400;
  --warn-soft: #fbf1dc;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20, 18, 14, .04), 0 2px 8px rgba(20, 18, 14, .04);
  --shadow-lg: 0 12px 40px rgba(20, 18, 14, .14);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 .6em; }
.boot { padding: 80px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ============ Layout ============ */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 56px;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; }
.brand small { color: var(--muted); font-weight: 500; }
.topbar .char-title { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .char-title strong { color: var(--text); }
.topbar .actions { display: flex; gap: 6px; }

.layout {
  display: grid; grid-template-columns: 220px minmax(0, 1fr) 300px; gap: 24px;
  max-width: 1440px; margin: 0 auto; padding: 24px 20px 80px;
}
.stepnav { position: sticky; top: 80px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.stepnav button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer; text-align: left; color: var(--muted);
}
.stepnav button:hover { background: rgba(0, 0, 0, .035); color: var(--text); }
.stepnav button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.stepnav .num {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 600; border: 1.5px solid var(--line-strong); color: var(--muted); background: var(--surface);
}
.stepnav .done .num { background: var(--ok); border-color: var(--ok); color: #fff; }
.stepnav .open .num { border-color: var(--accent); color: var(--accent); }
.stepnav .sep { height: 1px; background: var(--line); margin: 8px 10px; }

.main { min-width: 0; }
.page-head { margin-bottom: 18px; }
.page-head .kicker { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.page-head p { color: var(--muted); max-width: 70ch; margin-top: 6px; }

.summary { position: sticky; top: 80px; align-self: start; max-height: calc(100vh - 100px); overflow: auto; }

/* ============ Karten & Flächen ============ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.section { margin-bottom: 22px; }
.section > h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section-note { color: var(--muted); margin: -4px 0 12px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }

.guide {
  background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 18px; color: #3b3935;
}
.guide summary { cursor: pointer; font-weight: 600; color: var(--text); }
.guide .md { margin-top: 8px; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.pick {
  position: relative; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s;
}
.pick:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.pick.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pick.disabled { opacity: .5; cursor: not-allowed; }
.pick h3 { margin-bottom: 4px; }
.pick .meta { color: var(--muted); font-size: 12.5px; }
.pick .check { position: absolute; top: 12px; right: 12px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: #fff; display: none; place-items: center; font-size: 11px; }
.pick.selected .check { display: grid; }

/* ============ Formularelemente ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
  font-weight: 500; white-space: nowrap; transition: background .1s, border-color .1s;
}
.btn:hover { background: var(--surface-2); border-color: #c4bfb5; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #8e2a25; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: rgba(0, 0, 0, .04); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn.danger { color: var(--accent); }
.btn svg { width: 16px; height: 16px; }
.iconbtn { width: 30px; height: 30px; padding: 0; justify-content: center; }

label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
label.field > span { color: var(--muted); font-weight: 500; }
input[type=text], input[type=number], input:not([type]), select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none; transition: border-color .1s, box-shadow .1s;
}
textarea { height: auto; min-height: 90px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=number] { width: 80px; }
input.num-sm { width: 64px; text-align: center; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 13px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--text); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 13px; transition: all .1s; user-select: none;
}
.chip:hover { border-color: #bdb7ac; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.fixed { background: var(--surface-2); color: var(--muted); cursor: default; border-style: dashed; }
.chip.off { opacity: .4; cursor: not-allowed; }
.chip .sub { font-size: 11px; opacity: .75; }

.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.open { background: var(--accent-soft); color: var(--accent); }
.badge.neutral { background: #efede8; color: var(--muted); }
.page-ref {
  display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 4px; font-size: 11px; font-weight: 600;
  color: var(--muted); background: #efede8; white-space: nowrap; vertical-align: 2px; cursor: help; letter-spacing: .01em;
}
.tag { display: inline-block; padding: 1px 7px; border-radius: 4px; background: #efede8; color: #4c4a45; font-size: 12px; margin: 0 4px 4px 0; }

/* ============ Regeltexte ============ */
.md { color: #34322e; }
.md p { margin: 0 0 .65em; }
.md p:last-child { margin-bottom: 0; }
.md ul { margin: .3em 0 .7em; padding-left: 1.2em; }
.md li { margin: .15em 0; }
.md h5 { font-size: 13px; margin: .8em 0 .3em; }
.md-table { overflow-x: auto; margin: .5em 0 .8em; }
.md table { border-collapse: collapse; font-size: 12.5px; min-width: 60%; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 5px 10px 5px 0; text-align: left; vertical-align: top; }
.md th { font-weight: 600; color: var(--muted); }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ============ Merkmale & Auswahlen ============ */
.feature { border-top: 1px solid var(--line); padding: 14px 0; }
.feature:first-child { border-top: 0; padding-top: 4px; }
.feature-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.feature-head h3 { font-size: 14.5px; }
.feature-head .lvl { font-size: 12px; color: var(--muted); font-weight: 600; min-width: 58px; }
.feature .md { margin-top: 6px; }
.feature details > summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 4px; list-style: none; }
.feature details > summary::before { content: '▸ '; }
.feature details[open] > summary::before { content: '▾ '; }

.choice { margin-top: 10px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.choice.pending { border-color: var(--accent-line); background: #fdf8f7; }
.choice-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.choice-head .label { font-weight: 600; }
.choice .nested { margin-top: 10px; padding-left: 12px; border-left: 2px solid var(--line); }
.opt-list { display: flex; flex-direction: column; gap: 6px; }
.opt {
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: 9px 12px; cursor: pointer;
}
.opt:hover { border-color: var(--line-strong); }
.opt.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.opt.off { opacity: .45; cursor: not-allowed; }
.opt-head { display: flex; align-items: center; gap: 8px; }
.opt-head .box { width: 16px; height: 16px; border: 1.5px solid var(--line-strong); border-radius: 4px; flex: none; display: grid; place-items: center; font-size: 11px; color: #fff; }
.opt.on .box { background: var(--accent); border-color: var(--accent); }
.opt-head .name { font-weight: 550; }
.opt .md { margin-top: 6px; font-size: 13px; }
.opt .prereq { font-size: 12px; color: var(--warn); }

.asi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.asi-cell { text-align: center; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 4px; background: var(--surface); }
.asi-cell .ab { font-size: 11px; font-weight: 700; color: var(--muted); }
.asi-cell .val { font-weight: 650; font-size: 15px; }
.asi-cell .ctl { display: flex; justify-content: center; gap: 4px; margin-top: 4px; }

/* ============ Attribute ============ */
.ability-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.ability-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px; text-align: center; }
.ability-box .ab { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.ability-box .name { font-size: 12px; color: var(--faint); margin-bottom: 6px; }
.ability-box .score { font-size: 26px; font-weight: 700; line-height: 1.1; }
.ability-box .mod { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px; background: #efede8; font-weight: 600; font-size: 13px; }
.ability-box select, .ability-box input { text-align: center; margin-top: 6px; }
.ability-box .parts { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.ability-box.primary { border-color: var(--accent-line); background: #fffcfb; }
.pb-meter { display: flex; align-items: center; gap: 10px; }
.pb-meter .bar { flex: 1; height: 6px; border-radius: 3px; background: #ebe8e2; overflow: hidden; }
.pb-meter .fill { height: 100%; background: var(--accent); transition: width .2s; }
.dice-row { display: flex; gap: 6px; flex-wrap: wrap; }
.die { min-width: 44px; padding: 6px 8px; text-align: center; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font-weight: 650; }
.die small { display: block; font-weight: 400; font-size: 10.5px; color: var(--faint); }
.die.used { opacity: .35; }

/* ============ Tabellen ============ */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.tbl-wrap.scroll { max-height: 440px; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: var(--surface-2); }
.tbl tr.on td { background: #fdf5f4; }

/* ============ Übersicht rechts ============ */
.sum-card { padding: 16px; }
.sum-name { font-family: var(--serif); font-size: 24px; font-weight: 700; line-height: 1.1; }
.sum-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.sum-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 14px 0; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 4px; text-align: center; }
.stat .v { font-weight: 700; font-size: 17px; line-height: 1.2; }
.stat .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sum-abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.sum-ab { text-align: center; padding: 5px 0; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); }
.sum-ab .ab { font-size: 9.5px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.sum-ab .m { font-weight: 700; font-size: 14px; }
.sum-ab .s { font-size: 10.5px; color: var(--faint); }
.sum-list { margin-top: 14px; }
.sum-list h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.sum-list ul { margin: 0; padding: 0; list-style: none; }
.sum-list li { padding: 3px 0; font-size: 12.5px; display: flex; gap: 6px; }
.sum-list li::before { content: '•'; color: var(--accent); }
.sum-list li.clickable { cursor: pointer; }
.sum-list li.clickable:hover { color: var(--accent); }

/* ============ Charakterliste ============ */
.char-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.char-card { padding: 16px 18px; cursor: pointer; }
.char-card:hover { border-color: var(--line-strong); }
.char-card .name { font-family: var(--serif); font-size: 22px; font-weight: 700; }
.char-card .meta { color: var(--muted); font-size: 12.5px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.hero { padding: 36px 32px; margin-bottom: 20px; display: flex; gap: 28px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.hero h1 { font-family: var(--serif); font-size: 34px; }
.hero p { color: var(--muted); max-width: 56ch; margin-top: 6px; }

/* ============ Dialog / Drawer ============ */
dialog { border: 0; padding: 0; border-radius: var(--radius); box-shadow: var(--shadow-lg); max-width: min(720px, calc(100vw - 32px)); width: 100%; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(28, 27, 25, .35); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.dlg-head h2 { flex: 1; }
.dlg-body { padding: 18px 20px; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); z-index: 100; font-size: 13px; }
.warn-box { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13px; }
.info-link { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; font-weight: inherit; }
.info-link:hover { color: var(--accent); text-decoration-color: var(--accent); }

.level-list { display: flex; flex-direction: column; }
.level-row { display: grid; grid-template-columns: 70px 1fr 150px 90px 36px; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.level-row:last-child { border-bottom: 0; }
.level-row .lv { font-weight: 650; }
.search { position: relative; }
.search input { padding-left: 32px; }
.search::before { content: ''; position: absolute; left: 11px; top: 11px; width: 12px; height: 12px; border: 1.8px solid var(--faint); border-radius: 50%; }
.search::after { content: ''; position: absolute; left: 22px; top: 23px; width: 5px; height: 1.8px; background: var(--faint); transform: rotate(45deg); }
.nav-foot { display: flex; justify-content: space-between; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }

/* ============ Responsiv ============ */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr); }
  .summary { display: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 60px; gap: 12px; }
  .stepnav { position: static; flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .stepnav button { width: auto; white-space: nowrap; }
  .stepnav .sep { display: none; }
  .ability-grid, .asi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topbar { padding: 0 12px; }
  .topbar .btn .lbl { display: none; }
  .brand small { display: none; }
  .level-row { grid-template-columns: 50px 1fr 36px; }
  .level-row .hpcell, .level-row .pbcell { display: none; }
}

/* Footer & Rechtliches */
.site-footer { border-top: 1px solid var(--line); background: var(--surface-2); margin-top: 20px; }
.site-footer-inner { max-width: 1440px; margin: 0 auto; padding: 18px 20px 26px; display: flex; gap: 24px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.site-footer-inner p { margin: 0; max-width: 80ch; }
.site-footer nav { display: flex; gap: 16px; }
.site-footer a { color: var(--muted); text-decoration: none; font-weight: 500; }
.site-footer a:hover { color: var(--accent); }
.layout + .site-footer { margin-top: 0; }
.legal-sec { margin-top: 18px; }
.legal-sec:first-child { margin-top: 0; }
.legal-sec h2 { margin-bottom: 6px; }
.legal ul { padding-left: 20px; margin: 6px 0; }
.legal li { margin: 3px 0; }

/* Arbeitsanzeige */
.busy { position: fixed; inset: 0; background: rgba(246, 245, 242, .75); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 200; }
.busy-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 22px 28px; display: flex; align-items: center; gap: 14px; font-weight: 500; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  body { background: #fff; }
  #app, .busy, .site-footer { display: none !important; }
}
