.brand-mark {
    margin: 0 0 0.35rem;
    font-family: var(--font-serif);
    font-size: clamp(2.8rem, 6vw, 4.2rem);
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1;
    color: var(--color-secondary);
}

.chapter-header { margin-bottom: 1.75rem; }

.chapter-number {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--color-primary);
}

.chapter-title {
    margin: 0.25rem 0 0.5rem;
    font-family: var(--font-serif);
    font-size: 2.6rem;
    line-height: 1.15;
    font-weight: 700;
    color: var(--color-secondary);
}

.chapter-lead,
.chapter-meta {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}

.chapter-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    align-items: center;
}

.chapter-divider {
    margin-top: 1rem;
    height: 2px;
    width: 100%;
    background: linear-gradient(90deg, var(--color-accent), var(--color-primary), transparent);
    border-radius: 2px;
}

/* On-page mini TOC for long chapters */
.page-toc {
    position: sticky;
    top: calc(var(--header-height) + 0.35rem);
    z-index: 20;
    margin: 0 0 1.25rem;
    padding: 0.55rem 0.75rem 0.65rem;
    background: rgba(247, 243, 234, 0.94);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    backdrop-filter: blur(6px);
    box-shadow: var(--shadow-sm);
}
.page-toc-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.15rem 0.1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-sans);
    color: var(--color-text-secondary);
    text-align: left;
}
.page-toc-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-primary);
}
.page-toc-count {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}
.page-toc-count::before { content: '· '; }
.page-toc-chevron {
    margin-left: auto;
    width: 0.45rem;
    height: 0.45rem;
    border-right: 1.5px solid var(--color-primary);
    border-bottom: 1.5px solid var(--color-primary);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}
