/* ==========================================================================
   A MATHEMATICAL THEORY OF COMMUNICATION — Claude E. Shannon (1948)
   Distraction-Free Modern Reading Edition Stylesheet
   ========================================================================== */

@import url('fonts.css');

:root {
    --font-scale: 1.05rem;
    --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', Consolas, Monaco, monospace;
    --font-display: 'Cinzel', 'Newsreader', Georgia, serif;

    --sidebar-width: 320px;
    --content-max-width: 70ch;
    --header-height: 56px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* --------------------------------------------------------------------------
   Themes
   -------------------------------------------------------------------------- */

/* Light Theme (Clean Academic Paper) */
html[data-theme="light"] {
    --bg-base: #fcfbf9;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f7f5f0;
    --bg-sidebar: #f7f5f0;
    --border-subtle: #e6e2d8;
    --border-strong: #d2ccbf;
    --text-main: #1f1e1d;
    --text-secondary: #5a554e;
    --text-muted: #878074;
    --text-light: #aba396;
    --accent: #0284c7; /* Bell Blue / Information Cyan */
    --accent-hover: #0369a1;
    --accent-subtle: #e0f2fe;
    --code-bg: #f3f0e8;
    --theorem-bg: #f8fafc;
    --theorem-border: #bae6fd;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* Parchment Theme (Warm Library Sepia) */
html[data-theme="parchment"] {
    --bg-base: #f5eedb;
    --bg-surface: #faefe0;
    --bg-surface-elevated: #ede2cd;
    --bg-sidebar: #ede2cd;
    --border-subtle: #ded1b8;
    --border-strong: #caba9e;
    --text-main: #2d2417;
    --text-secondary: #5e523f;
    --text-muted: #877864;
    --text-light: #ad9e88;
    --accent: #0f766e; /* Deep Teal */
    --accent-hover: #115e59;
    --accent-subtle: #ccfbf1;
    --code-bg: #e6dac1;
    --theorem-bg: #ede4cf;
    --theorem-border: #c8b99c;
    --shadow-sm: 0 1px 3px rgba(45, 36, 23, 0.06);
    --shadow-md: 0 4px 14px rgba(45, 36, 23, 0.09);
    --shadow-lg: 0 10px 30px rgba(45, 36, 23, 0.12);
}

/* Dark Theme (Obsidian Night Reader) */
html[data-theme="dark"] {
    --bg-base: #121214;
    --bg-surface: #1a1a1e;
    --bg-surface-elevated: #222228;
    --bg-sidebar: #17171a;
    --border-subtle: #2d2d34;
    --border-strong: #40404a;
    --text-main: #e6e6ea;
    --text-secondary: #a2a2ad;
    --text-muted: #74747f;
    --text-light: #52525c;
    --accent: #38bdf8; /* Glowing Sky */
    --accent-hover: #7dd3fc;
    --accent-subtle: #082f49;
    --code-bg: #1e1e24;
    --theorem-bg: #181c24;
    --theorem-border: #0369a1;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
}

/* --------------------------------------------------------------------------
   Reset & Base Styles
   -------------------------------------------------------------------------- */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-serif);
    font-size: var(--font-scale);
    line-height: 1.76;
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

::selection {
    background-color: var(--accent-subtle);
    color: var(--text-main);
}

/* --------------------------------------------------------------------------
   Top Progress Bar
   -------------------------------------------------------------------------- */

#progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    z-index: 1000;
}

#progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--accent);
    transition: width 0.1s linear;
}

/* --------------------------------------------------------------------------
   Top Header Bar
   -------------------------------------------------------------------------- */

#site-header {
    position: sticky;
    top: 0;
    height: var(--header-height);
    background-color: var(--bg-base);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 900;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 1.25rem;
    max-width: 1500px;
    margin: 0 auto;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.35rem 0.65rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.header-btn:hover {
    color: var(--text-main);
    border-color: var(--border-strong);
    background: var(--bg-surface);
}

#toc-toggle {
    display: flex;
}

.header-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.breadcrumb-author {
    font-weight: 600;
    color: var(--text-secondary);
}

.breadcrumb-sec {
    color: var(--accent);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Theme Picker */
.theme-picker {
    display: flex;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 2px;
}

.theme-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0.25rem 0.55rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-btn:hover {
    color: var(--text-main);
}

.theme-btn.active {
    background: var(--bg-surface);
    color: var(--text-main);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.font-scaler {
    display: flex;
    gap: 2px;
}

.font-btn {
    padding: 0.35rem 0.55rem;
    font-weight: 600;
    min-width: 32px;
    justify-content: center;
}

.cite-btn {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.cite-btn:hover {
    color: #fff;
    background: var(--accent);
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

#layout-wrapper {
    display: flex;
    max-width: 1500px;
    margin: 0 auto;
    position: relative;
}

/* Sidebar / Table of Contents */
#sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    height: calc(100vh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 800;
    transition: transform var(--transition-normal), background-color var(--transition-normal);
}

.sidebar-header {
    padding: 1.25rem 1.25rem 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.sidebar-series {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
}

.sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
}

.sidebar-paper-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-main);
    margin-bottom: 0.2rem;
}

