/* ==========================================================================
   Gráphagos Thesis - Editorial Reading Stylesheet
   Designed for deep reading, academic typography, and modern responsive UI
   ========================================================================== */

:root {
    --bg-page: #ffffff;
    --bg-card: #ffffff;
    --bg-card-subtle: #f7f7f7;
    --bg-header: #ffffff;
    --border-color: #e5e5e5;
    --border-subtle: #f0f0f0;

    --text-primary: #222222;
    --text-secondary: #555555;
    --text-muted: #888888;
    --link-color: #222222;
    --link-hover: #000000;
    --accent-color: #222222;

    --font-serif: "PT Serif", Georgia, Cambria, "Times New Roman", serif;
    --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --font-heading: var(--font-mono);
    --font-display: var(--font-mono);
    --font-sans: var(--font-mono);
    --font-caption: var(--font-mono);

    --container-max: 1170px;
    --content-max-width: 820px;
    --transition-speed: 0.25s;
    --card-shadow: 0 2px 16px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
    --bg-page: #121212;
    --bg-card: #1c1c1c;
    --bg-card-subtle: #242424;
    --bg-header: #1c1c1c;
    --border-color: #2f2f2f;
    --border-subtle: #282828;

    --text-primary: #eeeeee;
    --text-secondary: #bbbbbb;
    --text-muted: #888888;
    --link-color: #ffffff;
    --link-hover: #cccccc;
    --accent-color: #ffffff;

    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

body {
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-family: var(--font-serif);
    font-size: 18px;
    line-height: 1.85;
    padding-top: 75px;
    overflow-x: hidden;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

/* Reading Progress Indicator */
#progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    z-index: 1001;
}

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

/* Header & Navigation (Matching Graphagos.com) */
.navbar#site-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color var(--transition-speed) ease, border-color var(--transition-speed) ease;
}

.navbar#site-header.header-hidden {
    transform: translateY(-100%);
}

.header-container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0;
    height: 75px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.logo-img {
    height: 35px;
    width: auto;
    display: block;
}