.page-toc.is-collapsed .page-toc-chevron {
    transform: rotate(-45deg);
}
.page-toc-list {
    list-style: none;
    margin: 0.45rem 0 0;
    padding: 0.15rem 0.1rem 0.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.45rem;
    max-height: 9.5rem;
    overflow: auto;
    scrollbar-gutter: stable;
    scrollbar-width: auto;
    scrollbar-color: var(--scrollbar-thumb, #8a7355) var(--scrollbar-track, #e0d8cb);
}
.page-toc.is-collapsed .page-toc-list {
    display: none;
}
.page-toc-list::-webkit-scrollbar {
    width: var(--scrollbar-size, 12px);
    height: var(--scrollbar-size, 12px);
    background: var(--scrollbar-track, #e0d8cb);
}
.page-toc-list::-webkit-scrollbar-track {
    background: var(--scrollbar-track, #e0d8cb);
}
.page-toc-list::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb, #8a7355);
    border-radius: 8px;
    border: 2px solid var(--scrollbar-track, #e0d8cb);
    min-height: 28px;
}
.page-toc-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover, #6b5a42);
}
.page-toc-list::-webkit-scrollbar-corner {
    background: var(--scrollbar-track, #e0d8cb);
}
.page-toc-link {
    display: inline-block;
    max-width: 100%;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    border: 1px solid transparent;
    background: rgba(107, 90, 66, 0.08);
    color: var(--color-text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    line-height: 1.25;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.page-toc-item--h3 .page-toc-link {
    background: transparent;
    border-color: var(--color-border);
    font-size: 0.76rem;
    color: var(--color-text-muted);
}
.page-toc-link:hover {
    border-color: var(--color-accent);
    color: var(--color-secondary);
}
.page-toc-link.is-active {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: var(--color-accent-soft);
}
body.is-editing .page-toc {
    display: none;
}

/* Actions chapter: sticky action tabs (variant B "table") */
.action-switcher--table {
    background: #1a1612;
    border: 1px solid #2c2620;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(20, 17, 14, 0.18);
}
.action-switcher-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.1rem 0.05rem 0.2rem;
}
.action-switcher-title {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--color-accent);
}
.action-switcher-meta {
    font-size: 0.78rem;
    color: rgba(232, 224, 212, 0.55);
}
.action-switcher-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(7.2rem, 1fr));
    gap: 0.4rem;
    max-height: none;
    overflow: visible;
}
.action-switcher-tab {
    appearance: none;
    display: inline-block;
    max-width: 100%;
    border: 1px solid rgba(196, 165, 116, 0.35);
    background: transparent;
    color: #e8e0d4;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    min-height: 2.5rem;
    padding: 0.7rem 0.55rem;
    text-align: center;
    text-decoration: none;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.action-switcher-tab:hover {
    border-color: rgba(196, 165, 116, 0.85);
    background: rgba(196, 165, 116, 0.12);
    color: #e8e0d4;
}
.action-switcher-tab:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
.action-switcher-tab.is-active,
.action-switcher-tab.is-active:hover {
    background: #c4a574;
    border-color: #c4a574;
    color: #1a1612;
}
.action-switcher-tab--overview {
    border-style: dashed;
    color: #e4d5b8;
}
.action-switcher-tab--overview:hover {
    color: #e4d5b8;
}
.action-switcher-tab--overview.is-active,
.action-switcher-tab--overview.is-active:hover {
    background: transparent;
    border-style: solid;
    border-color: #c4a574;
    color: #e4d5b8;
    box-shadow: inset 0 0 0 1px #c4a574;
}
.action-panel > h3:first-child,
.action-panel--overview > h2:first-child {
    margin-top: 0;
}
.action-panel > h3:first-child {
    font-size: 1.85rem;
}
.action-panel {
    scroll-margin-top: calc(var(--header-height) + 5.5rem);
}
.action-switcher-chrome[hidden] {
    display: none !important;
}

.chapter-content {
    background: var(--color-paper);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.75rem 1.6rem 2rem;
    box-shadow: var(--shadow-sm);
    /* Must stay visible — any non-visible overflow traps sticky mode bars */
    overflow: visible;
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4 {
    font-family: var(--font-serif);
    color: var(--color-secondary);
    line-height: 1.3;
    scroll-margin-top: calc(var(--header-height) + 4.5rem);
}

.chapter-content h1 { font-size: 2rem; margin: 0.35rem 0 0.75rem; }
/* Section rhythm: light rule above each h2 except the first in chapter / mode pane */
.chapter-content h2 {
    font-size: 1.55rem;
    margin: 1.85rem 0 0.65rem;
    padding-top: 1.05rem;
    border-top: 1px solid var(--color-border);
    font-weight: 600;
}
.chapter-content > h2:first-of-type,
.chapter-content > h1:first-child + h2,
.combat-mode-pane > h2:first-of-type,
.combat-mode-pane > .combat-mode-section:first-child > h2:first-child,
.attr-panel > h2:first-of-type,
.action-panel > h2:first-of-type {
    border-top: none;
    padding-top: 0;
    margin-top: 0.35rem;
}
/* ### название действия — крупнее; #### секции (Модификаторы, Исходы) — заметно мельче */
.chapter-content h3 {
    font-size: 1.7rem;
    margin: 1.45rem 0 0.5rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}
.chapter-content h4 {
    font-size: 1.12rem;
    margin: 1.15rem 0 0.4rem;
    font-weight: 600;
    opacity: 0.92;
}
.chapter-content h5 {
    font-size: 1rem;
    margin: 1rem 0 0.35rem;
    font-weight: 600;
}

.action-panel h4 {
    font-size: 1.14rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.2rem;
}

/* Action tab: standard section cards */
.action-section-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.15rem 0 1rem;
    position: static;
    z-index: auto;
    padding: 0.5rem 0.55rem;
    background: rgba(107, 90, 66, 0.06);
    border: 1px solid var(--color-border);
    border-radius: 10px;
}

.action-section-nav-link {
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-paper);
    color: var(--color-text-secondary);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
}

.action-section-nav-link:hover {
    border-color: var(--color-accent);
    color: var(--color-secondary);
}

.action-section {
    margin: 0 0 1rem;
    padding: 0.85rem 1rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.28);
    scroll-margin-top: calc(var(--header-height) + 9rem);
}

