/* Mythical Blue · Themes
   <html data-style> picks the theme: mythical-blue (the original look),
   neutral, or raperonzolo. <html data-theme> still picks daylight or
   moonlight. The day palettes below only apply in daylight, so every theme
   keeps the same moonlight colours; Neutral and Raperonzolo drop the
   nautical artwork (compass, ship, title banner) in both modes. */

/* Federo: an Art Nouveau display face for the Raperonzolo theme (only downloaded when used). */
@import url('https://fonts.googleapis.com/css2?family=Federo&display=swap');

.theme-title {
  display: none;
}

/* ─── Shared: no nautical artwork outside Mythical Blue ────────────────── */

html:is([data-style="neutral"], [data-style="raperonzolo"]) :is(.compass-watermark, .ship-art, img[src*="title-banner"]) {
  display: none !important;
}

html:is([data-style="neutral"], [data-style="raperonzolo"]) .ftr svg {
  display: none;
}

html:is([data-style="neutral"], [data-style="raperonzolo"]) .theme-title {
  display: block;
  margin: 4px 0 10px;
  color: var(--navy-deep);
  font-family: 'Cinzel Decorative', serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 1.5px;
  line-height: 1.15;
  text-align: center;
}

html[data-theme="moonlight"]:is([data-style="neutral"], [data-style="raperonzolo"]) .theme-title {
  color: var(--moon-heading);
  text-shadow: 0 0 12px rgba(121, 194, 255, .25);
}

/* On the character sheet the text title takes the banner's place at the top. */
html:is([data-style="neutral"], [data-style="raperonzolo"]) .sheet > .theme-title {
  position: absolute;
  top: 58px;
  left: 90px;
  right: 90px;
  margin: 0;
  font-size: 34px;
}

html:is([data-style="neutral"], [data-style="raperonzolo"]) .sheet {
  padding-top: 150px;
}

@media (max-width: 768px) {
  html:is([data-style="neutral"], [data-style="raperonzolo"]) .sheet > .theme-title {
    top: 24px;
    left: 60px;
    right: 60px;
    font-size: 22px;
  }

  html:is([data-style="neutral"], [data-style="raperonzolo"]) .sheet {
    padding-top: 78px;
  }
}

/* ─── Neutral ──────────────────────────────────────────────────────────── */

html[data-style="neutral"] .corner {
  display: none;
}

