/* Mobile-first. Base = one column that stacks; wider screens get a grid. */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--serif);
  -webkit-text-size-adjust: 100%;
}
.boot { padding: 2rem; color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

#app {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 0.7rem 3rem;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 0.6rem 0.2rem;
  border-bottom: 1px solid var(--border);
}
.brand {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.02em;
  color: var(--accent2);
}
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn {
  font: 600 0.95rem var(--sans);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  min-height: 40px; /* comfy tap target */
}
.btn:hover { border-color: var(--rule); }
.btn:active { transform: translateY(1px); }
.theme-toggle { min-width: 40px; padding: 0.4rem; font-size: 1.1rem; line-height: 1; }

/* ---- page settings popover ---- */
.settings-wrap { position: relative; display: inline-flex; }
.settings-btn { min-width: 40px; padding: 0.4rem; font-size: 1.15rem; line-height: 1; }
.settings-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 214px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.7rem; box-shadow: 0 8px 30px var(--shadow); display: none;
}
.settings-panel.open { display: block; }
.settings-actions { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.6rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--border); }
.settings-actions-row { display: grid; gap: 0.3rem; }
.settings-actions-row.r3 { grid-template-columns: repeat(3, 1fr); }
.settings-actions-row.r2 { grid-template-columns: repeat(2, 1fr); }
.settings-actions .btn { width: 100%; justify-content: center; text-align: center; padding-inline: 0.35rem; }
.settings-head { font: 700 0.72rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.5rem; }
.settings-row { display: flex; align-items: center; gap: 0.5rem; font: 500 0.9rem var(--sans); color: var(--ink); cursor: pointer; }
.settings-row input { accent-color: var(--accent2); width: 16px; height: 16px; cursor: pointer; }
.settings-row + .settings-row { margin-top: 0.55rem; }
.settings-ver { display: block; margin-top: 0.7rem; padding-top: 0.6rem; border-top: 1px solid var(--border);
  font: 500 0.74rem var(--sans); color: var(--faint); text-align: center; text-decoration: none; }
.settings-ver:hover { color: var(--muted); }
.settings-slider { cursor: default; }
.settings-slider > span:first-child { flex: none; }
.settings-slider .fx-slider { flex: 1; min-width: 96px; width: auto; height: auto; cursor: pointer; }
.settings-slider .fx-slider:disabled { opacity: .4; cursor: default; }
.settings-val { flex: none; min-width: 2.6em; text-align: right; font: 600 0.72rem var(--sans); color: var(--muted); }

/* ---- cards / sections ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  margin-bottom: var(--gap);
  box-shadow: 0 1px 4px var(--shadow);
}
.section-title {
  margin: 0 0 0.7rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent2);
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

/* ---- generic fields ---- */
.field { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.field.stacked { flex-direction: column; align-items: stretch; gap: 0.25rem; }
.field-label { font: 600 0.8rem var(--sans); color: var(--muted); min-width: 3.2rem; text-transform: uppercase; letter-spacing: 0.03em; }
.field-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.field-row .field { margin-bottom: 0; }

input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45rem 0.5rem;
  min-height: 40px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }
textarea { width: 100%; resize: vertical; font-family: var(--serif); }
.grow { flex: 1; width: 100%; }
.num { width: 4.2rem; text-align: center; }
/* strip number spinners for a cleaner look */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- identity ---- */
.identity { display: grid; grid-template-columns: auto 1fr; gap: var(--gap); align-items: start; }
.portrait {
  width: 92px; height: 92px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  background: var(--field);
  display: grid; place-items: center;
}
.portrait-img { width: 100%; height: 100%; object-fit: cover; }
.identity-fields { min-width: 0; }

/* ---- attributes ---- */
.attr-cols { display: grid; grid-template-columns: 1fr; gap: var(--gap); }
.attr-col-head { display: flex; align-items: baseline; gap: 0.4rem; font: 700 0.9rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.4rem; }
.attr-total { color: var(--accent2); }
.attr-cards { display: grid; gap: 0.4rem; }
.attr-card {
  display: grid;
  grid-template-columns: 3.5rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.attr-name { font: 700 0.85rem var(--sans); color: var(--ink); }
.attr-fields { display: flex; gap: 0.3rem; }
.attr-base { width: 3rem; text-align: center; }
.attr-mod { width: 3rem; text-align: center; color: var(--muted); }
.attr-eff {
  min-width: 2rem; text-align: center;
  font: 700 1rem var(--sans);
  color: var(--accent2);
  padding: 0 0.3rem;
}

/* ---- resources ---- */
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.6rem; }
.res { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem; background: var(--field); border: 1px solid var(--border); border-radius: 6px; }
.res-label { font: 600 0.75rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.res-vals { display: flex; align-items: center; gap: 0.35rem; }
.res-cur { width: 3.4rem; text-align: center; }
.res-sep { color: var(--faint); }
.res-max { font-weight: 700; color: var(--accent2); min-width: 1.5rem; }

/* ---- dynamic lists (classes / elements / verbs / skills / perks) ---- */
.sublist { margin-bottom: 0.6rem; }
.sub-title { margin: 0.6rem 0 0.4rem; font: 700 0.8rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.casting-magic { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.li-rows { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.4rem; }
.li-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.li-name { text-transform: capitalize; min-width: 0; overflow-wrap: anywhere; }
.li-level { width: 3rem; text-align: center; padding: 0.3rem; min-height: 34px; }
.li-del {
  border: none; background: none; color: var(--faint);
  font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0 0.3rem; min-height: 34px;
}
.li-del:hover { color: var(--accent); }
.perk-row { grid-template-columns: 1fr auto; }
.li-row:has(.shard-warn) { grid-template-columns: 1fr auto auto auto; }
.shard-warn { color: var(--accent); cursor: help; font-size: 0.9rem; }

.add-combo { display: flex; gap: 0.4rem; }
.add-input { flex: 1; min-width: 0; min-height: 38px; }
.add-btn { min-width: 40px; padding: 0.4rem; font-size: 1.15rem; line-height: 1; }
.count-badge { font: 600 0.8rem var(--sans); color: var(--faint); }

@media (max-width: 480px) {
  .casting-magic { grid-template-columns: 1fr; }
}

/* ---- spellbook ---- */
.spell-attrs { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 0.4rem; margin-bottom: 0.8rem; }
.spell-attr { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; padding: 0.4rem; background: var(--field); border: 1px solid var(--border); border-radius: 6px; }
.spell-attr.power { border-color: var(--accent2); }
.sa-name { font: 600 0.7rem var(--sans); color: var(--muted); text-transform: capitalize; }
.sa-val { width: 3rem; text-align: center; }
.sa-val.readonly { font: 700 1.1rem var(--sans); color: var(--accent2); }

.spell-list { display: grid; grid-template-columns: 1fr; gap: 0.7rem; }
.spell-card { position: relative; padding: 0.7rem 0.8rem; background: var(--field); border: 1px solid var(--border); border-radius: 7px; }
.spell-card.custom { border-left: 3px solid var(--accent2); }
.spell-costs { position: absolute; top: 0.6rem; right: 0.7rem; display: flex; gap: 0.4rem; font: 600 0.85rem var(--sans); color: var(--accent2); }
.spell-name { font: 700 1.05rem var(--serif); color: var(--ink); margin-bottom: 0.15rem; padding-right: 3rem; }
.spell-school { display: flex; gap: 0.35rem; margin-bottom: 0.4rem; }
.elt-tag, .verb-tag { font: 600 0.68rem var(--sans); text-transform: uppercase; letter-spacing: 0.03em; padding: 0.1rem 0.4rem; border-radius: 4px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); }
.spell-meta { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.4rem; }
.spell-desc { font-size: 0.92rem; line-height: 1.5; }
.spell-desc .dyn, .spell-meta .dyn { color: var(--accent2); font-weight: 700; }
.spell-desc .elt { font-style: italic; }
.spell-del { position: absolute; bottom: 0.4rem; right: 0.5rem; }
.empty-hint { color: var(--muted); font-style: italic; margin: 0.3rem 0; }

.add-spell { margin-top: 0.8rem; }
.add-spell summary { cursor: pointer; color: var(--accent2); font: 600 0.9rem var(--sans); }
.add-spell-form { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.6rem; }
.add-spell-form select { min-height: 40px; }

/* ---- arsenal ---- */
.armor-block { margin-bottom: 0.9rem; }
.armor-total { color: var(--accent2); font-weight: 700; }
.armor-notes { margin: 0.4rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.85rem; }
.derived-num { font: 700 1rem var(--sans); color: var(--accent2); padding: 0 0.3rem; }

.weapons-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.weapons-table th { text-align: left; font: 600 0.7rem var(--sans); color: var(--muted); text-transform: uppercase; padding: 0.2rem 0.3rem; border-bottom: 1px solid var(--border); }
.weapons-table td { padding: 0.15rem 0.2rem; border-bottom: 1px solid var(--border); }
.weapons-table .cell { min-height: 32px; padding: 0.25rem 0.35rem; width: 100%; }
.weapons-table .w-name { min-width: 6rem; }
.weapons-table .w-sm { width: 4rem; }
.weapons-table .w-xs { width: 3rem; }
.weapons-table .w-note { min-width: 7rem; }
.weapons-table select.cell { min-width: 5rem; }

.attack-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.6rem; }
.attack-card { padding: 0.6rem 0.7rem; background: var(--field); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 7px; }
.attack-check { font: 700 0.95rem var(--sans); color: var(--accent2); margin: 0.15rem 0 0.35rem; }

/* ---- level-up draft ---- */
.lu-btn { border-color: var(--accent2); color: var(--accent2); }
.lu-overlay { position: fixed; inset: 0; z-index: 50; display: none; align-items: flex-start; justify-content: center; padding: 1rem; overflow-y: auto; background: rgba(0,0,0,0.6); }
.lu-overlay.visible { display: flex; }
.lu-panel { width: 100%; max-width: 1000px; background: var(--page); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; box-shadow: 0 8px 40px var(--shadow); margin: auto 0; }
.lu-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.lu-title { margin: 0; font-size: 1.25rem; color: var(--accent2); }
.lu-actions { display: flex; gap: 0.5rem; }
.lu-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.8rem; }
.lu-filter-search { flex: 1 1 180px; min-width: 140px; padding: 0.35rem 0.55rem; background: var(--field); color: var(--ink); border: 1px solid var(--border); border-radius: 6px; }
.lu-filter-sel { padding: 0.35rem 0.5rem; background: var(--field); color: var(--ink); border: 1px solid var(--border); border-radius: 6px; }
.lu-filter-avail { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); white-space: nowrap; cursor: pointer; }
.lu-filter-count { margin-left: auto; font-size: 0.82rem; color: var(--muted); }

