/* ==========================================================================
   AS WE MAY THINK — Dr. Vannevar Bush (1945)
   Distraction-Free Digital 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: 300px;
    --content-max-width: 68ch;
    --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 (Atlantic Monthly 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: #a83232;
    --accent-hover: #8b2525;
    --accent-subtle: #faede8;
    --code-bg: #f3f0e8;
    --card-bg: #f8f6f0;
    --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: #8b3a2b;
    --accent-hover: #702e21;
    --accent-subtle: #ecdcc9;
    --code-bg: #e8ddc4;
    --card-bg: #ede4cf;
    --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: #f59e0b;
    --accent-hover: #fbbf24;
    --accent-subtle: #382405;
    --code-bg: #1e1e24;
    --card-bg: #1e1e25;
    --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.8;
    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: var(--accent);
    transition: width 0.1s linear;
}

/* --------------------------------------------------------------------------
   Top Navigation Deck
   -------------------------------------------------------------------------- */

#top-bar {
    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);
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

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

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

.topbar-branding {
    display: flex;
    flex-direction: column;
    margin-left: 0.5rem;
}

.topbar-paper-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--text-main);
    line-height: 1.15;
}

.topbar-author {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1;
}

.icon-btn, .control-btn, .theme-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.35rem 0.65rem;
    transition: all var(--transition-fast);
}

.icon-btn:hover, .control-btn:hover, .theme-btn:hover {
    background-color: var(--bg-surface-elevated);
    border-color: var(--border-strong);
    color: var(--text-main);
}

.theme-controls, .font-controls {
    display: flex;
    gap: 0.25rem;
}