.action-section > h4:first-child {
    margin-top: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.action-section--lead {
    background: linear-gradient(135deg, rgba(196, 165, 116, 0.16), rgba(255, 255, 255, 0.2));
    border-color: rgba(196, 165, 116, 0.45);
}

.action-section--mods {
    border-left: 3px solid var(--color-primary);
}

.action-section--diff {
    border-left: 3px solid var(--color-accent);
}

.action-section--notes {
    background: rgba(107, 90, 66, 0.05);
    border-style: dashed;
}

.action-rule-callout {
    padding: 0.75rem 0.9rem;
    border-radius: 10px;
    background: rgba(196, 165, 116, 0.14);
    border-left: 3px solid var(--color-accent);
    font-family: var(--font-sans);
    color: var(--color-text);
}

.action-rule-callout--player {
    background: #1a1612;
    color: #f0e8dc;
    border-left-color: var(--color-accent);
}

.action-rule-callout--player,
.action-rule-callout--player * {
    color: #f0e8dc;
}

.action-rule-callout--player strong {
    color: var(--color-accent);
}

/* Overview tab */
.action-flow-strip {
    list-style: none;
    margin: 0.75rem 0 1.25rem;
    padding: 0.65rem 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.15rem;
    align-items: center;
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 650;
    background: rgba(107, 90, 66, 0.06);
    border: 1px solid var(--color-border);
    border-radius: 12px;
}

.action-flow-step {
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    background: var(--color-paper);
    border: 1px solid var(--color-border);
    color: var(--color-secondary);
}

.action-flow-sep {
    flex: 0 0 auto;
    padding: 0 0.2rem;
    color: var(--color-primary);
    font-weight: 700;
    line-height: 1;
    user-select: none;
}

.action-overview-step {
    margin: 0 0 0.85rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: var(--color-paper);
    color: var(--color-text);
}

.action-overview-step > h3:first-child {
    margin-top: 0;
    font-size: 1.25rem;
    color: var(--color-secondary);
}

.action-overview-step--armor {
    background: linear-gradient(180deg, #2a241e, #1a1612);
    border-color: #c4a574;
    color: #f0e8dc;
}

.action-overview-step--armor,
.action-overview-step--armor * {
    color: #f0e8dc;
}

.action-overview-step--armor h3,
.action-overview-step--armor strong,
.action-overview-step--armor .rule-title {
    color: var(--color-accent);
}

.action-overview-step--armor a {
    color: #e4d5b8;
    text-decoration-color: rgba(196, 165, 116, 0.7);
}

.action-overview-step--armor .rule-spoiler {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(196, 165, 116, 0.35);
    color: #f0e8dc;
}

.action-overview-step--armor .rule-spoiler summary {
    color: var(--color-accent);
}

.action-overview-step--armor code,
.action-overview-step--armor pre {
    background: rgba(0, 0, 0, 0.35);
    color: #f0e8dc;
}

html[data-theme='dark'] .action-section,
html[data-theme='dark'] .action-overview-step {
    background: #221c17;
    border-color: #3a322a;
    color: #e8e0d4;
}

html[data-theme='dark'] .action-section > h4,
html[data-theme='dark'] .action-overview-step > h3 {
    color: #f0e8dc;
}

html[data-theme='dark'] .action-flow-strip {
    background: rgba(255, 255, 255, 0.04);
    border-color: #3a322a;
}

html[data-theme='dark'] .action-flow-step {
    background: #1a1612;
    border-color: #3a322a;
    color: #f0e8dc;
}

html[data-theme='dark'] .action-flow-sep {
    color: var(--color-accent);
}

@media (max-width: 768px) {
    .action-section-nav {
        position: static;
        overflow-x: auto;
        flex-wrap: nowrap;
    }
}

/* Attribute modes: Проверка / Прогрессия */
.attr-mode-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.35rem 0 1rem;
    position: sticky;
    /* Below app header + sticky attribute switcher (same stack as .page-toc) */
    top: calc(var(--header-height, 60px) + 0.35rem + var(--attr-switcher-h, 4.75rem));
    z-index: 18;
    padding: 0.4rem 0.15rem;
    background: var(--color-paper);
    border-bottom: 1px solid var(--color-border);
}
.attr-panel,
.action-panel--overview {
    scroll-margin-top: calc(
        var(--header-height, 60px) + 0.35rem + var(--attr-switcher-h, 4.75rem) + 0.75rem
    );
}
.attr-mode-chip {
    appearance: none;
    border: 1px solid rgba(196, 165, 116, 0.45);
    background: transparent;
    color: inherit;
    border-radius: 6px;
    padding: 0.45rem 0.85rem;
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
}
.attr-mode-chip:hover {
    border-color: var(--color-accent);
    background: rgba(196, 165, 116, 0.1);
}
.attr-mode-chip.is-active {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: var(--color-accent-soft);
}

/* Combat chapter: Суть | Стол | Справка */
.combat-mode-bar {
    top: var(--header-height, 60px);
    margin-top: 0.15rem;
}
.combat-mode-pane[hidden] {
    display: none !important;
}
.combat-mode-section {
    margin: 0 0 0.25rem;
}
.combat-mode-pane > .combat-mode-section:first-child > h2:first-child {
    margin-top: 0.35rem;
}
.chapter-content--combat-modes {
    padding-top: 0.15rem;
}
.attr-sub-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0 0 0.85rem;
}
.attr-diff-picker {
    margin: 0.35rem 0 0.75rem;
}
.attr-diff-bar {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6.8rem, 1fr));
    gap: 0.35rem;
    margin-bottom: 0.65rem;
}
.attr-diff-chip {
    appearance: none;
    border: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.55);
    color: var(--color-text);
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
    line-height: 1.2;
}
.attr-diff-chip small {
    display: block;
    margin-top: 0.12rem;
    font-weight: 600;
    opacity: 0.75;
}
.attr-diff-chip.is-active {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: var(--color-accent-soft);
}
.attr-diff-pane {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.85rem;
    background: rgba(107, 90, 66, 0.05);
}
.attr-mod-picker {
    margin: 0.35rem 0 0.75rem;
}
.attr-mod-rule {
    margin: 0 0 0.65rem;
}
.attr-mod-rule > summary {
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 700;
    padding: 0.45rem 0.75rem;
}
.attr-mod-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.65rem;
}
.attr-mod-chip {
    appearance: none;
    border: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.55);
    color: var(--color-text);
    border-radius: 6px;
    padding: 0.4rem 0.65rem;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1.25;
    text-align: left;
    max-width: 100%;
}
.attr-mod-chip:hover {
    border-color: var(--color-accent);
    background: rgba(196, 165, 116, 0.1);
}
.attr-mod-chip.is-active {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: var(--color-accent-soft);
}
.attr-mod-pane {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.85rem;
    background: rgba(107, 90, 66, 0.05);
}
.attr-mod-pane[hidden] {
    display: none !important;
}
.attr-mod-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.attr-mod-table td {
    vertical-align: top;
    padding: 0.28rem 0.35rem 0.28rem 0;
    border-bottom: 1px solid rgba(107, 90, 66, 0.12);
}
.attr-mod-table tr:last-child td {
    border-bottom: none;
}
.attr-mod-code {
    width: 3.2rem;
    white-space: nowrap;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-weight: 700;
    color: var(--color-secondary);
}
.attr-mod-text {
    color: var(--color-text);
}
.attr-range-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0 0 0.55rem;
}
.attr-level-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0 0 0.65rem;
}
.attr-level-chip {
    appearance: none;
    min-width: 2.1rem;
    border: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.55);
    color: var(--color-text);
    border-radius: 6px;
    padding: 0.32rem 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1.2;
}
.attr-level-chip:hover {
    border-color: var(--color-accent);
    background: rgba(196, 165, 116, 0.1);
}
.attr-level-chip.is-active {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: var(--color-accent-soft);
}
h4.attr-level-title {
    font-size: 1.05rem;
    margin: 0.35rem 0 0.55rem;
    border-bottom: none;
    padding-bottom: 0;
}
.attr-level-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.55rem 0.75rem;
    background: rgba(107, 90, 66, 0.05);
    display: grid;
    gap: 0.55rem;
    margin: 0 0 0.75rem;
}
.attr-level-card[hidden] {
    display: none !important;
}
.attr-level-card-head {
    font-family: var(--font-sans);
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0 0 0.15rem;
}
.attr-fork-intro {
    margin: 0 0 0.45rem;
}
.attr-fork-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0 0 0.5rem;
}
.attr-fork-chip {
    appearance: none;
    border: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.55);
    color: var(--color-text);
    border-radius: 6px;
    padding: 0.35rem 0.55rem;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
    line-height: 1.2;
}
.attr-fork-chip small {
    display: block;
    margin-top: 0.1rem;
    font-weight: 600;
    opacity: 0.75;
}
.attr-fork-chip:hover {
    border-color: var(--color-accent);
    background: rgba(196, 165, 116, 0.1);
}
.attr-fork-chip.is-active {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: var(--color-accent-soft);
}
.attr-fork-pane[hidden] {
    display: none !important;
}
.attr-fork-pane p {
    margin: 0;
}
.attr-level-field {
    display: grid;
    grid-template-columns: 5.5rem minmax(0, 1fr);
    gap: 0.55rem 0.75rem;
    align-items: start;
}
.attr-level-field-label {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    padding-top: 0.15rem;
}
.attr-level-field-body {
    font-size: 0.95rem;
    line-height: 1.45;
}
.attr-level-field-body > :first-child {
    margin-top: 0;
}
.attr-level-field-body > :last-child {
    margin-bottom: 0;
}
.attr-level-field.is-muted .attr-level-field-body {
    color: var(--color-text-muted);
    opacity: 0.75;
}
@media (max-width: 640px) {
    .attr-level-field {
        grid-template-columns: 1fr;
        gap: 0.2rem;
    }
}
.attr-level-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
    margin: 0 0 0.85rem;
    font-size: 0.88rem;
    color: var(--color-text-muted);
}
.attr-level-jump input {
    width: 4.2rem;
    padding: 0.35rem 0.45rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font: inherit;
    background: var(--color-paper);
    color: var(--color-text);
}
h4.attr-level-focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
    border-radius: 4px;
}
.attr-mode-pane[hidden],
.attr-sub-pane[hidden],
.attr-diff-pane[hidden],
.attr-range-pane[hidden] {
    display: none !important;
}

