/* Shared reading layout. All rules are scoped to the article enhancement. */
:root {
    --rg-paper: #ffffff;
    --rg-ink: #243043;
    --rg-heading: #142235;
    --rg-muted: #63768b;
    --rg-line: #dce4ed;
    --rg-blue: #2767b0;
    --rg-tint: #edf4fc;
    --rg-code: #142333;
    --rg-shadow: 0 4px 30px #293d5c06;
    --rg-sticky-top: 0px;
    --rg-anchor-offset: 20px;
}
html.dark, :root[data-theme="dark"] {
    --rg-paper: #192430;
    --rg-ink: #d2dce8;
    --rg-heading: #edf4fc;
    --rg-muted: #a3b3c5;
    --rg-line: #344355;
    --rg-blue: #91c0ff;
    --rg-tint: #20354e;
    --rg-code: #101921;
    --rg-shadow: 0 4px 30px #0001;
}
/* A readable fallback remains when scripts or Tailwind are unavailable. */
#article-body[data-static-reading] {
    box-sizing: border-box;
    max-width: 800px;
    margin: 0 auto;
    padding: 40px;
    border: 1px solid var(--rg-line);
    border-radius: 12px;
    background: var(--rg-paper);
    color: var(--rg-ink);
    font-size: 16px;
    line-height: 1.85;
    overflow-wrap: anywhere;
}
#article-body[data-static-reading] p { margin: 0 0 19px; }
#article-body[data-static-reading] ul { list-style: disc; }
#article-body[data-static-reading] ol { list-style: decimal; }
#article-body[data-static-reading] table { display: block; width: 100%; max-width: 100%; overflow-x: auto; }
#article-body[data-static-reading] pre, #article-body[data-static-reading] .katex-display { max-width: 100%; overflow-x: auto; }
@media (max-width: 600px) {
    #article-body[data-static-reading] { padding: 26px 21px; font-size: 15px; }
}
#article-body .reading-table-scroll { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-inline: contain; margin: 20px 0 28px; }
#article-body .reading-table-scroll:focus-visible { outline: 3px solid #669cce; outline-offset: 4px; }
#article-body .reading-table-scroll > table { display: table; min-width: 100%; max-width: none; overflow: visible; margin: 0; }
#article-body .reading-math-source { display: inline-block; max-width: 100%; overflow-x: auto; white-space: pre-wrap; vertical-align: middle; }
@media (max-width: 600px) {
    #article-body .reading-table-scroll > table { min-width: 540px; }
}
main.rg-main { width: 100%; max-width: none; padding: 30px 24px 40px; }
.rg-layout { max-width: 1336px; margin: 0 auto; color: var(--rg-ink); }
.rg-layout *, .rg-dialog * { box-sizing: border-box; }
.rg-layout .rg-article { width: 100%; min-width: 0; max-width: 800px; margin: 0 auto; }
.rg-main #article-body.rg-paper {
    min-width: 0;
    background: var(--rg-paper);
    color: var(--rg-ink);
    border: 1px solid var(--rg-line);
    border-radius: 12px;
    padding: 40px;
    box-shadow: var(--rg-shadow);
    font-size: 16px;
    line-height: 1.85;
}
.rg-paper h1 { font-size: 29.6px; line-height: 1.42; letter-spacing: -.5px; margin: 0 0 22px; font-weight: 720; color: var(--rg-heading); }
.rg-paper h2 { font-size: 22.4px; line-height: 1.5; margin: 36px 0 14px; padding-bottom: 8px; border-color: var(--rg-line); font-weight: 650; color: var(--rg-heading); }
.rg-paper h3 { font-size: 18.4px; margin: 26px 0 12px; font-weight: 650; color: var(--rg-heading); }
.rg-paper :is(h1, h2, h3, h4, [id]) { scroll-margin-top: var(--rg-anchor-offset); }
.rg-paper p { margin: 0 0 19px; line-height: 1.85; overflow-wrap: anywhere; }
.rg-paper strong { color: var(--rg-heading); font-weight: 650; }
.rg-paper ul, .rg-paper ol { padding-left: 26px; margin: 0 0 20px; }
.rg-paper ul { list-style: disc; }
.rg-paper ol { list-style: decimal; }
.rg-paper li { margin-bottom: 7px; }
.rg-paper li > p { margin-bottom: 8px; }
.rg-paper a { color: var(--rg-blue); text-underline-offset: 3px; }
.rg-paper table { display: block; width: 100%; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 14px; line-height: 1.75; margin: 20px 0 28px; overscroll-behavior-inline: contain; }
.rg-paper th, .rg-paper td { border: 1px solid var(--rg-line); padding: 10px 12px; text-align: left; vertical-align: top; min-width: 100px; }
.rg-paper th { background: var(--rg-tint); font-weight: 650; }
.rg-paper tbody tr:nth-child(even) { background: color-mix(in srgb, var(--rg-tint) 30%, var(--rg-paper)); }
.rg-paper pre { max-width: 100%; background: var(--rg-code); color: #dce7f6; padding: 18px 20px; border-radius: 9px; overflow-x: auto; font-size: 13px; line-height: 1.85; margin: 22px 0; }
.rg-paper code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; background: var(--rg-tint); color: var(--rg-blue); padding: 2px 5px; border-radius: 4px; }
.rg-paper pre code { background: transparent; color: inherit; padding: 0; font-size: inherit; }
.rg-paper .katex { font-size: 1.08em; }
.rg-paper .katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; margin: 1em 0; padding: 3px 0; }
.rg-paper .mermaid { max-width: 100%; overflow-x: auto; background: var(--rg-paper); border-color: var(--rg-line); }
.rg-paper .mermaid svg { max-width: 100%; }
.rg-layout a, .rg-dialog a { color: var(--rg-blue); text-underline-offset: 3px; }
.rg-layout button, .rg-dialog button { color: inherit; font: inherit; cursor: pointer; }
.rg-layout :is(button, a, summary):focus-visible, .rg-dialog :is(button, a):focus-visible { outline: 3px solid #669cce; outline-offset: 4px; }
.rg-layout [hidden] { display: none !important; }
.rg-left-rail { min-width: 0; font-size: 12px; }
.rg-rail-intro { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 22px; font-size: 10px; }
.rg-rail-intro > span { color: var(--rg-muted); letter-spacing: 1px; }
.rg-rail-intro a { text-decoration: none; font-size: 10px; }
.rg-disclosure { margin: 0 0 23px; }
.rg-disclosure > summary { display: flex; justify-content: space-between; align-items: center; padding: 0 0 13px; margin-bottom: 11px; border-bottom: 1px solid var(--rg-line); font-size: 12px; letter-spacing: .6px; font-weight: 650; color: var(--rg-heading); cursor: pointer; list-style: none; }
.rg-disclosure > summary::-webkit-details-marker, .rg-margin-note > summary::-webkit-details-marker { display: none; }
.rg-disclosure > summary > span { color: var(--rg-muted); font-size: 16px; transform: rotate(-90deg); }
.rg-disclosure[open] > summary > span { transform: none; }
.rg-toc a { display: block; color: var(--rg-muted); line-height: 1.6; font-size: 11.5px; text-decoration: none; padding: 5px 5px 5px 11px; border-left: 2px solid transparent; overflow-wrap: anywhere; }
.rg-toc a.rg-toc-child { padding-left: 21px; font-size: 10.5px; }
.rg-toc a.is-active { color: var(--rg-blue); border-left-color: var(--rg-blue); background: var(--rg-tint); }
.rg-toc a:hover { color: var(--rg-blue); }
.rg-symbol-context { color: var(--rg-blue); font-size: 10.5px; line-height: 1.7; margin: 0 0 12px; }
.rg-symbol-list { margin: 0; font-size: 11px; line-height: 1.75; }
.rg-symbol-list > div { display: grid; grid-template-columns: minmax(42px, .32fr) minmax(0, 1fr); gap: 8px; margin-bottom: 13px; }
.rg-symbol-list dt { color: var(--rg-blue); font-family: Georgia, 'Times New Roman', serif; font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.rg-symbol-list dd { color: var(--rg-muted); margin: 0; overflow-wrap: anywhere; }
.rg-symbol-type { display: block; font-size: 9px; margin-top: 3px; opacity: .8; }
.rg-symbol-note { display: block; font-size: 10px; margin-top: 4px; }
.rg-symbol-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--rg-line); font-size: 10px; }
.rg-symbol-actions .rg-symbol-open { font-size: 10px; padding: 4px 7px; border: 1px solid var(--rg-line); border-radius: 5px; color: var(--rg-blue); background: var(--rg-tint); }
.rg-symbol-actions a { text-decoration: none; }
.rg-symbol-boundary { color: var(--rg-muted); font-size: 12px; line-height: 1.8; }
.rg-more-symbols { margin: 7px 0; font-size: 10px; color: var(--rg-muted); }
.rg-empty { font-size: 11px; color: var(--rg-muted); line-height: 1.85; margin: 12px 0; }
.rg-reference-link { display: block; border-top: 1px solid var(--rg-line); padding-top: 15px; font-size: 10px; text-decoration: none; }
.rg-right-rail { position: relative; min-width: 0; }
.rg-notes-heading { display: flex; justify-content: space-between; align-items: center; gap: 6px; color: var(--rg-heading); font-size: 12px; letter-spacing: .5px; border-bottom: 1px solid var(--rg-line); padding-bottom: 13px; }
.rg-note-count { display: inline-block; font-size: 9px; letter-spacing: 0; color: var(--rg-muted); margin-left: 4px; }
.rg-notes-heading .rg-notes-toggle { border: 0; background: none; color: var(--rg-muted); font-size: 10px; padding: 3px; white-space: nowrap; }
.rg-notes { position: relative; min-height: 90px; }
.rg-margin-note { position: absolute; left: 0; width: 100%; padding: 0 2px 0 13px; border-left: 2px solid #adc6dd; color: var(--rg-muted); font-size: 11px; line-height: 1.75; transition: background .18s; }
.rg-margin-note:target, .rg-margin-note.is-highlighted { background: var(--rg-tint); border-left-color: var(--rg-blue); }
.rg-margin-note > summary { display: flex; align-items: flex-start; gap: 7px; cursor: pointer; list-style: none; line-height: 1.6; }
.rg-note-number { color: var(--rg-blue); font: 10px/1.8 ui-monospace, monospace; }
.rg-note-name { color: var(--rg-heading); font-weight: 650; font-size: 12px; min-width: 0; overflow-wrap: anywhere; }
.rg-term-en { display: block; color: var(--rg-muted); font-size: 10px; font-weight: 450; letter-spacing: .1px; }
.rg-note-chevron { color: var(--rg-muted); margin-left: auto; }
.rg-margin-note:not([open]) .rg-note-chevron { transform: rotate(-90deg); }
.rg-margin-note p { margin: 8px 0; overflow-wrap: anywhere; }
.rg-note-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 13px; margin-top: 7px; font-size: 10px; }
.rg-note-links a { text-decoration: none; }
.rg-note-links button { padding: 0; border: 0; color: var(--rg-muted); background: none; font-size: 10px; }
.rg-notes-hidden .rg-notes { visibility: hidden; }
.rg-paper .rg-term-trigger { display: inline; font: inherit; font-weight: inherit; color: inherit; background: none; border: 0; border-bottom: 1px dotted #88a4c1; border-radius: 0; padding: 0; line-height: inherit; text-align: inherit; vertical-align: baseline; }
.rg-paper .rg-term-trigger.rg-first-term { border-bottom-style: solid; border-bottom-color: var(--rg-blue); }
.rg-paper .rg-term-trigger:hover { background: var(--rg-tint); color: var(--rg-blue); }
.rg-dialog { width: min(500px, calc(100vw - 32px)); max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); overflow: auto; overscroll-behavior: contain; border: 1px solid var(--rg-line); border-radius: 14px; background: var(--rg-paper); color: var(--rg-ink); padding: 20px 24px; box-shadow: 0 16px 80px #0003; margin: auto; }
.rg-dialog::backdrop { background: #14223566; backdrop-filter: blur(2px); }
.rg-dialog-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 11px; color: var(--rg-muted); margin-bottom: 18px; }
.rg-dialog-top .rg-dialog-close { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; background: none; border: 0; border-radius: 6px; font-size: 27px; line-height: 1; padding: 0; }
.rg-dialog-close:hover { background: var(--rg-tint); }
.rg-dialog h2 { font-size: 22px; line-height: 1.5; font-weight: 650; color: var(--rg-heading); margin: 0 0 5px; }
.rg-dialog p { font-size: 14px; line-height: 1.85; margin: 16px 0; overflow-wrap: anywhere; }
.rg-dialog p.rg-term-en { font-size: 12px; margin-top: 0; }
.rg-dialog p.rg-symbol-context { color: var(--rg-blue); font-size: 12px; }
.rg-dialog .rg-dialog-context { background: var(--rg-tint); border-radius: 8px; padding: 12px 15px; }
.rg-dialog strong { color: var(--rg-heading); font-weight: 600; }
.rg-dialog-links { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; font-size: 12px; margin-top: 20px; }
.rg-dialog-links button { border: 1px solid var(--rg-line); border-radius: 5px; padding: 6px 10px; background: var(--rg-tint); color: var(--rg-blue); font-size: 12px; }
.rg-dialog a { font-size: 12px; }
.rg-dialog .rg-symbol-list { font-size: 13px; }
.rg-dialog .rg-symbol-list > div { grid-template-columns: 80px minmax(0, 1fr); }
.rg-dialog .rg-symbol-list dt { font-size: 16px; }
.rg-dialog .rg-symbol-type, .rg-dialog .rg-symbol-note { font-size: 11px; }
@media (min-width: 1280px) {
    .rg-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 800px) minmax(0, 1fr); gap: 24px; align-items: start; }
    .rg-left-rail { position: sticky; top: var(--rg-sticky-top); max-height: calc(100vh - var(--rg-sticky-top) - 24px); max-height: calc(100dvh - var(--rg-sticky-top) - 24px); overflow-y: auto; scrollbar-width: thin; padding: 4px 6px 20px 0; }
    .rg-toc { max-height: 43vh; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
    .rg-symbols-disclosure { margin-top: 28px; }
}
@media (max-width: 1279px) {
    .rg-layout { display: block; max-width: 800px; }
    .rg-right-rail { display: none; }
    .rg-left-rail { position: sticky; top: var(--rg-sticky-top); z-index: 35; display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; padding: 10px 8px 0; margin: 0 -8px 10px; border-radius: 8px; background: var(--rg-paper); box-shadow: 0 4px 18px #00000008; }
    .rg-rail-intro { grid-column: 1 / -1; margin-bottom: 12px; }
    .rg-rail-intro a { font-size: 11px; }
    .rg-disclosure { position: relative; min-width: 0; margin-bottom: 14px; }
    .rg-disclosure > summary { border: 1px solid var(--rg-line); background: var(--rg-paper); padding: 9px 12px; border-radius: 7px; margin: 0; min-height: 42px; font-size: 12px; letter-spacing: 0; }
    .rg-disclosure[open] > .rg-toc, .rg-disclosure[open] > .rg-symbol-panel { position: absolute; z-index: 30; top: calc(100% + 7px); left: 0; right: 0; max-height: min(65vh, 550px); overflow: auto; overscroll-behavior: contain; background: var(--rg-paper); border: 1px solid var(--rg-line); box-shadow: 0 10px 30px #0002; padding: 15px; border-radius: 8px; }
    .rg-toc a { padding-top: 8px; padding-bottom: 8px; font-size: 12px; }
    .rg-toc a.rg-toc-child { font-size: 11px; }
    .rg-symbol-list { font-size: 12px; }
    .rg-symbol-context { font-size: 11px; }
    .rg-reference-link { display: none; }
    .rg-symbol-actions .rg-symbol-open { min-height: 34px; font-size: 11px; }
}
@media (max-width: 860px) {
    main.rg-main { padding: 24px 20px 32px; }
    .rg-main #article-body.rg-paper { padding: 32px; }
}
@media (max-width: 600px) {
    main.rg-main { padding: 19px 12px 28px; }
    .rg-left-rail { padding: 8px 4px 0; margin-left: 0; margin-right: 0; gap: 0 10px; }
    .rg-disclosure[open] > .rg-toc, .rg-disclosure[open] > .rg-symbol-panel { width: calc(100vw - 32px); max-width: 420px; }
    .rg-symbols-disclosure[open] > .rg-symbol-panel { left: auto; right: 0; }
    .rg-main #article-body.rg-paper { padding: 26px 21px; border-radius: 10px; font-size: 15px; line-height: 1.95; }
    .rg-paper h1 { font-size: 25px; line-height: 1.45; letter-spacing: -.25px; margin-bottom: 18px; }
    .rg-paper h2 { font-size: 20px; margin-top: 31px; }
    .rg-paper h3 { font-size: 17px; }
    .rg-paper table { font-size: 12px; }
    .rg-paper th, .rg-paper td { padding: 8px 9px; }
    .rg-paper pre { font-size: 11px; padding: 14px; }
    .rg-paper .katex { font-size: 1em; }
    .rg-paper .rg-term-trigger { min-height: 24px; }
    .rg-dialog { padding: 16px 20px 22px; }
}
@media (prefers-reduced-motion: reduce) {
    .rg-layout *, .rg-dialog, .rg-dialog * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
@media print {
    main.rg-main { padding: 0; }
    .rg-layout { display: block; max-width: none; }
    .rg-left-rail, .rg-right-rail, .rg-dialog { display: none !important; }
    .rg-main #article-body.rg-paper { padding: 0; border: 0; box-shadow: none; }
    .rg-paper .rg-term-trigger { border: 0; }
}

/* Inline evidence remains readable before the reader enhancement mounts. */
#article-body .reading-evidence-figure { margin: 24px 0 28px; padding: 16px; border: 1px solid var(--rg-line); border-radius: 10px; background: var(--rg-paper); }
#article-body .reading-evidence-figure > a:first-child { display: block; cursor: zoom-in; }
#article-body .reading-evidence-figure img { display: block; width: 100%; max-width: 560px; height: auto; margin: 0 auto; background: #fff; }
#article-body .reading-evidence-figure img[src$=".svg"] { max-width: 100%; }
#article-body .reading-evidence-figure figcaption { margin-top: 14px; color: var(--rg-muted); font-size: 13px; line-height: 1.75; }
#article-body > details { margin: 18px 0; padding: 14px 16px; border: 1px solid var(--rg-line); border-radius: 8px; }
#article-body > details > summary { cursor: pointer; color: var(--rg-heading); font-weight: 600; line-height: 1.7; }
#article-body > details[open] > summary { margin-bottom: 14px; }
@media (max-width: 600px) {
    #article-body .reading-evidence-figure { padding: 8px; margin-left: -8px; margin-right: -8px; }
    #article-body .reading-evidence-figure figcaption { font-size: 12px; }
}