/* type multi-select popover (Class / Element / Category) */
.lu-ms { position: relative; }
.lu-ms-btn { cursor: pointer; }
.lu-ms-btn::after { content: " ▾"; color: var(--muted); }
.lu-ms-menu { display: none; position: absolute; z-index: 30; top: calc(100% + 4px); left: 0;
  min-width: 230px; max-height: 60vh; overflow: auto; padding: 0.5rem 0.6rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45); }
.lu-ms.open .lu-ms-menu { display: block; }
.lu-ms-group + .lu-ms-group { margin-top: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.5rem; }
.lu-ms-grouphd { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.35rem;
  font: 700 0.68rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.lu-ms-grouphd span { margin-right: auto; }
.lu-ms-mini { font: 600 0.66rem var(--sans); color: var(--accent); background: none;
  border: 1px solid var(--border); border-radius: 4px; padding: 0.05rem 0.4rem; cursor: pointer; }
.lu-ms-mini:hover { border-color: var(--accent); }
.lu-ms-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.05rem 0.7rem; }
.lu-ms-opt { display: flex; align-items: center; gap: 0.35rem; padding: 0.12rem 0;
  font-size: 0.82rem; color: var(--ink); cursor: pointer; }
.lu-ms-opt input { margin: 0; }
.lu-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.9rem; }
.lu-card { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.7rem; background: var(--field); border: 1px solid var(--border); border-top: 4px solid var(--rule); border-radius: 8px; }
.lu-card.locked { opacity: 0.55; }
.lu-card.common { --rar: #8a8172; }
.lu-card.uncommon { --rar: #4f9e6a; }
.lu-card.scarce { --rar: var(--accent2); }
.lu-card.rare { --rar: #9b6dc9; }
.lu-card.legendary { --rar: var(--accent); }
/* rarity reads through the whole card border + the centred title colour (no separate label) */
.lu-card { border-color: var(--rar, var(--border));}
.lu-types { display: flex; align-items: center; font: 600 0.65rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); }

/* Level-up history / ledger */
.lu-history { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 1px; }
.lu-log { display: grid; grid-template-columns: 11rem 1fr; gap: 0.6rem; align-items: baseline; padding: 0.3rem 0.5rem; border-radius: 5px; font-size: 0.86rem; }
.lu-log:nth-child(odd) { background: color-mix(in srgb, var(--field) 60%, transparent); }
.lu-log-when { color: var(--faint); font: 0.72rem/1.3 var(--sans); white-space: nowrap; }
.lu-log-msg { color: var(--muted); }
.lu-log.start .lu-log-msg { color: var(--ink); }
.lu-log.chosen { background: color-mix(in srgb, var(--accent2) 14%, var(--field)); }
.lu-log.chosen .lu-log-msg { color: var(--accent2); font-weight: 700; }
.lu-log.reroll .lu-log-msg { font-style: italic; color: var(--faint); }
.lu-log.edit { border-left: 2px solid color-mix(in srgb, var(--rule) 45%, transparent); }
.lu-log.edit .lu-log-msg { color: var(--muted); }
@media (max-width: 520px) { .lu-log { grid-template-columns: 1fr; gap: 0; } }
.lu-name { font: 700 1.05rem var(--serif); color: var(--rar, var(--ink)); text-align: center; }
.lu-effect { font-size: 0.88rem; line-height: 1.45; flex: 1; margin-bottom: 0.55rem;}
.lu-choice { width: 100%; min-height: 40px; }
.lu-roll { display: flex; align-items: center; gap: 0.6rem; }
.lu-roll-val { font: 700 1.3rem var(--sans); color: var(--accent2); min-width: 1.5rem; text-align: center; }
.lu-reqs { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.lu-req { font: 600 0.68rem var(--sans); padding: 0.1rem 0.4rem; border-radius: 4px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); }
.lu-req.unmet { color: var(--broken); border-color: var(--broken); }
.lu-choose { border-color: var(--accent2); color: var(--accent2); }
.lu-choose:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- wider screens ---- */
@media (min-width: 620px) {
  #app { padding: 0 1rem 3rem; }
  .attr-cols { grid-template-columns: repeat(3, 1fr); }
}
/* (#app stays a plain block; hero/attributes/rows are full-width blocks) */

/* =========================================================================
   REDESIGN PASS — hero, vitals, compact attributes, masonry, Archipel skin
   ========================================================================= */

/* subtle warm vignette for atmosphere */
body {
  background:
    radial-gradient(130% 90% at 50% -10%, color-mix(in srgb, var(--bg) 82%, #35291c) 0%, var(--bg) 55%) no-repeat fixed,
    var(--bg);
}

/* headings: serif + the rulebook's fading gradient underline */
.section-title {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--title-ink, var(--accent2));
  border-bottom: none;
  padding-bottom: 0.28rem;
  margin: 0 0 0.85rem;
  letter-spacing: 0.01em;
  background: linear-gradient(to right, var(--title-ink, var(--accent2)) 0%, var(--title-ink, var(--accent2)) 38%, transparent 100%) left bottom / 100% 2px no-repeat;
}
.brand { font-family: var(--serif); font-weight: 800; font-size: 1.55rem; }

/* cards: warmer material — top highlight + softer depth */
.card {
  box-shadow: 0 2px 7px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.045);
}

/* soften the second layer of borders so it's not boxes-in-boxes */
.li-row, .res, .attr-tile, .lu-req { border-color: color-mix(in srgb, var(--border) 70%, transparent); }

/* ---- hero header ---- */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 1rem; align-items: start; position: relative; overflow: hidden; isolation: isolate; }
/* faint class emblem watermark, centred in the middle block's often-empty right area,
   behind all content (anchored within .hero-main) */
.hero-emblem {
  position: absolute; z-index: -1; pointer-events: none; user-select: none;
  right: 0; top: 50%; transform: translateY(-50%);
  height: 90%; width: auto; max-width: 58%; object-fit: contain; object-position: center;
  opacity: 0.25;
}
.hero-portrait {
  width: 160px; height: 160px; flex: none;
  border-radius: 12px; overflow: hidden; cursor: pointer;
  border: 2px solid var(--rule); background: var(--field);
  box-shadow: 0 2px 10px var(--shadow);
}
.hero-portrait-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-main { min-width: 0; display: flex; flex-direction: column; gap: 0.55rem; position: relative; }
.hero-name {
  font: 700 1.85rem var(--serif); color: var(--ink);
  background: transparent; border: none; border-bottom: 2px solid transparent;
  padding: 0.05rem 0.1rem; width: 100%; min-height: auto;
}
.hero-name:focus { outline: none; border-bottom-color: var(--accent2); }
.hero-name-row { display: flex; align-items: center; gap: 0.5rem; }
.hero-name-row .hero-name { flex: 1 1 auto; min-width: 0; width: auto; }
.hero-name-row .hero-adv { flex: none; }
.hero-name-row .hero-notes { flex: none; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; align-items: center; }
.level-group { display: flex; align-items: center; gap: 0.35rem; }
.lvlup-btn { min-height: 32px; min-width: 34px; padding: 0.28rem 0.5rem; font-size: 1rem; line-height: 1; font-weight: 700; color: var(--accent2); border-color: var(--accent2); }
.meta { display: flex; align-items: center; gap: 0.35rem; }
.meta-label { font: 600 0.66rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.meta-input { width: auto; min-width: 2.4rem; min-height: 32px; padding: 0.22rem 0.4rem; }
.meta-num { width: 3rem; text-align: center; }
.meta-derived { font: 700 1rem var(--sans); color: var(--accent2); }

.hero-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { font: 600 0.72rem var(--sans); padding: 0.18rem 0.55rem; border-radius: 999px; background: var(--field); border: 1px solid var(--border); color: var(--ink); }
.chip-class { border-color: var(--rule); }
.chip-elt { border-color: var(--accent2); }
.chip-muted { color: var(--faint); font-style: italic; border-style: dashed; }

/* ---- vital bars ---- */
.hero-vitals { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; margin-top: 0.1rem; }
.vital { flex: 1 1 150px; min-width: 140px; }
.vital-label { font: 600 0.66rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); display: block; margin-bottom: 0.15rem; }
.vital-head { display: flex; align-items: center; justify-content: space-between; gap: 0.3rem; margin-bottom: 0.15rem; }
.vital-head .vital-label { margin-bottom: 0; }
.vital-mod { width: 2.3rem; margin-top: 0; }
.vital-track { position: relative; height: 26px; border-radius: 6px; background: var(--field); border: 1px solid var(--border); overflow: hidden; }
.vital-fill { position: absolute; left: 0; top: 0; bottom: 0; opacity: 0.5; transition: width 0.25s ease; }
.vital-hp { background: var(--accent); }
.vital-mana { background: var(--accent2); }
.vital-stam { background: var(--rule); }
.vital-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 0.05rem; font: 700 0.95rem var(--sans); }
.vital-cur { width: 2.4rem; text-align: right; background: transparent; border: none; color: var(--ink); padding: 0; min-height: auto; font: inherit; }
.vital-cur:focus { outline: none; }
.vital-max { color: var(--ink); opacity: 0.75; }
.hero-pill { display: flex; flex-direction: column; align-items: center; gap: 0.05rem; padding: 0.2rem 0.5rem; background: var(--field); border: 1px solid var(--border); border-radius: 6px; }
.pill-label { font: 600 0.58rem var(--sans); text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.pill-val { width: 2.6rem; text-align: center; padding: 0.18rem; min-height: 30px; }
.hero-pill.warn .pill-val { color: var(--accent); }

/* ---- compact attributes ---- */
.attr-col-head { display: flex; justify-content: space-between; align-items: baseline; font: 700 0.78rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.45rem; }
.attr-col-head .attr-total { color: var(--accent2); font-size: 1.05rem; }
.attr-tiles { display: grid; gap: 0.35rem; }
.attr-tile { display: grid; grid-template-columns: 2.2rem 1fr auto; align-items: center; gap: 0.4rem; padding: 0.25rem 0.45rem; background: var(--field); border: 1px solid var(--border); border-radius: 6px; }
.attr-abbr { font: 700 0.72rem var(--sans); color: var(--muted); }
.attr-eff { font: 700 1.35rem var(--sans); color: var(--accent2); text-align: center; }
.attr-edit { display: flex; gap: 0.2rem; }
.attr-in { width: 2.4rem; text-align: center; padding: 0.2rem; min-height: 30px; font-size: 0.85rem; }
.attr-mod { color: var(--muted); }

/* ---- notes ---- */
.note-field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.6rem; }