.attr-switcher.attr-switcher--compact {
    overflow: visible;
    padding: 0.45rem 0.65rem 0.55rem;
}
.attr-switcher--compact .action-switcher-top {
    margin-bottom: 0.35rem;
    padding: 0;
}
.attr-switcher-current {
    font-weight: 600;
    color: #e8e0d4 !important;
}
.attr-cat-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: stretch;
}
.attr-cat-trigger {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 1px solid rgba(196, 165, 116, 0.35);
    background: transparent;
    color: #e8e0d4;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.2;
    min-height: 2rem;
    padding: 0.4rem 0.65rem;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}
.attr-cat-trigger--overview {
    text-transform: none;
    letter-spacing: 0.01em;
    border-style: dashed;
    color: var(--color-accent-soft);
}
.attr-cat-trigger:hover,
.attr-cat-trigger.is-open {
    border-color: rgba(196, 165, 116, 0.85);
    background: rgba(196, 165, 116, 0.12);
}
.attr-cat-trigger.is-active {
    background: #c4a574;
    border-color: #c4a574;
    color: #1a1612;
}
.attr-cat-trigger--overview.is-active {
    background: transparent;
    border-style: solid;
    border-color: #c4a574;
    color: #e4d5b8;
    box-shadow: inset 0 0 0 1px #c4a574;
}
.attr-cat-chevron {
    width: 0.35rem;
    height: 0.35rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    opacity: 0.75;
    margin-top: -0.15rem;
}
.attr-cat-trigger.is-open .attr-cat-chevron {
    transform: rotate(-135deg);
    margin-top: 0.1rem;
}
.attr-drawer {
    margin-top: 0.45rem;
    padding: 0.45rem;
    border: 1px solid rgba(196, 165, 116, 0.28);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.22);
}
.attr-drawer[hidden] {
    display: none !important;
}
.attr-drawer-pane {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}
.attr-drawer-pane[hidden] {
    display: none !important;
}
.attr-cat-item {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid rgba(196, 165, 116, 0.3);
    background: transparent;
    color: #e8e0d4;
    font-family: var(--font-sans);
    font-size: 0.84rem;
    font-weight: 600;
    text-align: center;
    padding: 0.5rem 0.75rem;
    border-radius: 5px;
    cursor: pointer;
    line-height: 1.2;
    min-height: 2.65rem;
}
.attr-cat-item:hover,
.attr-cat-item:focus-visible {
    background: rgba(196, 165, 116, 0.14);
    border-color: rgba(196, 165, 116, 0.55);
    outline: none;
}
.attr-cat-item.is-active {
    background: #c4a574;
    border-color: #c4a574;
    color: #1a1612;
}