.theme-btn.active {
    background-color: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.read-stats {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    color: var(--text-muted);
}

.divider {
    width: 1px;
    height: 20px;
    background-color: var(--border-subtle);
}

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

.app-layout {
    display: flex;
    max-width: 1440px;
    margin: 0 auto;
    min-height: calc(100vh - var(--header-height));
}

/* --------------------------------------------------------------------------
   Sticky Table of Contents Sidebar
   -------------------------------------------------------------------------- */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    border-right: 1px solid var(--border-subtle);
    background-color: var(--bg-sidebar);
    transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.sidebar-sticky {
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    padding: 1.5rem 1.25rem 3rem 1.25rem;
}

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

.toc-title {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.close-btn {
    display: none;
    font-size: 1rem;
    padding: 0.2rem 0.4rem;
}

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.toc-item {
    border-radius: var(--radius-sm);
    transition: background-color var(--transition-fast);
}

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

.toc-bullet {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 50%;
    background-color: var(--border-subtle);
    color: var(--text-secondary);
}

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

.toc-item.active .toc-link {
    color: var(--accent);
    background-color: var(--accent-subtle);
    font-weight: 600;
}

.toc-item.active .toc-bullet {
    background-color: var(--accent);
    color: #ffffff;
}

/* --------------------------------------------------------------------------
   Main Reader Document
   -------------------------------------------------------------------------- */

.reader-main {
    flex-grow: 1;
    min-width: 0;
    padding: 2.5rem 2rem 6rem 2.5rem;
}

.paper-article {
    max-width: var(--content-max-width);
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Academic Paper Header
   -------------------------------------------------------------------------- */

.paper-header {
    margin-bottom: 3.5rem;
    text-align: center;
    padding-bottom: 2.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.journal-stamp {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 2rem;
    font-family: var(--font-sans);
    color: var(--text-muted);
}

.journal-name {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.journal-volume {
    font-size: 0.82rem;
    font-style: italic;
}

.journal-issue {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.paper-title {
    font-family: var(--font-display);
    font-size: 2.75rem;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: 0.03em;
    color: var(--text-main);
    margin-bottom: 1.5rem;
}

.author-block {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin-bottom: 2rem;
}

.author-by {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
}

.author-name {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent);
}

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

.header-abstract-banner {
    background-color: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--accent);
    padding: 1.25rem 1.5rem;
    margin-bottom: 2rem;
    border-radius: var(--radius-md);
    text-align: left;
}

.abstract-quote {
    font-style: italic;
    font-size: 1.02rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Quick Jump Chips */
.quick-jump-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.78rem;
}

.jump-label {
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 0.25rem;
}

.jump-chip {
    background-color: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.jump-chip:hover {
    background-color: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent);
}

/* --------------------------------------------------------------------------
   Foreword Card
   -------------------------------------------------------------------------- */

.foreword-section {
    margin-bottom: 3.5rem;
}

.foreword-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-sm);
}

.foreword-header {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.foreword-tag {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent);
}

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

.foreword-source {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.foreword-body p {
    font-size: 1.02rem;
    line-height: 1.75;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.foreword-signature {
    font-style: italic;
    text-align: right;
    color: var(--text-main);
    margin-top: 1.5rem;
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   Paper Sections & Typography
   -------------------------------------------------------------------------- */

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

.section-header {
    margin-bottom: 1.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.section-number {
    display: inline-block;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.section-title {
    font-family: var(--font-display);
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: 0.02em;
    color: var(--text-main);
}

.section-subtitle {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

.section-content p {
    margin-bottom: 1.4rem;
    text-align: justify;
    hyphens: auto;
}

/* Drop-cap for initial paragraph */
.lead-para::first-letter {
    font-family: var(--font-display);
    float: left;
    font-size: 3.5rem;
    line-height: 0.85;
    margin-top: 0.15rem;
    margin-right: 0.6rem;
    padding: 0.1rem;
    color: var(--accent);
    font-weight: 700;
}

/* Pull Quotes */
.pull-quote {
    margin: 2.5rem 0;
    padding: 1.5rem 2rem;
    background-color: var(--card-bg);
    border-left: 4px solid var(--accent);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    box-shadow: var(--shadow-sm);
}

.pull-quote p {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-style: italic;
    line-height: 1.65;
    color: var(--text-main);
    margin-bottom: 0 !important;
}

/* --------------------------------------------------------------------------
   Figures & SVG Schematics
   -------------------------------------------------------------------------- */

.diagram-figure {
    margin: 3rem 0;
    background-color: var(--card-bg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.diagram-wrapper {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    padding: 0.5rem 0;
}

.diagram-caption {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-top: 1.25rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
}

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

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

.colophon-box {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

.colophon-item h4 {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 0.4rem;
}

.colophon-item p {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-secondary);
    text-align: left;
}

.colophon-list {
    list-style: disc;
    padding-left: 1.5rem;
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.colophon-list li {
    font-family: var(--font-sans);
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.colophon-item a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Citation Modal
   -------------------------------------------------------------------------- */

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

.modal.active {
    display: flex;
}

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

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

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

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

.modal-close-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    border-radius: var(--radius-sm);
}

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

.modal-body {
    padding: 1.5rem;
}

.cite-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.5rem;
}

.cite-tab-btn {
    background: transparent;
    border: none;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.cite-tab-btn:hover {
    color: var(--text-main);
    background-color: var(--bg-surface-elevated);
}

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

.cite-panel {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.cite-panel.active {
    display: flex;
}

.cite-code {
    background-color: 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.5;
    color: var(--text-main);
    white-space: pre-wrap;
    word-break: break-all;
}

.copy-cite-btn {
    align-self: flex-end;
    background-color: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

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

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

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 320px;
        height: 100vh;
        z-index: 1500;
        transition: left 0.3s ease;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-sticky {
        height: 100vh;
        top: 0;
    }

    .close-btn {
        display: block;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 1400;
    }

    .sidebar-backdrop.active {
        display: block;
    }

    .reader-main {
        padding: 2rem 1.5rem 4rem 1.5rem;
    }
}

@media (max-width: 680px) {
    .topbar-paper-title {
        display: none;
    }

    .read-stats {
        display: none;
    }

    .paper-title {
        font-size: 2.1rem;
    }

    .author-name {
        font-size: 1.2rem;
    }

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

    .pull-quote {
        padding: 1.25rem;
    }

    .pull-quote p {
        font-size: 1.02rem;
    }
}

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

@media print {
    #top-bar, #progress-container, .sidebar, #sidebar-backdrop, .quick-jump-bar, #cite-modal {
        display: none !important;
    }

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

    .reader-main {
        padding: 0 !important;
        max-width: 100% !important;
    }

    .paper-section {
        page-break-inside: avoid;
        margin-bottom: 2rem;
    }

    .diagram-figure {
        box-shadow: none;
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }
}
