:root {
  --bg: #12141a;
  --panel: #1a1d26;
  --panel-2: #212633;
  --line: #2e3444;
  --ink: #e6e8ee;
  --muted: #9aa3b8;
  --accent: #7fb2ff;
  --gold: #d9b06a;
  --danger: #e0605f;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* display:grid/flex on a component silently defeats the hidden attribute; this puts it back. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2, h3 { font-weight: 600; letter-spacing: 0.01em; }
h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin: 0 0 0.6rem; }
.muted { color: var(--muted); }

.topbar {
  display: flex; gap: 0.6rem; align-items: center;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--gold); letter-spacing: 0.06em; }
.save-state { margin-left: auto; font-size: 0.8rem; color: var(--muted); }
.roll-target { font-size: 0.8rem; color: var(--muted); }

select, input, textarea, button {
  font: inherit; color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.35rem 0.55rem;
}
textarea { width: 100%; min-height: 8rem; resize: vertical; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.ghost { background: transparent; }
button.roll { background: #26314a; border-color: #35456a; }
button.roll:hover { background: #2f3d5e; }
button.tiny { padding: 0.15rem 0.45rem; font-size: 0.8rem; }

/* minmax(0,…) on both tracks: without it a grid item refuses to shrink below its content and the
   panes overlap instead of the rail staying 320px wide. */
.sheet { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 1rem; padding: 1rem; align-items: start; }
.rail, .pane { min-width: 0; }
@media (max-width: 900px) { .sheet { grid-template-columns: 1fr; } }

.rail { display: grid; gap: 0.75rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem; min-width: 0; overflow-wrap: anywhere; }
.card:empty { display: none; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.2rem 0; flex-wrap: wrap; }
.row + .row { border-top: 1px dashed var(--line); }
.grid-abilities { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.ability { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.45rem; text-align: center; }
.ability label { display: block; font-size: 0.7rem; text-transform: uppercase; color: var(--muted); }
.ability input { width: 100%; text-align: center; background: transparent; border: none; padding: 0.1rem; }
.ability .mod { color: var(--accent); font-weight: 600; }
.ability .buttons { display: flex; gap: 0.2rem; justify-content: center; margin-top: 0.25rem; }
.ability .buttons button { white-space: nowrap; padding: 0.12rem 0.32rem; font-size: 0.72rem; }

.pips { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.pip { width: 1.15rem; height: 1.15rem; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); padding: 0; }
.pip.spent { background: var(--gold); border-color: var(--gold); }

.tabs { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.tabs button { background: transparent; border-color: transparent; color: var(--muted); }
.tabs button.active { background: var(--panel); border-color: var(--line); color: var(--ink); }
.tab-body { display: grid; gap: 0.75rem; }

.feature { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.85rem; }
.feature summary { cursor: pointer; display: flex; gap: 0.5rem; align-items: baseline; }
.feature summary h3 { margin: 0; font-size: 1rem; }
.feature .lvl { color: var(--gold); font-size: 0.78rem; }
.feature .origin { color: var(--muted); font-size: 0.78rem; margin-left: auto; }
.feature .body { margin-top: 0.5rem; color: #d3d8e4; }
.feature .body p { margin: 0.5rem 0; }
.feature .body table { border-collapse: collapse; width: 100%; }
.feature .body td, .feature .body th { border: 1px solid var(--line); padding: 0.25rem 0.4rem; text-align: left; }
.tags { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.4rem; }
.tag { font-size: 0.72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0.05rem 0.5rem; }
.tag.cost { color: var(--gold); border-color: #5a4a28; }

.spell-level { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.85rem; }
.spell { display: flex; align-items: center; gap: 0.5rem; padding: 0.15rem 0; }
.spell.always { color: var(--gold); }

.list { display: grid; gap: 0.4rem; }
.line.skill { grid-template-columns: auto minmax(0, 1fr) auto auto; }
button.rank { font-size: 0.9rem; line-height: 1; width: 1.8rem; }
.spell-detail { margin: 0.35rem 0 0.6rem 1.6rem; padding: 0.5rem 0.7rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); }
.spell-meta { display: flex; flex-wrap: wrap; gap: 0.75rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.spell summary { cursor: pointer; list-style: none; }
.spell summary::-webkit-details-marker { display: none; }
details.spell { padding: 0.1rem 0; }
.coins { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4rem; }
.coins label { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; }
.coins input { width: 100%; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 0.4rem; align-items: center; }
.line input { min-width: 0; }

.roll-log { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.35rem; max-height: 16rem; overflow-y: auto; }
.roll-log li { font-size: 0.85rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.3rem 0.45rem; }
.roll-log .total { color: var(--accent); font-weight: 700; }
.roll-log .nat20 { color: #6fd08c; }
.roll-log .nat1 { color: var(--danger); }
.roll-log .note { color: var(--muted); font-size: 0.75rem; }

.empty { padding: 4rem 1rem; text-align: center; color: var(--muted); }
.warn { background: #3a2a1c; border: 1px solid #5a4327; color: #f0d6ab; padding: 0.5rem 0.7rem; border-radius: var(--radius); font-size: 0.85rem; }

/* --- sign-in page --- */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(26rem, 92vw); text-align: center; }
.login .brand { font-size: 2rem; margin: 0 0 0.25rem; }
.login .tabs { justify-content: center; margin: 1.2rem 0 0.8rem; }
.login .card { display: grid; gap: 0.8rem; text-align: left; }
.field { display: grid; gap: 0.25rem; }
.field span { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.field input { width: 100%; }