[data-theme="dark"] .logo-img {
    filter: invert(1);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-icon,
.btn-action.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover,
.btn-action.btn-icon:hover {
    background-color: var(--bg-card-subtle);
    border-color: var(--text-primary);
    transform: translateY(-1px);
}

.hidden {
    display: none !important;
}

/* Reading Container */
.reading-container {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem 5rem 1.5rem;
    overflow-wrap: break-word;
}

.reading-container a {
    overflow-wrap: anywhere;
}

/* Hero Header */
.hero-header {
    text-align: center;
    padding: 4rem 1rem 3.5rem 1rem;
    margin-bottom: 1.0rem;
}

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

.hero-author {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-style: normal;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.hero-meta {
    font-family: var(--font-caption);
    font-size: 0.85rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Chapter Content / Reading Flow */
.chapter-card {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin-bottom: 4rem;
    box-shadow: none;
}

@media (max-width: 768px) {
    .reading-container {
        padding: 1.5rem 18px 4rem 18px;
    }

    .chapter-card {
        padding: 0;
        border: none;
        border-radius: 0;
        margin-bottom: 3rem;
        box-shadow: none;
    }

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

.chapter-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.chapter-title {
    font-family: var(--font-heading);
    font-size: 2.1rem;
    line-height: 1.3;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.015em;
}

/* Overview Card / TOC */
.overview-card h2 {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    margin-top: 1.8rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.overview-card ol.sections {
    font-family: var(--font-mono);
    list-style: none;
    padding-left: 0;
    margin-bottom: 2.5rem;
    counter-reset: sec-counter;
}

.overview-card ol.sections>li {
    font-family: var(--font-mono);
    position: relative;
    padding: 0.55rem 0 0.55rem 2.4rem;
    font-size: 0.95rem;
    border-bottom: 1px dashed var(--border-subtle);
}

.overview-card ol.sections>li>a {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.overview-card ol.sections>li>a:hover {
    color: var(--accent-color);
}

.overview-card ol.sections ol {
    font-family: var(--font-mono);
    margin-top: 0.4rem;
    padding-left: 1.5rem;
    list-style-type: decimal;
    font-size: 0.88rem;
}

.overview-card ol.sections ol li {
    font-family: var(--font-mono);
    padding: 0.25rem 0;
}

.overview-card ol.sections ol a {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    text-decoration: none;
}

.overview-card ol.sections ol a:hover {
    color: var(--accent-color);
}

/* Typography Inside Content */
.overview-card p {
    font-size: 18px;
    margin-top: 0;
    margin-bottom: 0;
    text-indent: 0;
    color: var(--text-primary);
}

.overview-card p+p {
    text-indent: 1.5em;
    margin-top: 0;
}

.chapter-content p {
    font-size: 18px;
    margin-top: 0;
    margin-bottom: 0;
    text-indent: 0;
    color: var(--text-primary);
}

.chapter-content p+p {
    text-indent: 1.5em;
    margin-top: 0;
}

/* Reset indent after non-paragraph elements */
.chapter-content h1+p,
.chapter-content h2+p,
.chapter-content h3+p,
.chapter-content h4+p,
.chapter-content h5+p,
.chapter-content h6+p,
.chapter-content ol+p,
.chapter-content ul+p,
.chapter-content pre+p,
.chapter-content blockquote+p,
.chapter-content .wp-caption+p,
.chapter-content div+p {
    text-indent: 0;
}

/* Blockquote extracts with inline padding */
.chapter-content p[style*="padding-left"] {
    text-indent: 0 !important;
    margin-top: 1.4rem !important;
    margin-bottom: 1.4rem !important;
}

.chapter-content p[style*="padding-left"]+p {
    text-indent: 0;
}

/* Paragraphs wrapping images */
.chapter-content p:has(img) {
    text-indent: 0 !important;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.chapter-content p:has(img)+p {
    text-indent: 0;
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4 {
    font-family: var(--font-heading);
    color: var(--text-primary);
    margin-top: 2.4rem;
    margin-bottom: 1rem;
    line-height: 1.35;
}

.chapter-content h1 {
    font-size: 1.65rem;
}

.chapter-content h2 {
    font-size: 1.45rem;
}

.chapter-content h3 {
    font-size: 1.25rem;
    font-family: var(--font-caption);
}

.chapter-content h4 {
    font-size: 1.15rem;
}

.chapter-content h5 {
    font-family: var(--font-caption);
    font-size: 1rem;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
}

.chapter-content h6 {
    font-family: var(--font-caption);
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 0.5rem;
    font-weight: normal;
}

.chapter-content a {
    color: var(--link-color);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    transition: color 0.2s ease;
}

.chapter-content a:hover {
    color: var(--link-hover);
}

.chapter-content blockquote {
    font-size: 18px;
    margin: 1.8rem 0;
    padding: 1rem 1.6rem;
    border-left: 4px solid var(--accent-color);
    background-color: var(--bg-card-subtle);
    font-style: italic;
    border-radius: 0 6px 6px 0;
}

.chapter-content ol,
.chapter-content ul {
    margin: 1.4rem 0 1.8rem 2.2rem;
}

.chapter-content li {
    font-size: 18px;
    margin-bottom: 0.6rem;
}

/* Figures & Images */
.wp-caption {
    max-width: 100% !important;
    width: auto !important;
    margin: 2.2rem auto;
    background: transparent;
    padding: 0;
    border: none;
    border-radius: 0;
}

.wp-caption img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.chapter-content .wp-caption-text,
.wp-caption-text {
    font-family: var(--font-caption);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-top: 0.85rem;
    margin-bottom: 0;
    text-indent: 0 !important;
}

/* Image formatting within paragraphs & galleries */
.chapter-content img {
    max-width: 100%;
    height: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    display: block;
    margin: 1.5rem auto;
}

/* Bibliography styling (preserve hanging indent and item spacing, break long URLs) */
#section-7 .chapter-content p {
    text-indent: -50px !important;
    padding-left: 50px;
    margin-bottom: 0.75rem !important;
    overflow-wrap: anywhere;
    word-break: break-word;
}

#section-7 .chapter-content a {
    overflow-wrap: anywhere;
    word-break: break-all;
}

@media (max-width: 768px) {
    #section-7 .chapter-content p {
        text-indent: -28px !important;
        padding-left: 28px !important;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    #section-7 .chapter-content a {
        overflow-wrap: anywhere;
        word-break: break-all;
    }
}

/* Appendix gallery styling */
#section-8 .chapter-content p {
    text-align: center;
    text-indent: 0 !important;
    margin-bottom: 1rem;
}

#section-8 .chapter-content img {
    display: inline-block;
    max-width: 380px;
    width: 100%;
    margin: 0.75rem;
    vertical-align: top;
    border: none;
    border-radius: 0;
    box-shadow: none;
    cursor: default;
}

/* Wide generation boards & evolutionary history images in Appendix */
#section-8 .chapter-content img.img-full-width,
#section-8 .chapter-content img[src*="pafta"],
#section-8 .chapter-content img[src*="ki_evrim"],
#section-8 .chapter-content img[width="1045"] {
    display: block;
    max-width: 100% !important;
    width: 100% !important;
    margin: 2rem auto;
}

/* Drawer (Table of Contents) */
.drawer {
    position: fixed;
    top: 0;
    right: -360px;
    width: 340px;
    max-width: 85vw;
    height: 100vh;
    background-color: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.15);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer.open {
    right: 0;
}

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

.drawer-header h3 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    color: var(--text-primary);
}

.drawer-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.drawer-nav {
    font-family: var(--font-mono);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.drawer-nav a {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.drawer-nav a:hover {
    color: var(--accent-color);
    background-color: var(--bg-card-subtle);
}

.drawer-nav .sub-nav {
    display: flex;
    flex-direction: column;
    padding-left: 1rem;
    border-left: 2px solid var(--border-subtle);
    margin-left: 0.6rem;
    gap: 0.35rem;
}

.drawer-nav .sub-nav a {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* Modal (About) */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    max-width: 520px;
    width: 100%;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transform: translateY(12px);
    transition: transform 0.25s ease;
}

.modal.open .modal-card {
    transform: translateY(0);
}

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

.modal-header h3 {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    font-size: 0.95rem;
}

.modal-body p {
    margin-bottom: 1rem;
}

.citation-box {
    background-color: var(--bg-card-subtle);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    margin: 1.2rem 0;
}

.citation-text {
    font-family: var(--font-serif);
    font-size: 0.9rem;
    margin-top: 0.35rem;
    margin-bottom: 0 !important;
}

/* Backdrop */
.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1050;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* CTA Band (Matching Graphagos.com) */
.cta-band {
    background-color: var(--bg-card-subtle);
    padding: 38px 20px;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    transition: background-color var(--transition-speed) ease, border-color var(--transition-speed) ease;
}

.cta-container {
    max-width: var(--container-max);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 28px;
    flex-wrap: wrap;
    text-align: center;
}

.cta-text {
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 400;
    color: var(--text-primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 500;
    padding: 12px 28px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    text-decoration: none;
    letter-spacing: 0.03em;
}

.btn-primary {
    background-color: #222222;
    color: #ffffff;
}

.btn-primary:hover {
    background-color: #000000;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    text-decoration: none;
}

[data-theme="dark"] .btn-primary {
    background-color: #ffffff;
    color: #121212;
}

[data-theme="dark"] .btn-primary:hover {
    background-color: #e5e5e5;
    color: #000000;
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.2);
}

/* Footer (Matching Graphagos.com) */
#subfooter {
    background-color: #1a1a1a;
    color: #999;
    padding: 20px 20px;
    font-size: 12px;
    border-top: 1px solid #2a2a2a;
    font-family: var(--font-mono);
}

.footer-container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.copyright p {
    margin-bottom: 8px;
    line-height: 1.6;
    color: #999;
}

.copyright a,
.footer-back-to-top a {
    color: #ddd;
    text-decoration: underline;
    transition: color 0.2s ease;
}

.copyright a:hover,
.footer-back-to-top a:hover {
    color: #ffffff;
}

/* Floating Back to Top Button */
.floating-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--accent-color);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

[data-theme="dark"] .floating-btn {
    background-color: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: #ffffff;
}

.floating-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.floating-btn:hover {
    background-color: #000000;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .floating-btn:hover {
    background-color: #383838;
}

@media (max-width: 768px) {
    .header-container {
        padding: 0 20px;
    }

    .floating-btn {
        bottom: 1.25rem;
        right: 1.25rem;
        width: 40px;
        height: 40px;
    }
}

/* Print Stylesheet */
@media print {

    #site-header,
    #progress-container,
    .cta-band,
    .drawer,
    .modal,
    .backdrop,
    .footer-top,
    .floating-btn {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 12pt;
    }

    .chapter-card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        page-break-before: always;
    }
}