.library-main { position: relative; z-index: 1; }
[hidden] { display: none !important; }

.login-card { width: min(560px,calc(100% - 30px)); margin: clamp(55px,10vh,110px) auto; padding: clamp(28px,5vw,48px); border: 1px solid var(--line); border-top: 2px solid var(--ember); background: rgba(25,25,23,.94); box-shadow: var(--shadow); }
.login-card h1 { margin: 12px 0 10px; color: var(--ink); font: 600 clamp(1.7rem,5vw,2.25rem)/1.25 var(--serif); letter-spacing: .08em; }
.login-card > p { margin: 0; color: var(--muted); font: .92rem/1.75 var(--serif); }
.login-form { display: grid; gap: 7px; margin-top: 28px; }
.login-form label { color: var(--muted); font-size: .72rem; letter-spacing: .05em; }
.login-form > div { display: grid; grid-template-columns: minmax(0,1fr) auto; }
.login-form button { padding: 0 18px; border: 0; color: white; background: var(--ember); }

.library-layout { display: grid; grid-template-columns: minmax(220px,260px) minmax(460px,1fr) minmax(390px,460px); gap: clamp(14px,1.7vw,26px); align-items: start; width: min(1600px,calc(100% - 28px)); margin: 0 auto; padding: 15px 0; }
.library-left-rail, .library-right-rail, .library-center { min-width: 0; }
.library-right-rail { align-content: start; }
.library-search-panel { min-height: 238px; }
.library-search-panel .jump-form { margin-bottom: 18px; }
.library-project-summary { display: grid; gap: 6px; margin-top: 18px; padding: 15px 0 17px; border-top: 1px solid var(--line); }
.library-project-summary strong { color: var(--ink); font: 600 .88rem/1.5 var(--serif); }
.library-project-summary small { color: var(--muted); font-size: .66rem; }

