/* ==========================================================================
   PAPER LAYOUT - Portable 3-Column Layout System for Academic Project Pages
   ========================================================================== */

/* === CSS CUSTOM PROPERTIES === */
:root {
    /* Layout Dimensions */
    --layout-toc-width: 180px;
    --layout-content-width: 864px;  /* 720px * 1.2 */
    --layout-sidenote-width: 220px;
    --layout-gap: 40px;

    /* Colors */
    --bg-page: #ffffff;
    --bg-header: linear-gradient(135deg, #ffffff 0%, #f8f6f2 40%, #fdf8f0 100%);
    --text-primary: #1a1a1a;
    --text-secondary: #444;
    --text-muted: #666;
    --accent: #2563eb;
    --border-light: #e5e5e5;

    /* Typography */
    --font-serif: 'Bitstream Charter', 'Charter', Georgia, serif;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --text-base: 18px;
    --leading-relaxed: 1.75;

    /* Spacing */
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
}

/* === BASE STYLES === */
body {
    background-color: var(--bg-page);
    font-family: var(--font-serif);
    font-size: var(--text-base);
    line-height: var(--leading-relaxed);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
}

/* === HEADER (Outside Grid) === */
.paper-header {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-light);
    padding: var(--space-xl) var(--space-lg);
}

.paper-header-inner {
    max-width: 1200px;
    margin: 0 auto;
}

/* === 3-COLUMN GRID LAYOUT === */
.paper-layout {
    display: grid;
    grid-template-columns:
        var(--layout-toc-width)
        var(--layout-gap)
        minmax(0, var(--layout-content-width))
        var(--layout-gap)
        var(--layout-sidenote-width);
    max-width: calc(
        var(--layout-toc-width) +
        var(--layout-content-width) +
        var(--layout-sidenote-width) +
        var(--layout-gap) * 2
    );
    margin: 0 auto;
    padding: var(--space-xl) var(--space-md);
}

/* === TABLE OF CONTENTS (Left Column) === */
.paper-toc {
    grid-column: 1;
    position: sticky;
    top: 120px;
    height: fit-content;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    line-height: 1.5;
}

.paper-toc h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 var(--space-md) 0;
}

.paper-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.paper-toc li {
    margin-bottom: var(--space-sm);
}

.paper-toc a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
    display: block;
    padding: 2px 0;
}

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

.paper-toc a.active {
    color: var(--accent);
    font-weight: 500;
}

/* === MAIN CONTENT (Center Column) === */
.paper-content {
    grid-column: 3;
    min-width: 0; /* Prevent grid blowout */
}

/* All direct children use full width of content column */
.paper-content > * {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* Typography in content */
.paper-content h1 {
    font-size: 2rem;
    margin: var(--space-2xl) 0 var(--space-lg) 0;
    line-height: 1.3;
}

.paper-content h2 {
    font-size: 1.6rem;
    margin: var(--space-xl) 0 var(--space-md) 0;
    line-height: 1.3;
}

.paper-content h3 {
    font-size: 1.3rem;
    margin: var(--space-lg) 0 var(--space-md) 0;
    line-height: 1.4;
}

.paper-content p {
    margin: 0 0 var(--space-lg) 0;
    font-size: 1.1rem;
}

/* Figures - same width as text */
.paper-content figure {
    width: 100%;
    margin: var(--space-xl) 0;
}

.paper-content figure img {
    width: 100%;
    height: auto;
    display: block;
}

.paper-content figcaption {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: var(--space-sm);
    line-height: 1.5;
    text-align: left;
}

/* Tables - same width as text */
.paper-content table {
    width: 100%;
    margin: var(--space-xl) 0;
    border-collapse: collapse;
}

/* === SIDENOTES === */
.sidenote-container {
    position: relative;
}

/* Mobile default: sidenotes appear inline */
.sidenote {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin: var(--space-md) 0;
    padding: var(--space-sm) var(--space-md);
    background: #f8f9fa;
    border-left: 3px solid #94a3b8;
    font-style: italic;
    border-radius: 0 4px 4px 0;
}

/* Desktop: sidenotes in right margin */
@media (min-width: 1200px) {
    .sidenote {
        position: absolute;
        right: calc(-1 * (var(--layout-sidenote-width) + var(--layout-gap)));
        top: 0;
        width: var(--layout-sidenote-width);
        margin: 0;
        padding: 0 0 0 var(--space-md);
        background: none;
        border-left: 1px solid var(--border-light);
        border-radius: 0;
    }
}

/* === SIDENOTES COLUMN (Right - empty placeholder) === */
.paper-sidenotes {
    grid-column: 5;
    /* This column exists to reserve space; sidenotes float into it */
}

/* === RESPONSIVE DESIGN === */

/* Tablet/Narrow Desktop: Hide TOC, content centered */
@media (max-width: 1199px) {
    .paper-layout {
        display: block;
        max-width: var(--layout-content-width);
        margin: 0 auto;
        padding: var(--space-lg);
    }

    .paper-toc {
        display: none;
    }

    .paper-content {
        width: 100%;
    }

    .paper-sidenotes {
        display: none;
    }

    /* Sidenotes become inline blocks */
    .sidenote {
        position: static;
        width: 100%;
    }
}

/* Mobile: Full width with minimal padding */
@media (max-width: 767px) {
    .paper-layout {
        padding: var(--space-md);
    }

    .paper-content h1 {
        font-size: 1.6rem;
    }

    .paper-content h2 {
        font-size: 1.4rem;
    }

    .paper-content h3 {
        font-size: 1.2rem;
    }

    .paper-content p {
        font-size: 1rem;
    }
}

/* === UTILITY CLASSES === */

/* Horizontal rule */
.paper-content hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: var(--space-2xl) 0;
}