/* ---- layout: full-width hero + attributes, then fixed 2-up rows. Grid cells
   (not multicol) so a card growing — or the haunt visiting — never reshuffles
   its neighbours. align-items:start lets each card size to its own content. ---- */
.sheet-row { display: grid; grid-template-columns: 1fr; gap: var(--gap); align-items: start; margin-top: var(--gap); }
@media (min-width: 900px) {
  .sheet-row.two { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1300px) {
  #app { max-width: 1280px; }
}

/* topbar must not overflow on phones */
.btn { white-space: nowrap; }
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .btn { padding: 0.4rem 0.6rem; font-size: 0.85rem; min-height: 38px; }
  .lu-btn, .theme-toggle { min-height: 38px; }
  .hero-name { font-size: 1.45rem; }
}

/* ---- level-up card art ---- */
.lu-card { overflow: hidden; padding-top: 0; }
.lu-art {
  height: 88px; margin: 0 -0.7rem 0.55rem; background-size: cover; background-position: center 28%;
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 -34px 26px -22px var(--field);
  cursor: zoom-in;
}
.lu-card > .lu-types { padding: 0 0.05rem; }

/* card gallery — rotating art of taken cards (page setting) */
.card-gallery .cg-frame {
  height: 350px; border-radius: 8px; border: 1px solid var(--border);
  background-size: cover; background-position: center 28%; cursor: zoom-in;
  box-shadow: inset 0 -46px 34px -28px var(--field);
}