/* Outcome picker — one result at a time */
.outcome-picker {
    margin: 0.75rem 0 1.25rem;
}
.outcome-picker-hint {
    margin: 0 0 0.65rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-text-muted);
}
.outcome-picker-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.45rem;
    margin-bottom: 0.85rem;
}
.outcome-chip {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 0.45rem;
    padding: 0.4rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    line-height: 1.2;
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.outcome-chip:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}
.outcome-chip:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
.outcome-chip.is-active {
    box-shadow: 0 0 0 2px var(--color-paper), 0 0 0 4px currentColor;
}

.outcome-chip--tragedy {
    background: #5c1f24;
    color: #f6d5d8;
    border-color: #7a2c33;
}
.outcome-chip--fail {
    background: #7a3b28;
    color: #f8e0d4;
    border-color: #9a4d36;
}
.outcome-chip--mid {
    background: #6b5a3a;
    color: #f3ead7;
    border-color: #8a7450;
}
.outcome-chip--success {
    background: #2f5a40;
    color: #d9f0e2;
    border-color: #3f7a55;
}
.outcome-chip--triumph {
    background: #8a6a2a;
    color: #fff4d6;
    border-color: #c4a574;
}

.outcome-pane {
    padding: 0.85rem 1rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: rgba(107, 90, 66, 0.05);
}
.outcome-pane-title {
    margin-top: 0 !important;
    font-size: 1.05rem !important;
}
.outcome-pane--tragedy { border-color: rgba(122, 44, 51, 0.45); }
.outcome-pane--fail { border-color: rgba(154, 77, 54, 0.45); }
.outcome-pane--mid { border-color: rgba(138, 116, 80, 0.45); }
.outcome-pane--success { border-color: rgba(63, 122, 85, 0.45); }
.outcome-pane--triumph { border-color: rgba(196, 165, 116, 0.55); }