.library-toc { display: grid; gap: 2px; margin: 9px 16px 18px; }
.library-toc details { border-bottom: 1px solid #302e29; }
.library-toc summary { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; min-height: 42px; color: var(--muted); cursor: pointer; list-style: none; }
.library-toc summary::-webkit-details-marker { display: none; }
.library-toc summary::after { color: #777168; content: "⌄"; transition: transform 160ms ease; }
.library-toc details[open] summary::after { transform: rotate(180deg); }
.library-toc summary strong { overflow: hidden; font: 600 .78rem/1.35 var(--serif); text-overflow: ellipsis; white-space: nowrap; }
.library-toc details.active summary strong { color: var(--gold); }
.toc-sections { display: grid; gap: 1px; padding: 0 0 8px; }
.toc-section { display: block; width: 100%; min-height: 34px; padding: 6px 7px; border: 0; border-left: 2px solid transparent; color: #918d84; background: transparent; cursor: pointer; text-align: left; }
.toc-section:hover { color: var(--ink); background: var(--paper-soft); }
.toc-section.active { border-left-color: var(--ember-bright); color: var(--ink); background: rgba(180,31,39,.1); }
.toc-section span { overflow: hidden; font: .72rem/1.35 var(--serif); text-overflow: ellipsis; white-space: nowrap; }
.toc-section-child { min-height: 31px; padding-left: 20px; }
.toc-section-child span { color: #827d74; font-size: .68rem; }
.toc-section-child::before { margin-right: 7px; color: #5d5850; content: "↳"; font-size: .68rem; }

.speech-settings { display: grid; gap: 13px; padding: 3px 0 18px; }
.speech-settings > label:not(.speech-toggle) { display: grid; gap: 6px; color: var(--muted); font-size: .68rem; letter-spacing: .04em; }
.speech-settings select { width: 100%; min-width: 0; height: 38px; padding: 0 10px; border: 1px solid #49463f; border-radius: 0; color: var(--ink); background: #11110f; font: .76rem var(--sans); }
.speech-toggle { display: flex; align-items: center; gap: 8px; min-height: 34px; color: var(--ink); font: .72rem/1.45 var(--serif); cursor: pointer; }
.speech-toggle input { width: 16px; height: 16px; accent-color: var(--ember-bright); }
.library-speech-panel .reading-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.library-speech-panel .reading-controls button:first-child { grid-column: 1 / -1; }
.library-speech-panel .reading-controls button:not(:first-child) { border-color: #a89b89; color: #2c2722; background: #e8e0d3; font-weight: 700; }
.library-speech-panel .reading-controls button:not(:first-child):hover:not(:disabled) { border-color: #d6c8b3; background: #fff8ec; }
.library-speech-panel .reading-controls button:disabled { color: #777067; background: #c9c0b3; opacity: .62; }
.library-speech-panel .speech-note { min-height: 1.5em; margin: 0; color: var(--muted); font-size: .68rem; line-height: 1.5; }

.annotation-manager { display: grid; gap: 11px; padding: 3px 0 18px; }
.annotation-manager > label { display: grid; gap: 6px; color: var(--muted); font-size: .68rem; letter-spacing: .04em; }
.annotation-manager input[type="search"], .annotation-manager > label select, .annotation-name, .annotation-note, .annotation-card-actions select { width: 100%; min-width: 0; border: 1px solid #49463f; border-radius: 0; color: var(--ink); background: #11110f; font: .74rem/1.45 var(--sans); }
.annotation-manager input[type="search"], .annotation-manager > label select, .annotation-name, .annotation-card-actions select { height: 36px; padding: 0 9px; }
.annotation-note { resize: vertical; padding: 8px 9px; }
.annotation-export-actions { display: grid; grid-template-columns: 1fr; gap: 6px; }
.annotation-export-actions button { display: grid; place-items: center; min-height: 34px; padding: 0 8px; border: 1px solid #615b52; color: var(--ink); background: #25231f; font: 700 .68rem var(--sans); cursor: pointer; }
.annotation-status { min-height: 1.4em; margin: 0; color: var(--muted); font-size: .66rem; line-height: 1.45; }
.annotation-list { display: grid; gap: 9px; }
.annotation-empty { margin: 0; padding: 18px 10px; border: 1px dashed #454139; color: #8e887e; font: .72rem/1.6 var(--serif); text-align: center; }
.annotation-card { padding: 0; border: 1px solid #403c35; border-left: 3px solid #8f7b39; background: rgba(255,255,255,.025); }
.annotation-card.unresolved { border-left-color: #a33a31; }
.annotation-card > summary { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 3px 8px; padding: 10px; cursor: pointer; list-style: none; }
.annotation-card > summary::-webkit-details-marker { display: none; }
.annotation-card > summary::after { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: #a69e92; content: "⌄"; transition: transform 160ms ease; }
.annotation-card[open] > summary::after { transform: rotate(180deg); }
.annotation-card-body { display: grid; gap: 7px; padding: 0 10px 10px; }
.annotation-name { color: #f0e8dc; font-weight: 700; }
.annotation-location { color: #a69e92; font: .62rem/1.4 var(--sans); }
.annotation-excerpt { display: -webkit-box; margin: 0; overflow: hidden; color: #d2cabf; font: .7rem/1.55 var(--serif); -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.annotation-card-actions { display: grid; grid-template-columns: minmax(0,1fr) auto auto; gap: 5px; }
.annotation-card-actions button { min-height: 34px; padding: 0 8px; border: 1px solid #665f55; color: var(--ink); background: #292621; cursor: pointer; }
.annotation-card-actions .danger { border-color: #6f3937; color: #e9bab6; }
.annotation-warning { color: #d49285; font: .62rem/1.45 var(--sans); }
.annotation-table-preview { max-height: 260px; overflow: auto; border: 1px solid #484238; background: #f4efe5; }
.annotation-mixed-preview { display: grid; gap: 10px; }
.annotation-table-preview table { width: 100%; border-collapse: collapse; color: #302923; font: .65rem/1.4 var(--serif); }
.annotation-table-preview th, .annotation-table-preview td { padding: 5px 6px; border: 1px solid #c7bdad; text-align: left; vertical-align: top; }
.annotation-table-preview th { background: #e4dacb; font-weight: 700; }
.annotation-image-previews { display: grid; gap: 10px; }
.annotation-image-preview { margin: 0; padding: 6px; border: 1px solid #484238; background: #f4efe5; }
.annotation-image-preview img { display: block; width: 100%; height: auto; }
.annotation-image-preview figcaption { margin-top: 5px; color: #5e554c; font: .64rem/1.4 var(--sans); text-align: center; }
.library-copy table.annotation-table-highlight { outline: 3px solid rgba(198,162,44,.82); outline-offset: 3px; }
.library-copy table.annotation-table-yellow th, .library-copy table.annotation-table-yellow td { box-shadow: inset 0 0 0 1000px rgba(232,205,74,.28); }
.library-copy table.annotation-table-red th, .library-copy table.annotation-table-red td { box-shadow: inset 0 0 0 1000px rgba(214,91,79,.24); }
.library-copy table.annotation-table-blue th, .library-copy table.annotation-table-blue td { box-shadow: inset 0 0 0 1000px rgba(71,161,197,.24); }
.library-copy table.annotation-table-red { outline-color: rgba(180,65,57,.68); }
.library-copy table.annotation-table-blue { outline-color: rgba(48,130,164,.68); }
.library-copy table.annotation-table-highlight.annotation-focus { outline-width: 5px; animation: annotation-focus 900ms ease-in-out 2 alternate; }
.library-copy .rulebook-image { cursor: pointer; }
.library-copy .rulebook-image.annotation-image-highlight { padding: 5px; outline: 3px solid rgba(198,162,44,.82); outline-offset: 3px; background: rgba(232,205,74,.2); }
.library-copy .rulebook-image.annotation-image-red { outline-color: rgba(180,65,57,.68); background: rgba(214,91,79,.18); }
.library-copy .rulebook-image.annotation-image-blue { outline-color: rgba(48,130,164,.68); background: rgba(71,161,197,.18); }
.library-copy .rulebook-image.annotation-image-highlight.annotation-focus { outline-width: 5px; animation: annotation-focus 900ms ease-in-out 2 alternate; }
.annotation-toolbar { position: fixed; z-index: 55; display: flex; align-items: center; gap: 6px; padding: 7px 8px 7px 11px; border: 1px solid #5b554b; border-top: 2px solid var(--ember-bright); color: var(--ink); background: #171715; box-shadow: 0 10px 30px rgba(0,0,0,.4); font: .68rem var(--sans); }
.annotation-toolbar button { width: 30px; height: 30px; padding: 0; border: 1px solid rgba(255,255,255,.28); color: #211d19; cursor: pointer; font: 800 .65rem var(--sans); }
.annotation-toolbar [data-annotation-color="yellow"] { background: #e9d978; }
.annotation-toolbar [data-annotation-color="red"] { background: #e49a91; }
.annotation-toolbar [data-annotation-color="blue"] { background: #91c7dc; }
.library-copy mark.annotation-highlight { padding: .04em .08em; border-radius: 2px; color: inherit; box-decoration-break: clone; -webkit-box-decoration-break: clone; cursor: pointer; }
.library-copy mark.annotation-yellow { background: rgba(229,202,68,.5); box-shadow: inset 0 -2px 0 rgba(150,115,10,.38); }
.library-copy mark.annotation-red { background: rgba(214,91,79,.38); box-shadow: inset 0 -2px 0 rgba(143,32,37,.4); }
.library-copy mark.annotation-blue { background: rgba(71,161,197,.36); box-shadow: inset 0 -2px 0 rgba(34,105,135,.42); }
.library-copy mark.annotation-focus { outline: 3px solid rgba(143,32,37,.62); outline-offset: 3px; animation: annotation-focus 900ms ease-in-out 2 alternate; }
@keyframes annotation-focus { from { outline-color: rgba(143,32,37,.18); } to { outline-color: rgba(143,32,37,.82); } }

.library-reader, .library-results { width: 100%; }
.reading-controls { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.reading-controls button, .library-pager button { min-height: 36px; padding: 0 11px; border: 1px solid #8f806e; color: #554940; background: rgba(255,255,255,.16); cursor: pointer; }
.reading-controls button:first-child { border-color: #8f2025; color: white; background: #8f2025; }
.reading-controls button:disabled, .library-pager button:disabled { cursor: default; opacity: .35; }
.library-copy { min-height: 420px; }
body[data-library-font="small"] .library-copy { font-size: .9em; }
body[data-library-font="large"] .library-copy { font-size: 1.12em; }
body[data-library-leading="compact"] .library-copy { line-height: 1.55; }
body[data-library-leading="relaxed"] .library-copy { line-height: 2; }
.library-copy .rules-heading { margin-top: 28px; padding-bottom: 8px; border-bottom: 1px solid rgba(92,72,56,.22); color: #332923; font-weight: 700; }
.library-copy .bullet-heading { padding-left: 0; }
.library-copy strong { font-weight: 700; }
.library-copy p.no-indent { text-indent: 0; }
.translation-reference { margin-left: .06em; color: #8a3f21; font: 700 .65em/0 var(--sans); vertical-align: super; }
.translation-note { margin: 8px 0 16px !important; color: #8a8178; font: .7rem/1.55 var(--sans) !important; letter-spacing: .02em; }
.author-note { margin: 14px 0 20px !important; padding: 12px 15px; border-left: 3px solid #a45a27; color: #5c493d; background: rgba(164,90,39,.08); font: .78rem/1.65 var(--sans) !important; }
.author-note::before { color: #8a3f21; content: attr(data-note-label) "："; font-weight: 700; }
.rulebook-link { color: #7b291f; font-weight: 700; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.rulebook-link:hover, .rulebook-link:focus-visible { color: #a31f25; }
.literary-quote { margin: 24px 0 0; padding: 18px 22px 14px; border-left: 3px solid #8f2025; color: #433932; background: rgba(143,32,37,.055); font: italic 1rem/1.9 var(--serif); }
.quote-attribution { margin: 0 0 24px !important; padding: 0 22px 16px 25px; border-left: 3px solid #8f2025; color: #433932; background: rgba(143,32,37,.055); font: italic 1rem/1.9 var(--serif) !important; text-align: right !important; }
.structured-list { display: grid; gap: 7px; margin: 10px 0 22px; padding: 0; list-style: none; }
.structured-list li { position: relative; padding-left: 20px; color: #4d433b; font: .92rem/1.7 var(--serif); }
.structured-list li::before { position: absolute; left: 2px; top: .68em; width: 7px; height: 7px; border: 1px solid rgba(143,32,37,.78); background: rgba(143,32,37,.1); content: ""; transform: rotate(45deg); }
#chapter-06-section-06-block-40 { margin-bottom: 0; }
#chapter-06-section-06-block-44 { margin: 0 !important; padding-left: 20px; }
#chapter-06-section-06-block-44-part-2 { margin-top: 0; }
.rulebook-image { margin: 24px 0 30px; }
.rulebook-image img { display: block; width: 100%; height: auto; border: 1px solid rgba(68,55,45,.28); box-shadow: 0 12px 28px rgba(35,25,18,.14); }
.rulebook-image figcaption { margin-top: 8px; color: #766b62; font: .72rem/1.45 var(--sans); letter-spacing: .06em; text-align: center; }
.rulebook-definition { margin: 20px 0 26px; padding: 0 0 16px; border-bottom: 1px solid rgba(92,72,56,.18); }
.rulebook-definition .rules-heading { margin-top: 0; }
.rulebook-definition dl { display: grid; grid-template-columns: max-content minmax(0,1fr); gap: 7px 10px; margin: 12px 0 0; }
.rulebook-definition dt { color: #6d2c2f; font: 700 .78rem/1.7 var(--sans); }
.rulebook-definition dd { margin: 0; color: #4d433b; font: .9rem/1.7 var(--serif); }
.rulebook-diagram { margin: 18px 0 24px; padding: 16px 18px; overflow-x: auto; border: 1px solid rgba(92,72,56,.3); color: #4d433b; background: rgba(177,139,82,.08); font: .84rem/1.75 var(--serif); white-space: pre-wrap; }
.rulebook-table { margin: 26px 0 30px; }
.rulebook-table figcaption { margin-bottom: 10px; color: #332923; font: 700 1.02rem/1.5 var(--serif); text-align: center; }
.rulebook-table-scroll { overflow-x: auto; border: 1px solid rgba(92,72,56,.42); overscroll-behavior-inline: contain; scroll-behavior: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
.rulebook-table-scroll-top { height: 16px; margin: 0 0 6px; overflow-x: auto; overflow-y: hidden; border: 1px solid rgba(92,72,56,.28); background: rgba(120,105,86,.08); scrollbar-color: #786956 rgba(120,105,86,.12); }
.rulebook-table-scroll-top-track { height: 1px; }
.rulebook-table table { width: 100%; min-width: 520px; border-collapse: collapse; color: #40362f; background: rgba(255,255,255,.2); font: .78rem/1.45 var(--serif); }
.rulebook-table table.compact-table { min-width: 0; table-layout: fixed; }
.rulebook-table th, .rulebook-table td { padding: 8px 10px; border-right: 1px solid rgba(92,72,56,.23); border-bottom: 1px solid rgba(92,72,56,.23); text-align: center; vertical-align: middle; }
.rulebook-table td.long-cell { min-width: 210px; text-align: left; }
.rulebook-table td.manual-break-cell { min-width: 0; text-align: center; }
.rulebook-table table.compact-table td.long-cell { min-width: 0; overflow-wrap: anywhere; }
.rulebook-table th:last-child, .rulebook-table td:last-child { border-right: 0; }
.rulebook-table tbody tr:last-child td { border-bottom: 0; }
.rulebook-table th { color: #fffaf0; background: #786956; font-weight: 700; }
.rulebook-table tbody tr:nth-child(even) { background: rgba(177,139,82,.12); }
.speech-active { border-radius: 2px; outline: 2px solid rgba(164,90,39,.4); outline-offset: 4px; background: rgba(218,175,77,.2) !important; box-shadow: 0 0 0 7px rgba(218,175,77,.07); transition: background 160ms ease,outline-color 160ms ease; }
.rulebook-box { position: relative; margin: 24px 0; padding: 20px 22px 10px; border: 2px solid #786956; color: #302822; background: rgba(177,139,82,.09); box-shadow: inset 0 0 0 4px rgba(120,105,86,.12); }
.rulebook-box > :first-child { margin-top: 0; }
.rulebook-box > :last-child { margin-bottom: 0; }
.rulebook-box .rules-heading { border-bottom-color: rgba(92,72,56,.34); }
.skill-index { margin-top: 0; padding-bottom: 20px; }
.skill-index .rules-heading { margin: 0 0 8px; }
.skill-index-legend { margin: 0 0 16px; color: #655a50; font-size: .76rem; line-height: 1.65; }
.skill-index-legend span { display: block; }
.skill-index-links { columns: 3; column-gap: 16px; }
.skill-index-links a, .skill-index-links span { display: block; min-width: 0; padding: 3px 0; break-inside: avoid; color: #61231f; font: 700 .76rem/1.4 var(--serif); overflow-wrap: anywhere; text-decoration-color: rgba(97,35,31,.35); text-underline-offset: 2px; }
.skill-index-links a:hover { color: #9a1e24; text-decoration-color: currentColor; }
.skill-index-links .unlinked { color: #625a52; font-weight: 500; }
.price-index .skill-index-links { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px 24px; columns: auto; }
.price-index-group { min-width: 0; }
.price-index-group h3 { margin: 0 0 8px; padding-bottom: 5px; border-bottom: 1px solid rgba(92,72,56,.22); color: #4e4037; font: 700 .9rem/1.45 var(--serif); }
.price-index-group-links { display: grid; align-content: start; }
.skill-card { margin: 22px 0; padding: 18px 20px 8px; border: 1px solid rgba(92,72,56,.3); border-left: 3px solid #8f2025; background: rgba(255,255,255,.2); }
.skill-title { scroll-margin-top: 90px; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid rgba(92,72,56,.24); color: #332923; font: 700 1.18rem/1.45 var(--serif); }
.skill-subheading { margin: 20px 0 7px; color: #4e4037; font: 700 .94rem/1.5 var(--serif); }
.skill-card > :last-child { margin-bottom: 0; }
.floating-back-to-top { position: fixed; right: var(--reader-right-offset,max(18px,env(safe-area-inset-right))); bottom: max(22px,env(safe-area-inset-bottom)); z-index: 18; min-height: 40px; padding: 0 14px; border: 1px solid rgba(143,32,37,.78); border-radius: 999px; color: #fff8ec; background: rgba(112,39,36,.94); box-shadow: 0 8px 24px rgba(36,20,16,.3); cursor: pointer; font: 700 .72rem/1 var(--sans); backdrop-filter: blur(6px); }
.floating-back-to-top:hover, .floating-back-to-top:focus-visible { border-color: #b42129; background: #8f2025; }
.spell-card > p:first-of-type, .spell-card > p:nth-of-type(2) { margin-bottom: 6px; text-indent: 0; }
.mythos-tome-index .skill-index-links, .occult-book-index .skill-index-links { columns: 2; }
.mythos-tome-card > p:first-of-type, .occult-book-card > p:first-of-type { text-indent: 0; }
.mythos-tome-fields, .occult-book-fields { margin: 12px 0 4px; padding-top: 10px; border-top: 1px solid rgba(92,72,56,.2); text-indent: 0 !important; line-height: 1.72; }
.mythos-tome-fields strong, .occult-book-fields strong { color: #5d2824; }
.library-copy mark, .result-excerpt mark { padding: 0 .1em; color: #fff4cc; background: #9c2026; }
.library-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 36px; padding-top: 18px; border-top: 1px solid rgba(92,72,56,.24); }

.library-results > .text-button { margin: -12px 0 22px; color: #7b291f; }
.result-list { display: grid; gap: 10px; }
.result-list .choice-button { grid-template-columns: minmax(0,1fr) auto; overflow: hidden; color: #332923; }
.result-copy { display: block; min-width: 0; white-space: normal; }
.result-copy strong { display: block; margin-bottom: 7px; font: 600 .9rem/1.4 var(--serif); }
.result-list .result-excerpt { display: block; margin: 0; overflow-wrap: anywhere; color: #685e56; font: .82rem/1.65 var(--serif); white-space: normal; }
.result-page { color: #8c211f; font: 700 .68rem/1 Georgia,serif; white-space: nowrap; }
.result-empty { padding: 42px 20px; border: 1px solid rgba(92,72,56,.28); color: #756b61; text-align: center; }

@media (min-width:1500px) {
  .library-layout { grid-template-columns: minmax(230px,260px) minmax(560px,1fr) minmax(390px,440px); width: min(1840px,calc(100% - 28px)); }
}

@media (max-width:900px) {
  .library-panel-tabs { grid-template-columns: repeat(4,1fr); }
  .library-layout { display: block; width: min(100% - 20px,700px); padding: 6px 0 max(21px,env(safe-area-inset-bottom)); }
  .library-center { width: 100%; }
  .library-reader, .library-results { min-height: calc(100vh - 126px); min-height: calc(100svh - 126px); }
  .rulebook-table-scroll-top { display: none; }
}

@media (max-width:430px) {
  .login-card { padding: 25px 20px 22px; }
  .login-form > div { grid-template-columns: 1fr; gap: 7px; }
  .login-form button { min-height: 42px; }
  .library-copy { min-height: 300px; }
  .skill-index-links { columns: 2; }
  .skill-card { padding: 16px 15px 7px; }
  .rulebook-table table.compact-table { font-size: .7rem; }
  .rulebook-table table.compact-table th, .rulebook-table table.compact-table td { padding: 6px 4px; overflow-wrap: anywhere; }
}