/* click-to-zoom full card art */
.art-lightbox {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 2rem; background: rgba(0, 0, 0, 0.85); cursor: zoom-out;
}
.art-lightbox-img { max-width: 100%; max-height: 100%; border-radius: 6px; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6); }

/* =========================================================================
   HERO ROW v2 — full-height portrait · main · resources section
   ========================================================================= */
.hero { grid-template-columns: auto 1fr auto; align-items: stretch; gap: 1.1rem; }
.hero-portrait { width: 177px; height: auto; align-self: stretch; min-height: 130px; border-radius: 10px; position: relative; }
.hero-portrait-img { width: 100%; height: 100%; object-fit: cover; }

/* per-class portrait frame: the frame art IS the chrome. Fixed width + aspect-ratio for
   the height (Firefox derives height-from-width fine; it collapses on width-from-height,
   and align-self:stretch+height:100% blows up when no sibling sets the row height). The
   portrait sits BEHIND, in an opening DIV inset per class (an <img> is replaced and won't
   fill insets), showing through the frame's transparent window. */
.hero-portrait.framed {
  width: 210px; aspect-ratio: 1024 / 1280; height: auto; align-self: start;
  border: none; background: none; box-shadow: none; overflow: visible; border-radius: 0;
}
.hero-portrait-opening { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; z-index: 1; }
.hero-portrait.framed .hero-portrait-opening { border-radius: 2px; }
.hero-portrait-frame { display: none; }
.hero-portrait.framed .hero-portrait-frame {
  display: block; position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: fill; z-index: 2; pointer-events: none;
}
.hero-main { justify-content: center; gap: 0.6rem; }

/* resources get their own bordered section on the right */
.hero-resources {
  display: flex; flex-direction: column; justify-content: center; gap: 0.6rem;
  min-width: 240px; padding-left: 1.1rem; border-left: 1px solid var(--border);
}
.hero-vitals { flex-direction: column; align-items: stretch; gap: 0.45rem; }
.hero-vitals .vital { flex: none; min-width: 0; }
.hero-pills { display: flex; gap: 0.5rem; }
.hero-pills .hero-pill { flex: 1; flex-direction: row; justify-content: space-between; align-items: center; }

/* class resources — themed pip counters (Rage, Chi, Force…) */
.class-resources { display: flex; flex-direction: column; gap: 0.4rem; }
.class-resources:empty { display: none; }
.cres { display: flex; align-items: center; gap: 0.55rem; }
.cres-head { display: flex; align-items: center; gap: 0.25rem; min-width: 4.6rem; }
.cres-name { font: 700 0.62rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.cres-hint { display: inline-flex; align-items: center; justify-content: center; width: 0.95rem; height: 0.95rem; border-radius: 50%; border: 1px solid var(--border); color: var(--muted); font: 600 0.6rem var(--sans); cursor: help; }
.cres-pips { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.cres-pip { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--field); border: 1px solid var(--border); box-sizing: border-box; }
.cres-pip-img { width: 88%; height: 88%; object-fit: contain; }
.cres-pips:not(.open) .cres-pip { cursor: pointer; transition: transform 0.08s, border-color 0.15s, box-shadow 0.15s; }
.cres-pips:not(.open) .cres-pip:hover { transform: scale(1.12); border-color: var(--accent); }
.cres-pip.filled { border-color: color-mix(in srgb, var(--accent2) 55%, var(--border)); box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.4); }
.cres-pip.filled .cres-pip-img { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.6)); }
.cres-pip.empty .cres-pip-img { filter: grayscale(1) brightness(0.7); opacity: 0.16; }
.cres-pips.open { gap: 0.3rem; }
.cres-count { font: 800 0.95rem var(--sans); min-width: 1.2rem; text-align: center; }
.cres-step { width: 1.5rem; height: 1.5rem; padding: 0; border: 1px solid var(--border); background: var(--field); border-radius: 5px; color: var(--ink); font: 700 1rem var(--sans); line-height: 1; cursor: pointer; }
.cres-step:hover { border-color: var(--accent); color: var(--accent); }