.chapter-content p { margin: 0 0 0.9rem; }
.chapter-content ul, .chapter-content ol { margin: 0 0 0.95rem; padding-left: 1.35rem; }
.chapter-content li { margin: 0.22rem 0; }
.chapter-content li > ul,
.chapter-content li > ol { margin: 0.35rem 0 0.45rem; }
.chapter-content blockquote:not(.rule-block) {
    margin: 1rem 0;
    padding: 0.15rem 0 0.15rem 1rem;
    border-left: 2px solid rgba(196, 165, 116, 0.55);
    color: var(--color-text-secondary);
}
.chapter-content hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 1.6rem 0;
}
/* h2 already carries the section rule — drop a redundant HR above it */
.chapter-content hr:has(+ h1),
.chapter-content hr:has(+ h2) {
    display: none;
}
.chapter-content .rulebook-table {
    margin: 1.15rem 0 1.35rem;
}
.chapter-content a { color: var(--color-primary-dark); }
.chapter-content a.rule-ref {
    font-family: var(--font-sans);
    font-size: 0.92em;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: rgba(196, 165, 116, 0.7);
    text-underline-offset: 0.15em;
}
.chapter-content a.rule-ref:hover {
    color: var(--color-secondary);
    text-decoration-color: var(--color-accent);
}
.chapter-content code {
    /* Inline game terms (`Трагедия`, `Провал`) — same book face as body */
    font-family: var(--font-serif);
    font-size: 1em;
    font-weight: 600;
    font-style: normal;
    background: rgba(107, 90, 66, 0.08);
    padding: 0.05em 0.28em;
    border-radius: 3px;
    color: var(--color-secondary);
}
.chapter-content pre {
    background: var(--color-secondary);
    color: #f5f0e8;
    padding: 1rem 1.15rem;
    border-radius: var(--radius-md);
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 1.05rem 0 1.25rem;
}
.chapter-content pre code {
    font-family: var(--font-mono);
    font-weight: 400;
    background: transparent;
    padding: 0;
    color: inherit;
}

.rule-block,
blockquote.rule-block {
    background: rgba(107, 90, 66, 0.08);
    border-left: 3px solid var(--color-primary);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    padding: 1.1rem 1.25rem;
    margin: 1.35rem 0;
    font-style: normal;
    color: var(--color-text-secondary);
}

.rule-block.important {
    border-left-color: var(--color-danger);
    background: rgba(139, 58, 46, 0.07);
}

.rule-block.example {
    border-left-color: var(--color-success);
    background: rgba(61, 107, 82, 0.07);
}

.rule-block.attention {
    border-left-color: #b45309;
    background: rgba(180, 83, 9, 0.10);
}

.rule-block.note {
    border-left-color: #3d5a73;
    background: rgba(61, 90, 115, 0.09);
}

/* Inline editor background on a callout overrides the default tint */
.rule-block[style*='background'],
blockquote.rule-block[style*='background'] {
    /* keep left border; background comes from style attr */
}