html[data-style="neutral"]:not([data-theme="moonlight"]) {
  --navy: #3b4048;
  --navy-deep: #23272d;
  --navy-soft: #5a606b;
  --gold: #a39274;
  --gold-deep: #6f6147;
  --gold-light: #cdbd9a;
  --ink: #2a2e35;
  --ink-soft: #5d636e;
  --tone-gold-rgb: 163, 146, 116;
  --tone-gold-light-rgb: 190, 172, 134;
  --tone-gold-deep-rgb: 111, 97, 71;
  --tone-paper-rgb: 255, 255, 255;
  --tone-navy-rgb: 59, 64, 72;
  --tone-navy-deep-rgb: 35, 39, 45;
  --tone-ink-soft-rgb: 93, 99, 110;
  --tone-navy: #3b4048;
  --tone-navy-deep: #23272d;
  --tone-ink: #2a2e35;
  --tone-ink-soft: #5d636e;
  --tone-gold: #a39274;
  --tone-gold-deep: #6f6147;
  --tone-parchment: #f5f3ee;
  --tone-parchment-image: linear-gradient(180deg, #f8f7f3, #f1eee7);
  --tone-page-bg: linear-gradient(#3a3d43 0%, #474a51 50%, #55585f 100%);
}

/* Navigation icons in graphite and taupe instead of navy and gold. */
html[data-style="neutral"]:not([data-theme="moonlight"]) :is(.tab-icon, .nav-icon) {
  filter: grayscale(.9) contrast(1.05);
}

/* ─── Raperonzolo: lavender and lilac with sage green ──────────────────── */

/* The Art Nouveau frame (below) replaces the corner ornaments. */
html[data-style="raperonzolo"] .corner {
  display: none;
}

html[data-style="raperonzolo"]:not([data-theme="moonlight"]) {
  --navy: #5b3f7e;
  --navy-deep: #3e2860;
  --navy-soft: #7b61a0;
  --gold: #9d82c2;
  --gold-deep: #4f7d4b;
  --gold-light: #c8e2b8;
  --ink: #3a2a52;
  --ink-soft: #6c5a86;
  --tone-gold-rgb: 157, 130, 194;
  --tone-gold-light-rgb: 132, 178, 122;
  --tone-gold-deep-rgb: 79, 125, 75;
  --tone-paper-rgb: 255, 252, 255;
  --tone-navy-rgb: 91, 63, 126;
  --tone-navy-deep-rgb: 62, 40, 96;
  --tone-ink-soft-rgb: 108, 90, 134;
  --tone-navy: #5b3f7e;
  --tone-navy-deep: #3e2860;
  --tone-ink: #3a2a52;
  --tone-ink-soft: #6c5a86;
  --tone-gold: #9d82c2;
  --tone-gold-deep: #4f7d4b;
  --tone-parchment: #f3edf9;
  /* One layer only: the image is also used inside background shorthands. */
  --tone-parchment-image: linear-gradient(165deg, #f8f3fd 0%, #f1e8f8 55%, #edf2ea 100%);
  --tone-page-bg: linear-gradient(#3b2752 0%, #523a6c 50%, #6b5287 100%);
}

/* Values typed over a calculated one are marked in green instead of amber. */
html[data-style="raperonzolo"]:not([data-theme="moonlight"]) .sheet .is-manual {
  color: #3f7a3a !important;
}

/* Navy and gold icons shift to violet and green. */
html[data-style="raperonzolo"]:not([data-theme="moonlight"]) :is(.tab-icon, .nav-icon) {
  filter: hue-rotate(38deg) saturate(1.15);
}

html[data-style="raperonzolo"]:not([data-theme="moonlight"]) .theme-title {
  color: var(--navy);
}

html[data-style="raperonzolo"] .theme-title::before,
html[data-style="raperonzolo"] .theme-title::after {
  content: '✿';
  display: inline-block;
  margin: 0 .45em;
  color: var(--gold-deep);
  font-size: .6em;
  vertical-align: middle;
}

html[data-style="raperonzolo"][data-theme="moonlight"] .theme-title::before,
html[data-style="raperonzolo"][data-theme="moonlight"] .theme-title::after {
  color: #c9b5ee;
}

/* ─── Moonlight for Neutral and Raperonzolo: plain dark blue, no texture ─── */

html:is([data-style="neutral"], [data-style="raperonzolo"])[data-theme="moonlight"] {
  --tone-parchment-image: none;
}

html:is([data-style="neutral"], [data-style="raperonzolo"])[data-theme="moonlight"] :is(.start-page, .sheet, .dm-screen-header, .initiative-panel, .spell-picker-modal, .spell-editor-modal, .library-picker-modal, .npc-picker-modal, .home-page) {
  background-image: none;
}

html:is([data-style="neutral"], [data-style="raperonzolo"])[data-theme="moonlight"] .login-card {
  background-image: linear-gradient(135deg, hsla(calc(var(--night-hue) + 12.7deg), 88.6%, 13.7%, .90), hsla(calc(var(--night-hue) + 9.8deg), 83.5%, 19%, .72));
}

/* ─── Raperonzolo: Art Nouveau ─────────────────────────────────────────────
   Arched panels, whiplash ornaments, a full arch framing the sheet, pill
   tabs and buttons, ringed medallions, and Federo lettering. Shapes and
   ornament apply in both modes; ornament colour follows --nouveau-line. */

html[data-style="raperonzolo"] {
  --nouveau-font: 'Federo', 'Cinzel', serif;
  --nouveau-line: var(--gold);
  --nouveau-accent: var(--gold-deep);
}

html[data-style="raperonzolo"][data-theme="moonlight"] {
  --nouveau-line: #c9b5ee;
  --nouveau-accent: #9cc493;
}

/* Lettering */
html[data-style="raperonzolo"] :is(.sb-hdr, .abn, .dsbox-title, .tab, .theme-title, .inventory-subtab, .party-title, .party-subhdr, .start-page h1, .character-card strong, .home-page h1, .home-page h2, .login-card h1, .dm-screen-header h1, .initiative-panel h2, .npc-picker-header h2, .cal-month-of, .cal-year, .feature-name) {
  font-family: var(--nouveau-font);
  font-weight: 400;
}

html[data-style="raperonzolo"] .sb-hdr {
  padding: 9px 8px 8px;
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, transparent, var(--nouveau-line) 18%, var(--nouveau-line) 82%, transparent) 1;
  font-size: 12.5px;
  letter-spacing: 2.6px;
}

/* Whiplash curls either side of each section title (curl outward, bead toward the text). */
html[data-style="raperonzolo"] .sb-hdr::before,
html[data-style="raperonzolo"] .sb-hdr::after {
  content: '';
  width: 62px;
  height: 16px;
  background: var(--nouveau-line);
  -webkit-mask: url('../assets/themes/raperonzolo/whiplash.svg') center / contain no-repeat;
  mask: url('../assets/themes/raperonzolo/whiplash.svg') center / contain no-repeat;
}

html[data-style="raperonzolo"] .sb-hdr::before { left: 24px; }
html[data-style="raperonzolo"] .sb-hdr::after { right: 24px; transform: translateY(-50%) scaleX(-1); }

/* Arched panels */
html[data-style="raperonzolo"] .sb-card {
  border-radius: 26px 26px 8px 8px;
}

html[data-style="raperonzolo"] .sb-card::after {
  inset: 4px;
  border-radius: 22px 22px 6px 6px;
}

html[data-style="raperonzolo"] .ab {
  padding-top: 14px;
  border-radius: 90px 90px 12px 12px / 44px 44px 12px 12px;
}

html[data-style="raperonzolo"] .ab::after {
  inset: 4px;
  border-radius: 86px 86px 9px 9px / 40px 40px 9px 9px;
}

html[data-style="raperonzolo"] .abn {
  font-size: 12px;
  letter-spacing: 2.4px;
}

html[data-style="raperonzolo"] :is(.bonbox, .cbox, .dsbox) {
  border-radius: 20px 20px 6px 6px;
}

html[data-style="raperonzolo"] :is(.calendar-widget, .character-card, .login-card, .dm-screen-header, .initiative-panel, .home-page, .party-tile, .companion-card, .statblock-result-card, .custom-statblock-panel) {
  border-radius: 28px 28px 10px 10px;
}

html[data-style="raperonzolo"] :is(.combatant-row, .inline-statblock) {
  border-radius: 18px 18px 8px 8px;
}

html[data-style="raperonzolo"] :is(.spell-picker-modal, .spell-editor-modal, .library-picker-modal, .npc-picker-modal) {
  border-radius: 28px;
}

html[data-style="raperonzolo"] .sheet-toolbar {
  border-radius: 999px;
}

/* Ringed medallions for the header stats */
html[data-style="raperonzolo"] :is(.hdr-fields .hstat > input, .hp-readout input, .bonbox input, .modcircle) {
  box-shadow: 0 0 0 3px rgba(var(--tone-paper-rgb), .75), 0 0 0 4px var(--nouveau-line);
}

html[data-style="raperonzolo"][data-theme="moonlight"] :is(.hdr-fields .hstat > input, .hp-readout input, .bonbox input, .modcircle) {
  box-shadow: 0 0 0 3px hsla(calc(var(--night-hue) + 12deg), 70%, 12%, .9), 0 0 0 4px var(--nouveau-line);
}

/* Pill tabs and buttons */
html[data-style="raperonzolo"] .sheet .tabs {
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--nouveau-line);
  border-radius: 999px;
}

html[data-style="raperonzolo"] .sheet .tab {
  margin-bottom: 0;
  padding: 7px 16px;
  border: none;
  border-radius: 999px;
  letter-spacing: 2px;
}

html[data-style="raperonzolo"] .sheet .tab.on {
  background: var(--navy);
  color: #fff;
}

html[data-style="raperonzolo"] .sheet .tab.on .tab-icon {
  filter: brightness(0) invert(1);
}

html[data-style="raperonzolo"][data-theme="moonlight"] .sheet .tab.on {
  background: rgba(201, 181, 238, .24);
  color: var(--moon-heading);
}

html[data-style="raperonzolo"] :is(.sheet-toolbar button, .add-btn, .feature-add, .inventory-add, .overview-action-link, .start-page button, .dm-primary-button, .dm-secondary-button, .dm-subtle-button, .account-primary, .account-secondary, .login-card button) {
  border-radius: 999px;
}

html[data-style="raperonzolo"] .overview-split-button > .overview-action-link:first-child {
  border-radius: 999px 0 0 999px;
}

html[data-style="raperonzolo"] .overview-split-toggle {
  border-radius: 0 999px 999px 0;
}

html[data-style="raperonzolo"] .overview-split-menu {
  border-radius: 16px;
  overflow: hidden;
}

html[data-style="raperonzolo"] .overview-split-menu button {
  border-radius: 0;
}

html[data-style="raperonzolo"] .sheet-toolbar :is(.sheet-copy-button, .sheet-delete-button, .sheet-settings-button) {
  border-radius: 50%;
}

/* Art Nouveau frame around the sheet: flowing green vines weaving along the
   edges, spilling over them and curling into tendrils, with rampion sprays in two
   opposite corners. public/js/nouveau-frame.js draws it as an inline SVG
   sized to the framed element; --frame-scale sets the size of its details. */
.nouveau-frame {
  display: none;
}

html[data-style="raperonzolo"] .nouveau-frame {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  overflow: visible;
  pointer-events: none;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nouveau-defs {
  position: absolute;
}

html[data-style="raperonzolo"] :is(.nouveau-frame, .nouveau-defs) {
  --vine: #5d8c50;
  --vine-light: #a9cd97;
  --stem: #557f49;
  --leaf: #7aa56b;
  --leaf-dark: #4d7843;
  --petal: #a888e6;
  --petal-pale: #d9c9f7;
  --petal-deep: #7652bf;
  --petal-edge: #6c4bb0;
  --throat: #fbf8ff;
  --vein: #6a47ad;
}

html[data-style="raperonzolo"][data-theme="moonlight"] :is(.nouveau-frame, .nouveau-defs) {
  --vine: #86b977;
  --vine-light: #c6e5b8;
  --stem: #8fbb86;
  --leaf: #5f9258;
  --leaf-dark: #3f6b3b;
  --petal: #b196ec;
  --petal-pale: #ddd0f8;
  --petal-deep: #7d5cc6;
  --petal-edge: #cbb8ef;
  --throat: #fbf8ff;
  --vein: #6d4fb0;
}

.nouveau-frame .nf-vine { fill: var(--vine); }
.nouveau-frame .nf-vine-light { fill: var(--vine-light); opacity: .55; }
.nouveau-frame .nf-stem { stroke: var(--stem); stroke-width: 1.4; }
.nouveau-frame .nf-stem-main { stroke-width: 2.4; }
.nouveau-frame .nf-sepal { stroke: var(--stem); stroke-width: 1.1; }
.nouveau-frame .nf-leaf { fill: url(#nf-leaf); stroke: var(--leaf-dark); stroke-width: .7; }
.nouveau-frame .nf-midrib { stroke: var(--leaf-dark); stroke-width: .7; opacity: .8; }
.nouveau-frame .nf-cup,
.nouveau-frame .nf-petal { fill: url(#nf-corolla); }
.nouveau-frame .nf-petal { stroke: var(--petal-edge); stroke-width: .5; }
.nouveau-frame .nf-bell { fill: url(#nf-bell); stroke: var(--petal-edge); stroke-width: .5; }
.nouveau-frame .nf-bell-back { fill: var(--petal-deep); }
.nouveau-frame .nf-mouth { fill: url(#nf-mouth); }
.nouveau-frame .nf-throat { fill: var(--throat); opacity: .75; }
.nouveau-frame .nf-vein { stroke: var(--vein); stroke-width: .5; opacity: .55; }
.nouveau-frame .nf-style { stroke: #fff; stroke-width: 1; }
.nouveau-frame .nf-style-dot { fill: #fff; }
.nouveau-defs .nf-c-throat { stop-color: var(--throat); }
.nouveau-defs .nf-c-pale { stop-color: var(--petal-pale); }
.nouveau-defs .nf-c-petal { stop-color: var(--petal); }
.nouveau-defs .nf-c-deep { stop-color: var(--petal-deep); }
.nouveau-defs .nf-c-leaf { stop-color: var(--leaf); }
.nouveau-defs .nf-c-leaf-dark { stop-color: var(--leaf-dark); }

/* Leave room around the sheet for the frame to spill into. */
html[data-style="raperonzolo"] .sheet {
  --frame-scale: 1;
  overflow-x: visible;
  margin-bottom: 48px;
}

html[data-style="raperonzolo"] .sheet-toolbar {
  margin-bottom: 64px;
}

/* The settings panel opens in the gap above the framed sheet. */
html[data-style="raperonzolo"] .sheet-toolbar:has(+ .character-settings:not([hidden])) {
  margin-bottom: 16px;
}

html[data-style="raperonzolo"] .character-settings {
  margin-bottom: 64px;
  border-radius: 28px;
  overflow: hidden;
}

/* The character overview and the DM screen get the same frame, with room
   inside for the vines and outside for them to spill into. */
html[data-style="raperonzolo"] #startPage {
  --frame-scale: 1;
  overflow: visible;
  padding: 60px 76px 150px;
}

html[data-style="raperonzolo"] .dm-screen-shell {
  --frame-scale: 1;
  position: relative;
  width: calc(100% - 40px);
  /* narrower windows trade side padding for tracker width; the vines then overlap the panel edges */
  padding: 64px clamp(8px, calc(50vw - 620px), 48px) 140px;
}

/* Keep the footer clear of the bottom corner loops. */
html[data-style="raperonzolo"] .sheet {
  padding-bottom: 150px;
}

@media (max-width: 1099px) {
  html[data-style="raperonzolo"] .sheet {
    padding-left: 64px;
    padding-right: 64px;
    padding-bottom: 110px;
  }

  html[data-style="raperonzolo"] :is(.sheet, #startPage, .dm-screen-shell) {
    --frame-scale: .55;
  }

  html[data-style="raperonzolo"] #startPage {
    padding: 40px 44px 110px;
  }

  html[data-style="raperonzolo"] .dm-screen-shell {
    padding: 40px 8px 110px;
  }

  html[data-style="raperonzolo"] :is(.sheet-toolbar, .character-settings) {
    margin-bottom: 40px;
  }
}

/* Title with a whiplash divider underneath instead of the flowers either side. */
html[data-style="raperonzolo"] .theme-title {
  letter-spacing: 3px;
}

html[data-style="raperonzolo"] .theme-title::before {
  content: none;
}

html[data-style="raperonzolo"] .theme-title::after {
  content: '';
  display: block;
  width: min(260px, 80%);
  height: 26px;
  margin: 6px auto 0;
  background: var(--nouveau-line);
  -webkit-mask: url('../assets/themes/raperonzolo/divider.svg') center / contain no-repeat;
  mask: url('../assets/themes/raperonzolo/divider.svg') center / contain no-repeat;
}

@media (max-width: 768px) {
  html[data-style="raperonzolo"] .sheet {
    padding-left: 26px;
    padding-right: 26px;
    padding-bottom: 70px;
  }

  html[data-style="raperonzolo"] .sheet {
    --frame-scale: .42;
    width: auto;
    margin: 0 14px 24px;
  }

  html[data-style="raperonzolo"] :is(#startPage, .dm-screen-shell) {
    --frame-scale: .42;
    width: auto;
    margin: 0 14px 24px;
    padding: 30px 18px 70px;
  }

  html[data-style="raperonzolo"] :is(.sheet-toolbar, .character-settings) {
    margin-bottom: 26px;
  }

  html[data-style="raperonzolo"] .theme-title::after {
    height: 18px;
    margin-top: 2px;
  }

  html[data-style="raperonzolo"] .sb-hdr::before,
  html[data-style="raperonzolo"] .sb-hdr::after {
    width: 44px;
  }
}


/* Phones: the five section tabs share the width (icon over a small label) instead of scrolling
   sideways, and the bar sticks to the top of the screen. Kept last so it
   also applies over the pill tabs above. */
@media (max-width: 768px) {
  html .sheet .tabs {
    top: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    overflow: visible;
    padding: 4px;
    border-radius: 16px;
  }

  html .sheet .tabs .tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 0;
    padding: 6px 1px 5px;
    border-radius: 12px;
    font-size: 7.5px;
    letter-spacing: .3px;
    white-space: nowrap;
  }

  html .sheet .tabs .tab .tab-icon {
    margin: 0;
  }
}

/* Phones: a compact character sheet toolbar with short labels ("Home", "Save", "Overview"). */
@media (max-width: 768px) {
  html .sheet-toolbar {
    gap: 5px;
    padding: 6px;
    border-radius: 20px;
  }

  html .sheet-toolbar button {
    min-width: 0;
    min-height: 30px;
    padding: 5px 7px;
    font-size: 11px;
    letter-spacing: .3px;
    line-height: 1.1;
  }

  html .sheet-toolbar :is(.sheet-copy-button, .sheet-delete-button, .sheet-settings-button, #saveCharacterBtn) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 6px;
    border-radius: 50%;
  }

  html .sheet-toolbar :is(.sheet-copy-button, .sheet-delete-button, .sheet-settings-button) svg,
  html .sheet-toolbar .toolbar-icon {
    display: block;
    width: 16px;
    height: 16px;
  }

  html .sheet-toolbar #saveCharacterBtn .toolbar-text {
    display: none;
  }

  .toolbar-long {
    display: none;
  }
}

@media (max-width: 370px) {
  html .sheet-toolbar button {
    padding: 5px 5px;
    font-size: 10.5px;
  }
}


/* Filter bars: a Filters button on phones pops the filters out; search stays visible. */
.filter-toggle {
  display: none;
}

@media (max-width: 768px) {
  html .filter-panel {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px 10px;
  }

  html .filter-panel > * {
    flex: 1 1 calc(50% - 10px);
    min-width: 0;
    grid-column: auto !important;
  }

  html .filter-panel > .filter-keep {
    flex: 1 1 calc(100% - 140px);
    order: 0;
  }

  html .filter-panel > .filter-toggle {
    display: inline-flex;
    flex: 0 0 auto;
    order: 1;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid rgba(var(--tone-gold-rgb), .6);
    border-radius: 999px;
    background: transparent;
    color: var(--navy-deep);
    cursor: pointer;
    font: 700 10px/1.2 "Cinzel", serif;
    letter-spacing: .6px;
    text-transform: uppercase;
  }

  html .filter-panel > .filter-toggle::before { content: "⚙"; font-size: 12px; }
  html .filter-panel > .filter-toggle::after { content: "▾"; }
  html .filter-panel.is-open > .filter-toggle::after { content: "▴"; }
  html .filter-panel > .filter-toggle.has-active { background: var(--navy); color: #fff7dc; }

  html .filter-panel > :not(.filter-keep, .filter-toggle) {
    order: 2;
  }

  html .filter-panel:not(.is-open) > :not(.filter-keep, .filter-toggle) {
    display: none !important;
  }

  html .filter-panel > .feature-filter-count {
    flex-basis: 100%;
    order: 3;
  }
}

html[data-theme="moonlight"] .filter-panel > .filter-toggle {
  border-color: var(--moon-ghost-soft-line);
  color: var(--moon-text-soft);
}

html[data-theme="moonlight"] .filter-panel > .filter-toggle.has-active {
  background: var(--moon-ghost-bright);
  color: hsl(calc(var(--night-hue) + 10deg), 70%, 12%);
}

/* ─── Phones: slimmer corner buttons and toolbar, pinned Main views, full-width Raperonzolo ─── */
@media (max-width: 768px) {
  html .help-action {
    top: 10px;
    width: 34px;
    height: 34px;
  }

  html .help-action { right: 50px; font-size: 16px; }
  html .help-action.help-action-corner { right: 10px; }

  html .sheet-toolbar { gap: 4px; padding: 5px; }
  html .sheet-toolbar::after { flex-basis: 76px; }

  html .sheet-toolbar button {
    min-height: 26px;
    padding: 3px 7px;
    font-size: 10.5px;
  }

  html .sheet-toolbar :is(.sheet-copy-button, .sheet-delete-button, .sheet-settings-button, #saveCharacterBtn) {
    width: 26px;
    height: 26px;
    padding: 5px;
  }

  html .sheet-toolbar :is(#saveCharacterBtn, .sheet-copy-button, .sheet-delete-button, .sheet-settings-button) { flex-basis: 26px; }
  html .sheet-toolbar :is(.sheet-copy-button, .sheet-delete-button, .sheet-settings-button) svg,
  html .sheet-toolbar .toolbar-icon { width: 14px; height: 14px; }

  /* Section tabs stick to the top; the Main views stick right below them. */
  html .sheet .tabs { top: 0; }

  html #pg-main .inventory-subnav.main-subnav {
    position: sticky;
    top: 53px;
    z-index: 19;
    background:
      linear-gradient(rgba(255, 250, 234, .55), rgba(255, 250, 234, .55)),
      var(--tone-parchment-image) center / 1000px auto,
      var(--tone-parchment);
    box-shadow: 0 2px 8px rgba(60, 40, 10, .12);
  }

  html[data-theme="moonlight"] #pg-main .inventory-subnav.main-subnav {
    background: hsl(calc(var(--night-hue) + 11.5deg), 60%, 13%);
  }

  /* Raperonzolo: same margins as the other themes; the vines overlap the edges instead of taking room. */
  html[data-style="raperonzolo"] .sheet {
    --frame-scale: .34;
    margin: 0 0 24px;
    padding-left: 10px;
    padding-right: 10px;
  }

  html[data-style="raperonzolo"] :is(#startPage, .dm-screen-shell) {
    --frame-scale: .34;
    margin: 0 8px 24px;
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* Phones: a tidier toolbar. Row 1 holds small outlined Home / Overview links; row 2 shares the width between the save icon, the rests, Undo,
   Copy, and Delete, so both rows start and end on the same edges. */
@media (max-width: 768px) {
  html .sheet-toolbar {
    gap: 6px 5px;
    padding: 6px 8px;
    border-radius: 14px;
  }

  html .sheet-toolbar :is(#siteNavMenuBtn, #backToStartBtn, #backToCampaignBtn) {
    flex: 0 0 auto;
    min-height: 24px;
    padding: 2px 10px;
    border: 1px solid currentColor;
    background: transparent;
    box-shadow: none;
    color: var(--navy);
    font-size: 10.5px;
  }

  html[data-theme="moonlight"] .sheet-toolbar :is(#siteNavMenuBtn, #backToStartBtn, #backToCampaignBtn) {
    color: var(--moon-text-soft);
  }

  /* A full-width, zero-height break after row 1, so the actions always start row 2
     (the negative margin cancels the extra row gap). */
  html .sheet-toolbar::after {
    flex: 0 0 100%;
    height: 0;
    margin-bottom: -6px;
  }

  html .sheet-toolbar :is(#shortRestBtn, #longRestBtn, #undoCharacterForm, #currentCharacterForm) {
    flex: 1 1 0;
    min-width: 0;
  }

  html .sheet-toolbar :is(#shortRestBtn, #longRestBtn),
  html .sheet-toolbar > form button {
    min-height: 26px;
    white-space: nowrap;
  }
}

/* Phones: row 2 reads Short Rest, Long Rest, then the Save, Undo, Copy, and Delete icons,
   so Short Rest lines up under Home. */
@media (max-width: 768px) {
  html .sheet-toolbar #shortRestBtn { order: 2; }
  html .sheet-toolbar #longRestBtn { order: 3; }
  html .sheet-toolbar :is(#shortRestBtn, #longRestBtn) { min-width: 72px; }
  html .sheet-toolbar #saveCharacterBtn { order: 4; }
  html .sheet-toolbar #undoCharacterForm { order: 5; flex: 0 0 26px; }
  /* While previewing an older version: Back to Current and the note share a third row. */
  html .sheet-toolbar #currentCharacterForm { order: 9; flex: 0 0 auto; }
  html .sheet-toolbar .sheet-version-preview { order: 10; flex: 1 1 0; min-width: 0; font-size: 11px; line-height: 1.25; }
  html .sheet-toolbar .sheet-copy-button { order: 7; }
  html .sheet-toolbar .sheet-delete-button { order: 8; }
  html .sheet-toolbar .sheet-settings-button { order: 8; }
  html .sheet-toolbar #currentCharacterForm::before { content: none; }

  html .sheet-toolbar #undoCharacterForm button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    min-height: 26px;
    padding: 5px;
    border-radius: 50%;
  }

  html .sheet-toolbar #undoCharacterForm .toolbar-icon {
    display: block;
    width: 14px;
    height: 14px;
  }

  html .sheet-toolbar #undoCharacterForm .toolbar-text {
    display: none;
  }
}

/* Character sheet toolbar, all widths and themes (replaces the look of the earlier layers):
   quiet navigation links on the left, a joined Short Rest | Long Rest control, one filled Save button,
   and light icon buttons for Undo, Copy, Delete, and Settings. Phones and tablets use two rows:
   navigation and Settings, then the rests and the actions. */
html[data-theme] body .sheet-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 14px;
}

html[data-style="raperonzolo"] body .sheet-toolbar { border-radius: 24px; }

html[data-theme] body .sheet-toolbar [hidden] { display: none !important; }

/* Text buttons flow as text (so "Back to Home" keeps its spaces); buttons with an icon are flex. */
html[data-theme] body .sheet-toolbar button:not(.sheet-menu-button) {
  display: inline-block;
  line-height: 32px;
}

html[data-theme] body .sheet-toolbar :is(#saveCharacterBtn, #undoCharacterForm button, .sheet-copy-button, .sheet-delete-button, .sheet-settings-button) {
  display: inline-flex;
}

html[data-theme] body .sheet-toolbar button {
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
  min-width: 0;
  height: 34px;
  min-height: 0;
  margin: 0;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  color: var(--navy-deep);
  font: 600 12.5px/1 'Cinzel', serif;
  letter-spacing: .04em;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

html[data-style="raperonzolo"] body .sheet-toolbar button { border-radius: 999px; }

/* Navigation and icon buttons have no border (beats the older phone and moonlight border rules). */
html[data-theme] body .sheet-toolbar :is(#siteNavMenuBtn, #backToStartBtn, #backToCampaignBtn, #undoCharacterForm button, .sheet-copy-button, .sheet-delete-button, .sheet-settings-button) {
  border-color: transparent !important;
  background: transparent;
}

html[data-theme] body .sheet-toolbar :is(#siteNavMenuBtn, #backToStartBtn, #backToCampaignBtn, #undoCharacterForm button, .sheet-copy-button, .sheet-delete-button, .sheet-settings-button):is(:hover, :focus-visible),
html[data-theme] body .sheet-toolbar button:hover,
html[data-theme] body .sheet-toolbar button:focus-visible {
  background: rgba(var(--tone-navy-rgb), .08);
  outline: none;
}

html[data-theme] body .sheet-toolbar button:focus-visible { box-shadow: 0 0 0 2px rgba(var(--tone-gold-rgb), .7); }

html[data-theme] body .sheet-toolbar :is(.toolbar-icon, button > svg) {
  display: block;
  flex: none;
  width: 17px;
  height: 17px;
  stroke-width: 1.8;
}

/* Rests: one joined control. */
html[data-theme] body .sheet-toolbar :is(#shortRestBtn, #longRestBtn) {
  border-color: rgba(var(--tone-gold-rgb), .85);
  background: rgba(var(--tone-paper-rgb), .35);
  padding: 0 16px;
}

html[data-theme] body .sheet-toolbar #shortRestBtn { margin-left: auto; border-radius: 8px 0 0 8px; }
html[data-theme] body .sheet-toolbar #longRestBtn { margin-left: -9px; border-left-color: rgba(var(--tone-gold-rgb), .45); border-radius: 0 8px 8px 0; }
html[data-style="raperonzolo"] body .sheet-toolbar #shortRestBtn { border-radius: 999px 0 0 999px; }
html[data-style="raperonzolo"] body .sheet-toolbar #longRestBtn { border-radius: 0 999px 999px 0; }

html[data-theme] body .sheet-toolbar :is(#shortRestBtn, #longRestBtn):hover { background: rgba(var(--tone-gold-rgb), .18); }

/* Save: the one filled button. */
html[data-theme] body .sheet-toolbar #saveCharacterBtn {
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
}

html[data-theme] body .sheet-toolbar #saveCharacterBtn:hover { background: var(--navy-deep); }

/* Icon buttons. */
html[data-theme] body .sheet-toolbar :is(.sheet-copy-button, .sheet-delete-button, .sheet-settings-button) {
  width: 34px;
  padding: 0;
}

html[data-theme] body .sheet-toolbar .sheet-copy-button { margin-left: 0; }
html[data-theme] body .sheet-toolbar .sheet-delete-button.sheet-delete-button:hover { background: rgba(170, 40, 30, .1); color: #a3281e; }

html[data-theme] body .sheet-toolbar > form { display: contents; }
html[data-theme] body .sheet-toolbar > form[hidden] { display: none !important; }

html[data-theme] body .sheet-toolbar #currentCharacterForm button { border-color: rgba(var(--tone-gold-rgb), .85); }

html[data-theme] body .sheet-toolbar .sheet-version-preview {
  color: rgba(var(--tone-navy-deep-rgb), .75);
  font: italic 12px/1.3 'Lora', serif;
}

/* Desktop order: navigation, then (on the right) rests, Save, Undo, the version note, and the icons. */
html[data-theme] body .sheet-toolbar :is(#siteNavMenuBtn, #backToStartBtn, #backToCampaignBtn) { order: 1; }
html[data-theme] body .sheet-toolbar #shortRestBtn { order: 3; }
html[data-theme] body .sheet-toolbar #longRestBtn { order: 4; }
html[data-theme] body .sheet-toolbar #saveCharacterBtn { order: 5; margin-left: 6px; }
html[data-theme] body .sheet-toolbar #undoCharacterForm button { order: 6; }
/* While previewing an older version, Back to Current and the note get a row of their own. */
html[data-theme] body .sheet-toolbar:has(#currentCharacterForm:not([hidden]))::before {
  content: "";
  order: 19;
  flex: 0 0 100%;
  height: 0;
}

html[data-theme] body .sheet-toolbar #currentCharacterForm button { order: 20; }
html[data-theme] body .sheet-toolbar .sheet-version-preview { order: 21; flex: 1 1 0; min-width: 0; }
html[data-theme] body .sheet-toolbar :is(.sheet-copy-button, .sheet-delete-button, .sheet-settings-button) { order: 9; }
html[data-theme] body .sheet-toolbar .sheet-copy-button { margin-left: 6px; }
html[data-theme] body .sheet-toolbar::after { content: none; }

/* Moonlight. */
html[data-theme="moonlight"] body .sheet-toolbar button { color: var(--moon-text); }
html[data-theme="moonlight"] body .sheet-toolbar :is(#siteNavMenuBtn, #backToStartBtn, #backToCampaignBtn, #undoCharacterForm button, .sheet-copy-button, .sheet-delete-button, .sheet-settings-button):is(:hover, :focus-visible),
html[data-theme="moonlight"] body .sheet-toolbar button:hover,
html[data-theme="moonlight"] body .sheet-toolbar button:focus-visible { background: var(--moon-surface-glass); }
html[data-theme="moonlight"] body .sheet-toolbar :is(#shortRestBtn, #longRestBtn) { background: hsla(calc(var(--night-hue) + 12deg), 70%, 12%, .45); }

html[data-theme="moonlight"] body .sheet-toolbar #saveCharacterBtn {
  background: linear-gradient(180deg, var(--moon-button-from), var(--moon-button-to));
  color: var(--moon-heading);
}

html[data-theme="moonlight"] body .sheet-toolbar .sheet-delete-button:hover { color: #ffb4a6; }
html[data-theme="moonlight"] body .sheet-toolbar .sheet-version-preview { color: var(--moon-text-soft); }

/* Short labels ("Home", "Overview", "Save") so the whole toolbar fits on one row on desktop. */
html[data-theme] body .sheet-toolbar .toolbar-long { display: none; }

/* Phones and tablets: two rows. */
@media (max-width: 1040px) {
  html[data-theme] body .sheet-toolbar { row-gap: 6px; padding: 6px 8px; }

  html[data-theme] body .sheet-toolbar .sheet-settings-button { order: 1; margin-left: auto; }

  html[data-theme] body .sheet-toolbar::after {
    content: "";
    order: 2;
    flex: 0 0 100%;
    height: 0;
    margin: 0;
  }

  html[data-theme] body .sheet-toolbar :is(#shortRestBtn, #longRestBtn) { flex: 1 1 0; }
  html[data-theme] body .sheet-toolbar #shortRestBtn { margin-left: 0; }
  html[data-theme] body .sheet-toolbar #saveCharacterBtn .toolbar-text,
  html[data-theme] body .sheet-toolbar #undoCharacterForm .toolbar-text { display: none; }
  html[data-theme] body .sheet-toolbar :is(#saveCharacterBtn, #undoCharacterForm button) { width: 34px; padding: 0; }
  html[data-theme] body .sheet-toolbar .sheet-copy-button { margin-left: 0; }
}

@media (max-width: 768px) {
  html[data-theme] body .sheet-toolbar { gap: 4px; row-gap: 6px; padding: 6px; border-radius: 16px; }

  html[data-theme] body .sheet-toolbar button {
    height: 32px;
    padding: 0 9px;
    font-size: 11.5px;
    letter-spacing: .02em;
  }

  html[data-theme] body .sheet-toolbar #siteNavMenuBtn { width: 32px; padding: 0; }
  html[data-theme] body .sheet-toolbar :is(#shortRestBtn, #longRestBtn) { padding: 0 6px; }
  html[data-theme] body .sheet-toolbar #longRestBtn { margin-left: -5px; }

  html[data-theme] body .sheet-toolbar :is(#saveCharacterBtn, #undoCharacterForm button, .sheet-copy-button, .sheet-delete-button, .sheet-settings-button) {
    width: 32px;
  }

  html[data-theme] body .sheet-toolbar #saveCharacterBtn { margin-left: 4px; }
}

/* Overview pages (campaign, characters): a quiet back link like the sheet toolbar's, and a matched pair of
   actions: Open DM Screen outlined, + New Character filled with a slim ▾ attached. On phones they share a row. */
html[data-theme] body .overview-actions .overview-action-link::before,
html[data-theme] body .overview-actions .overview-action-link::after {
  content: none;
}

html[data-theme] body .overview-actions-start .overview-action-link {
  width: auto;
  min-width: 0;
  margin-left: -10px;
  padding: 7px 10px;
  border: 0 !important;
  border-radius: 8px;
  background: none;
  box-shadow: none;
  color: var(--navy-deep);
  font: 600 12.5px/1.2 'Cinzel', serif;
  letter-spacing: .04em;
  text-transform: none;
}

html[data-theme] body .overview-actions-start .overview-action-link:hover,
html[data-theme] body .overview-actions-start .overview-action-link:focus-visible {
  background: rgba(var(--tone-navy-rgb), .08);
  transform: none;
}

html[data-theme] body .overview-actions:not(.overview-actions-start) {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 10px;
}

html[data-theme] body .overview-actions:not(.overview-actions-start) .overview-action-link {
  min-width: 0;
  height: 40px;
  padding: 0 20px;
  border-radius: 8px;
  font-size: 12.5px;
  letter-spacing: .04em;
  text-transform: none;
}

html[data-theme] body .overview-actions #openDMButton {
  border: 1px solid rgba(var(--tone-gold-rgb), .9);
  background: rgba(var(--tone-paper-rgb), .4);
  box-shadow: none;
  color: var(--navy-deep);
}

html[data-theme] body .overview-actions #openDMButton:hover,
html[data-theme] body .overview-actions #openDMButton:focus-visible {
  background: rgba(var(--tone-gold-rgb), .16);
}

html[data-theme] body .overview-split-button { display: inline-flex; }
html[data-theme] body .overview-split-button[hidden] { display: none; }
html[data-theme] body .overview-actions:not(.overview-actions-start) .overview-split-button > .overview-action-link:first-child { border-radius: 8px 0 0 8px; }

html[data-theme] body .overview-actions:not(.overview-actions-start) .overview-split-toggle {
  width: 40px;
  margin-left: 0;
  padding: 0;
  border-left-color: rgba(255, 255, 255, .3);
  border-radius: 0 8px 8px 0;
  font-size: 11px;
}

html[data-style="raperonzolo"] body .overview-actions-start .overview-action-link,
html[data-style="raperonzolo"] body .overview-actions:not(.overview-actions-start) .overview-action-link { border-radius: 999px; }
html[data-style="raperonzolo"] body .overview-actions:not(.overview-actions-start) .overview-split-button > .overview-action-link:first-child { border-radius: 999px 0 0 999px; }
html[data-style="raperonzolo"] body .overview-actions:not(.overview-actions-start) .overview-split-toggle { border-radius: 0 999px 999px 0; }

html[data-theme="moonlight"] body .overview-actions-start .overview-action-link,
html[data-theme="moonlight"] body .overview-actions #openDMButton { color: var(--moon-text); }
html[data-theme="moonlight"] body .overview-actions-start .overview-action-link:hover { background: var(--moon-surface-glass); }
html[data-theme="moonlight"] body .overview-actions #openDMButton { background: hsla(calc(var(--night-hue) + 12deg), 70%, 12%, .45); }

@media (max-width: 768px) {
  html[data-theme] body .overview-actions:not(.overview-actions-start) {
    flex-wrap: nowrap;
    gap: 8px;
    padding-top: 12px;
  }

  html[data-theme] body .overview-actions:not(.overview-actions-start) > :not([hidden]) {
    flex: 1 1 0;
    min-width: 0;
  }

  html[data-theme] body .overview-actions:not(.overview-actions-start) .overview-action-link {
    height: 38px;
    padding: 0 10px;
    font-size: 12px;
    letter-spacing: .02em;
    white-space: nowrap;
  }

  html[data-theme] body .overview-split-button > .overview-action-link:first-child { flex: 1 1 auto; }
  html[data-theme] body .overview-actions .overview-split-toggle { flex: 0 0 34px; width: 34px; padding: 0; }
  html[data-theme] body .overview-actions #openDMButton .nav-icon { width: 16px; height: 16px; }
}

/* Character sheet section buttons (Attacks, Features & Traits, Spells, Companions, Inventory): one filled
   "+ Add …" button, then outlined "+ Custom …" and Edit buttons, all the same size; on phones they share the row. */
html[data-theme] body .section-action-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
}

html[data-theme] body .section-action-buttons .section-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  margin: 0;
  padding: 0 13px;
  border: 1px solid var(--gold-deep);
  border-radius: 7px;
  background: var(--navy);
  box-shadow: none;
  color: #fff;
  font: 600 11.5px/1.2 'Cinzel', serif;
  letter-spacing: .04em;
  text-transform: none;
  white-space: nowrap;
  cursor: pointer;
}

html[data-theme] body .section-action-buttons .section-add:hover,
html[data-theme] body .section-action-buttons .section-add:focus-visible {
  filter: brightness(1.12);
}

html[data-theme] body .section-action-buttons .section-add-secondary {
  border-color: rgba(var(--tone-gold-rgb), .9);
  background: rgba(var(--tone-paper-rgb), .45);
  color: var(--navy-deep);
}

html[data-theme] body .section-action-buttons .section-add-secondary:hover,
html[data-theme] body .section-action-buttons .section-add-secondary:focus-visible {
  background: rgba(var(--tone-gold-rgb), .16);
  filter: none;
}

html[data-theme] body .section-action-buttons .section-add.editing-active {
  border-color: var(--gold-deep);
  background: var(--gold);
  color: var(--navy-deep);
}

html[data-style="raperonzolo"] body .section-action-buttons .section-add { border-radius: 999px; }

html[data-theme="moonlight"] body .section-action-buttons .section-add {
  border-color: var(--moon-ghost-line);
  background: linear-gradient(180deg, hsla(calc(var(--night-hue) + 5.5deg), 75%, 29.8%, .94), hsla(calc(var(--night-hue) + 10.8deg), 90%, 15.7%, .96));
  color: var(--moon-ghost-bright);
}

html[data-theme="moonlight"] body .section-action-buttons .section-add-secondary {
  background: transparent;
  color: var(--moon-text);
}

html[data-theme="moonlight"] body .section-action-buttons .section-add.editing-active {
  background: var(--gold);
  color: var(--navy-deep);
}

/* Room under the buttons so the card's inner border line does not cross them. */
html[data-theme] body .section-heading-actions:has(.section-add) {
  padding-bottom: 14px;
}

/* On wider screens the buttons sit beside the title, centered in the heading instead of on its top border. */
@media (min-width: 769px) {
  html[data-theme] body .section-heading-actions:has(.section-add) {
    align-items: center;
  }
}

/* Attacks: the buttons sit above the list, so the + Add Attack menu opens downward over it. */
html[data-theme] body .attack-actions {
  margin: 4px 0 10px;
  padding: 0 8px;
}

.attack-menu-custom {
  margin-bottom: 6px;
  border-bottom: 1px dotted rgba(var(--tone-gold-rgb), .5) !important;
}

@media (max-width: 768px) {
  html[data-theme] body .section-action-buttons {
    width: 100%;
  }

  html[data-theme] body .section-action-buttons > .section-add,
  html[data-theme] body .section-action-buttons > .attack-add-wrap {
    flex: 1 1 0;
  }

  html[data-theme] body .section-action-buttons .attack-add-wrap .section-add {
    width: 100%;
  }

  html[data-theme] body .section-action-buttons .section-add {
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }
}