.sidebar-author {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.sidebar-journal {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--text-muted);
    font-style: italic;
}

/* TOC Navigation List */
.toc-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.toc-header {
    display: none; /* Used only if standalone */
}

.toc-list, .toc-sublist {
    list-style: none;
}

.toc-part-group {
    margin-top: 0.85rem;
    margin-bottom: 0.35rem;
}

.toc-part-header {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
}

.toc-part-badge {
    font-family: var(--font-sans);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
}

.toc-part-title {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    line-height: 1.3;
}

.toc-part-title:hover {
    color: var(--text-main);
}

.toc-item {
    margin: 1px 0;
}

.toc-link {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    padding: 0.32rem 0.6rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    line-height: 1.35;
    transition: all var(--transition-fast);
}

.toc-link:hover {
    background-color: var(--bg-surface);
    color: var(--text-main);
}

.toc-item.active > .toc-link {
    background-color: var(--bg-surface);
    color: var(--accent);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.toc-sec-num {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    flex-shrink: 0;
}

.toc-item.active .toc-sec-num {
    color: var(--accent);
}

.toc-sec-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toc-sublist {
    padding-left: 0.6rem;
    border-left: 1px solid var(--border-subtle);
    margin-left: 0.6rem;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-sidebar);
}

.sidebar-footer-links {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    margin-bottom: 0.25rem;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-link:hover {
    color: var(--accent);
}

.footer-sep {
    color: var(--border-strong);
}

.sidebar-footer-copy {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Sidebar Backdrop (Mobile) */
#sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 750;
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

#sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* --------------------------------------------------------------------------
   Main Content Area
   -------------------------------------------------------------------------- */

#main-content {
    flex: 1;
    min-width: 0;
    padding: 2.5rem 2rem 6rem 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.paper-hero {
    max-width: var(--content-max-width);
    width: 100%;
    margin-bottom: 3.5rem;
    padding-bottom: 2.5rem;
    border-bottom: 1px solid var(--border-subtle);
    text-align: center;
}

.hero-eyebrow {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 1rem;
}

.hero-title {
    font-family: var(--font-display);
    font-size: 2.35rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
    color: var(--text-main);
    margin-bottom: 1.25rem;
}

.hero-author-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    font-family: var(--font-sans);
    font-size: 1.05rem;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.hero-author {
    letter-spacing: 0.05em;
}

.hero-date {
    color: var(--text-muted);
    font-weight: 400;
}

.hero-journal {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 1.75rem;
    line-height: 1.5;
}

.hero-epigraph {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.75rem;
    margin: 1.75rem auto 1.75rem auto;
    max-width: 58ch;
}

.epigraph-quote {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 1.08rem;
    line-height: 1.6;
    color: var(--text-main);
    border: none;
    padding: 0;
    margin: 0;
}

.hero-meta-badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.25rem;
}

.meta-badge {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
}

/* Paper Content Container */
.paper-content {
    max-width: var(--content-max-width);
    width: 100%;
}

/* Part Dividers */
.part-divider {
    margin: 4.5rem 0 2rem 0;
    padding-top: 2.5rem;
    border-top: 2px solid var(--border-strong);
    text-align: center;
}

.part-eyebrow {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--accent);
    margin-bottom: 0.35rem;
}

.part-title {
    font-family: var(--font-display);
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
}

/* Sections */
.paper-section {
    margin-bottom: 3.5rem;
    scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.35rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.section-heading {
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.35;
}

.heading-anchor {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--border-strong);
    text-decoration: none;
    opacity: 0;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}

.section-header:hover .heading-anchor {
    opacity: 1;
}

.heading-anchor:hover {
    color: var(--accent);
}

/* Paragraphs & Text */
p {
    margin-bottom: 1.35rem;
    text-align: justify;
    text-justify: inter-word;
    hyphens: auto;
}

ol, ul {
    margin-bottom: 1.5rem;
    padding-left: 1.85rem;
}

li {
    margin-bottom: 0.65rem;
}

strong, b {
    font-weight: 600;
    color: var(--text-main);
}

em, i {
    font-style: italic;
}

a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

/* --------------------------------------------------------------------------
   Mathematical Typesetting (KaTeX)
   -------------------------------------------------------------------------- */

.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.6rem 0;
    margin: 1.5rem 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.katex {
    font-size: 1.08em;
}

/* --------------------------------------------------------------------------
   Theorems
   -------------------------------------------------------------------------- */

.theorem-card {
    background: var(--theorem-bg);
    border: 1px solid var(--theorem-border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.5rem;
    margin: 2.25rem 0;
    box-shadow: var(--shadow-sm);
    scroll-margin-top: calc(var(--header-height) + 2rem);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.theorem-card:hover {
    box-shadow: var(--shadow-md);
}

.theorem-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.65rem;
}

.theorem-badge {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
}

.theorem-anchor {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-muted);
    text-decoration: none;
    opacity: 0.5;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}

.theorem-anchor:hover {
    opacity: 1;
    color: var(--accent);
}