/* Links */
.paper-content a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.paper-content a:hover {
    border-bottom-color: var(--accent);
}

/* Lists */
.paper-content ol,
.paper-content ul {
    margin: 0 0 var(--space-lg) var(--space-lg);
    padding: 0;
}

.paper-content li {
    margin-bottom: var(--space-sm);
}

/* Blockquotes */
.paper-content blockquote {
    margin: var(--space-lg) 0;
    padding: var(--space-md) var(--space-lg);
    background: #f8f9fa;
    border-left: 4px solid var(--accent);
    font-style: italic;
    color: var(--text-secondary);
}

/* Code blocks */
.paper-content pre {
    background: #f5f5f5;
    padding: var(--space-md);
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.9rem;
    margin: var(--space-lg) 0;
}

.paper-content code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9em;
}

/* === BYLINE / AUTHOR INFO === */
.paper-byline {
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    padding: var(--space-lg) 0;
    margin-bottom: var(--space-xl);
    text-align: center;
}

.paper-byline a {
    color: var(--text-primary);
    text-decoration: none;
}

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

/* === KEY FINDINGS === */
.key-findings {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin: var(--space-xl) 0;
    padding: var(--space-lg);
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

.key-findings-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 0 0 var(--space-sm) 0;
}

.key-finding {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
}

.key-finding-number {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}

.key-finding-text {
    flex: 1;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    margin: 0;
}

.key-finding-text strong {
    color: var(--accent);
}

@media (max-width: 767px) {
    .key-findings {
        padding: var(--space-md);
    }

    .key-finding-number {
        width: 24px;
        height: 24px;
        font-size: 0.75rem;
    }

    .key-finding-text {
        font-size: 0.95rem;
    }
}

/* === FINDING BOX - Gray callout for inline findings === */
.finding-box {
    background-color: rgba(240, 240, 240, 0.9);
    border: 1.2pt solid rgba(25, 25, 25, 0.6);
    border-radius: 10pt;
    padding: 2pt 10pt;
    margin: 1em 0;
    box-shadow: 2px 2px 4px rgba(128, 128, 128, 0.3);
    box-sizing: border-box;
}

.finding-box ul {
    margin: 0.5em 0;
    padding-left: 1.2em;
    list-style-type: disc;
}

.finding-box li {
    margin-bottom: 0.5em;
    line-height: 1.5;
}

.finding-box li:last-child {
    margin-bottom: 0;
}

/* === AUDIO PLAYER === */
.audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #f8f9fa;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    max-width: 500px;
    margin: 0 auto;
}

.audio-player-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.audio-player-btn:hover {
    background: #1d4ed8;
    transform: scale(1.05);
}

.audio-player-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.audio-player-btn .pause-icon {
    display: none;
}

.audio-player.playing .audio-player-btn .play-icon {
    display: none;
}

.audio-player.playing .audio-player-btn .pause-icon {
    display: block;
}

.audio-player-progress {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.audio-player-bar {
    width: 100%;
    height: 4px;
    background: #e5e5e5;
    border-radius: 2px;
    cursor: pointer;
    position: relative;
}

.audio-player-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
}

.audio-player-time {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.audio-player-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.audio-player-speed {
    padding: 4px 8px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 42px;
    text-align: center;
}

.audio-player-speed:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.audio-player-share {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.audio-player-share:hover {
    border-color: var(--accent);
}

.audio-player-share svg {
    width: 14px;
    height: 14px;
    fill: var(--text-muted);
}

.audio-player-share:hover svg {
    fill: var(--accent);
}

/* Mobile responsive */
@media (max-width: 480px) {
    .audio-player {
        flex-wrap: wrap;
        gap: 10px;
    }

    .audio-player-progress {
        order: 3;
        width: 100%;
        flex: none;
    }

    .audio-player-controls {
        margin-left: auto;
    }
}
