:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe8db;
  --text: #2a2420;
  --muted: #6e6359;
  --border: #ddd2c0;
  --accent: #8c2f2b;
  --accent-text: #fff;
  --ok: #2f6b3a;
  --veil: #9a6a12;
  --line: #a3302b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f;
    --surface: #211d17;
    --surface-2: #2b261e;
    --text: #ece5d8;
    --muted: #a99d8c;
    --border: #3a3329;
    --accent: #d0655d;
    --accent-text: #1a1310;
    --ok: #7cc48a;
    --veil: #e0b04f;
    --line: #ef7a72;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f; --surface: #211d17; --surface-2: #2b261e; --text: #ece5d8;
  --muted: #a99d8c; --border: #3a3329; --accent: #d0655d; --accent-text: #1a1310;
  --ok: #7cc48a; --veil: #e0b04f; --line: #ef7a72; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, system-ui, sans-serif;
}
h1, h2, h3, .brand { font-family: Cinzel, Georgia, serif; letter-spacing: .02em; }
h1 { font-size: 1.7rem; margin: 0 0 .25rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .25rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .85rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-size: 1.25rem; font-weight: 700; text-decoration: none; color: var(--text); }
#account { display: flex; align-items: center; gap: 10px; min-width: 0; }
#account img { width: 28px; height: 28px; border-radius: 50%; }
#account .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

main { max-width: 900px; margin: 0 auto; padding: 24px 16px 64px; }

button, .btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 8px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--line); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
a.card { display: block; text-decoration: none; color: inherit; }
a.card:hover { border-color: var(--accent); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.dm { color: var(--accent); border-color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0 20px; overflow-x: auto; }
.tabs a {
  padding: 8px 12px; text-decoration: none; color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }

.hero { text-align: center; padding: 48px 0; }
.hero h1 { font-size: 2.4rem; }
.hero p { max-width: 520px; margin: 8px auto 24px; }

label { display: block; font-weight: 500; margin-bottom: 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field + .field { margin-top: 12px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }

dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 20px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: .9rem; max-width: 100%;
  overflow-wrap: anywhere;
}
.chip button { border: 0; background: none; padding: 0 2px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; font-size: .85rem; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.num { text-align: center; width: 64px; }

.rating { display: flex; gap: 4px; flex-wrap: wrap; }
.rating input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.rating label {
  margin: 0; font-weight: 500; font-size: .85rem; padding: 3px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); color: var(--muted);
}
.rating input:focus-visible + label { outline: 2px solid var(--accent); }
.rating input[value="ok"]:checked + label { color: var(--ok); border-color: var(--ok); }
.rating input[value="veil"]:checked + label { color: var(--veil); border-color: var(--veil); }
.rating input[value="line"]:checked + label { color: var(--line); border-color: var(--line); }
.t-ok { color: var(--ok); } .t-veil { color: var(--veil); } .t-line { color: var(--line); font-weight: 600; }

.topic-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }
.error { color: var(--line); }

@media (max-width: 560px) {
  h1 { font-size: 1.4rem; }
  .hero h1 { font-size: 1.9rem; }
  #account .name { display: none; }
}

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.kpi-label { font-size: .85rem; color: var(--muted); }
.kpi-value { font-size: 1.9rem; font-weight: 600; line-height: 1.2; margin-top: 4px; overflow-wrap: anywhere; }
.kpi-sub { font-size: .8rem; color: var(--muted); margin-top: 4px; }
#account a { white-space: nowrap; }

/* ----- character builder & sheet ----- */
a.btn { display: inline-block; text-decoration: none; color: var(--text); }
a.btn.primary { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.builder { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; margin-top: 12px; }
.builder-summary { position: sticky; top: 12px; }
@media (max-width: 820px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder-summary { position: static; order: -1; }
}
.builder select { margin-top: 2px; }
details.feature { border-top: 1px solid var(--border); padding: 6px 0; }
details.feature summary { cursor: pointer; font-weight: 500; }
details.feature .pre { margin-top: 6px; }
.checks { display: grid; gap: 4px 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
label.check { display: flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }
label.check input { width: auto; }
.option-list { max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; }
.option { padding: 6px 0; border-bottom: 1px solid var(--border); }
.option:last-child { border-bottom: 0; }
.option details.feature { border: 0; padding: 2px 0 0; }
.option details.feature summary { font-weight: 400; font-size: .8rem; color: var(--muted); }
.source-row { padding: 6px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
table.scores td, table.scores th { padding: 4px 6px; }
.sheet h4 { margin: 12px 0 4px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.scores-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.score { text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: 4px 0; }
.score-label { font-size: .7rem; color: var(--muted); font-weight: 600; }
.score-mod { font-size: 1.1rem; font-weight: 600; }
.score-val { font-size: .75rem; color: var(--muted); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; }
.stat-row > div { border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; text-align: center; }
.stat-row span { display: block; font-size: .7rem; color: var(--muted); }
.mini-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 8px; font-size: .8rem; color: var(--muted); }
.mini-grid.skills { grid-template-columns: repeat(2, 1fr); }
.mini-grid .prof { color: var(--text); font-weight: 600; }
.mini-grid .prof::before { content: "● "; color: var(--accent); }
.char-name { text-decoration: none; color: inherit; }
.char-name:hover h3 { color: var(--accent); }
table.scores th.num, table.scores td.num { width: auto; }
table.scores abbr { text-decoration: none; font-weight: 600; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand img { display: block; }
.hero-logo { display: block; margin: 0 auto 12px; }
#account a.name { color: var(--text); text-decoration: none; }
#account a.name:hover { text-decoration: underline; }
#account a img { display: block; }

/* Header: brand left, admin button centered, account right */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; }
.topbar .brand { justify-self: start; }
#header-center { justify-self: center; }
#account { justify-self: end; }
a.btn.admin-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; font-weight: 600; }
a.btn.admin-btn:hover { background: var(--surface-2); }
@media (max-width: 640px) {
  .topbar { grid-template-columns: 1fr auto; row-gap: 8px; }
  #header-center { grid-column: 1 / -1; grid-row: 2; }
  #header-center:empty { display: none; }
}
button.btn-mini { font-size: .75rem; padding: 3px 7px; border-radius: 6px; }
.rsvp button { padding: 5px 12px; }