.theorem-body {
    font-style: italic;
    line-height: 1.75;
}

.theorem-body p:last-child {
    margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   English Approximation Samples (§3)
   -------------------------------------------------------------------------- */

.approximation-sample {
    background: var(--code-bg);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1.2rem;
    margin: 0.85rem 0 1.35rem 0;
    font-family: var(--font-mono);
    font-size: 0.88rem;
    line-height: 1.65;
    word-break: break-all;
    color: var(--text-main);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
}

/* --------------------------------------------------------------------------
   Figures & Tables
   -------------------------------------------------------------------------- */

.paper-figure {
    margin: 2.75rem 0;
    text-align: center;
    scroll-margin-top: calc(var(--header-height) + 2rem);
}

.figure-img-wrap {
    display: inline-block;
    max-width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.table-img-wrap {
    padding: 1rem;
    max-width: 100%;
    overflow-x: auto;
}

.figure-img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    transition: filter var(--transition-normal);
}

/* In Dark Mode, invert diagrams to crisp white-on-dark lines */
html[data-theme="dark"] .figure-img {
    filter: invert(0.9) hue-rotate(180deg) contrast(1.1);
}

figcaption {
    font-family: var(--font-sans);
    font-size: 0.86rem;
    color: var(--text-secondary);
    margin-top: 0.85rem;
    line-height: 1.5;
    max-width: 60ch;
    margin-left: auto;
    margin-right: auto;
}

figcaption strong {
    color: var(--text-main);
    font-weight: 700;
}

/* --------------------------------------------------------------------------
   Footnotes
   -------------------------------------------------------------------------- */

.footnote-ref {
    font-family: var(--font-mono);
    font-size: 0.8em;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    padding: 0 0.15rem;
    cursor: pointer;
    vertical-align: super;
}

.footnotes-section {
    margin-top: 5rem;
    padding-top: 2.5rem;
    border-top: 2px solid var(--border-strong);
}

.footnote-item {
    margin-bottom: 1rem;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.fn-backlink {
    font-family: var(--font-sans);
    color: var(--accent);
    text-decoration: none;
    margin-left: 0.35rem;
}

/* Footnote Popover Tooltip */
.fn-popover {
    position: absolute;
    width: 380px;
    max-width: 90vw;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.fn-popover.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.popover-arrow {
    position: absolute;
    top: -6px;
    left: 24px;
    width: 10px;
    height: 10px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-strong);
    border-top: 1px solid var(--border-strong);
    transform: rotate(45deg);
}

.popover-inner {
    padding: 0.85rem 1rem;
}

.popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.popover-badge {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent);
}

.popover-close {
    background: none;
    border: none;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.popover-body {
    font-family: var(--font-serif);
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-main);
}

.popover-footer {
    margin-top: 0.5rem;
    text-align: right;
}

.popover-jump-btn {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--accent);
    text-decoration: none;
}

/* --------------------------------------------------------------------------
   Colophon
   -------------------------------------------------------------------------- */

.colophon-card {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.75rem 2rem;
    margin-top: 1.5rem;
}

.colophon-card p {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.colophon-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-md);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    border: 1px solid var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
    color: var(--text-main);
    border-color: var(--border-strong);
}

/* --------------------------------------------------------------------------
   Citations Modal
   -------------------------------------------------------------------------- */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    width: 620px;
    max-width: 92vw;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 2010;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-body {
    padding: 1.25rem 1.5rem 1.5rem 1.5rem;
}

.citation-tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.citation-tab {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.citation-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.citation-box-wrap {
    position: relative;
}

.citation-code {
    background: var(--code-bg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-main);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 280px;
}

.copy-btn {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.55rem;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-fast);
}

.copy-btn:hover {
    color: var(--text-main);
    border-color: var(--border-strong);
}

/* --------------------------------------------------------------------------
   Responsive Breakpoints
   -------------------------------------------------------------------------- */

@media (max-width: 1050px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1500;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close-btn {
        display: block;
    }

    #sidebar-backdrop {
        display: block;
    }

    #main-content {
        padding: 2rem 1.5rem 5rem 1.5rem;
    }
}

@media (max-width: 650px) {
    .header-breadcrumb {
        display: none;
    }

    .hero-title {
        font-size: 1.85rem;
    }

    .part-title {
        font-size: 1.5rem;
    }

    .section-heading {
        font-size: 1.25rem;
    }

    p {
        text-align: left;
    }
}

/* --------------------------------------------------------------------------
   Print Stylesheet
   -------------------------------------------------------------------------- */

@media print {
    #site-header, #sidebar, #progress-container, .colophon-actions, .theme-picker, .font-scaler, .cite-btn {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 11pt;
        line-height: 1.5;
    }

    #main-content {
        padding: 0 !important;
        max-width: 100% !important;
    }

    .paper-hero {
        border-bottom: 2px solid #000;
    }

    .theorem-card {
        border: 1px solid #999 !important;
        background: #fff !important;
        page-break-inside: avoid;
    }

    .paper-figure {
        page-break-inside: avoid;
    }

    a {
        color: #000 !important;
        text-decoration: none !important;
    }
}