.rule-title {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-primary-dark);
    margin-bottom: 0.35rem;
}

.rule-block.attention > .rule-title {
    color: #9a3412;
}

.rule-block.note > .rule-title {
    color: #334155;
}

/* Spoiler blocks: ::: Title … ::: */
.rule-spoiler {
    margin: 1.1rem 0;
    border: 1px solid rgba(107, 90, 66, 0.22);
    border-radius: var(--radius-md);
    background: rgba(107, 90, 66, 0.04);
    overflow: hidden;
}
.rule-spoiler > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    padding: 0.7rem 1rem;
    font-family: var(--font-serif);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
.rule-spoiler > summary::-webkit-details-marker {
    display: none;
}
.rule-spoiler > summary::before {
    content: '';
    width: 0.45rem;
    height: 0.45rem;
    border-right: 2px solid var(--color-primary);
    border-bottom: 2px solid var(--color-primary);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    flex-shrink: 0;
    margin-top: -0.1rem;
}
.rule-spoiler[open] > summary::before {
    transform: rotate(45deg);
    margin-top: 0.05rem;
}
.rule-spoiler > summary:hover {
    background: rgba(107, 90, 66, 0.08);
}
.rule-spoiler-body {
    padding: 0 1rem 1rem;
    border-top: 1px solid rgba(107, 90, 66, 0.14);
}
.rule-spoiler-body > :first-child {
    margin-top: 0.85rem;
}
.rule-spoiler-body > :last-child {
    margin-bottom: 0;
}

.breadcrumbs {
    font-family: var(--font-serif);
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: baseline;
}
.breadcrumbs a {
    color: var(--color-primary-dark);
    text-decoration: none;
    font-weight: 600;
}
.breadcrumbs a:hover {
    color: var(--color-secondary);
    text-decoration: underline;
    text-decoration-color: var(--color-accent);
    text-underline-offset: 0.15em;
}
.breadcrumbs .current {
    color: var(--color-text-secondary);
    font-weight: 600;
}
.breadcrumbs > span:not(.current):not([class*="tier"]) {
    opacity: 0.55;
    font-weight: 400;
}
.breadcrumbs .tier-pill {
    font-family: inherit;
    font-size: 0.78em;
    font-weight: 600;
    letter-spacing: 0.06em;
}

.chapter-navigation {
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: stretch;
    margin-top: 2rem;
    padding-top: 1.25rem;
}

.nav-prev, .nav-next, .nav-toc {
    font-family: var(--font-sans);
    text-decoration: none;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
    background: var(--color-paper);
    min-width: 0;
}
.nav-prev, .nav-next { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }
.nav-toc {
    align-self: center;
    font-weight: 600;
    color: var(--color-primary-dark);
}
.nav-dir { font-size: 0.72rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.nav-label { font-weight: 600; }
.nav-prev:hover, .nav-next:hover, .nav-toc:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-md);
}

.index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.35rem;
    margin-top: 0.5rem;
}

.index-section h2,
.index-section h3 {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    margin: 0 0 0.65rem;
    color: var(--color-primary-dark);
}

.index-list { list-style: none; margin: 0; padding: 0; }
.index-list a {
    display: grid;
    grid-template-columns: 2.75rem 1fr;
    gap: 0.5rem;
    padding: 0.4rem 0.3rem;
    text-decoration: none;
    color: var(--color-text);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.94rem;
}
.index-list a:hover { background: rgba(107, 90, 66, 0.1); }
.index-num { color: var(--color-text-muted); font-variant-numeric: tabular-nums; }

.search-page-form {
    display: flex;
    gap: 0.5rem;
    margin: 1rem 0;
}
.search-page-form input {
    flex: 1;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    background: var(--color-paper);
}