/* prominent class / element chips */
.hero-chips { gap: 0.4rem; margin-top: 0.1rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font: 700 0.85rem var(--sans); padding: 0.3rem 0.7rem; border-radius: 999px;
  border: 1.5px solid var(--border); text-transform: capitalize;
}
.chip b { font-weight: 800; opacity: 0.8; font-size: 0.92em; }
.chip-class { border-color: var(--rule); background: color-mix(in srgb, var(--rule) 13%, transparent); color: var(--ink); }
.chip-elt.elt-fire   { border-color: #c9542a; color: #e2925f; background: color-mix(in srgb, #c9542a 15%, transparent); }
.chip-elt.elt-water  { border-color: #2f8fb0; color: #74c2da; background: color-mix(in srgb, #2f8fb0 15%, transparent); }
.chip-elt.elt-air    { border-color: #6aa9c4; color: #a3d2e2; background: color-mix(in srgb, #6aa9c4 15%, transparent); }
.chip-elt.elt-earth  { border-color: #b0894a; color: #d3ad6c; background: color-mix(in srgb, #b0894a 15%, transparent); }
.chip-elt.elt-light  { border-color: #c9a83f; color: #e3c774; background: color-mix(in srgb, #c9a83f 15%, transparent); }
.chip-elt.elt-shadow { border-color: #8a72b3; color: #b59fda; background: color-mix(in srgb, #8a72b3 15%, transparent); }
.chip-elt.elt-body   { border-color: #c25a45; color: #e0917d; background: color-mix(in srgb, #c25a45 15%, transparent); }

/* stack on narrow: portrait+main top, resources full-width below (bars go horizontal) */
@media (max-width: 820px) {
  .hero { grid-template-columns: auto 1fr; }
  .hero-resources { grid-column: 1 / -1; min-width: 0; padding-left: 0; padding-top: 0.7rem; border-left: none; border-top: 1px solid var(--border); }
  .hero-vitals { flex-direction: row; flex-wrap: wrap; }
  .hero-vitals .vital { flex: 1 1 150px; }
}

/* ---- hero: collapsible description + free resources ---- */
.desc-collapsible { margin-top: 0.15rem; }
.desc-preview {
  display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; white-space: pre-wrap; cursor: text;
  font-size: 0.9rem; line-height: 1.4; color: var(--muted);
  border-left: 2px solid var(--border); padding: 0.1rem 0 0.1rem 0.6rem;
}
.desc-preview:hover { border-left-color: var(--rule); }
.desc-preview.empty { font-style: italic; color: var(--faint); }
.desc-edit { width: 100%; min-height: 4rem; resize: vertical; }

.hero-free { display: block; margin-top: 0.1rem; }
.free-input {
  width: 100%; min-height: 2.4rem; resize: vertical; font-size: 0.85rem;
  color: var(--muted); background: var(--field);
}
.free-input::placeholder { font-style: italic; color: var(--faint); }

/* path opt-ins popup */
.optins-open { align-self: flex-start; }
.optin-intro { margin: 0 0 0.8rem; font-size: 0.85rem; color: var(--muted); line-height: 1.45; }
.optin-section { margin: 1rem 0 0.5rem; font: 700 0.75rem var(--sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent2); }
.optin-group { margin-bottom: 0.7rem; }
.optin-group-title { margin: 0.4rem 0 0.25rem; font: 700 0.72rem var(--sans); text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.optin-row { display: flex; gap: 0.55rem; align-items: flex-start; padding: 0.3rem 0.35rem; border-radius: 6px; cursor: pointer; }
.optin-row:hover { background: var(--field); }
.optin-row input { margin-top: 0.2rem; flex: none; }
.optin-body { min-width: 0; }
.optin-head { display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap; }
.optin-tag { font: 700 0.6rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); border: 1px solid var(--border); border-radius: 4px; padding: 0.02rem 0.3rem; }
.optin-desc { font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.optin-module { margin-bottom: 0.6rem; padding-top: 0.4rem; border-top: 1px dashed var(--border); }
.optin-module-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.2rem; color: var(--ink); }
.optin-loader { margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.5rem; }
.optin-paste { width: 100%; box-sizing: border-box; resize: vertical; min-height: 3rem; padding: 0.4rem 0.5rem; font: 0.8rem/1.4 var(--mono, monospace); }
.optin-loader-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.optin-err { font-size: 0.82rem; color: var(--accent); min-height: 1em; }
.optin-err.ok { color: #4f9e6a; }

/* error toasts (see ui/toast.js) — red, dismissable, with a "Copy details" button */
.toast-stack { position: fixed; bottom: 1rem; right: 1rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(92vw, 430px); }
.toast { display: flex; align-items: center; gap: 0.55rem; padding: 0.6rem 0.7rem; border-radius: 8px; font-size: 0.85rem; line-height: 1.35; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45); animation: toast-in 0.18s ease-out; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s; }
.toast-error { background: #7f1d1d; color: #ffe9e9; border: 1px solid #c0392b; }
.toast-ico { font-size: 1rem; flex: none; }
.toast-msg { flex: 1; min-width: 0; }
.toast-copy { flex: none; background: rgba(255, 255, 255, 0.16); color: inherit; border: 1px solid rgba(255, 255, 255, 0.32); border-radius: 5px; padding: 0.18rem 0.5rem; font-size: 0.78rem; cursor: pointer; white-space: nowrap; }
.toast-copy:hover { background: rgba(255, 255, 255, 0.26); }
.toast-x { flex: none; background: none; border: none; color: inherit; font-size: 1.15rem; line-height: 1; cursor: pointer; padding: 0 0.15rem; opacity: 0.8; }
.toast-x:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* action-token tracker (optional, page setting) — one counter box per token type */
.token-tracker { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.5rem; margin-top: 0.3rem; }
.tt-head { display: inline-flex; align-items: baseline; gap: 0.3rem; font: 700 0.72rem var(--sans); text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.tt-draw { font: 800 1rem var(--sans); color: var(--accent2); cursor: pointer; }
.tt-grid { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; }
.tt-tok { display: inline-flex; flex-direction: column; align-items: center; gap: 0.02rem; min-width: 2.1rem; padding: 0.2rem 0.25rem 0.15rem; background: var(--field); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; user-select: none; transition: border-color .1s, opacity .1s; }
.tt-tok:hover { border-color: var(--accent2); }
.tt-tok.zero { opacity: 0.5; }
.tt-ico { font-size: 1rem; line-height: 1.1; }
.tt-n { font: 800 0.85rem var(--sans); color: var(--accent2); line-height: 1; }
.tt-tok.zero .tt-n { color: var(--faint); }

/* =========================================================================
   Hero meta line v3 + advanced modal
   ========================================================================= */
.hero-main { justify-content: flex-start; }        /* name aligned to the top */
.hero-resources { justify-content: flex-start; }
.hero-meta { align-items: center; }
.meta-race { min-width: 5rem; width: auto; font-weight: 600; }
.hero-chips { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }

.adv-btn { min-height: 32px; min-width: 34px; padding: 0.28rem 0.5rem; font-size: 0.95rem; line-height: 1; }
.hero-adv { margin-left: auto; }

/* modal (reusable across sections for rarely-used controls) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: flex-start; justify-content: center; padding: 1rem; overflow-y: auto;
  background: rgba(0, 0, 0, 0.6);
}
.modal-overlay.visible { display: flex; }
.modal-panel {
  width: 100%; max-width: 640px; margin: auto 0;
  background: var(--page); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 40px var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.modal-title { margin: 0; font: 700 1.15rem var(--serif); color: var(--accent2); }
.modal-body { padding: 1rem; }
.adv-content { display: flex; flex-direction: column; gap: 1rem; }
.adv-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.adv-size { border-top: 1px solid var(--border); padding-top: 0.8rem; }
.adv-hint { margin: 0.4rem 0 0; font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
@media (max-width: 560px) { .adv-lists { grid-template-columns: 1fr; } }

/* preview fills the leftover column height (max-height set in JS); editing shows full text */
.desc-collapsible { display: block; }
.desc-preview {
  display: block; -webkit-line-clamp: none; line-clamp: none;
  overflow: hidden;
}
/* fade the cut-off edge only when there is actually more text below (toggled in JS) */
.desc-preview.clamped {
  -webkit-mask-image: linear-gradient(to bottom, #000 80%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 80%, transparent 100%);
}
.desc-edit { min-height: 4rem; }

/* =========================================================================
   Attributes v2 — compact classic stat boxes (base big, modifier small)
   ========================================================================= */
.attr-cols { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 620px) { .attr-cols { grid-template-columns: repeat(3, 1fr); } }
.attr-col-head { display: flex; align-items: baseline; justify-content: space-between; font: 700 0.78rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.45rem; }
.attr-col-head .attr-total { color: var(--accent2); font-size: 1.05rem; }
.attr-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); gap: 0.35rem; }
.attr-box {
  display: flex; flex-direction: column; align-items: center; gap: 0.05rem;
  padding: 0.3rem 0.15rem 0.25rem; background: var(--field);
  border: 1px solid var(--border); border-radius: 7px; cursor: text;
}
.attr-abbr { font: 700 0.62rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; }
.attr-base {
  width: 100%; text-align: center; background: transparent; border: none;
  font: 800 1.5rem var(--sans); color: var(--ink); padding: 0; min-height: auto; line-height: 1.1;
}
.attr-base:focus { outline: none; color: var(--accent2); }
/* Modifier chip — a small overlaid slot with a faded "+0", reading clearly as a
   place to add a temporary bonus. Shared by attributes and the vital max-mods. */
.attr-mod {
  width: 2.3rem; margin-top: 0.12rem; text-align: center;
  background: color-mix(in srgb, var(--border) 38%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  border-radius: 5px;
  font: 700 0.72rem var(--sans); color: var(--faint); padding: 0.05rem 0; min-height: 1.05rem; line-height: 1;
}
.attr-mod::placeholder { color: color-mix(in srgb, var(--faint) 70%, transparent); }
.attr-mod:focus { outline: none; color: var(--ink); border-color: var(--accent2); }
.attr-mod.pos { color: #4f9e6a; }
.attr-mod.neg { color: var(--accent); }

.attr-boxes { grid-template-columns: repeat(5, 1fr); }
/* Magic attributes reuse .attr-box but sit in the Magic card, not the 3-group attribute grid.
   Size their container as a fraction so each box equals a character attribute box (5 fluid
   boxes fill it). The fraction depends on the layout regime, so it steps at the same
   breakpoints: attr goes 3-column at 620px, the Magic card goes half-width at 900px. */
.attr-boxes.magic-boxes { max-width: 100%; margin-inline: auto; }           /* <620: attr 1-col, Magic full-width */
@media (min-width: 620px) { .attr-boxes.magic-boxes { max-width: 33.3%; } } /* attr 3-col, Magic still full-width */
@media (min-width: 900px) { .attr-boxes.magic-boxes { max-width: 66%; } }   /* attr 3-col, Magic card half-width */

/* attributes: larger base + column separators */
.attr-base { font-size: 1.92rem; }
@media (min-width: 620px) {
  .attr-cols { gap: 0; }
  .attr-col { padding: 0 1.1rem; }
  .attr-col:first-child { padding-left: 0; }
  .attr-col:last-child { padding-right: 0; }
  .attr-col:not(:last-child) { border-right: 1px solid var(--border); }
}

/* ---- perks v2: compact chips + description + advanced ---- */
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.85rem; }
.sec-head .section-title { flex: 1; margin-bottom: 0; }
.sec-adv { min-height: 30px; min-width: 32px; padding: 0.24rem 0.45rem; font-size: 0.9rem; line-height: 1; }

/* Shards sub-block: a gallery row of the held shards, under the magic attributes */
.shards-block { margin-top: 0.7rem; }
.shard-row { display: flex; flex-wrap: wrap; gap: 0.5rem 0.6rem; }
.shard-card { display: flex; flex-direction: column; align-items: center; gap: 0.12rem; width: 58px; cursor: help; }
.shard-card-img {
  width: 48px; height: 48px; object-fit: contain; border-radius: 50%; padding: 3px;
  background: radial-gradient(circle, color-mix(in srgb, var(--sc, #8a8a8a) 24%, transparent) 0%, transparent 68%);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.28));
}
.shard-card-name { font-size: 0.63rem; line-height: 1.05; text-align: center; color: var(--muted); text-transform: capitalize; }
.shard-card.elt-fire   { --sc: #c9542a; }
.shard-card.elt-water  { --sc: #2f8fb0; }
.shard-card.elt-air    { --sc: #6aa9c4; }
.shard-card.elt-earth  { --sc: #b0894a; }
.shard-card.elt-light  { --sc: #c9a83f; }
.shard-card.elt-shadow { --sc: #8a72b3; }

.perk-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.5rem; }
.perk-chip {
  display: inline-flex; align-items: baseline; gap: 0.25rem;
  padding: 0.25rem 0.6rem; border-radius: 999px;
  background: var(--field); border: 1px solid var(--border);
  font-size: 0.85rem; cursor: pointer; text-transform: capitalize;
}
.perk-chip:hover { border-color: var(--rule); }
.perk-lvl { color: var(--accent2); font-weight: 800; font-size: 0.85em; }
.chip-spec { color: var(--muted); font-style: italic; font-size: 0.9em; }
.perk-desc { font-size: 0.88rem; line-height: 1.45; color: var(--muted); padding: 0.55rem 0.65rem; background: var(--field); border: 1px solid var(--border); border-radius: 6px; }
.perk-desc b { color: var(--ink); }

/* custom-perk creator (in the Add/remove perks popup) */
.cp-create { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.5rem; }
.cp-title { margin: 0; font: 700 0.72rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.cp-name { width: 100%; }
.cp-desc { width: 100%; box-sizing: border-box; resize: vertical; min-height: 3rem; padding: 0.4rem 0.5rem; line-height: 1.4; }
.cp-add-btn { align-self: flex-start; }
.cp-list { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.cp-list:empty { display: none; }
.cp-list-lbl { font: 600 0.72rem var(--sans); color: var(--faint); }
.cp-chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.5rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.82rem; color: var(--ink); }
.cp-del { background: none; border: none; color: var(--faint); cursor: pointer; font-weight: 700; padding: 0; line-height: 1; }
.cp-del:hover { color: var(--accent); }
.perk-empty { color: var(--faint); font-style: italic; font-size: 0.9rem; }
.li-plus { color: var(--accent2); font-size: 1.1rem; }

/* ---- arsenal: page summary + wide advanced popup ---- */
.modal-panel.wide { max-width: 920px; }

/* Notebook popup */
.modal-panel.notes-modal { max-width: 960px; }
.notebook { display: flex; flex-direction: column; gap: 0.6rem; }
.nb-tabs { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: flex-end; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.nb-tab { background: var(--field); border: 1px solid var(--border); border-radius: 7px 7px 0 0; padding: 0.32rem 0.6rem; font: 600 0.85rem var(--sans); color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }
.nb-tab.active { color: var(--ink); border-color: var(--rule); background: color-mix(in srgb, var(--rule) 12%, var(--field)); }
.nb-tab.nb-add { color: var(--faint); font-weight: 700; padding-inline: 0.55rem; }
.nb-x { color: var(--faint); font-weight: 700; line-height: 1; padding: 0 0.2rem; border-radius: 4px; }
.nb-x:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.nb-text { width: 100%; height: 62vh; resize: vertical; box-sizing: border-box; padding: 0.6rem 0.7rem; font: 0.95rem/1.55 var(--sans); background: var(--field); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; }
.arsenal-adv { display: flex; flex-direction: column; gap: 1rem; }

.arsenal-summary { display: flex; flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 1rem 1.2rem; }
.armor-col { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; flex: none; }
.armor-col > .field-label { align-self: flex-start; }
.summary-row { display: flex; align-items: center; gap: 0.6rem; }
.armor-summary { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
.armor-desc { color: var(--muted); font-size: 0.9rem; text-align: center; }
/* per-damage-type armour breakdown (only types with a value > 0) + resistances */
.armor-types { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; width: 100%; }
.armor-type-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem; }
.armor-type {
  display: flex; flex-direction: column; align-items: center; min-width: 3rem;
  padding: 0.15rem 0.4rem 0.25rem; border: 1px solid var(--border); border-radius: 6px; background: var(--field);
}
.armor-type .at-val { font: 700 1.05rem var(--sans); color: var(--ink); line-height: 1.1; }
.armor-type .at-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.armor-type-immaterial { border-color: color-mix(in srgb, var(--accent) 42%, var(--border)); }
.armor-type-immaterial .at-label { color: color-mix(in srgb, var(--accent) 70%, var(--muted)); }
.armor-resists { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.3rem; max-width: 230px; }
.armor-resists .ar-label { font: 700 0.62rem var(--sans); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); opacity: 0.75; }
.armor-resists .ar-item { font-size: 0.74rem; color: var(--muted); padding: 0.05rem 0.4rem; border: 1px solid var(--border); border-radius: 4px; background: var(--field); }

/* chest piece + round class-coloured armour badge */
.armor-chest { position: relative; flex: none; width: 110px; display: flex; align-items: center; justify-content: center; }
.armor-chest-img { display: block; width: 100%; height: auto; }
.armor-chest:not(.has-chest) .armor-chest-img { display: none; }
.armor-chest:not(.has-chest) { width: auto; }
.armor-badge {
  position: absolute; top: 46%; left: 50%; transform: translate(-50%, -50%);
  min-width: 1.9em; height: 1.9em; padding: 0 0.2em; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--badge-col, var(--accent2));
  border: 2px solid rgba(0, 0, 0, 0.45);
  color: #fff; font: 800 1.05rem var(--sans);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.armor-chest:not(.has-chest) .armor-badge { position: static; transform: none; }

.equipped { display: flex; flex-direction: column; gap: 0.4rem; flex: 1 1 220px; min-width: 200px; }
.equip-head { display: flex; align-items: center; gap: 0.6rem; }
.equip-select { flex: 1; max-width: 16rem; min-height: 38px; }
.equip-card .attack-card { margin: 0; }
.equip-actions { display: flex; flex-direction: column; gap: 0.4rem; }
.equip-actions:empty { display: none; }
.attack-card.class-attack { border-left: 3px solid var(--accent2); }
.ca-tag { font: 600 0.6rem var(--sans); text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin-left: 0.45rem; vertical-align: middle; }

/* ---- attack modifiers on the attack card ---- */
.attack-mods { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin-top: 0.5rem; }
.attack-mods:empty { display: none; }
.mods-label { font: 600 0.68rem var(--sans); text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.attack-mod { font: 600 0.78rem var(--sans); padding: 0.15rem 0.5rem; border-radius: 999px; background: color-mix(in srgb, var(--accent) 15%, transparent); border: 1px solid var(--accent); color: var(--accent); cursor: help; }

/* ---- spellbook: merged summary + wide popup ---- */
.spell-summary { display: flex; flex-direction: column; gap: 0.9rem; }
.sub-block > .sub-title { margin-top: 0; }
.magic-boxes { grid-template-columns: repeat(5, 1fr); }  /* like the character grid; width set by .attr-boxes.magic-boxes max-width */
.attr-base.readonly { color: var(--accent2); }
.attr-spacer { min-height: 1rem; }
.spellbook-adv { display: flex; flex-direction: column; gap: 1rem; }
.spellbook-adv .spell-list { max-height: 55vh; overflow-y: auto; }

/* ---- spellbook: bare closed-grimoire button, sharing the Verbs row (right-aligned) ---- */
.magic-verbs-row { display: flex; align-items: center; gap: 1rem; }
.magic-verbs-row .sub-block { flex: 1; min-width: 0; }
.sb-btn { flex: none; background: none; border: none; padding: 0; cursor: pointer; line-height: 0; transition: transform .12s ease; }
.sb-btn:hover { transform: translateY(-2px) scale(1.03); }
.sb-btn:active { transform: translateY(0); }
.sb-book-btn { height: 78px; width: auto; display: block; filter: drop-shadow(0 3px 7px rgba(0, 0, 0, .5)); }

/* ---- spellbook: the open grimoire (popup), two-page spread over the book art ---- */
.sb-overlay {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  padding: 1rem; overflow: auto; background: rgba(0, 0, 0, 0.72);
}
.sb-stack { position: relative; display: flex; flex-direction: column; align-items: center; gap: .6rem; margin: auto; width: min(780px, 96vw); }
.sb-open {
  --sb: var(--accent2); --ink-page: #3b2f1c;
  position: relative; width: 100%; aspect-ratio: 1280 / 1024;
  background: url(../assets/fx/spellbook/open.png) center/contain no-repeat;
  filter: drop-shadow(0 14px 40px rgba(0,0,0,.6));
}
/* the reminder + remap strip above the book */
.sb-topbar {
  width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .5rem 1.1rem;
  padding: .5rem .7rem; border-radius: 10px; color: var(--ink);
  background: rgba(20, 17, 12, .85); border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}
.sb-magic-strip { display: flex; gap: .35rem; flex-wrap: wrap; }
.sb-mbox {
  display: flex; flex-direction: column; align-items: center; min-width: 46px;
  padding: .2rem .4rem; border-radius: 6px; border: 1px solid var(--border); background: rgba(255, 255, 255, .03);
}
.sb-mbox.remapped { border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 15%, transparent); }
.sb-power { justify-content: space-between; }
.sb-power-in {
  width: 2.6rem; text-align: center; font: 800 1.05rem var(--serif); color: var(--ink); line-height: 1.1;
  background: var(--field); border: 1px solid var(--border); border-radius: 5px; padding: .05rem .1rem; margin-top: .1rem;
}
.sb-mabbr { font: 600 .58rem var(--sans); color: var(--muted); letter-spacing: .04em; }
.sb-mval { font: 800 1.05rem var(--serif); color: var(--ink); line-height: 1.1; }
.sb-msrc { font: 500 .56rem var(--sans); color: var(--muted); text-transform: uppercase; }
.sb-mbox.remapped .sb-msrc { color: var(--accent2); }
.sb-remap { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem; }
.sb-remap-lbl { font: 600 .7rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sb-remap-item { display: inline-flex; align-items: center; gap: .25rem; font: 600 .74rem var(--sans); color: var(--ink); text-transform: capitalize; }
.sb-remap-sel { font-size: .76rem; padding: .12rem .3rem; background: var(--field); color: var(--ink); border: 1px solid var(--border); border-radius: 5px; }
/* the two parchment page regions (measured from the art) */
.sb-leaf {
  position: absolute; top: 17.5%; bottom: 21%; overflow: auto; overflow-x: hidden;
  color: var(--ink-page); font-family: var(--serif); padding: 0 .2rem;
}
.sb-left  { left: 15.5%; right: 53.5%; }
.sb-right { left: 54%;   right: 13.5%; }
.sb-leaf-in { position: relative; animation: sb-turn .22s ease; }
.sb-open.turn .sb-leaf-in { animation: sb-turn .22s ease; }
@keyframes sb-turn { from { opacity: 0; transform: translateX(6px); } to { opacity: 1; transform: none; } }
.sb-leaf-name { font: 700 clamp(.95rem, 2.1vw, 1.3rem) var(--serif); color: #2c2213; margin-bottom: .3rem; padding-right: 2.4rem; line-height: 1.15; }
.sb-leaf-cost { position: absolute; top: 0; right: .1rem; font: 700 .8rem var(--sans); color: #7a3410; display: flex; gap: .3rem; }
.sb-leaf-cost .other { color: #6b5b3a; font-weight: 600; }
.sb-leaf-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .4rem; }
.sb-leaf-tags .elt-tag, .sb-leaf-tags .verb-tag {
  font: 600 .66rem var(--sans); padding: .05rem .4rem; border-radius: 10px; text-transform: capitalize;
  border: 1px solid color-mix(in srgb, var(--ink-page) 35%, transparent); background: rgba(255,255,255,.25);
}
.sb-leaf-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .7rem; font-size: clamp(.68rem, 1.5vw, .82rem); color: #6b5b3a; margin-bottom: .45rem; }
.sb-meta-item { white-space: nowrap; }
.sb-meta-item[title] { cursor: help; }
.sb-meta-val { font-weight: 600; }
.sb-leaf-desc { font-size: clamp(.72rem, 1.6vw, .95rem); line-height: 1.45; }
.sb-leaf-desc .dyn, .sb-leaf-meta .dyn, .sb-leaf-eltfx .dyn { color: #a1521a; font-weight: 700; }
.sb-leaf-desc .dyn[title], .sb-leaf-meta .dyn[title] { cursor: help; }
/* per-element effect list under a spell description */
.sb-leaf-eltfx { display: flex; flex-direction: column; gap: .28rem; margin-top: .5rem; }
.eltfx-row { display: flex; align-items: baseline; gap: .45rem; font-size: clamp(.7rem, 1.5vw, .86rem); color: #6b5b3a; }
.eltfx-body { flex: 1; }
.eltfx-tag {
  flex: none; min-width: 3.4rem; text-align: center; font: 700 .58rem var(--sans); text-transform: uppercase;
  letter-spacing: .04em; padding: .08rem .35rem; border-radius: 4px; border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 12%, transparent);
}
/* reuse the sheet's element palette (saturated hues read well on the parchment leaf) */
.eltfx-tag.elt-fire,   .rider-chip.elt-fire   { color: #b3471f; }
.eltfx-tag.elt-water,  .rider-chip.elt-water  { color: #226980; }
.eltfx-tag.elt-air,    .rider-chip.elt-air    { color: #3f7c96; }
.eltfx-tag.elt-earth,  .rider-chip.elt-earth  { color: #856224; }
.eltfx-tag.elt-light,  .rider-chip.elt-light  { color: #9a7c15; }
.eltfx-tag.elt-shadow, .rider-chip.elt-shadow { color: #6a54a0; }
.eltfx-tag.elt-body,   .rider-chip.elt-body   { color: #a63f2a; }
/* optional techniques from owned "spell effect" cards, shown under a spell of that element */
.sb-leaf-riders { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; margin-top: .5rem; }
.sb-leaf-riders .riders-lbl { font: 700 .58rem var(--sans); text-transform: uppercase; letter-spacing: .05em; color: #6b5b3a; opacity: .7; }
.rider-chip {
  font: 600 .68rem var(--sans); padding: .06rem .4rem; border-radius: 4px; border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 10%, transparent); cursor: help; text-decoration: none;
}
/* status-effect words carry a reference tooltip (spell descriptions + weapon attacks) */
.status { text-decoration: underline dotted; text-underline-offset: 2px; text-decoration-thickness: 1px; cursor: help; }
abbr.status { text-decoration: underline dotted; } /* override UA abbr styling consistently */
.sb-leaf-desc .elt { font-style: italic; margin-left: .3rem; }
.sb-leaf-del {
  position: absolute; bottom: -.1rem; right: .1rem; width: 1.5rem; height: 1.5rem; line-height: 1;
  border: none; border-radius: 50%; background: rgba(120,40,20,.14); color: #7a3410; cursor: pointer; font-size: 1rem;
}
.sb-leaf-del:hover { background: rgba(120,40,20,.28); }
.sb-leaf-add .add-spell-form { display: flex; flex-direction: column; gap: .45rem; margin-top: .2rem; }
.sb-leaf-add input, .sb-leaf-add textarea, .sb-leaf-add select {
  font-size: clamp(.7rem, 1.6vw, .85rem); background: rgba(255,255,255,.4); border: 1px solid rgba(60,47,28,.3); color: #2c2213;
}
.sb-leaf-add .field-label { color: #6b5b3a; font-size: .66rem; }
.sb-leaf-add .btn { align-self: flex-start; padding: .3rem .7rem; }

/* nav arrows over the binding, close top-right, counter on the spine */
.sb-nav {
  position: absolute; top: 0; bottom: 0; width: 13%;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer;
  font: 700 2rem var(--serif); color: transparent; text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
  transition: background .15s ease, color .15s ease;
}
.sb-nav.prev { left: 0; }
.sb-nav.next { right: 0; }
/* invisible until hovered — then a slight element-tinted wash (fading to the outer edge)
   and the arrow appears */
.sb-nav:hover:not(:disabled) { color: #efe6d0; }
.sb-nav.prev:hover:not(:disabled) { background: linear-gradient(to left, transparent, color-mix(in srgb, var(--sb) 26%, transparent)); }
.sb-nav.next:hover:not(:disabled) { background: linear-gradient(to right, transparent, color-mix(in srgb, var(--sb) 26%, transparent)); }
.sb-nav:disabled { cursor: default; }
.sb-close {
  position: absolute; top: -10px; right: -10px; z-index: 3; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--border); background: rgba(20, 17, 12, .92); color: #efe6d0; cursor: pointer;
  font-size: .9rem; line-height: 1; box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
.sb-close:hover { background: rgba(0, 0, 0, .9); }
.sb-counter {
  position: absolute; bottom: 3.5%; left: 50%; transform: translateX(-50%);
  font: 600 .72rem var(--sans); color: #efe6d0; text-shadow: 0 1px 3px rgba(0,0,0,.8); letter-spacing: .05em;
}

/* per-element accent for the open-book nav */
.sb-open.elt-fire   { --sb: #c9542a; }
.sb-open.elt-water  { --sb: #2f8fb0; }
.sb-open.elt-air    { --sb: #6aa9c4; }
.sb-open.elt-earth  { --sb: #b0894a; }
.sb-open.elt-light  { --sb: #c9a83f; }
.sb-open.elt-shadow { --sb: #8a72b3; }
.sb-open.elt-body   { --sb: #c25a45; }

/* bigger, session-edited note fields (inventory & notes are used most) */
.note-field textarea { min-height: 3.5rem; line-height: 1.5; }

/* the three books get their own full-width row, one per column on desktop;
   align-items:start lets each column size to its own auto-grown content. */
.notes-row { display: grid; grid-template-columns: 1fr; gap: var(--gap); align-items: start; margin-top: var(--gap); }
.note-col .note-field { margin-bottom: 0; }
/* let the auto-grow height win — .grow's flex:1 would otherwise collapse the
   textarea back to its min size and clip long content. */
.note-col .note-field textarea { flex: none; }
@media (min-width: 900px) { .notes-row { grid-template-columns: repeat(3, 1fr); } }

/* ---- character creation wizard ---- */
.cw { display: flex; flex-direction: column; gap: 1.1rem; }
.cw-section h3 { margin: 0 0 0.5rem; font: 700 1rem var(--sans); display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.cw-hint, .cw-section h3 span { font: 400 0.82rem var(--sans); color: var(--muted); }
.cw-hint b, .cw-section h3 b { color: var(--accent2); font-size: 0.95rem; }
.cw-section h3 b.cw-warn { color: var(--accent); }
.cw-name { width: 100%; max-width: 22rem; font: 600 1.05rem var(--serif); padding: 0.4rem 0.6rem; background: var(--panel); color: var(--ink); border: 1px solid var(--border); border-radius: 6px; }
.cw-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.cw-chip { font: 600 0.85rem var(--sans); padding: 0.3rem 0.65rem; border: 1px solid var(--border); border-radius: 999px; background: var(--panel); color: var(--ink); cursor: pointer; }
.cw-chip:hover { border-color: var(--accent2); }
.cw-chip.sel { background: var(--accent2); border-color: var(--accent2); color: var(--page); }
.cw-attrs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem 1.2rem; }
.cw-attr-col h4 { margin: 0 0 0.3rem; font: 700 0.8rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.cw-row { display: flex; align-items: center; gap: 0.35rem; padding: 0.12rem 0; }
.cw-label { flex: 1; font-size: 0.9rem; text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cw-step { padding: 0 0.5rem; line-height: 1.5; }
.cw-val { min-width: 1.2rem; text-align: center; color: var(--accent2); }
.cw-val.cw-warn { color: var(--accent); cursor: help; }
.cw-skills { max-width: 24rem; }
.cw .add-combo { max-width: 24rem; margin-top: 0.4rem; }
.cw-foot { display: flex; justify-content: space-between; gap: 0.8rem; border-top: 1px solid var(--border); padding-top: 0.9rem; }
.cw-create { background: var(--accent2); border-color: var(--accent2); color: var(--page); font-weight: 700; }
@media (max-width: 560px) { .cw-attrs { grid-template-columns: 1fr; } }
.cw-race-picks { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.5rem; }
.cw-race-perks { font: 400 0.85rem var(--sans); color: var(--muted); }
.cw-race-perk { color: var(--accent2); cursor: help; text-transform: capitalize; }
.cw-race-picks .add-input { max-width: 14rem; }
