/* ==========================================================================
   Grimoire — dark illuminated-manuscript theme
   Palette from the mood boards: walnut-black ground, vellum type, burnished
   gilt for ornament, oxblood for weight, arcane teal as the single "magic" light.
   ========================================================================== */
:root {
  --ink: #0d0a08;
  --ink-2: #14100c;
  --leather: #1b1510;
  --leather-2: #241b14;
  --vellum: #eadfc6;
  --vellum-2: #c9bb9c;
  --vellum-3: #9a8c70;
  --gilt: #c9a45c;
  --gilt-hi: #ecd29a;
  --gilt-lo: #8a6d34;
  --oxblood: #7a2121;
  --teal: #4fb3ae;
  --line: rgba(201, 164, 92, .28);
  --line-2: rgba(201, 164, 92, .5);

  --abjuration: #86aed3; --conjuration: #9b86d6; --divination: #e0b25a; --enchantment: #d0739b;
  --evocation: #e07a3f; --illusion: #b394e6; --necromancy: #8bbd72; --transmutation: #52b894;

  --f-display: "Cinzel", "Trajan Pro", Georgia, serif;
  --f-deco: "Cinzel Decorative", "Cinzel", Georgia, serif;
  --f-body: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --f-text: "Alegreya", "Cormorant Garamond", Georgia, serif; /* small running text: spell descriptions */
  --ez: cubic-bezier(.2, .7, .1, 1);
  --pad: clamp(16px, 4vw, 56px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  background: var(--ink);
  background-image: radial-gradient(1200px 700px at 50% -10%, rgba(79, 179, 174, .06), transparent 60%);
  color: var(--vellum);
  font: 400 19px/1.55 var(--f-body);
  font-feature-settings: "liga", "onum";
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body::before { /* page texture on its own fixed layer: painted once, never on scroll */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(rgba(13, 10, 8, .72), rgba(13, 10, 8, .72)), var(--img-texture, none) center / cover no-repeat;
}
body.tome-open, body.sheet { overflow: hidden; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--gilt-hi); text-underline-offset: 3px; text-decoration-color: var(--line-2); }
a:hover { text-decoration-color: currentColor; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 1em; height: 1em; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 1px solid var(--gilt-hi); outline-offset: 3px; }
::selection { background: rgba(201, 164, 92, .35); color: #fff; }

/* ---------- Hero ---------- */
.hero {
  position: relative; min-height: min(100svh, 980px);
  display: grid; align-items: end;
  padding: clamp(28px, 6vh, 90px) var(--pad) clamp(56px, 9vh, 104px);
  overflow: hidden; isolation: isolate;
}
.hero-bg { position: absolute; inset: 0; z-index: -2; overflow: hidden; }
.hero-img {
  position: absolute; inset: -6% -2% -14%;
  background: var(--img-hero, radial-gradient(circle at 60% 40%, #2a2016, var(--ink))) center 35% / cover no-repeat;
  transform: scale(1.06); will-change: transform;
  filter: saturate(.92) contrast(1.04);
}
.hero-veil {
  position: absolute; inset: 0; z-index: -1;
  background:
    linear-gradient(180deg, rgba(13, 10, 8, .72) 0%, rgba(13, 10, 8, .35) 30%, rgba(13, 10, 8, .55) 62%, var(--ink) 100%),
    radial-gradient(120% 90% at 50% 45%, transparent 35%, rgba(13, 10, 8, .8) 100%);
}
.hero-inner { max-width: 1180px; width: 100%; margin: 0 auto; text-align: center; display: grid; justify-items: center; }
.crest { position: relative;
  width: min(440px, 86vw, 46vh); aspect-ratio: 3 / 1; margin-bottom: -6px;
  background: var(--img-crest, none) center / contain no-repeat;
  opacity: 0; animation: rise 1.4s .15s var(--ez) forwards;
}
/* inner shadow + 2px white inner glow on the ornament: both read the crest's own alpha edge through SVG filters; the glow blends with overlay */
.crest::before, .crest::after { content: ''; position: absolute; inset: 0; background: var(--img-crest, none) center / contain no-repeat; pointer-events: none; }
.crest::before { filter: url(#crestInnerShadow); }
.crest::after {
  filter: url(#crestInnerGlow); mix-blend-mode: overlay;
  /* flowing Perlin noise as an alpha mask: the light shimmers across the ornament instead of sitting still */
  -webkit-mask-image: url('img/crest-shimmer.png'); mask-image: url('img/crest-shimmer.png');
  -webkit-mask-size: 260px 260px; mask-size: 260px 260px; -webkit-mask-repeat: repeat; mask-repeat: repeat;
  animation: crestShimmer 22s linear infinite;
}
@keyframes crestShimmer { from { -webkit-mask-position: 0 0; mask-position: 0 0; } to { -webkit-mask-position: 260px 130px; mask-position: 260px 130px; } }
@media (prefers-reduced-motion: reduce) { .crest::after { animation: none; } }
html:not(.has-crest) .crest::before, html:not(.has-crest) .crest::after { display: none; }
html:not(.has-crest) .crest {
  aspect-ratio: auto; height: 34px; width: 220px; background:
    radial-gradient(circle, var(--gilt) 0 3px, transparent 4px) center / 12px 12px no-repeat,
    linear-gradient(90deg, transparent, var(--gilt) 30%, transparent 48%, transparent 52%, var(--gilt) 70%, transparent) center / 100% 1px no-repeat;
}
.eyebrow {
  margin: 0 0 10px; font: 500 clamp(12px, 1.1vw, 14px)/1 var(--f-display);
  letter-spacing: .42em; text-transform: uppercase; color: var(--gilt);
  opacity: 0; animation: rise 1.2s .25s var(--ez) forwards;
}
.title {
  margin: 0; font: 700 clamp(64px, 14.5vw, 212px)/.86 var(--f-deco);
  letter-spacing: -.01em;
  background: linear-gradient(180deg, #fff3d6 0%, var(--gilt-hi) 38%, var(--gilt) 62%, var(--gilt-lo) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .6)) drop-shadow(0 18px 40px rgba(0, 0, 0, .7));
  padding-bottom: .06em;
}
.title .line { display: block; overflow: hidden; padding: 0 .04em .04em; }
.title-3d { position: relative; width: min(100%, 1180px); height: clamp(100px, min(19vw, 26vh), 250px); display: grid; place-items: center; font-size: clamp(52px, 12vw, 170px); filter: none; }
/* Keep the canvas top anchored, but give tumbling letters extra landing room below the heading. */
.title-3d .title-stage { position: absolute; inset: -12% -3% -34%; display: block; opacity: 0; z-index: 70; isolation: isolate; transition: opacity .5s ease; }
.title-stage::before { content: ''; position: absolute; inset: 8% 0; background: radial-gradient(ellipse 22% 46% at var(--glow-x, 50%) 58%, rgba(255, 188, 76, .18), rgba(211, 140, 35, .05) 55%, transparent 100%); filter: blur(16px); pointer-events: none; }
.title-stage canvas { position: relative; width: 100%; height: 100%; display: block; }
.title-3d { background: none; }
.title-3d .line { position: absolute; inset: 0; display: block; overflow: visible; padding: 0; pointer-events: none; opacity: 1; transition: opacity 2.4s cubic-bezier(.65, 0, .35, 1) .2s; }
/* A large, soft, warm-white glow sitting behind the swash text — additive (plus-lighter) so it brightens the
   night sky under it rather than sitting as a flat coloured disc, with no directional shadow of its own. */
.title-3d .line::before {
  content: ''; position: absolute; inset: -40% -10%; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse 46% 62% at 50% 52%, rgba(255, 252, 240, .55), rgba(255, 226, 160, .22) 45%, transparent 72%);
  filter: blur(28px); mix-blend-mode: plus-lighter;
  opacity: 0; animation: swashin 1.8s .35s cubic-bezier(.65, 0, .35, 1) forwards;
}
/* Outlined Belluga swash artwork: scale + opacity only, with no live font file on the site. */
.title-3d .line > .title-swash {
  position: absolute; left: 50%; top: 50%; width: min(92vw, 900px); height: auto;
  translate: -50% -50%; rotate: -3deg; scale: .58; transform: none; transform-origin: 50% 50%;
  filter: none;   /* no drop-shadow here — the ambient glow in .line::before carries all the light */
  opacity: 0; animation: swashin 1.4s .35s cubic-bezier(.65, 0, .35, 1) forwards;
  transition: scale 2.4s cubic-bezier(.65, 0, .35, 1) .2s;
}
.title-3d.is-rendered .line { opacity: .15; }
.title-3d.is-rendered .line > .title-swash { scale: 1; }
@keyframes swashin { to { opacity: 1; } }
.title-3d.is-rendered .title-stage { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .title-3d .title-stage { transition: none; } .title-3d .line { will-change: auto; } }
.hero-stats {
  display: flex; align-items: center; gap: clamp(14px, 3vw, 36px); margin-top: clamp(14px, 2.6vh, 34px);
  opacity: 0; animation: rise 1.2s .85s var(--ez) forwards; flex-wrap: wrap; justify-content: center;
}
.hero-stats div { display: grid; justify-items: center; }
.hero-stats b { font: 600 clamp(24px, 2.6vw, 34px)/1 var(--f-display); color: var(--vellum); }
.hero-stats span { font: 500 11px/1 var(--f-display); letter-spacing: .28em; text-transform: uppercase; color: var(--vellum-3); margin-top: 8px; }
.hero-stats i { width: 5px; height: 5px; background: var(--gilt); transform: rotate(45deg); opacity: .7; }
.scroll-cue {
  margin-top: clamp(16px, 3.4vh, 40px); display: inline-grid; justify-items: center; gap: 6px;
  font: 500 11px/1 var(--f-display); letter-spacing: .32em; text-transform: uppercase; color: var(--gilt);
  text-decoration: none; opacity: 0; animation: rise 1.2s 1.05s var(--ez) forwards;
}
.scroll-cue .ic { width: 20px; height: 20px; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes lineup { to { transform: none; } }

/* ---------- Schools ---------- */
.schools { padding: clamp(24px, 5vh, 56px) var(--pad) clamp(28px, 5vh, 56px); max-width: 1480px; margin: 0 auto; }
/* the horizon's black base melts into the page: top 50px of the content section fades from black, full viewport width */
.schools { position: relative; isolation: isolate; }
.schools::before { content: ''; position: absolute; z-index: -1; top: 0; left: 50%; width: 100vw; margin-left: -50vw; height: 50px; background: linear-gradient(#040404, rgba(4, 4, 4, 0)); pointer-events: none; }
.schools-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 22px; margin-bottom: clamp(18px, 3vh, 30px); }
.schools-head h2 { margin: 0; font: 500 clamp(13px, 1.1vw, 15px)/1 var(--f-display); letter-spacing: .38em; text-transform: uppercase; color: var(--gilt); }
.rule { height: 1px; background: linear-gradient(90deg, transparent, var(--line-2)); }
.rule:last-child { background: linear-gradient(90deg, var(--line-2), transparent); }
.school-row { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: clamp(6px, 1vw, 14px); }
.school {
  position: relative; display: grid; justify-items: center; align-content: start; gap: 4px;
  padding: 14px 6px 16px; background: none; border: 1px solid transparent; border-radius: 3px;
  transition: border-color .4s var(--ez), background .4s var(--ez), opacity .4s var(--ez);
  --c: var(--gilt);
}
.school .sig-wrap { position: relative; width: clamp(64px, 8vw, 118px); aspect-ratio: 1; display: grid; place-items: center; }
.school .sig-wrap::before {
  content: ""; position: absolute; inset: 8%; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--c) 45%, transparent), transparent 70%);
  opacity: 0; transition: opacity .5s var(--ez), transform .5s var(--ez); transform: scale(.8);
}
.school img { position: relative; width: 100%; height: 100%; object-fit: contain; transition: transform .7s var(--ez), filter .5s; filter: drop-shadow(0 4px 14px rgba(0, 0, 0, .6)); }
.school .sname { font: 600 clamp(11px, .95vw, 14px)/1.1 var(--f-display); letter-spacing: .12em; text-transform: uppercase; color: var(--vellum); margin-top: 8px; }
.school .sgloss { font: italic 400 14px/1.2 var(--f-body); color: var(--vellum-3); text-align: center; }
.school .scount { font: 500 11px/1 var(--f-display); letter-spacing: .18em; color: var(--gilt); opacity: .75; margin-top: 4px; }
.school:hover img { transform: translateY(-3px) scale(1.04); filter: drop-shadow(0 0 16px color-mix(in srgb, var(--c) 45%, transparent)) brightness(1.08); }
.school:hover .sig-wrap::before, .school.on .sig-wrap::before { opacity: 1; transform: scale(1); }
.school.on { border-color: var(--line); background: linear-gradient(180deg, rgba(201, 164, 92, .07), transparent); }
.school.on img { filter: drop-shadow(0 0 18px color-mix(in srgb, var(--c) 60%, transparent)) brightness(1.15); }
.school.dim { opacity: .42; }
.school.dim:hover { opacity: .8; }
.school[data-school="abjuration"] { --c: var(--abjuration); } .school[data-school="conjuration"] { --c: var(--conjuration); }
.school[data-school="divination"] { --c: var(--divination); } .school[data-school="enchantment"] { --c: var(--enchantment); }
.school[data-school="evocation"] { --c: var(--evocation); } .school[data-school="illusion"] { --c: var(--illusion); }
.school[data-school="necromancy"] { --c: var(--necromancy); } .school[data-school="transmutation"] { --c: var(--transmutation); }

/* ---------- Codex bar (sticky filters) ---------- */
.codex {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  background: linear-gradient(180deg, rgba(13, 10, 8, .96), rgba(13, 10, 8, .9));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  transition: box-shadow .4s;
}
.codex::after { /* gilt hairline under the bar */
  content: ""; position: absolute; left: 0; right: 0; bottom: -4px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201, 164, 92, .25) 20%, rgba(201, 164, 92, .25) 80%, transparent);
}
.codex.stuck { box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .9); }
.codex { transition: box-shadow .4s, transform .55s var(--ez); }
html.flip-open .codex { transform: translateY(-110%); }   /* tucked away while a card is open; slides back down on close */
.codex-inner {
  max-width: 1480px; margin: 0 auto; padding: 12px var(--pad);
  display: flex; align-items: center; gap: 10px;
}
.search {
  flex: 1 1 240px; min-width: 190px; max-width: 360px; position: relative; display: flex; align-items: center;
  border: 1px solid var(--line); background: rgba(0, 0, 0, .35); border-radius: 3px; height: 44px; padding: 0 12px; gap: 10px;
  transition: border-color .3s;
}
.search:focus-within { border-color: var(--gilt); }
.search .ic { color: var(--gilt); width: 17px; height: 17px; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--vellum); font: 400 18px/1 var(--f-body); }
.search input::placeholder { color: var(--vellum-3); font-style: italic; }
.search input::-webkit-search-cancel-button { filter: sepia(1) saturate(3) hue-rotate(5deg); }
.search kbd { font: 500 11px/1 var(--f-display); color: var(--vellum-3); border: 1px solid var(--line); border-radius: 2px; padding: 3px 6px; }

.filters { display: contents; }
.sheet-head, .sheet-foot { display: none; }
.fgroups { display: flex; gap: 2px; flex-wrap: nowrap; margin-left: auto; }
.fgroup { position: relative; }
.fbtn {
  height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: none; border: 1px solid transparent; border-radius: 3px; white-space: nowrap;
  transition: border-color .3s, background .3s;
}
.fbtn:hover, .fgroup.open .fbtn { border-color: var(--line); background: rgba(201, 164, 92, .05); }
.flabel { font: 600 12px/1 var(--f-display); letter-spacing: .16em; text-transform: uppercase; color: var(--vellum-2); }
.fval { font: italic 400 16px/1 var(--f-body); color: var(--vellum-3); max-width: 7.5em; overflow: hidden; text-overflow: ellipsis; }
.fgroup.active .fval { color: var(--gilt-hi); font-style: normal; }
.fgroup.active .flabel { color: var(--gilt); }
.chev { width: 14px; height: 14px; color: var(--gilt); transition: transform .3s var(--ez); }
.fgroup.open .chev { transform: rotate(180deg); }

.panel {
  position: absolute; top: calc(100% + 12px); left: 0; z-index: 40;
  width: 300px; max-height: min(70vh, 560px); overflow: auto; overscroll-behavior: contain;
  background: linear-gradient(180deg, #1d1611, #140f0b);
  border: 1px solid var(--line-2); border-radius: 3px;
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, .85), inset 0 1px 0 rgba(236, 210, 154, .08);
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .25s var(--ez), transform .25s var(--ez), visibility 0s .25s;
  scrollbar-width: thin; scrollbar-color: var(--gilt-lo) transparent;
}
.fgroup.panel-wide .panel { width: 360px; }
.fgroup:nth-last-child(-n+3) .panel { left: auto; right: 0; }
.fgroup.open .panel { opacity: 1; visibility: visible; transform: none; transition: opacity .25s var(--ez), transform .25s var(--ez); }
.panel-inner { padding: 8px; display: grid; gap: 1px; }
.ohead { margin: 10px 10px 4px; font: 600 10.5px/1 var(--f-display); letter-spacing: .26em; text-transform: uppercase; color: var(--gilt); }
.ohead:first-child { margin-top: 4px; }
.opt {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 8px 10px; background: none; border: 0; border-radius: 2px; transition: background .2s;
}
.opt:hover { background: rgba(201, 164, 92, .08); }
.opt .box { width: 16px; height: 16px; border: 1px solid var(--line-2); border-radius: 2px; display: grid; place-items: center; flex: 0 0 auto; transition: background .2s, border-color .2s; }
.opt .box .ic { width: 12px; height: 12px; stroke-width: 2.4; color: var(--ink); opacity: 0; }
.opt.on .box { background: var(--gilt); border-color: var(--gilt); }
.opt.on .box .ic { opacity: 1; }
.otext { flex: 1; display: grid; min-width: 0; }
.oname { font: 500 17px/1.2 var(--f-body); color: var(--vellum); }
.opt.on .oname { color: var(--gilt-hi); }
.onote { font: italic 400 13.5px/1.25 var(--f-body); color: var(--vellum-3); }
.src { font: 600 9px/1 var(--f-display); letter-spacing: .12em; font-style: normal; color: var(--gilt); border: 1px solid var(--line); padding: 2px 4px 1px; border-radius: 2px; vertical-align: 2px; margin-left: 4px; }
.ohint { font: 600 11px/1 var(--f-display); letter-spacing: .1em; color: var(--vellum-3); }
.on-n { font: 500 12px/1 var(--f-display); color: var(--vellum-3); min-width: 2.2em; text-align: right; font-variant-numeric: tabular-nums; }
.opt.nil { opacity: .38; }
.osig { width: 28px; height: 28px; object-fit: contain; }
.pclear { margin: 6px 4px 2px; padding: 8px; background: none; border: 1px dashed var(--line); color: var(--gilt); font: 500 11px/1 var(--f-display); letter-spacing: .18em; text-transform: uppercase; border-radius: 2px; }

.d-acid { color: #9fd44a; } .d-bludgeoning { color: #b39a7d; } .d-cold { color: #9fd6f0; } .d-fire { color: #f07a36; }
.d-force { color: #c9a0f0; } .d-lightning { color: #7fb3ff; } .d-necrotic { color: #7fae6a; } .d-piercing { color: #d6c9a8; }
.d-poison { color: #6fc27a; } .d-psychic { color: #f08ad0; } .d-radiant { color: #ffe08a; } .d-slashing { color: #d9d2c0; }
.d-thunder { color: #8aa2d6; } .d-healing { color: #f2d06a; }
/* --di: each damage type's ink on paper (the colours above glow on the dark bar and panels) */
.d-acid { --di: #557d0f; } .d-bludgeoning { --di: #6e5132; } .d-cold { --di: #23739a; } .d-fire { --di: #b8430f; }
.d-force { --di: #7038ad; } .d-lightning { --di: #2856b8; } .d-necrotic { --di: #3b6428; } .d-piercing { --di: #6f5f3a; }
.d-poison { --di: #237a32; } .d-psychic { --di: #a8307f; } .d-radiant { --di: #a37508; } .d-slashing { --di: #5f5849; }
.d-thunder { --di: #34498a; } .d-healing { --di: #a67a0a; }
/* damage glyphs (sprite #dmg-<type>): solid silhouettes, sized to the text around them */
.dic { width: 1em; height: 1em; flex: 0 0 auto; fill: currentColor; stroke: none; vertical-align: -.14em; }
.opt .dic { width: 16px; height: 16px; filter: drop-shadow(0 0 4px color-mix(in srgb, currentColor 55%, transparent)); }
.chip .dic { width: 13px; height: 13px; margin-right: 5px; vertical-align: -2px; }
/* the card's damage roundels: open gilt rings centred under the class line, one per type (up to three) */
.card-dmg { position: relative; z-index: 2; display: flex; justify-content: center; gap: 6px; margin-top: auto; padding-top: 12px; pointer-events: none; }   /* pushed to the card foot so seals line up across a row */
.dmg-coin {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%;
  position: relative; color: var(--di, var(--ink-2)); font: 700 11px/1 var(--f-display); letter-spacing: .02em;
  box-shadow: inset 0 0 0 1.5px var(--gilt);   /* a shadow, not a border: borders snap to whole pixels and knock the inner ring off-centre */
}
.dmg-coin::before { content: ""; position: absolute; inset: 4px; border-radius: 50%; border: 1px solid var(--gilt-lo); opacity: .7; }
.dmg-coin .dic { width: 18px; height: 18px; color: var(--di); }
.dmg-coin.more { color: var(--gilt-lo); }
/* damage dice in the text: the type's glyph and ink ride along */
.h-dmg { white-space: nowrap; }
.h-dmg .dic { color: var(--di); width: 1.05em; height: 1.05em; margin-right: .16em; }
.h-dtype { color: var(--di); font-weight: 600; }

.bar-end { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.seg button { height: 42px; padding: 0 12px; background: none; border: 0; font: 600 11px/1 var(--f-display); letter-spacing: .14em; text-transform: uppercase; color: var(--vellum-3); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: rgba(201, 164, 92, .14); color: var(--gilt-hi); }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; background: none;
  border: 1px solid var(--line); border-radius: 3px; color: var(--gilt); transition: border-color .3s, background .3s, color .3s;
}
.icon-btn:hover:not(:disabled) { border-color: var(--gilt); background: rgba(201, 164, 92, .08); color: var(--gilt-hi); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn .ic { width: 18px; height: 18px; }
.sheet-btn { display: none; }

.active-row { max-width: 1480px; margin: 0 auto; padding: 2px var(--pad) 10px; display: flex; align-items: center; gap: 14px; }
.active-row .seg button { height: 32px; }
.books { position: relative; }
#booksBtn { position: relative; }
.books-n:empty { display: none; }
.books-n:not(:empty) { position: absolute; top: -6px; right: -6px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; display: grid; place-items: center;
  background: var(--gilt); color: var(--ink); font: 700 10px/1 var(--f-display); box-shadow: 0 0 0 2px #120e0b; }
.books-pop { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; width: 360px; max-width: calc(100vw - 2 * var(--pad));
  max-height: min(78vh, 640px); overflow: auto; overscroll-behavior: contain; padding: 14px 16px 12px;
  background: #1a140f; border: 1px solid var(--line-2); border-radius: 3px; box-shadow: 0 20px 40px -12px #000;
  scrollbar-width: thin; scrollbar-color: var(--gilt-lo) transparent; }
.books-pop[hidden] { display: none; }
@media (max-width: 640px) { /* phones: the panel spans the screen instead of hanging off the button */
  .books-pop { position: fixed; left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top)); width: auto; max-width: none; max-height: calc(100svh - 24px); z-index: 90; }
}
.books-x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-color: transparent; }
.books-x .ic { width: 15px; height: 15px; }
.books-h { margin: 0 0 4px; font: 600 11px/1 var(--f-display); letter-spacing: .18em; text-transform: uppercase; color: var(--gilt); }
.books-lede { margin: 0 0 12px; font: italic 400 15px/1.3 var(--f-body); color: var(--vellum-3); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.presets button { height: 28px; padding: 0 10px; background: none; border: 1px solid var(--line); border-radius: 2px;
  font: 600 10.5px/1 var(--f-display); letter-spacing: .12em; text-transform: uppercase; color: var(--vellum-3); transition: border-color .2s, background .2s, color .2s; }
.presets button:hover { border-color: var(--gilt); color: var(--gilt-hi); }
.presets button[aria-pressed="true"] { background: rgba(201, 164, 92, .16); border-color: var(--gilt); color: var(--gilt-hi); }
.books-tier { margin: 14px 0 2px; font: 600 10px/1.2 var(--f-display); letter-spacing: .22em; text-transform: uppercase; color: var(--gilt); opacity: .8; }
.book { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; cursor: pointer; border-top: 1px solid var(--line); }
.books-tier + .book { border-top: 0; }
.book input { margin-top: 3px; accent-color: var(--gilt); flex: 0 0 auto; }
.book b { display: block; font: 500 16px/1.25 var(--f-body); color: var(--vellum); }
.book small { display: block; margin-top: 2px; font: italic 400 13.5px/1.3 var(--f-body); color: var(--vellum-3); }
.book:has(input:checked) b { color: var(--gilt-hi); }
.book:hover b { color: var(--gilt-hi); }
.books-foot { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line-2); font: italic 400 15px/1.2 var(--f-body); color: var(--vellum-3); }
.books-foot b { font: 600 15px/1 var(--f-display); font-style: normal; color: var(--gilt-hi); }
.active-row .icon-btn { width: 34px; height: 34px; }
.active-row .icon-btn .ic { width: 15px; height: 15px; }
.count { margin: 0; font: italic 400 17px/1 var(--f-body); color: var(--vellum-3); white-space: nowrap; }
.count b { font: 600 17px/1 var(--f-display); font-style: normal; color: var(--gilt-hi); margin-right: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  background: linear-gradient(180deg, rgba(201, 164, 92, .16), rgba(201, 164, 92, .06));
  border: 1px solid var(--line-2); border-radius: 2px;
  font: 600 11px/1 var(--f-display); letter-spacing: .1em; text-transform: uppercase; color: var(--gilt-hi);
  transition: background .2s, border-color .2s;
}
.chip .ic { width: 12px; height: 12px; opacity: .7; }
.chip:hover { border-color: var(--gilt); }
.chip.clear { background: none; border-style: dashed; color: var(--vellum-3); }

/* ---------- Results ---------- */
.results { max-width: 1480px; margin: 0 auto; padding: clamp(20px, 4vh, 40px) var(--pad) clamp(60px, 10vh, 120px); min-height: 60vh; }
.lvl-sec { margin-bottom: clamp(40px, 7vh, 88px); }
.lvl-head { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: clamp(14px, 2vw, 26px); margin: 0 0 clamp(18px, 3vh, 28px); scroll-margin-top: 150px; }
.lvl-num {
  width: 64px; height: 64px; display: grid; place-items: center;
  font: 600 22px/1 var(--f-display); color: var(--gilt-hi);
  background: var(--img-medallion, none) center / contain no-repeat;
  position: relative;
}
html:not(.has-medallion) .lvl-num { border: 1px solid var(--line-2); border-radius: 50%; box-shadow: inset 0 0 0 4px var(--ink), inset 0 0 0 5px var(--line); }
.lvl-title h2 { margin: 0; font: 600 clamp(24px, 2.6vw, 36px)/1 var(--f-display); letter-spacing: .04em; color: var(--vellum); }
.lvl-title p { margin: 6px 0 0; font: italic 400 16px/1 var(--f-body); color: var(--vellum-3); }
.lvl-rule { height: 1px; background: linear-gradient(90deg, var(--line-2), transparent); }
@media (min-width: 900px) {
  .lvl-head { grid-template-columns: auto auto minmax(0, 1fr) auto; }
  .lvl-title { display: contents; }
  .lvl-title h2 { grid-column: 2; grid-row: 1; white-space: nowrap; }
  .lvl-title p { grid-column: 4; grid-row: 1; margin: 0; text-align: right; white-space: nowrap; }
  .lvl-rule { grid-column: 3; grid-row: 1; align-self: center; }
}
/* the divider ornament centred in the space after the title, its tapering tips continued by thin gilt lines to both
   ends so the whole row reads as one rule. The art is 3:1 with its line tips at 2.4% / 97.6% of its width. */
html.has-divider .lvl-rule { --dh: clamp(44px, 6vw, 86px); position: relative; height: var(--dh); background: var(--img-divider) center / auto 100% no-repeat; opacity: .9; }
html.has-divider .lvl-rule::before, html.has-divider .lvl-rule::after {
  content: ""; position: absolute; top: calc(50% - .5px); height: 1px; pointer-events: none;
  width: max(0px, calc(50% - var(--dh) * 1.5 + var(--dh) * .08));   /* up to the art's tip, overlapping its taper a little */
  background: linear-gradient(90deg, transparent, rgba(214, 172, 80, .82) 24%, rgba(214, 172, 80, .82) 76%, transparent);
}
html.has-divider .lvl-rule::before { left: 0; }
html.has-divider .lvl-rule::after { right: 0; }
@media (max-width: 700px) { html.has-divider .lvl-rule { background-size: contain; } html.has-divider .lvl-rule::before, html.has-divider .lvl-rule::after { display: none; } }   /* phones: the whole ornament fits the narrow space */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: clamp(12px, 1.4vw, 20px); }

/* level index rail */
.rail {
  position: fixed; right: max(10px, calc((100vw - 1480px) / 2 - 58px)); top: calc(50% + 60px); transform: translateY(-50%); z-index: 20;
  display: none; flex-direction: column; gap: 2px; padding: 10px 0;
}
.rail::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: linear-gradient(180deg, transparent, var(--line), transparent); }
.rail a {
  position: relative; width: 36px; height: 28px; display: grid; place-items: center;
  font: 600 11px/1 var(--f-display); letter-spacing: .04em; color: var(--vellum-3); text-decoration: none;
  transition: color .3s;
}
.rail-label { position: relative; width: 26px; height: 26px; display: grid; place-items: center; }
.rail-label::before {
  content: ""; position: absolute; inset: 0; border: 1px solid rgba(236, 210, 154, .82); border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 164, 92, .16), transparent 74%); box-shadow: 0 0 12px rgba(201, 164, 92, .12);
  opacity: 0; transform: scale(.72); transition: opacity .22s ease, transform .22s ease; pointer-events: none;
}
.rail a:hover .rail-label::before, .rail a:focus-visible .rail-label::before { opacity: 1; transform: scale(1); }
.rail a::before { content: ""; position: absolute; inset: 4px 6px; background: #0d0a08; z-index: -1; }
.rail a:hover { color: var(--gilt-hi); }
.rail a.on { color: var(--gilt-hi); }
.rail a.on::after { content: ""; position: absolute; left: -2px; width: 5px; height: 5px; background: var(--gilt); transform: rotate(45deg); }
@media (prefers-reduced-motion: reduce) { .rail-label::before { transition: none; } }
@media (min-width: 1280px) { .rail.show { display: flex; opacity: 0; visibility: hidden; transition: opacity .5s var(--ez), visibility 0s .5s; } .rail.show.in-view { opacity: 1; visibility: visible; transition: opacity .5s var(--ez); } }

/* ---------- Spell card: a leaf of aged paper ----------
   Each card has its own rendered paper texture (offset + mirrored per spell).
   Gold artwork is darkened to ink and MULTIPLIED into the paper, so it prints
   into the grain; light effects on the dark page stay additive (fx.js). */
.card {
  --c: var(--gilt);
  --ink: #2a1c10; --ink-2: #4b3824; --ink-3: #6d5639; --rule: rgba(74, 50, 24, .32);
  position: relative; isolation: isolate; overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; min-height: 318px;
  padding: 18px 20px 18px;
  background: transparent;
  color: var(--ink);
  transition: transform .5s var(--ez), opacity .3s;
  content-visibility: auto; contain-intrinsic-size: 300px 318px;
  animation: cardin .7s var(--ez) backwards; animation-delay: calc(var(--i, 0) * 28ms);
}
@keyframes cardin { from { opacity: 0; transform: translateY(14px); } }
.card > .paper, .face > .paper {
  position: absolute; inset: 0; z-index: -2; pointer-events: none;
  background: var(--paper) center / 100% 100% no-repeat, var(--paper-lo, none) center / 100% 100% no-repeat;
  transform: scale(var(--fx, 1), var(--fy, 1));
  filter: drop-shadow(0 14px 14px rgba(0, 0, 0, .72));
  transition: filter .5s var(--ez);
}
.card::before { /* printed double rule inside the edge */
  content: ""; position: absolute; inset: 7px; pointer-events: none; z-index: 1;
  border: 1px solid var(--rule); box-shadow: inset 0 0 0 3px transparent, inset 0 0 0 4px rgba(74, 50, 24, .16);
}
.card.peel-hover, .card:focus-visible { transform: scale(1.02); z-index: 2; outline: none; }   /* comes toward the viewer instead of rising */
/* Pointer hover: the peel animation in app.js. Keep the same layer through the return landing frame too;
   only z-index is removed while resting, and the hint is released once the card scrolls offscreen. */
.card.peel { z-index: 2; }
.card.peel, .card.peel-resting, .card.peel-hover { will-change: transform; }
.card.returning { will-change: transform, opacity; transition: transform .5s var(--ez), opacity 0s; }
.card.returning.peel-hover { transform: none; z-index: auto; }
.card.peel-hover > .paper, .card:focus-visible > .paper {
  filter: drop-shadow(0 22px 20px rgba(0, 0, 0, .58)) drop-shadow(0 0 16px color-mix(in srgb, var(--c) 55%, transparent));
}
.card.lifted { opacity: 0; pointer-events: none; }
#results.card-hover { cursor: pointer; }   /* the hit area can reach past a tilted card's visible edge */
.card > .paper::after, .face > .paper::after { /* a faint clean-vellum wash where the text sits */
  content: ""; position: absolute; inset: 10% 9%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(246, 234, 204, .5), rgba(246, 234, 204, .22) 65%, transparent);
}

/* spell/school art multiplied in like a faded engraving */
.card-art {
  position: absolute; inset: 0 0 auto 0; height: 58%; z-index: -1;
  background: center 40% / cover no-repeat;
  mix-blend-mode: multiply; opacity: .22; filter: grayscale(.55) sepia(.6) contrast(1.15);
  /* fully faded by 74% of its own (58%-of-card) height, clearing the title zone: a bright element in the source
     art (e.g. Beacon of Hope's light beam) landing right behind the name made it hard to read */
  -webkit-mask: linear-gradient(180deg, #000 5%, transparent 74%); mask: linear-gradient(180deg, #000 5%, transparent 74%);
  transition: opacity .6s var(--ez), transform 1.4s var(--ez), filter .6s;
}
.card.has-art .card-art { opacity: .34; }
.card.peel-hover .card-art { opacity: .34; transform: scale(1.04); filter: grayscale(.2) sepia(.35) contrast(1.1); }
.s-abjuration { --c: var(--abjuration); } .s-conjuration { --c: var(--conjuration); } .s-divination { --c: var(--divination); } .s-enchantment { --c: var(--enchantment); }
.s-evocation { --c: var(--evocation); } .s-illusion { --c: var(--illusion); } .s-necromancy { --c: var(--necromancy); } .s-transmutation { --c: var(--transmutation); }

/* corners: tiered gilt ornaments (minimal -> maximal), printed in bronze ink via multiply */
.cn {
  position: absolute; width: 46px; height: 46px; z-index: 1; pointer-events: none;
  opacity: .92;
}
.cn.tl { top: 6px; left: 6px; } .cn.tr { top: 6px; right: 6px; transform: scaleX(-1); }
.cn.bl { bottom: 6px; left: 6px; transform: scaleY(-1); } .cn.br { bottom: 6px; right: 6px; transform: scale(-1, -1); }
/* The list-card frame sits slightly inside the card edge; the opened-card frame stays put. */
.grid > .card > .cn.tl { top: 9px; left: 9px; }
.grid > .card > .cn.tr { top: 9px; right: 9px; }
.grid > .card > .cn.bl { bottom: 9px; left: 9px; }
.grid > .card > .cn.br { bottom: 9px; right: 9px; }
html.has-corner:not(.has-tiers) .cn { background: var(--img-corner) 0 0 / contain no-repeat; }
html.has-tiers .cn { width: var(--cn); height: var(--cn); background: var(--corner) 0 0 / contain no-repeat; }
.orn-1 { --corner: var(--img-corner-1); --cn: 96px; } .orn-2 { --corner: var(--img-corner-2); --cn: 104px; }
.orn-3 { --corner: var(--img-corner-3); --cn: 112px; } .orn-4 { --corner: var(--img-corner-4); --cn: 124px; --inset: 8px; }
.orn-5 { --corner: var(--img-corner-5); --cn: 136px; --inset: 12px; } .orn-6 { --corner: var(--img-corner-6); --cn: 150px; --inset: 16px; }
html.has-tiers .card:not(.expanded) { padding: calc(22px + var(--inset, 0px)) calc(30px + var(--inset, 0px)) calc(var(--cn) * .4 + 6px); }
html.has-tiers .card:not(.expanded) .card-sig { margin: calc(var(--cn) * .1) calc(var(--cn) * .2 - 8px) 0 0; }
html.has-tiers .card:not(.expanded) .card-cls { padding-left: calc(var(--cn) * .12); }
html.has-tiers .card::before, .face::before { opacity: 0; } /* the generated corners carry the frame */
html:not(.has-corner):not(.has-tiers) .cn { border: 0 solid var(--ink-2); width: 14px; height: 14px; transform: none; }
html:not(.has-corner):not(.has-tiers) .cn.tl { border-width: 1px 0 0 1px; } html:not(.has-corner):not(.has-tiers) .cn.tr { border-width: 1px 1px 0 0; }
html:not(.has-corner):not(.has-tiers) .cn.bl { border-width: 0 0 1px 1px; } html:not(.has-corner):not(.has-tiers) .cn.br { border-width: 0 1px 1px 0; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 26px; position: relative; z-index: 2; }
.medal {
  width: 50px; height: 50px; display: grid; place-items: center; margin: -2px 0 0 -4px; position: relative;
  font: 700 15px/1 var(--f-display); color: var(--ink);
}
.medal::before { /* the medallion ring, printed like the corners */
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: 50%;
  background: var(--img-medallion-ink, none) center / contain no-repeat;
}
html:not(.has-medallion) .medal::before { border: 1px solid var(--ink-2); box-shadow: inset 0 0 0 3px transparent, inset 0 0 0 4px var(--rule); background: rgba(255, 244, 214, .25); }
.card-sig {
  width: 56px; height: 56px; object-fit: contain; margin: -4px -6px 0 0;
  transition: transform .8s var(--ez);
}
.card.peel-hover .card-sig { transform: scale(1.06); }
.card-name { position: relative; z-index: 2; margin: 0; font: 700 23px/1.08 var(--f-display); letter-spacing: .01em; color: var(--ink); text-wrap: balance; }
.card-sub { margin: 6px 0 12px; font: italic 500 16.5px/1.2 var(--f-body); color: color-mix(in srgb, var(--c) 45%, #3b2915); }
.card-meta { margin: 0 0 12px; display: grid; gap: 3px; padding-top: 12px; border-top: 1px solid var(--rule); }
.card-meta div { display: flex; align-items: baseline; gap: 9px; }
.card-meta dt { color: var(--ink-3); }
.card-meta dt .ic { width: 13px; height: 13px; transform: translateY(1px); }
.card-meta dd { margin: 0; font: 500 16.5px/1.3 var(--f-body); color: var(--ink-2); }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 23px; padding: 0 8px;
  font: 700 10.5px/1 var(--f-display); letter-spacing: .09em; text-transform: uppercase;
  border: 1px solid rgba(74, 50, 24, .42); border-radius: 2px; color: var(--ink-2); background: rgba(255, 246, 222, .28);
}
.tag .dic { width: 13px; height: 13px; margin: -1px -1px 0 -2px; color: var(--di); }
.t-save { color: #6a3f0c; border-color: rgba(120, 76, 20, .55); }
.t-atk { color: #7d2a14; border-color: rgba(125, 42, 20, .45); }
.t-flag { width: 23px; justify-content: center; padding: 0; color: #1d5f5b; border-color: rgba(29, 95, 91, .5); }
.card-cls { margin: auto 0 0; padding-top: 14px; font: 600 11px/1.5 var(--f-display); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.card .tags + .card-cls { margin-top: 12px; }
/* the book a supplement spell comes from, set after the school like a marginal note */
.card-book { font: 700 10px/1 var(--f-display); font-style: normal; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); white-space: nowrap; }
.card-book::before { content: "·"; margin: 0 .5em 0 .45em; letter-spacing: 0; }
.viasub { color: #7a4f14; text-transform: none; font: italic 500 14px/1 var(--f-body); letter-spacing: 0; }
/* Warm candle-light that follows the cursor across the paper. The parchment image itself is the alpha mask,
   including its torn outer edge and transparent holes, rather than the card's rectangular element box. */
.card > .paper::before {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(240px circle at var(--mx, 50%) var(--my, 30%), color-mix(in srgb, var(--c) 45%, #fff3cf), transparent 70%);
  -webkit-mask: var(--paper) center / 100% 100% no-repeat;
  mask: var(--paper) center / 100% 100% no-repeat;
  mix-blend-mode: overlay; opacity: 0; transition: opacity .45s var(--ez);
}
.card.peel-hover > .paper::before { opacity: .9; }

/* ---------- Flip: the card lifts out, turns over, and is read in the foreground ---------- */
.flip { position: fixed; inset: 0; z-index: 70; }
.flip[hidden] { display: none; }
.flip.fading, .flip.fading * { pointer-events: none !important; }   /* effects burning off after close */
.flip-backdrop { /* separate from #flip so blend modes inside the flip layer can't isolate it */
  position: fixed; z-index: 69; pointer-events: none;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 50%, rgba(13, 10, 8, .45), rgba(6, 4, 3, .82));
  backdrop-filter: blur(7px) saturate(.8); -webkit-backdrop-filter: blur(7px) saturate(.8);
  opacity: 0; transition: opacity .6s var(--ez);
}
.flip-backdrop.show { opacity: 1; }
.flip-backdrop[hidden] { display: none; }
html.flip-open { overflow: hidden; }
.fire { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.fx-layer { position: fixed; inset: 0; pointer-events: none; }
.fx-layer[hidden] { display: none; }
.fx-back { z-index: 69; }     /* after the backdrop (also 69) in the DOM, so above it; below the card (#flip, 70) */
.fx-front { z-index: 71; }    /* above the card */
.fire-front { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.flip-scene { position: absolute; inset: 0; perspective: 2200px; perspective-origin: 50% 45%; }
.flip-tilt { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .35s var(--ez); pointer-events: none; }
.flipper { position: absolute; transform-style: preserve-3d; pointer-events: auto; will-change: transform; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face.front { transform-origin: 0 0; animation: none; content-visibility: visible; cursor: default; }
.face.front:hover { transform-origin: 0 0; }
.face.back { transform: rotateY(180deg); isolation: isolate; color: var(--ink); outline: none;
  --ink: #2a1c10; --ink-2: #4b3824; --ink-3: #6d5639; --rule: rgba(74, 50, 24, .32); }
.face.back > .paper::after { inset: 5% 6%; background: radial-gradient(closest-side, rgba(246, 234, 204, .78), rgba(246, 234, 204, .55) 70%, rgba(246, 234, 204, .1)); }
.face.back > .paper { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .35)); }  /* no big dark shadow: it dimmed the effect layer behind the card */
.face.back .cn { display: none; }
/* Lifted layer: the gilt frame and the school emblem float above the paper on the z axis and cast
   shadows onto it, so they parallax against the page when the card tilts. */
.face.lift { transform: rotateY(180deg) translateZ(30px); transform-style: preserve-3d; pointer-events: none; }
.face.lift::before {
  content: ""; position: absolute; inset: 4.5% 5.5%; backface-visibility: hidden; opacity: 1;
  background: var(--img-frame, none) center / 100% 100% no-repeat;
  filter: brightness(.92) saturate(1.1) drop-shadow(0 1px 0 rgba(255, 236, 190, .35)) drop-shadow(0 10px 9px rgba(40, 24, 8, .5));
}
/* Glare on the gold frame: a thin white band masked to the frame's own shape. No loop: it only shows while
   the pointer (or the phone's tilt) moves the card, and slides with it (--glare-a angle, --glare-p position,
   --glare-o opacity, all set from the tilt handlers). */
.face.lift::after {
  content: ""; position: absolute; inset: 4.5% 5.5%; pointer-events: none; backface-visibility: hidden;
  transform: translateZ(1px);
  -webkit-mask: var(--img-frame, none) center / 100% 100% no-repeat; mask: var(--img-frame, none) center / 100% 100% no-repeat;
  background: linear-gradient(var(--glare-a, 115deg), transparent 0 40%, rgba(255, 248, 226, .22) 45%, rgba(255, 252, 240, 1) 50%, transparent 51.5% 100%) var(--glare-p, 50%) var(--glare-p, 50%) / 300% 300% no-repeat;
  opacity: var(--glare-o, 0); transition: opacity .5s var(--ez);
  mix-blend-mode: screen; mix-blend-mode: plus-lighter;   /* additive: adds light to the gold under it */
}
@media (prefers-reduced-motion: reduce) { .face.lift::after { opacity: 0; } }
.flip.reading .face.lift::after { opacity: 0; }
.lift-sig {
  position: absolute; object-fit: contain; border-radius: 50%; backface-visibility: hidden;
  transform: translateZ(22px);
  background: radial-gradient(circle, #1a130d 62%, transparent 64%);
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .55)) drop-shadow(0 14px 14px rgba(30, 18, 6, .55));
}
.back-inner { position: absolute; inset: 7% 9% 6.55%; /* bottom = visible bottom of the .f-nav buttons (7.5% layout, less ~1.2% for their perspective lift) */ z-index: 2; display: flex; flex-direction: column; container-type: inline-size; }
.back-head { flex: none; }
.back-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; outline: none;
  scrollbar-width: none;
  -webkit-mask: linear-gradient(180deg, transparent, #000 14px, #000 calc(100% - 26px), transparent); mask: linear-gradient(180deg, transparent, #000 14px, #000 calc(100% - 26px), transparent);
}
.back-scroll::-webkit-scrollbar { display: none; }
.x-sig-slot { display: block; width: 78px; height: 78px; flex: 0 0 auto; margin: -4px 8px 0 0; } /* up 4px; 8px + the head's 22px = 30px in from the edge */
.sheen { /* masked to the leaf's silhouette so it never lights the page around the ragged edge;
           mirrored with the paper, and the pointer position mirrored to match */
  position: absolute; inset: 0; z-index: 4; pointer-events: none; mix-blend-mode: soft-light;
  transform: scale(var(--fx, 1), var(--fy, 1));
  background: radial-gradient(60% 45% at calc(50% + (var(--sxn, 30) - 50) * var(--fx, 1) * 1%) calc(50% + (var(--syn, 20) - 50) * var(--fy, 1) * 1%),
    rgba(255, 244, 214, .55), transparent 70%);
  -webkit-mask: var(--paper) center / 100% 100% no-repeat; mask: var(--paper) center / 100% 100% no-repeat;
}
/* the buttons sit centred on the frame's bottom rule (frame inset 4.5% + rule 3.4% of the frame's height = 7.6%) */
.f-nav { position: absolute; left: 12%; right: 12%; bottom: calc(7.6% - 17px); display: flex; justify-content: center; gap: 10px; pointer-events: auto; transform: translateZ(14px); backface-visibility: hidden; }
.f-nav .icon-btn { width: 40px; height: 40px; border-radius: 50%; background: rgba(42, 28, 16, .85); border-color: rgba(236, 210, 154, .4); color: var(--gilt-hi); }
.f-nav .icon-btn:hover { background: rgba(42, 28, 16, 1); }
.x-actions { display: none; }
.x-plate {
  position: relative; height: clamp(190px, 44cqw, 300px); margin: 0; overflow: hidden;
  -webkit-mask: var(--crumble) center / 100% 100% no-repeat; mask: var(--crumble) center / 100% 100% no-repeat;
  background: center 40% / cover no-repeat, radial-gradient(80% 90% at 50% 40%, color-mix(in srgb, var(--c) 40%, #2a1d12), #120d09);
  box-shadow: 0 0 0 1px rgba(40, 26, 12, .7), 0 0 0 4px rgba(255, 244, 214, .35), 0 0 0 5px rgba(74, 50, 24, .45);
}
.x-plate.empty { background-image: radial-gradient(80% 90% at 50% 40%, color-mix(in srgb, var(--c) 40%, #2a1d12), #120d09); }
/* The picture sits deeper than the paper: an oversized layer that pans against the torn window.
   Oversize = the pan range, so at full tilt the picture's edge meets the window's edge exactly
   (1.5% of the width each side, 2% of the height top/bottom; translate % is of the layer itself:
   2*1.5/103 and 2*2/104). */
.x-plate-img {
  position: absolute; inset: -2% -1.5%;
  background: center / cover no-repeat;
  transform: translate(calc(var(--px, 0) * -2.85%), calc(var(--py, 0) * -3.75%));
  transition: transform .35s var(--ez);
}
.x-plate::after { /* shadow cast by the torn edge onto the recessed picture */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 18px 4px rgba(20, 12, 4, .7), inset 0 6px 14px rgba(20, 12, 4, .55);
}
.x-plate-veil { position: absolute; inset: 0; background: linear-gradient(180deg, transparent 55%, rgba(18, 13, 9, .55)); }
.x-actions { position: absolute; top: 20px; right: 20px; z-index: 4; display: flex; gap: 6px; }
.x-actions .icon-btn { width: 38px; height: 38px; background: rgba(13, 10, 8, .72); border-color: rgba(236, 210, 154, .45); color: var(--gilt-hi); backdrop-filter: blur(4px); }
.x-body { position: relative; z-index: 2; padding: 16px 22px 78px; } /* 78px: room to scroll the last line clear of the round .f-nav buttons and the bottom fade */
.x-head { display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 14px; margin: -39px 0 14px; padding: 0 22px; } /* 22px = .x-body's side padding, so the title lines up with the text */ /* emblem on the right, half (39px of 78) over the picture */
.x-head > div { flex: 1; min-width: 0; }
.x-sig {
  width: 78px; height: 78px; flex: 0 0 auto; object-fit: contain; border-radius: 50%;
  background: radial-gradient(circle, #1a130d 62%, transparent 64%);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .6));
}
.x-head > div { padding-top: 61px; }
.x-kicker { margin: 0 0 6px; font: 700 11.5px/1 var(--f-display); letter-spacing: .24em; text-transform: uppercase; color: color-mix(in srgb, var(--c) 40%, #5a3b12); }
.x-name { margin: 0; font: 700 clamp(28px, 2.6vw, 38px)/1.02 var(--f-display); color: var(--ink); text-wrap: balance; }
.x-meta { display: grid; grid-template-columns: 1fr 1fr; margin: 0 0 14px; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.x-meta div { padding: 10px 12px 10px 0; }
.x-meta div:nth-child(odd) { border-right: 1px solid var(--rule); }
.x-meta div:nth-child(even) { padding-left: 14px; }
.x-meta div:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
.x-meta .x-wide { grid-column: 1 / -1; border-right: 0; border-top: 1px solid var(--rule); padding-left: 0; }   /* the book: its own row across both columns */
.x-meta dt { font: 700 10px/1 var(--f-display); letter-spacing: .22em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 5px; }
.x-meta dd { margin: 0; font: 600 17px/1.3 var(--f-body); color: var(--ink); }
.x-meta dd em { color: var(--ink-3); }
.x-meta small { display: block; font: italic 500 14.5px/1.35 var(--f-body); color: var(--ink-3); margin-top: 3px; }
/* "At the table": the rules of the spell, lifted out of its description (data/rules.js) */
.x-rules-wrap { margin: 16px 0 0; border: 1px solid var(--rule); border-left: 2px solid color-mix(in srgb, var(--c) 45%, #7a4a10); background: rgba(255, 244, 214, .32); }
/* two columns of label-over-value cells; long facts take the full width */
.x-rules { margin: 0; display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: row dense; }
.x-rules div { padding: 7px 12px 8px; border-top: 1px dotted rgba(74, 50, 24, .28); min-width: 0; }

.x-rules div.wide { grid-column: 1 / -1; }
.x-rules dt { margin-bottom: 2px; font: 700 9.5px/1.4 var(--f-display); letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3); }
.x-rules dd { margin: 0; font: 500 15px/1.35 var(--f-text); color: #2d1f12; }
.x-rules div.r-key { order: -1; }   /* headline facts first */
.x-rules .r-fail dd, .x-rules .r-effect dd { font-weight: 700; }
@container (max-width: 400px) { .x-rules { grid-template-columns: 1fr; } .x-rules div:nth-child(2) { border-top: 1px dotted rgba(74, 50, 24, .28); } }
/* "Cast at": pick the slot level (or caster level for cantrips); the facts below are worked out for it */
.x-cast { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--rule); background: rgba(255, 244, 214, .35); }
.x-cast-k { margin-right: 6px; font: 700 9.5px/1 var(--f-display); letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3); }
.x-cast button { min-width: 34px; height: 26px; padding: 0 7px; border: 1px solid rgba(74, 50, 24, .35); border-radius: 13px; background: transparent; font: 600 13px/1 var(--f-text); color: var(--ink-2); cursor: pointer; transition: background .2s, border-color .2s, color .2s; }
.x-cast button:hover { border-color: var(--ink-2); background: rgba(255, 246, 222, .6); }
.x-cast button[aria-pressed="true"] { border-color: color-mix(in srgb, var(--c) 50%, #6a3f0c); background: color-mix(in srgb, var(--c) 22%, #6a3f0c); color: #fff4dc; }
/* a value raised by the chosen level */
.x-rules .h-num.up { color: color-mix(in srgb, var(--c) 45%, #6a3f0c); background: linear-gradient(transparent 60%, color-mix(in srgb, var(--c) 22%, transparent) 60%); }
/* inline highlights in the description: rules stand out, the prose around them stays quiet */
.h-num { font-weight: 700; color: #1e140a; }
/* in the running description the two facts that matter most at the table, damage dice and area, are set larger */
.x-text .h-dice, .x-text .h-area, .x-higher .h-dice, .x-higher .h-area { font-size: 1.14em; line-height: 1; }
.h-save { font-weight: 700; color: #6a3f0c; }
.h-cond { font-weight: 700; color: #7d2a14; background: linear-gradient(transparent 62%, rgba(125, 42, 20, .14) 62%); }
.h-tgt { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--c) 55%, #7a4a10); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.x-text { margin-top: 18px; font: 500 16.5px/1.5 var(--f-text); color: #2d1f12; }
.x-text p { margin: 0 0 .8em; }
.x-text > p:first-child::first-letter {
  float: left; font: 700 3.4em/.8 var(--f-deco); padding: .06em .1em 0 0;
  color: color-mix(in srgb, var(--c) 35%, #7a4a10);
}
.x-text ul { margin: 0 0 .6em; padding-left: 1.1em; }
.x-text b { color: #1e140a; }
.x-text table { width: 100%; border-collapse: collapse; margin: .4em 0 1em; font-size: 15.5px; }
.x-text th, .x-text td { text-align: left; padding: 5px 10px 5px 0; border-bottom: 1px solid var(--rule); }
.x-text th { font: 700 10.5px/1.2 var(--f-display); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
.x-src { margin: 10px 0 0; font: italic 500 15px/1.4 var(--f-body); color: var(--ink-3); }
.x-higher { margin-top: 14px; padding: 12px 16px; border-left: 2px solid color-mix(in srgb, var(--c) 40%, #7a4a10); background: rgba(255, 244, 214, .3); }
.x-higher h4, .x-avail h4 { margin: 0 0 6px; font: 700 11px/1 var(--f-display); letter-spacing: .22em; text-transform: uppercase; color: var(--ink-3); }
.x-higher p { margin: 0; font: 500 16.5px/1.5 var(--f-text); color: #2d1f12; }
.x-avail { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--rule); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pill {
  display: inline-flex; align-items: baseline; gap: 7px; padding: 8px 12px; background: rgba(255, 246, 222, .35);
  border: 1px solid rgba(74, 50, 24, .45); border-radius: 2px; font: 700 11.5px/1 var(--f-display); letter-spacing: .12em; text-transform: uppercase; color: var(--ink);
  transition: background .2s, border-color .2s;
}
.pill small { font: italic 500 14px/1 var(--f-body); letter-spacing: 0; text-transform: none; color: var(--ink-3); }
.pill:hover { background: rgba(255, 246, 222, .7); border-color: var(--ink-2); }
.pill.sub { border-style: dashed; }
.pill.via small { color: #7a4f14; }   /* a class that gets the spell from a later book's expanded list */
.muted { color: var(--ink-3); font-style: italic; }
@container (max-width: 520px) {
  .x-body { padding: 16px 20px 78px; }
  .x-head { padding: 0 20px; }
  .x-sig-slot { margin-right: 10px; }
  .x-meta { grid-template-columns: 1fr; }
  .x-meta div:nth-child(odd) { border-right: 0; }
  .x-meta div:nth-child(even) { padding-left: 0; }
  .x-meta div:not(:last-child) { border-bottom: 1px solid var(--rule); }
  .x-meta .x-wide { border-top: 0; }
}

.empty { max-width: 520px; margin: 8vh auto; text-align: center; display: grid; justify-items: center; }
.empty img { width: 120px; opacity: .8; }
.empty h2 { font: 600 30px/1.1 var(--f-display); margin: 18px 0 8px; }
.empty p { color: var(--vellum-3); font-style: italic; margin: 0 0 22px; }
.solid, .ghost {
  height: 46px; padding: 0 22px; border-radius: 3px;
  font: 600 12px/1 var(--f-display); letter-spacing: .18em; text-transform: uppercase;
}
.solid { background: linear-gradient(180deg, var(--gilt-hi), var(--gilt) 60%, var(--gilt-lo)); color: #1a120a; border: 0; box-shadow: 0 1px 0 rgba(255, 255, 255, .3) inset, 0 10px 24px -10px rgba(0, 0, 0, .9); }
.ghost { background: none; border: 1px solid var(--line-2); color: var(--gilt); }

/* Ambient shadow a peeling card casts on the page and its neighbours (web/app.js positions and sizes it per
   card). Three soft, off-centre, unevenly-sized radial pools instead of one even ring, so the falloff reads as
   light pooling under a lifted object rather than a flat, regular halo; biased low and slightly to one side. */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 100; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 12px 20px; background: #1d1611; border: 1px solid var(--line-2); border-radius: 3px;
  font: italic 400 17px/1 var(--f-body); color: var(--vellum); box-shadow: 0 20px 40px -10px #000;
  transition: opacity .3s var(--ez), transform .3s var(--ez);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Particle layers (fx.js) ---------- */
.fx { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 75; pointer-events: none; }
.school.on .sig-wrap::before { animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .55; transform: scale(1.08); } }

/* ---------- Footer ---------- */
.foot { max-width: 760px; margin: 0 auto; padding: 0 var(--pad) 72px; text-align: center; color: var(--vellum-3); font-size: 16px; }
.foot .divider { height: 40px; margin-bottom: 20px; background: linear-gradient(90deg, transparent, var(--line-2), transparent) center / 100% 1px no-repeat; }
html.has-divider .foot .divider { background: var(--img-divider) center / contain no-repeat; opacity: .8; }
.foot .small { font-size: 14px; font-style: italic; }

/* ---------- Responsive ---------- */
@media (max-width: 1540px) {
  .fval { display: none; }
  .fgroup.active .fbtn::after { content: ""; width: 6px; height: 6px; background: var(--gilt); transform: rotate(45deg); }
}
@media (max-width: 1320px) { /* eight filter groups: tighter buttons keep the bar on one line down to the sheet breakpoint */
  .fbtn { padding: 0 7px; gap: 6px; }
  .flabel { letter-spacing: .12em; }
  .codex-inner { gap: 8px; }
}
@media (max-width: 1080px) {
  .school-row { grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: 8px; }
  .school .sgloss { display: none; }
  .fgroups { display: none; }
  .sheet-btn {
    display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; background: none;
    border: 1px solid var(--line-2); border-radius: 3px; color: var(--gilt);
    font: 600 12px/1 var(--f-display); letter-spacing: .16em; text-transform: uppercase;
  }
  .sheet-btn b:not(:empty) { background: var(--gilt); color: var(--ink); min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; font-size: 11px; padding: 0 5px; }
  .search { max-width: none; }
  /* sheet */
  body.sheet .filters {
    display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 80;
    background: #120e0b; animation: fade .3s var(--ez);
  }
  body.sheet .fgroups { display: block; margin-left: 0; flex: 1; overflow-y: auto; padding: 0 var(--pad) 24px; }
  body.sheet .codex { backdrop-filter: none; -webkit-backdrop-filter: none; }
  body.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px var(--pad); border-bottom: 1px solid var(--line); font: 600 14px/1 var(--f-display); letter-spacing: .24em; text-transform: uppercase; color: var(--gilt); }
  body.sheet .sheet-foot { display: flex; gap: 10px; padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #0f0c09; }
  .sheet-foot .solid { flex: 1; }
  body.sheet .fgroup { border-bottom: 1px solid rgba(201, 164, 92, .14); }
  body.sheet .fbtn { width: 100%; height: 56px; padding: 0; border: 0; background: none; }
  body.sheet .fval { display: inline; margin-left: auto; }
  body.sheet .fgroup.active .fbtn::after { display: none; }
  body.sheet .panel { position: static; width: auto !important; max-height: none; box-shadow: none; border: 0; background: none; display: none; opacity: 1; visibility: visible; transform: none; }
  body.sheet .fgroup.open .panel { display: block; }
  body.sheet .panel-inner { padding: 0 0 14px; }
}
@media (max-width: 640px) {
  body { font-size: 18px; }
  .school-row { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 calc(var(--pad) * -1); padding: 0 var(--pad) 6px; scrollbar-width: none; }
  .school { flex: 0 0 104px; scroll-snap-align: start; }
  .school .sig-wrap { width: 72px; }
  .codex-inner { flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; gap: 8px; }
  .search { flex: 1 1 auto; min-width: 0; }
  .sheet-btn span { display: none; }
  .sheet-btn { padding: 0 12px; }
  .active-row { padding-bottom: 8px; }
  .chips:empty { display: none; }
  .search kbd { display: none; }
  .bar-end { margin-left: auto; }
  .orn span { display: none; }
  .seg button { padding: 0 10px; }
  .active-row { flex-wrap: wrap; gap: 8px; }
  .lvl-num { width: 52px; height: 52px; font-size: 18px; }
  .card { min-height: 0; }
  .card-head { margin-bottom: 18px; }
  .hero { min-height: 88svh; }
  .hero-stats { display: grid; grid-template-columns: repeat(4, auto); gap: 18px; }
  .hero-stats i { display: none; }
  .hero-stats span { letter-spacing: .18em; font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  .title .line > span { transform: none; opacity: 1; animation: none; }
  html { scroll-behavior: auto; }
}

.hero-glow {
  position: absolute; inset: 0; pointer-events: none; z-index: 0; will-change: opacity;
  background:
    radial-gradient(ellipse 12% 8% at 50% 100%, rgba(255, 244, 174, .55), rgba(255, 244, 174, 0) 100%),
    radial-gradient(ellipse 22% 17% at 50% 101%, rgba(255, 205, 64, .62), rgba(255, 205, 64, .22) 40%, rgba(255, 205, 64, 0) 100%),
    radial-gradient(ellipse 42% 32% at 50% 103%, rgba(255, 105, 20, .55), rgba(255, 105, 20, .2) 40%, rgba(255, 105, 20, 0) 100%),
    radial-gradient(ellipse 62% 52% at 50% 104%, rgba(255, 42, 10, .5), rgba(255, 42, 10, .17) 40%, rgba(255, 42, 10, 0) 100%);
  animation: glowBreath 7s ease-in-out infinite alternate;
  /* fade out at the very bottom so nothing glows in the gaps under the wavy ground line (no extra silhouette layer needed) */
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - var(--hz) * .10), transparent calc(100% - var(--hz) * .03)); mask-image: linear-gradient(to bottom, #000 calc(100% - var(--hz) * .10), transparent calc(100% - var(--hz) * .03));
}
@keyframes glowBreath { from { opacity: .82; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .hero-glow { animation: none; will-change: auto; } }
.hero-rays { position: absolute; top: 0; left: -10%; width: 120%; height: 100%; pointer-events: none; z-index: 0; transform-origin: 50% 0; will-change: transform, opacity; }
.hero-rays-a, .hero-rays-motes { animation: raysA 28s ease-in-out infinite alternate; }
/* the light drifts: a soft haze texture (img/rays-haze.png, alpha .55–1) slides slowly across each layer, so the beams
   brighten and dim along their length instead of only swaying as a whole */
.hero-rays-a { mix-blend-mode: screen; -webkit-mask: url('img/rays-haze.png') 0 0 / 620px 620px repeat; mask: url('img/rays-haze.png') 0 0 / 620px 620px repeat;
  animation: raysA 28s ease-in-out infinite alternate, raysHazeA 46s linear infinite; }
.hero-rays-b {
  animation: raysB 41s ease-in-out infinite alternate, raysHazeB 37s linear infinite;
  /* this layer's rays pass in front of the crest (screen blend: light adds over the gold), fading out below it so the title and text stay clean */
  z-index: 2; mix-blend-mode: screen;
  -webkit-mask: linear-gradient(to bottom, #000 0, #000 44%, transparent 60%), url('img/rays-haze.png') 0 0 / 540px 540px repeat;
  mask: linear-gradient(to bottom, #000 0, #000 44%, transparent 60%), url('img/rays-haze.png') 0 0 / 540px 540px repeat;
  -webkit-mask-composite: source-in; mask-composite: intersect;
}
@keyframes raysHazeA { to { -webkit-mask-position: 620px 1240px; mask-position: 620px 1240px; } }
@keyframes raysHazeB { to { -webkit-mask-position: 0 0, -540px 1080px; mask-position: 0 0, -540px 1080px; } }
/* dust motes drifting inside the beams (drawn by hero-atmosphere.js on the same pivot, so they sway with layer a) */
.hero-rays-motes { mix-blend-mode: screen; }
@keyframes raysA { from { transform: rotate(-1.6deg); opacity: .72; } to { transform: rotate(1.6deg); opacity: 1; } }
@keyframes raysB { from { transform: rotate(2deg) scaleX(1.04); opacity: 1; } to { transform: rotate(-1.4deg); opacity: .66; } }
@media (prefers-reduced-motion: reduce) { .hero-rays { animation: none; will-change: auto; } }
.hero-inner { position: relative; z-index: 1; }

/* The hero ends on a horizon silhouette (treeline + the adventuring party, torches lit by horizon.js) instead of a torn edge. */
.hero { --hz: clamp(150px, 16vw, 320px); padding-bottom: clamp(112px, 11.5vw, 235px); }   /* the strip's empty top quarter may sit behind the last line of content */
/* Five hand-drawn silhouettes on one baseline (all 1294 units tall): cliff | ground | party | ground | tavern.
   Left/right shrink and crop toward their outer edges on narrow screens; the party never crops. */
.hero-horizon { --hz-h: clamp(150px, 16vw, 320px); position: absolute; left: 0; right: 0; bottom: calc(var(--hz-h) * -.045); height: var(--hz-h); z-index: 2; pointer-events: none; }
/* --u = px per artwork unit (every piece is 1294 units tall). The crew is centred. Each wing sits at its outer edge until it would touch the
   crew box, then it sticks to the crew and the window crops the wing's outer side — the wings themselves are never squeezed or cropped. */
.hero-horizon { --u: calc(var(--hz-h) / 1294); }
.hz-row { position: absolute; inset: 0; }

.hz-row img { position: absolute; bottom: 0; height: 100%; display: block; max-width: none; user-select: none; -webkit-user-drag: none; }
.hz-left { width: calc(2483 * var(--u)); left: min(0px, calc((100% - 2179 * var(--u)) / 2 - 2483 * var(--u))); }
.hz-right { width: calc(2377 * var(--u)); right: min(0px, calc((100% - 2179 * var(--u)) / 2 - 2377 * var(--u))); }
.hz-crew { width: calc(2179 * var(--u)); left: 50%; transform: translateX(-50%); filter: brightness(.55); }   /* its blacks are lighter than the other pieces': match them */
.hz-ground { position: absolute; inset: 0; background: url('img/horizon-ground.svg') repeat-x left bottom / auto 100%; }   /* one ground layer across the full width, behind the pieces */
.hz-front, .hz-back { position: absolute; left: 0; width: 100%; display: block; }
.hz-back { z-index: 0; } .hz-row { z-index: 1; } .hz-front { z-index: 2; }

.motion-tilt-toggle { position:absolute; right:12px; bottom:12px; width:44px; height:44px; display:grid; place-items:center; z-index:10; padding:0; border:1px solid #8c7448; border-radius:50%; background:#17120e; color:#ead9b6; pointer-events:auto; }
.motion-tilt-toggle svg { width:24px; height:24px; }
.motion-tilt-toggle[aria-pressed="true"] { color:var(--gilt-hi, #e8c77a); border-color:var(--gilt-hi, #e8c77a); background:#2a1f12; }

/* small phones only (<= 420px): keep the hero inside the first screen so the horizon is fully visible — eyebrow on one line */
@media (max-width: 420px) {
  .eyebrow { letter-spacing: .26em; }
}

/* evening pine-forest hero (the default background): a readable, blue sky, so the top veil is far lighter than the library's; the horizon in the image sits at the top of the silhouette strip */
.hero-evening .hero-img { background-position: center 80%; filter: saturate(1) contrast(1.02); }
.hero-evening .hero-veil {
  background:
    linear-gradient(180deg, rgba(13, 10, 8, .30) 0%, rgba(13, 10, 8, .08) 26%, rgba(13, 10, 8, .16) 62%, var(--ink) 100%),
    radial-gradient(130% 95% at 50% 42%, transparent 50%, rgba(13, 10, 8, .5) 100%);
}

/* Foreground foliage (black, slightly blurred): one image per side, each at most 46% of the hero width so the two never meet or overlap on a phone.
   The art is cropped toward its outer edge (object-position) and its cropped inner edge fades out. They scale with the window (height: 100%),
   and slide outward as --fg-p (set by foreground.js on scroll) goes 0 -> 1. */
.fg { position: absolute; top: 0; height: 100%; width: auto; max-width: 46%; object-fit: cover; pointer-events: none; user-select: none;
  z-index: 3; filter: blur(1.4px); will-change: transform, opacity;   /* 3: in front of the 3D title (.hero-inner is 1) */ opacity: calc(1 - var(--fg-p, 0) * .55); }
.fg-left { left: 0; object-position: left top; transform-origin: 0 40%;
  -webkit-mask-image: linear-gradient(to right, #000 78%, transparent 100%); mask-image: linear-gradient(to right, #000 78%, transparent 100%);
  transform: translate3d(calc(var(--fg-p, 0) * -46%), calc(var(--fg-p, 0) * -3%), 0) scale(calc(1 + var(--fg-p, 0) * .14)); }
.fg-right { right: 0; object-position: right top; transform-origin: 100% 40%;
  -webkit-mask-image: linear-gradient(to left, #000 78%, transparent 100%); mask-image: linear-gradient(to left, #000 78%, transparent 100%);
  transform: translate3d(calc(var(--fg-p, 0) * 46%), calc(var(--fg-p, 0) * -3%), 0) scale(calc(1 + var(--fg-p, 0) * .14)); }
@media (prefers-reduced-motion: reduce) { .fg { will-change: auto; } }

/* phones: no foreground foliage */
@media (max-width: 700px) { .fg { display: none; } }

/* Reading mode: the open card becomes an article-width page (width/height set by targetRect in app.js).
   No flames, no tilt; the description gets a visible, themed scrollbar and a slightly larger text size. */
.flip.resizing .flipper { transition: left .45s var(--ez), top .45s var(--ez), width .45s var(--ez), height .45s var(--ez); }
/* no gilt frame (nor its glare) in reading mode; the paper keeps its torn edge on wide screens */
.flip.reading .face.lift::before { opacity: 0; }
.flip.reading .f-nav { bottom: 7.5%; }   /* no frame to sit on in reading mode */
.flip.reading .back-inner { inset: 4.5% 5% 6.55%; }
/* the page is wider than a comfortable line, so the text column stays centred at about 75 characters */
.flip.reading .x-body > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.flip.reading .x-head { max-width: calc(820px + 44px); margin-left: auto; margin-right: auto; } /* + its own 22px side padding */
.flip.reading .x-plate { height: clamp(220px, 30cqw, 340px); }
.flip.reading .x-text { font-size: 18px; }
.flip.reading .x-higher p { font-size: 17px; }
/* the page's own scrollbar (a native one isn't painted or draggable inside the 3D card): a plain flat thumb on a
   thin flat rule; placed and driven by syncBar() in app.js */
.r-bar { position: absolute; z-index: 3; width: 14px; cursor: pointer; }
.r-bar[hidden] { display: none; }
.r-bar::before { content: ""; position: absolute; left: 6px; top: 0; bottom: 0; width: 2px; background: rgba(74, 50, 24, .25); }
.r-thumb { position: absolute; left: 3px; top: 0; width: 8px; border-radius: 4px; touch-action: none; cursor: grab; background: #8a6a32; transition: background .15s; }
.r-thumb:hover, .r-thumb.drag { background: #6a4c1c; }
.r-thumb.drag { cursor: grabbing; }
.f-nav .f-read[aria-pressed="true"] { border-color: var(--gilt-hi); }
/* phones: reading mode fills the screen and the paper runs past its edges, so it is only a background */
@media (max-width: 699px) {
  .flip.reading .face.back > .paper { inset: -7% -9%; filter: none; }
  .flip.reading .back-inner { inset: 14px 6px 6.55%; }
  .flip.reading .r-bar { display: none; }
}
.flip.reading .motion-tilt-toggle { display: none; } /* no tilt while reading */

/* the Foundry VTT chat command, at the foot of the card (follows the "Cast at" picker) */
.x-foundry { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.x-foundry-k { font: 700 10px/1 var(--f-display); letter-spacing: .2em; text-transform: uppercase; color: var(--ink-3); }
.x-foundry code { padding: 5px 10px; border: 1px solid rgba(74, 50, 24, .35); border-radius: 3px; background: rgba(255, 246, 222, .5); font: 600 14px/1 ui-monospace, SFMono-Regular, Consolas, monospace; color: #2d1f12; }
.x-foundry button { height: 26px; padding: 0 12px; border: 1px solid rgba(74, 50, 24, .5); border-radius: 13px; background: transparent; font: 700 10px/1 var(--f-display); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); cursor: pointer; transition: background .2s, color .2s; }
.x-foundry button:hover { background: rgba(255, 246, 222, .7); color: var(--ink); }