.search-results { list-style: none; margin: 0; padding: 0; }
.search-hit { margin: 0 0 0.75rem; }
.search-hit a {
    display: block;
    padding: 1rem 1.15rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-paper);
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
}
.search-hit a:hover { border-color: var(--color-accent); }
.search-hit-meta {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.search-hit-title {
    display: block;
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--color-secondary);
    margin: 0.2rem 0;
}
.search-hit-ctx {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.bookmark-btn {
    appearance: none;
    border: 1px solid var(--color-border);
    background: var(--color-paper);
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.bookmark-btn.is-on {
    background: rgba(196, 165, 116, 0.2);
    border-color: var(--color-accent);
    color: var(--color-primary-dark);
}

.edit-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-paper);
    color: var(--color-primary-dark);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.edit-btn:hover {
    border-color: var(--color-accent);
    background: rgba(196, 165, 116, 0.16);
    color: var(--color-secondary);
}
.edit-btn.is-on {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
    color: var(--color-accent-soft);
}
.edit-btn.is-busy { opacity: 0.55; pointer-events: none; }
.edit-btn-icon { display: block; }
#editor-save.is-busy,
#editor-save:disabled {
    opacity: 0.55;
    pointer-events: none;
    cursor: wait;
}

.chapter-editor {
    margin-top: 0.5rem;
    background: var(--color-paper);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}
.chapter-editor-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    background: rgba(107, 90, 66, 0.06);
}
.chapter-editor-file {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--color-primary-dark);
    font-weight: 600;
}
.chapter-editor-hint {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    color: var(--color-text-muted);
    flex: 1;
}
.chapter-editor-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}
.chapter-editor-area {
    display: block;
    width: 100%;
    min-height: min(70vh, 42rem);
    padding: 1.15rem 1.25rem;
    border: none;
    resize: vertical;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--color-text);
    background: var(--color-bg-alt);
    outline: none;
}
.chapter-editor-status {
    margin: 0;
    padding: 0.55rem 1rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    border-top: 1px solid var(--color-border);
}
.chapter-editor-status[data-kind="error"] {
    color: var(--color-danger);
}
body.is-editing .chapter-navigation {
    opacity: 0.35;
    pointer-events: none;
}

.empty-state {
    font-family: var(--font-sans);
    color: var(--color-text-muted);
}

/* —— Attribute icons (auto-injected at render) —— */
.attr-term {
    /* Inline-block + absolute icon: visual 1.5em, line box ≈ text only */
    display: inline-block;
    position: relative;
    padding-left: 1.82em; /* 1.7em icon + small gap */
    vertical-align: baseline;
    white-space: nowrap;
    line-height: inherit;
}

.attr-icon {
    position: absolute;
    left: 0;
    /* Sit on the text baseline band without growing the line box */
    bottom: 0.08em;
    width: 1.7em;
    height: 1.7em;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(0 0.5px 0.5px rgba(20, 17, 14, 0.12));
}

.attr-name {
    font: inherit;
    color: inherit;
}

h1 .attr-term,
h2 .attr-term,
h3 .attr-term {
    padding-left: 1.55em;
}

h1 .attr-icon,
h2 .attr-icon,
h3 .attr-icon {
    width: 1.4em;
    height: 1.4em;
    bottom: 0.12em;
}

/* Attribute chapter: title of the open attribute tab — large badge in-flow
   (absolute icons overlapped the mode bar and caused jump on Суть/Стол/Прогрессия) */
.attr-panel > h2:first-of-type,
.attr-panel > h2 {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 110px;
    line-height: 1.15;
    margin-bottom: 0.35rem;
}

.attr-panel > h2 .attr-term,
.attr-panel > h2:first-of-type .attr-term {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    padding-left: 0;
    margin-right: 0;
    position: relative;
    white-space: nowrap;
}

.attr-panel > h2 .attr-icon,
.attr-panel > h2:first-of-type .attr-icon {
    position: static;
    width: 110px;
    height: 110px;
    bottom: auto;
    left: auto;
    flex: 0 0 auto;
}

/* Mode bar sits cleanly under the title */
.attr-panel > .attr-mode-bar {
    margin-top: 0.25rem;
}

/* Switcher current + drawer chips: icon in-flow, centered with label */
.attr-switcher-current,
.attr-cat-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.attr-switcher-current .attr-term,
.attr-cat-item .attr-term {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    padding-left: 0;
    vertical-align: middle;
    line-height: 1;
}

.attr-switcher-current .attr-icon,
.attr-cat-item .attr-icon {
    position: static;
    display: block;
    width: 1.85rem;
    height: 1.85rem;
    bottom: auto;
    left: auto;
    flex: 0 0 auto;
    /* Undo previous downward nudge; keep geometric center with label */
    transform: translateY(-0.04em);
}

html[data-theme='dark'] .attr-icon {
    filter: drop-shadow(0 0.5px 0.5px rgba(0, 0, 0, 0.35));
}
