* { box-sizing: border-box; }

:root {
  --bg: #1c1917;
  --surface: #292524;
  --border: #44403c;
  --border-strong: #57534e;
  --text: #e7e5e4;
  --muted: #a8a29e;
  --accent: #f5c46b;
  --action: #b45309;
  --action-hover: #c2620f;
  --error: #fca5a5;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

main { max-width: 860px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
/* Character pages (Build and Play): one width, so switching tabs doesn't resize the page.
   The Play sheet uses it for two columns. */
body.wide main { max-width: 1240px; }

/* Auth pages: a single card in the middle of the screen. */
body.centered { display: grid; place-items: center; padding: 1rem; }
body.centered main { width: 100%; max-width: 380px; padding: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.brand { color: var(--accent); font-weight: 700; text-decoration: none; }
.topbar-nav { display: flex; align-items: baseline; gap: 1.25rem; }
.topbar-nav a:not(.brand) { color: var(--muted); font-size: 0.9rem; text-decoration: none; }
.topbar-nav a:not(.brand):hover { color: var(--text); }
.topbar-user { display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}
.auth-card { padding: 2rem; }

h1 { margin: 0; font-size: 1.6rem; color: var(--accent); }
.subtitle { margin: 0.25rem 0 1.5rem; color: var(--muted); }
.muted { color: var(--muted); }

label { display: block; margin: 0.9rem 0 0.3rem; font-size: 0.9rem; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: inherit;
  font-size: 1rem;
}
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button {
  display: inline-block;
  padding: 0.7rem 1.1rem;
  border: 0;
  border-radius: 6px;
  background: var(--action);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--action-hover); }
.auth-card button { width: 100%; margin-top: 1.25rem; }
form.htmx-request button[type="submit"] { opacity: 0.6; cursor: wait; }

.link-button { padding: 0; background: none; color: var(--accent); font-weight: 400; }
.link-button:hover { background: none; text-decoration: underline; }

.error { margin: 1rem 0 0; color: var(--error); font-size: 0.9rem; }
.switch { margin: 1.25rem 0 0; text-align: center; font-size: 0.9rem; color: var(--muted); }
a { color: var(--accent); }

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* Character list */
.character-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.character-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; }
.character-name { font-weight: 600; }
.empty { text-align: center; }
.empty p { margin: 0 0 0.5rem; color: var(--muted); }

/* Character creation */
.character-form { display: grid; gap: 2rem; }
.character-form fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.character-form > button { justify-self: start; }
.section-title { display: block; margin: 0 0 0.75rem; padding: 0; font-size: 1.1rem; font-weight: 600; }

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 0.75rem;
}
.choice {
  position: relative;
  margin: 0;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.choice:hover { border-color: var(--border-strong); }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
/* The radio stays in the DOM for keyboard and screen-reader use; the card shows the state. */
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-name { display: block; font-weight: 600; }
.choice-summary { display: block; margin-top: 0.25rem; font-size: 0.85rem; color: var(--muted); line-height: 1.35; }

/* Validation errors */
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }
.form-actions .error { margin: 0; }
.field-error { margin: -0.4rem 0 0.75rem; }
.has-error .section-title { color: var(--error); }
.has-error input[type="text"] { border-color: var(--error); }
.has-error .choice { border-color: color-mix(in srgb, var(--error) 45%, var(--border)); }

/* Character page */
.page-header .subtitle { margin: 0.25rem 0 0; }
.sheet-section { margin-bottom: 2.25rem; }
.sheet-section h2 { margin: 0 0 0.75rem; font-size: 1.25rem; }
.group-title { margin: 1.25rem 0 0.5rem; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* Collapsible sections (partials/section.html, static/collapse.js): a ruled header with a
   chevron; collapsed, it shows a one-line digest of what's inside. */
details.sheet-section { margin-bottom: 0.5rem; border-top: 1px solid var(--border); scroll-margin-top: 7rem; }
.section-summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem;
  padding: 1rem 0 0.9rem; cursor: pointer; list-style: none; user-select: none;
}
.section-summary::-webkit-details-marker { display: none; }
.section-summary::before { content: "▸"; align-self: center; color: var(--muted); transition: transform 0.15s; }
details[open] > .section-summary::before { transform: rotate(90deg); }
.section-summary h2 { margin: 0; }
.section-summary:hover h2 { color: var(--accent); }
.section-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.section-digest { color: var(--muted); font-size: 0.9rem; }
details[open] > .section-summary .section-digest { display: none; }
.section-body { padding-bottom: 1.5rem; }
.section-actions { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin-bottom: 0.75rem; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }

.pending-choice { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; border-color: var(--accent); }
.pending-choice:has(form) { display: block; }
/* The Play sheet's in-play choices keep their dropdown on the same row. */
.pending-choice.play-pending { display: flex; }

.spell-list li { display: grid; gap: 0.15rem; }
.feature-name { font-weight: 600; }
.feature-choice { margin-top: 0.35rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; }
.feature-choice:has(form) { display: block; margin-top: 0.75rem; }
.feature-choice-summary { flex-basis: 100%; font-size: 0.9rem; }
.feature-text summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; width: fit-content; }
.feature-text p { margin: 0.25rem 0 0; font-size: 0.9rem; white-space: pre-line; }

.tag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tag-list li { padding: 0.35rem 0.7rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }

/* Choice forms loaded into the page */
.choice-form { display: grid; gap: 0.75rem; }
.choice-form-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.75rem; }
.choice-form-header .section-title { margin: 0; }
.choice-form .field-error { margin: 0; }
.choice-detail { display: block; margin-top: 0.15rem; font-size: 0.8rem; color: var(--accent); }

/* Inline rename */
.name-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.75rem; }
.name-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.name-form input[type="text"] { width: auto; flex: 1 1 16rem; font-size: 1.3rem; font-weight: 600; }
.name-form .error { flex-basis: 100%; margin: 0; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Delete character */
.danger-zone { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.danger-zone summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; width: fit-content; }
.danger-zone summary:hover { color: var(--error); }
.delete-form { margin-top: 0.75rem; max-width: 32rem; }
.delete-form p { margin: 0 0 0.75rem; }
.delete-form-row { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; }
.delete-form-row input[type="text"] { width: auto; flex: 1 1 10rem; }
.delete-form .error { margin: 0.5rem 0 0; }
.danger-button { background: #b91c1c; }
.danger-button:hover { background: #dc2626; }

/* Ability scores */
.section-heading { display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 0.75rem; }
.section-heading h2 { margin: 0; }
.ability-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr)); gap: 0.6rem; }
.ability-grid li { display: grid; justify-items: center; gap: 0.1rem; padding: 0.75rem 0.5rem; }
.ability-abbr { font-size: 0.8rem; letter-spacing: 0.06em; color: var(--muted); }
.ability-mod { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.ability-score { font-size: 0.9rem; color: var(--muted); }

.ability-editor { display: grid; gap: 1rem; width: 100%; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); }
.tab { background: none; color: var(--muted); font-weight: 500; border-radius: 6px 6px 0 0; padding: 0.5rem 0.9rem; }
.tab:hover { background: var(--surface); color: var(--text); }
.tab.active { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.ability-form { display: grid; gap: 1rem; }
.method-hint { margin: 0; font-size: 0.9rem; }

.rolls { border: 0; margin: 0; padding: 0; min-width: 0; }
.rolls legend { padding: 0; margin-bottom: 0.4rem; font-size: 0.9rem; }
.roll-inputs { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.roll-inputs input { width: 4rem; text-align: center; }
.rolls.has-error input { border-color: var(--error); }

.ability-rows { display: grid; gap: 0.4rem; max-width: 34rem; }
.ability-row {
  display: grid; grid-template-columns: minmax(7rem, 1fr) auto 3rem 5rem;
  align-items: center; gap: 0.75rem; padding: 0.35rem 0;
}
.ability-row .row-name { margin: 0; font-size: 0.95rem; }
.ability-row .field-error { grid-column: 1 / -1; margin: 0; }
.ability-row.has-error select { border-color: var(--error); }
.row-mod { font-weight: 700; color: var(--accent); text-align: center; }
.row-cost { font-size: 0.8rem; }

.ability-row select, .roll-inputs input {
  padding: 0.45rem 0.6rem; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: inherit; font: inherit; font-size: 1rem;
}
.ability-row select { min-width: 5rem; }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.stepper .step { width: 2.4rem; padding: 0.4rem 0; border-radius: 0; background: var(--surface); color: var(--text); font-size: 1.1rem; }
.stepper .step:hover:not(:disabled) { background: var(--border); }
.stepper .step:disabled { color: var(--border-strong); cursor: not-allowed; }
.step-value { min-width: 2.6rem; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.editor-status { margin: 0; }

/* Ability score increases: name, amount (a fixed +1, or a +2 / +1 toggle), resulting score. */
.increase-rows { display: grid; gap: 0.2rem; max-width: 26rem; }
.increase-row {
  display: grid; grid-template-columns: minmax(7rem, 1fr) 4.5rem 6rem;
  align-items: center; gap: 0.5rem; padding: 0.3rem 0;
}
.increase-amount { padding: 0.1rem 0.4rem; font-weight: 600; color: var(--accent); }
.increase-toggle { display: inline-flex; gap: 0.15rem; }
.increase-option {
  /* A label, so undo the form-label margin and size: rows match the "+1 to each" ones. */
  position: relative; margin: 0; padding: 0.1rem 0.4rem; border-radius: 4px;
  font-size: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.increase-option:hover { color: var(--text); background: var(--surface); }
.increase-option input { position: absolute; opacity: 0; width: 0; height: 0; margin: 0; }
.increase-option:has(input:checked) { color: var(--accent); }
.increase-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.increase-score { font-variant-numeric: tabular-nums; }

@media (max-width: 30rem) {
  .ability-row { grid-template-columns: 1fr auto 2.5rem; }
  .row-cost { grid-column: 2 / -1; text-align: right; margin-top: -0.35rem; }
}

/* Leveling */
.level-up-button { margin-left: 0.5rem; }
#level-up-slot:not(:empty) { margin-bottom: 2rem; }
.level-up-panel { display: grid; gap: 0.75rem; max-width: 36rem; }
.level-up-panel p { margin: 0; }
.level-up-form { display: grid; gap: 0.75rem; }
.level-up-form .section-title { margin: 0; }
.hp-options { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.hp-roll { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.hp-roll label { margin: 0; }
.hp-roll input { width: 3.5rem; text-align: center; padding: 0.5rem; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: inherit; font: inherit; }
.hp-roll.has-error input { border-color: var(--error); }
.remove-level { margin-top: 0.75rem; max-width: 32rem; }
.remove-level p { margin: 0 0 0.75rem; }
.danger-zone + .danger-zone { margin-top: 1rem; padding-top: 0; border-top: 0; }

/* Options the character already has from elsewhere */
.choice.known { cursor: not-allowed; opacity: 0.6; }
.choice.known:hover { border-color: var(--border); }
.choice-known { display: inline-block; margin-top: 0.3rem; font-size: 0.75rem; font-weight: 600; color: var(--accent); }

/* Collapsible option groups (e.g. spells by level) */
.choice-group { border-top: 1px solid var(--border); padding-top: 0.6rem; }
.choice-group + .choice-group { margin-top: 0.6rem; }
.choice-group > summary {
  display: flex; align-items: baseline; gap: 0.6rem; cursor: pointer; list-style: none;
  padding: 0.25rem 0 0.6rem; user-select: none;
}
.choice-group > summary::-webkit-details-marker { display: none; }
.choice-group > summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; }
.choice-group[open] > summary::before { transform: rotate(90deg); }
.choice-group-name { font-weight: 600; }
.choice-group > summary .muted { font-size: 0.85rem; }

/* Option filters (spells) */
[hidden] { display: none !important; }
.option-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.option-filters input[type="search"], .option-filters select, .copy-search input[type="search"] {
  padding: 0.45rem 0.6rem; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: inherit; font: inherit; font-size: 0.95rem;
}
.option-filters input[type="search"] { flex: 1 1 12rem; min-width: 0; }
.filter-check { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; font-size: 0.9rem; }
.filter-empty { flex-basis: 100%; font-size: 0.9rem; }

/* Build | Play tabs */
.page-tabs { display: flex; gap: 0.25rem; margin: -0.5rem 0 1.25rem; border-bottom: 1px solid var(--border); }
.page-tabs a { padding: 0.5rem 1rem; color: var(--muted); text-decoration: none; border-radius: 6px 6px 0 0; }
.page-tabs a:hover { color: var(--text); background: var(--surface); }
.page-tabs a.active { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }

/* Sheet: hit points */
.secondary-button { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.secondary-button:hover { background: var(--border); }
.hp-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.hp-form label { margin: 0; }
.hp-form input[type="text"] { width: 6.5rem; }
.hp-form input[name="source"], .hp-form input[name="label"] { width: auto; flex: 1 1 10rem; }
.hp-form .delta-input { width: 6rem; }
.hp-effect { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.add-effect { display: grid; gap: 0.5rem; }
#prepared-section .section-heading { margin-bottom: 0.5rem; }
#prepared-section .group-title { margin: 1.25rem 0 0; }

/* Spell lists: name line with tags */
.spell-groups { display: grid; gap: 0.6rem; }
.spell-groups .choice-group { padding-bottom: 0.4rem; }
.spell-list li { padding: 0.2rem 0; }
.spell-name-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem; }
.spell-tag {
  padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.02em; color: var(--muted); border: 1px solid var(--border-strong);
}
.spell-tag.ritual-only { color: var(--accent); border-color: var(--accent); }
#prepared-section .section-heading .group-title { margin: 0; }

/* Spell slots */
.slot-tracker { display: grid; gap: 0.4rem; margin: 0 0 1rem; }
.slot-tracker .group-title { margin: 0 0 0.1rem; }
.slot-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.slot-label { width: 4.5rem; font-size: 0.9rem; }
.slot-pips { display: inline-flex; gap: 0.35rem; }
.pip {
  width: 1.1rem; height: 1.1rem; padding: 0; border-radius: 50%;
  background: transparent; border: 2px solid var(--accent);
}
.pip.filled { background: var(--accent); }
.pip:hover { background: color-mix(in srgb, var(--accent) 45%, transparent); }
.pip:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* Casting */
.spell-tag.ritual { color: var(--accent); border-color: var(--accent); }
.spell-level-note { font-size: 0.8rem; }
.cast-menu { position: relative; margin-left: auto; }
.cast-button {
  list-style: none; cursor: pointer; padding: 0.2rem 0.75rem; border-radius: 6px;
  background: var(--action); color: #fff; font-size: 0.85rem; font-weight: 600;
}
.cast-button::-webkit-details-marker { display: none; }
.cast-button:hover { background: var(--action-hover); }
.cast-options {
  position: absolute; right: 0; z-index: 5; margin-top: 0.3rem; display: grid; gap: 0.3rem;
  padding: 0.5rem; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; min-width: 11rem;
}
.cast-options button { width: 100%; padding: 0.4rem 0.6rem; font-size: 0.85rem; text-align: left; }
.cast-none { margin-left: auto; font-size: 0.8rem; }

/* Rests and resources */
.rest-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.rest-bar .secondary-button { padding: 0.45rem 0.9rem; font-size: 0.9rem; }
.long-rest > summary { list-style: none; cursor: pointer; display: inline-block; border-radius: 6px; }
.long-rest > summary::-webkit-details-marker { display: none; }
/* Opens over the page from the sticky bar. */
.long-rest { position: relative; }
.long-rest-confirm { position: absolute; right: 0; z-index: 20; margin-top: 0.5rem; width: min(26rem, 90vw);
  display: grid; gap: 0.5rem; box-shadow: 0 8px 24px rgb(0 0 0 / 0.45); }
.long-rest-confirm p, .long-rest-confirm ul { margin: 0; }
.long-rest-confirm ul { padding-left: 1.2rem; }
.short-rest-panel { display: grid; gap: 1rem; margin: 1rem 0 2rem; border-color: var(--accent); }
.short-rest-panel h2 { margin: 0; }
.rest-block p { margin: 0.25rem 0 0.5rem; }
.rest-block .group-title { margin: 0; }
.recovery-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 1rem; }
.recovery-row { display: grid; gap: 0.25rem; margin: 0; font-size: 0.9rem; }
.recovery-row input { width: 4rem; padding: 0.4rem; text-align: center; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: inherit; font: inherit; }
.resource-label { min-width: 8rem; font-size: 0.95rem; font-weight: 600; }

/* Resources: what the picked option does */
.resource + .resource { margin-top: 0.75rem; }
.resource-option { font-weight: 400; color: var(--accent); }
.resource-detail { margin: 0.25rem 0 0; font-size: 0.9rem; color: var(--muted); }
.resource-detail strong { color: var(--text); font-weight: 600; }
.resource-spender { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; margin-top: 0.5rem; padding-left: 0.75rem; border-left: 2px solid var(--border); }
.resource-spender-text { display: grid; gap: 0.1rem; font-size: 0.9rem; }
.resource-spender-text .resource-detail { margin: 0; }
.resource-spender .small-button { flex-shrink: 0; }
.play-choice-select { padding: 0.35rem 0.5rem; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: inherit; font: inherit; font-size: 0.9rem; }

/* Dice */
.roll-button {
  padding: 0.4rem 0.7rem; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); font-weight: 500; font-size: 0.9rem;
}
.roll-button:hover { background: var(--border); }
.roll-result { font-size: 0.85rem; }

/* Damage reactions */
.damage-prompt { display: grid; gap: 0.75rem; border-color: var(--accent); max-width: 36rem; }
.damage-prompt .section-title { margin: 0; }
.reaction-form { display: grid; gap: 0.35rem; }
.reaction-form p { margin: 0; }

/* Copying spells, rule markers */
.copy-panel { margin-bottom: 1.25rem; border-color: var(--accent); }
.copy-rules { margin: 0; font-size: 0.9rem; }
.spell-tag.warning { color: var(--error); border-color: var(--error); }
.choice .spell-tag.warning { display: inline-block; margin-top: 0.3rem; }
.spell-note { font-size: 0.8rem; font-style: italic; }
.choice .spell-note { display: block; margin-top: 0.3rem; }
.copy-search { margin-top: 0.75rem; }
.copy-search input[type="search"] { flex: 1 1 14rem; min-width: 0; }
.copy-results { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.copy-result { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.5rem 0; border-top: 1px solid var(--border); }
.copy-result > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.6rem; }
.copy-result .choice-known { margin: 0; white-space: nowrap; }
.copy-result .secondary-button { padding: 0.35rem 0.9rem; }
.copy-pick { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.6rem; }
.copy-pick .choice-summary { flex-basis: 100%; margin: 0; }
/* The confirm step: spell, cost, note and buttons, evenly spaced. */
.copy-confirm { display: flex; flex-direction: column; gap: 1.1rem; margin-top: 1rem; }
.copy-confirm > p { margin: 0; }
.copy-confirm .form-actions { margin-top: 0.25rem; }
.copy-confirm .hp-form input[name="note"] { width: auto; flex: 1 1 14rem; }
.copy-panel .choice-form-header { justify-content: space-between; }
/* Removing a copied spell from the prepared editor's cards */
.card-remove { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem;
  margin-top: 0.5rem; font-size: 0.85rem; }
.card-remove .link-button { font-size: 0.85rem; }
.small-button { padding: 0.3rem 0.75rem; font-size: 0.85rem; }
/* Build page: spells by the level they were chosen at */
.spell-levels { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem;
  margin-top: 0.5rem; align-items: baseline; }
.spell-level-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.spell-level-choices .feature-choice:first-child { margin-top: 0; }
.spell-levels .spell-tag.warning { font-size: 0.7rem; }
@media (max-width: 480px) {
  .spell-levels { grid-template-columns: 1fr; gap: 0.15rem; }
  .spell-level-choices { margin-bottom: 0.4rem; }
}
/* Play page: abilities with saves */
.ac-effect-form select { padding: 0.45rem 0.5rem; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: inherit; font: inherit; font-size: 0.9rem; }
.ac-effect-form input[name="label"] { width: auto; flex: 1 1 9rem; }

.play-abilities { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.5rem; }
.play-abilities li { gap: 0.4rem; padding: 0.9rem 0.25rem 0.6rem; min-width: 0; }
.play-abilities .ability-abbr { font-weight: 600; }
.roll-number { padding: 0.1rem 0.4rem; background: none; border: 0; border-radius: 6px; color: var(--accent); cursor: pointer; }
.roll-number:hover { background: var(--border); }
.play-abilities .ability-mod { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.play-abilities .ability-score { padding: 0.05rem 0.6rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.85rem; }
.ability-save { margin-top: 0.15rem; padding-top: 0.45rem; width: 100%; border-top: 1px solid var(--border);
  border-radius: 0; font-size: 0.85rem; font-weight: 400; color: var(--muted); white-space: nowrap; }
.ability-save:hover { border-radius: 0 0 6px 6px; }
.play-abilities .ability-save { padding-inline: 0; font-size: 0.8rem; }
.ability-save.proficient { color: var(--text); font-weight: 600; }
.skill-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.15rem 1.25rem; }
.skill-list li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.5rem; }
.skill-roll { display: grid; grid-template-columns: 1rem 1fr auto; gap: 0.35rem; align-items: baseline; width: 100%; text-align: left; color: var(--muted); }
.skill-list li.proficient .skill-roll { color: var(--text); font-weight: 600; }
.skill-list .skill-mark { color: var(--accent); font-size: 0.75rem; }
.skill-list .skill-bonus { font-variant-numeric: tabular-nums; }
.skill-list .roll-result { font-size: 0.75rem; }
.skill-list .roll-result:empty { display: none; }
.attributes { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.25rem; margin: 0; }
.attributes dt { font-weight: 600; }
.attributes dd { display: grid; gap: 0.2rem; margin: 0; }
.play-abilities .roll-result { font-size: 0.75rem; text-align: center; }
.play-abilities .roll-result:empty { display: none; }
@media (max-width: 640px) { .play-abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.ac-spells { margin: 0; display: grid; }
.ac-spells li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.4rem 0.75rem; padding: 0.55rem 0; border-top: 1px solid var(--border); }
.ac-spells li:last-child { border-bottom: 1px solid var(--border); }
.ac-cast-slots { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.ac-spells .secondary-button { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

/* Play sheet: the sticky bar, the only place HP and AC are shown. Clicking HP or AC opens a
   panel over the page (temp HP and max HP effects; AC breakdown and effects). */
.vitals-bar {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center;
  gap: 0.6rem 1.5rem; margin: -0.5rem -1rem 1.25rem; padding: 0.6rem 1rem;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.vital-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.9rem; }
.vital { display: inline-grid; gap: 0.15rem; }
.vital-main { display: inline-flex; align-items: baseline; gap: 0.35rem; white-space: nowrap; }
/* How the number is made up, under it: AC's breakdown, HP's active max HP effects. */
.vital-detail { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.vital-effects { justify-self: start; padding: 0 0.45rem; border: 1px solid var(--accent); border-radius: 999px; color: var(--accent); }
.vital strong { font-size: 1.6rem; line-height: 1; color: var(--accent); }
.vital-label { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); }
.vital-temp { font-size: 0.85rem; color: var(--accent); }
.vital-caret { font-size: 0.75rem; color: var(--muted); }
.vital-menu { position: relative; }
.vital-menu > summary { list-style: none; cursor: pointer; padding: 0.15rem 0.35rem; border-radius: 6px; }
.vital-menu > summary::-webkit-details-marker { display: none; }
.vital-menu > summary:hover, .vital-menu[open] > summary { background: var(--surface); }
.vital-menu > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.vital-panel {
  position: absolute; left: 0; z-index: 20; margin-top: 0.4rem; width: min(30rem, calc(100vw - 2rem));
  display: grid; gap: 0.75rem; box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
}
.vital-panel p { margin: 0; }
.vital-panel .group-title { margin: 0.25rem 0 0.4rem; }
.vital-panel .error { margin: 0; }
/* Panel contents: groups (heading, list, one-line form) spaced apart, tight inside. */
.vital-panel.hp-panel { gap: 1.25rem; }
.panel-group { display: grid; gap: 0.5rem; }
.panel-group > .group-title { margin: 0; }
.panel-group > .group-title label { margin: 0; font-size: inherit; }
.group-title-note { font-weight: 400; text-transform: none; letter-spacing: 0; }
.effect-list { gap: 0.35rem; padding: 0.25rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.effect-list li { padding: 0.2rem 0; }
.inline-form { display: grid; gap: 0.5rem; align-items: center; }
.inline-form input[type="text"] { width: 100%; min-width: 0; padding: 0.5rem 0.65rem; }
.inline-form .secondary-button { padding: 0.5rem 0.9rem; }
.temp-hp-form { grid-template-columns: 4.5rem 1fr auto; }
.hp-effect-form { grid-template-columns: 1fr 5.5rem auto; }
.vital-hp-form input[type="text"] { width: 5.5rem; padding: 0.4rem 0.6rem; }
.vital-hp-form button { padding: 0.45rem 0.9rem; font-size: 0.9rem; }
.vitals-bar .rest-bar { margin-left: auto; }
.vitals-bar .rest-bar .secondary-button { padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.vitals-error { flex-basis: 100%; margin: 0; }
.damage-prompt { margin: 0 0 1.25rem; }
.play-abilities { margin-bottom: 1.5rem; }

/* Play sheet columns: one column in order of use; from 1100px, spells get their own column. */
.sheet-columns { display: flex; flex-direction: column; }
.sheet-column { display: contents; }
.sheet-columns .order-late { order: 1; }
@media (min-width: 1100px) {
  .sheet-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 0 2.5rem; align-items: start; }
  .sheet-column { display: block; }
}
.pending-section { margin-bottom: 1.5rem; }


/* Compact spell rows: the name line expands to the details; Cast sits beside it. */
.spell-list li.spell-row { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.spell-list li.spell-row:last-child { border-bottom: 0; }
.spell-details { flex: 1; min-width: 0; }
.spell-details > summary { cursor: pointer; list-style: none; }
.spell-details > summary::-webkit-details-marker { display: none; }
.spell-details > summary:hover .feature-name { color: var(--accent); }
.spell-more { display: grid; gap: 0.15rem; padding: 0.3rem 0 0.2rem; }
.spell-row .cast-menu { margin-left: 0; flex-shrink: 0; }

/* Build page: features grouped by source; each feature collapses to its name and picks */
.feature-group { margin-bottom: 0.75rem; }
.feature-group > summary {
  display: flex; align-items: baseline; gap: 0.6rem; padding: 0.4rem 0; cursor: pointer;
  list-style: none; user-select: none;
}
.feature-group > summary::-webkit-details-marker { display: none; }
.feature-group > summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; }
.feature-group[open] > summary::before { transform: rotate(90deg); }
.feature-group-name { font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.feature-group > summary .muted { font-size: 0.85rem; }
.feature-group .feature-list { gap: 0; margin-left: 1.1rem; }
.feature-group > summary .link-button { font-size: 0.85rem; }
.feature-group > summary + div:not(:empty) { margin: 0.25rem 0 0.5rem 1.1rem; }  /* Change form */
/* A section that comes with the group, like a background's origin feat. */
.feature-section-title { margin: 0.75rem 0 0.1rem 1.1rem; }
.feature-list > li { border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.feature-list > li:last-child { border-bottom: 0; }
.feature > summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.6rem; padding: 0.5rem 0;
  cursor: pointer; list-style: none;
}
.feature > summary::-webkit-details-marker { display: none; }
.feature > summary:hover .feature-name { color: var(--accent); }
.feature-level { font-size: 0.75rem; color: var(--muted); }
.feature-picks { color: var(--muted); font-size: 0.9rem; }
.feature-picks::before { content: "· "; }
.feature[open] > summary .feature-picks { display: none; }
.feature-body { display: grid; gap: 0.15rem; padding: 0 0 0.75rem; }
/* Phones: HP, AC (its breakdown wrapping under it) and the rests, stacked, in one row; the
   damage box under them. Keeps the pinned bar to two rows. */
@media (max-width: 640px) {
  .vitals-bar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 0.5rem 0.6rem; }
  .vital-group { display: contents; }
  .vital-group > .vital-menu { grid-column: 1; grid-row: 1; }
  .vitals-bar > .vital-menu { grid-column: 2; grid-row: 1; }
  .vitals-bar .rest-bar { grid-column: 3; grid-row: 1; flex-direction: column; align-items: stretch; gap: 0.3rem; margin: 0; }
  .vitals-bar .rest-bar .secondary-button { padding: 0.25rem 0.6rem; text-align: center; }
  .vitals-bar .long-rest > summary { display: block; }
  .vital-hp-form { grid-column: 1 / -1; grid-row: 2; }
  .vital-hp-form input[type="text"] { flex: 1; }
  .vitals-error { grid-column: 1 / -1; }
  .vital strong { font-size: 1.35rem; }
  .vital-detail { white-space: normal; }
  .vitals-bar .wide-only { display: none; }
  .vital-menu > summary { padding: 0.15rem 0.25rem; }
  /* Panels open under the whole bar rather than under HP or AC, so they fit on screen. */
  .vital-menu { position: static; }
  .vital-panel { left: 1rem; top: 100%; }
}
}

/* Inventory (Play sheet): coins, then compact item rows like the spell rows. */
/* Two titled parts, like Spells: Coins, then Items well below it. */
.coins { display: grid; gap: 0.6rem; }
.coins-total { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
#section-inventory .section-heading { margin-bottom: 0.5rem; }
#section-inventory .section-heading .group-title { margin: 0; }
.inventory-items-heading { margin-top: 2rem; }
.coins .error { margin: 0; }
/* Amount, coin, Add, Spend: one row of controls, all the same height and text size. */
.coin-change { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0.5rem; padding-top: 0.5rem; }
.coin-change > * {
  height: 2.25rem; margin: 0; padding: 0 0.75rem;
  border: 1px solid var(--border-strong); border-radius: 6px; font: inherit; font-size: 0.9rem;
}
.coin-change input[type="text"] { width: 5rem; background: var(--bg); text-align: right; font-variant-numeric: tabular-nums; }
.coin-change select { min-width: 7.5rem; padding-right: 0.4rem; background: var(--bg); color: inherit; }
.coin-change button { padding: 0 1rem; }
#coins:has(.coins-form) { display: block; }
.coin-fields { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; }
.coin-field { display: grid; gap: 0.2rem; }
.coin-field label { margin: 0; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.coin-field input[type="text"] { width: 6rem; padding: 0.35rem 0.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.coins-form .form-actions { margin-top: 0.6rem; }
.item-list li.item-row {
  display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.35rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.item-list li.item-row:last-child { border-bottom: 0; }
.item-details { flex: 1; min-width: 0; }
.item-details > summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem; cursor: pointer; list-style: none; }
.item-details > summary::-webkit-details-marker { display: none; }
.item-details > summary:hover .item-name { color: var(--accent); }
.item-quantity { color: var(--muted); font-variant-numeric: tabular-nums; }
.item-more { display: grid; gap: 0.4rem; padding: 0.4rem 0 0.2rem; font-size: 0.9rem; }
.item-notes { display: flex; gap: 0.4rem; }
.item-features { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.item-features li { display: grid; gap: 0.05rem; }
.item-notes input[type="text"] { padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.item-actions { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.item-actions .link-button { font-size: 0.85rem; }
/* Remove: a quiet × at the end of each row; it turns into "Remove X? Remove · Keep" in place. */
.item-remove-button { padding: 0 0.3rem; background: none; color: var(--muted); font-size: 1.1rem; font-weight: 400; line-height: 1; }
.item-remove-button:hover { background: none; color: var(--error); }
.item-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; font-size: 0.9rem; }
.qty-steps { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.qty-step { width: 1.9rem; padding: 0.2rem 0; border-radius: 0; background: var(--surface); color: var(--text); }
.qty-step:hover:not(:disabled) { background: var(--border); }
.qty-step:disabled { color: var(--border-strong); cursor: not-allowed; }
#inventory-add:not(:empty) { margin-bottom: 0.75rem; }
.add-fields { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; }
.add-fields select { padding: 0.45rem 0.6rem; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: inherit; font: inherit; }
.add-fields input[name="quantity"] { width: 4.5rem; }

.add-custom { margin: 0.75rem 0 0; font-size: 0.9rem; }

/* Homebrew library and item editor */
.homebrew-item { align-items: flex-start; flex-wrap: nowrap; }
.homebrew-item-text { display: grid; gap: 0.15rem; min-width: 0; }
.homebrew-item-summary { margin: 0.2rem 0 0; font-size: 0.9rem; }
.homebrew-item-actions { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.homebrew-form { display: grid; gap: 1.5rem; max-width: 52rem; }
.homebrew-form > .error { margin: 0; }
.homebrew-part { display: grid; gap: 0.75rem; margin: 0; padding: 0; border: 0; min-width: 0; }
.homebrew-part > legend { margin: 0 0 0.75rem; padding: 0; }
.hb-field { display: grid; gap: 0.3rem; min-width: 0; }
.hb-field label, .hb-label { margin: 0; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.hb-row { display: flex; flex-wrap: wrap; align-items: end; gap: 0.75rem 1.25rem; }
.hb-hint { margin: 0; font-size: 0.85rem; }
.hb-check { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0; font-size: 0.9rem; }
.hb-checks { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; }
.homebrew-form select, .homebrew-form textarea {
  padding: 0.55rem 0.7rem; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: inherit; font: inherit;
}
.homebrew-form textarea { width: 100%; resize: vertical; }
.homebrew-form input.hb-number { width: 6rem; }
.hb-spell-row select[name="spell_id"] { min-width: 13rem; }
.hb-grow { flex: 1 1 12rem; }
.homebrew-form input.hb-small { width: 4.5rem; }
.hb-ability { display: grid; gap: 0.4rem; padding-bottom: 0.75rem; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }

.homebrew-form .has-error input, .homebrew-form .has-error select { border-color: var(--error); }
.homebrew-form .field-error { margin: 0; }

/* A report of what just happened, like a potion's roll in the HP panel. */
.notice { margin: 0 0 0.5rem; padding: 0.4rem 0.6rem; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); font-size: 0.9rem; }

/* Sharing: the owner's Share menu, and the shared view's note */
.page-header-actions { display: flex; align-items: center; gap: 1.25rem; }
.share-menu { position: relative; }
.share-menu > summary { list-style: none; cursor: pointer; }
.share-menu > summary::-webkit-details-marker { display: none; }
.share-panel { right: 0; left: auto; width: min(26rem, 90vw); display: grid; gap: 0.6rem; }
.share-text { margin: 0; font-size: 0.9rem; }
.share-link { display: flex; gap: 0.4rem; }
.share-link input[type="text"] { padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.share-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem; font-size: 0.9rem; }
.view-only-note { font-size: 0.9rem; }
span.pip { display: inline-block; cursor: default; }
span.pip:hover { background: none; }
span.pip.filled:hover { background: var(--accent); }
.page-header .share-menu { position: relative; }  /* also on phones, where vital menus go static */
