/* ============================================================
   RESET & BASE
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Colors - Professional Blue & Gold */
    --primary-dark: #1A365D;
    --primary-blue: #2B6CB0;
    --primary-light: #EBF4FF;
    --gold: #D69E2E;
    --gold-light: #F6E05E;
    --gold-pale: #FAF5E6;
    --bg: #F7FAFC;
    --text: #1A202C;
    --text-light: #4A5568;
    --border: #E2E8F0;
    --card-bg: #FFFFFF;
    --shadow: rgba(26, 54, 93, 0.1);
    --nav-bg: #FFFFFF;
    --footer-bg: #1A365D;
    --footer-text: #CBD5E0;

    /* Fonts */
    --font-serif: 'Merriweather', Georgia, 'Times New Roman', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;

    /* Spacing */
    --max-width: 820px;
    --page-padding: 3rem 2rem;
    --radius: 12px;
    --transition: 0.3s ease;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --bg: #0D1117;
    --text: #E2E8F0;
    --text-light: #A0AEC0;
    --border: #2D3748;
    --card-bg: #161B22;
    --shadow: rgba(0, 0, 0, 0.4);
    --nav-bg: #161B22;
    --primary-light: #1A365D;
    --gold-pale: #1A1A0A;
    --footer-bg: #0D1117;
    --footer-text: #718096;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-serif);
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.8;
    font-size: 18px;
    transition: background-color var(--transition), color var(--transition);
}

/* ============================================================
   TOP BAR
   ============================================================ */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--nav-bg);
    border-bottom: 2px solid var(--gold);
    box-shadow: 0 2px 12px var(--shadow);
    transition: background-color var(--transition);
}

.top-bar-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.6rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.85rem;
}

.book-title-small {
    font-family: var(--font-sans);
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: 0.02em;
    display: none;
}

@media (min-width: 640px) {
    .book-title-small {
        display: inline;
    }
}

.chapter-indicator {
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--gold);
    background: var(--gold-pale);
    padding: 0.2rem 0.8rem;
    border-radius: 20px;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.ctrl-btn {
    font-family: var(--font-sans);
    font-weight: 600;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
    transition: all var(--transition);
    line-height: 1.6;
}

.ctrl-btn:hover {
    background: var(--gold);
    color: #fff;
    border-color: var(--gold);
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 4px;
    background: var(--border);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold), var(--primary-blue));
    transition: width 0.3s ease;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--page-padding);
    min-height: 80vh;
}

/* ============================================================
   PAGE SECTIONS (Cover, Title, Copyright, TOC)
   ============================================================ */
.page {
    display: none;
    animation: fadeIn 0.5s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- COVER PAGE ---- */
.cover-page {
    min-height: 80vh;
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.cover-page.active {
    display: flex;
}

.cover-inner {
    max-width: 700px;
    width: 100%;
}

.cover-badge {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 1.5rem;
    border: 2px solid var(--gold);
    display: inline-block;
    padding: 0.3rem 1.2rem;
    border-radius: 30px;
}

.cover-title {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: clamp(2.4rem, 7vw, 4.2rem);
    color: var(--primary-dark);
    line-height: 1.1;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.cover-subtitle {
    font-family: var(--font-serif);
    font-weight: 300;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    color: var(--primary-blue);
    margin-bottom: 0.2rem;
}

.cover-subtitle-secondary {
    font-family: var(--font-serif);
    font-weight: 300;
    font-size: clamp(0.9rem, 1.8vw, 1.3rem);
    color: var(--text-light);
    margin-bottom: 2rem;
}

.cover-divider {
    width: 80px;
    height: 3px;
    background: linear-gradient(90deg, var(--gold), var(--primary-blue));
    margin: 1.5rem auto;
    border-radius: 3px;
}

.cover-author {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-light);
    letter-spacing: 0.05em;
}

.cover-year {
    font-family: var(--font-sans);
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

/* ---- TITLE PAGE ---- */
.title-page {
    min-height: 70vh;
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.title-page.active {
    display: flex;
}

.title-inner {
    max-width: 650px;
    width: 100%;
}

.title-publisher {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    color: var(--gold);
    text-transform: uppercase;
    margin-bottom: 2rem;
}

.title-main {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3.2rem);
    color: var(--primary-dark);
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.title-sub {
    font-family: var(--font-serif);
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--primary-blue);
}

.title-sub2 {
    font-family: var(--font-serif);
    font-weight: 300;
    font-size: clamp(0.85rem, 1.5vw, 1.1rem);
    color: var(--text-light);
    margin-bottom: 2rem;
}

.title-divider {
    width: 60px;
    height: 2px;
    background: var(--gold);
    margin: 1.5rem auto;
}

.title-author {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-light);
    letter-spacing: 0.05em;
}

/* ---- COPYRIGHT PAGE ---- */
.copyright-page {
    min-height: 60vh;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.copyright-page.active {
    display: flex;
}

.copyright-inner {
    max-width: 550px;
    width: 100%;
}

.copyright-title {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.6rem;
    color: var(--primary-dark);
    margin-bottom: 2rem;
    text-align: center;
}

.copyright-text {
    font-family: var(--font-serif);
    font-size: 0.9rem;
    line-height: 1.9;
    color: var(--text-light);
    margin-bottom: 1.2rem;
    text-align: left;
}

/* ---- TABLE OF CONTENTS ---- */
.toc-page {
    min-height: 70vh;
    display: none;
    padding: 2rem 0;
}

.toc-page.active {
    display: block;
}

.toc-inner {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.toc-title {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 2.2rem;
    color: var(--primary-dark);
    text-align: center;
    margin-bottom: 2.5rem;
    letter-spacing: -0.01em;
}

.toc-part {
    margin-bottom: 2rem;
}

.toc-part-label {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gold);
    margin-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
}

.toc-item {
    display: flex;
    align-items: baseline;
    gap: 0.8rem;
    padding: 0.4rem 0;
    cursor: pointer;
    transition: color var(--transition);
    border-bottom: 1px solid transparent;
}

.toc-item:hover {
    color: var(--primary-blue);
}

.toc-item:hover .toc-title-text {
    color: var(--primary-blue);
}

.toc-chap {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--gold);
    min-width: 28px;
    text-align: right;
}

.toc-title-text {
    font-family: var(--font-serif);
    font-size: 1rem;
    flex: 1;
    color: var(--text);
    transition: color var(--transition);
}

.toc-page {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-light);
}

.toc-footer {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--gold);
    text-align: center;
}

.toc-thanks {
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 1.1rem;
}

/* ============================================================
   CHAPTERS (Rendered by JS)
   ============================================================ */
.chapter {
    display: none;
    animation: fadeIn 0.4s ease;
    padding: 0.5rem 0 2rem 0;
}

.chapter.active {
    display: block;
}

.chapter-number {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gold);
    margin-bottom: 0.3rem;
}

.chapter-title {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    color: var(--primary-dark);
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.chapter-part {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-light);
    margin-bottom: 1.5rem;
}

.chapter-divider {
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, var(--gold), var(--primary-blue));
    margin-bottom: 2rem;
    border-radius: 3px;
}

.chapter-body {
    font-family: var(--font-serif);
    font-size: 1rem;
    line-height: 1.9;
    color: var(--text);
}

.chapter-body h3 {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--primary-dark);
    margin-top: 1.8rem;
    margin-bottom: 0.6rem;
}

.chapter-body h4 {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    color: var(--primary-blue);
    margin-top: 1.4rem;
    margin-bottom: 0.4rem;
}

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

.chapter-body ul,
.chapter-body ol {
    margin: 0.8rem 0 1.2rem 1.5rem;
    padding-left: 0.5rem;
}

.chapter-body li {
    margin-bottom: 0.4rem;
}

.chapter-body blockquote {
    font-style: italic;
    border-left: 4px solid var(--gold);
    padding: 0.8rem 1.2rem;
    margin: 1.2rem 0;
    background: var(--gold-pale);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-light);
}

.chapter-body blockquote strong {
    color: var(--primary-dark);
}

.chapter-body .highlight-box {
    border: 2px solid var(--gold);
    background: var(--gold-pale);
    padding: 1.2rem 1.5rem;
    border-radius: var(--radius);
    margin: 1.5rem 0;
}

.chapter-body .highlight-box strong {
    color: var(--primary-dark);
}

.chapter-body .script-example {
    font-family: var(--font-serif);
    background: var(--primary-light);
    padding: 1.2rem 1.5rem;
    border-radius: var(--radius);
    margin: 1.2rem 0;
    border-left: 4px solid var(--primary-blue);
    font-style: italic;
    color: var(--text);
}

.chapter-body .script-example strong {
    font-style: normal;
    color: var(--primary-dark);
}

.chapter-body .rule-do {
    color: #276749;
    background: #F0FFF4;
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    border-left: 4px solid #48BB78;
    margin: 0.5rem 0;
}

.chapter-body .rule-dont {
    color: #9B2C2C;
    background: #FFF5F5;
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    border-left: 4px solid #FC8181;
    margin: 0.5rem 0;
}

/* ============================================================
   NAVIGATION
   ============================================================ */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.nav-btn {
    font-family: var(--font-sans);
    font-weight: 600;
    background: var(--primary-dark);
    color: #fff;
    border: none;
    padding: 0.6rem 1.4rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.nav-btn:hover:not(:disabled) {
    background: var(--gold);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(214, 158, 46, 0.3);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.nav-position {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-light);
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
    text-align: center;
    padding: 2rem 1rem 1rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
    font-size: 0.85rem;
    color: var(--text-light);
}

.footer-motto {
    font-family: var(--font-serif);
    font-style: italic;
    font-weight: 700;
    color: var(--gold);
    margin-top: 0.4rem;
    font-size: 0.95rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
    .main-content {
        padding: 1.5rem 1rem;
    }

    .top-bar-inner {
        padding: 0.4rem 1rem;
    }

    .top-bar-left {
        font-size: 0.75rem;
        gap: 0.5rem;
    }

    .ctrl-btn {
        font-size: 0.7rem;
        padding: 0.15rem 0.5rem;
    }

    .chapter-title {
        font-size: 1.6rem;
    }

    .chapter-body {
        font-size: 0.95rem;
    }

    .chapter-body ul,
    .chapter-body ol {
        margin-left: 1rem;
    }

    .nav-btn {
        padding: 0.4rem 1rem;
        font-size: 0.8rem;
    }

    .cover-title {
        font-size: 2.2rem;
    }

    .toc-item {
        padding: 0.5rem 0;
        gap: 0.5rem;
    }

    .toc-title-text {
        font-size: 0.9rem;
    }
}

@media print {

    .top-bar,
    .chapter-nav,
    .site-footer {
        display: none;
    }

    .page,
    .chapter {
        display: block !important;
        page-break-after: always;
    }

    .cover-page,
    .title-page,
    .copyright-page,
    .toc-page {
        min-height: auto;
        padding: 3rem 2rem;
    }

    body {
        font-size: 12pt;
        line-height: 1.6;
    }
}

/* ============================================================
   COVER CTA BUTTON
   ============================================================ */
.cover-cta {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1rem;
    background: var(--primary-dark);
    color: #fff;
    border: none;
    padding: 0.8rem 2.5rem;
    border-radius: 50px;
    cursor: pointer;
    margin-top: 2rem;
    transition: all var(--transition);
    letter-spacing: 0.03em;
    box-shadow: 0 4px 16px rgba(26, 54, 93, 0.25);
}

.cover-cta:hover {
    background: var(--gold);
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(214, 158, 46, 0.4);
}

[data-theme="dark"] .cover-cta {
    background: var(--gold);
    color: #1A202C;
}

[data-theme="dark"] .cover-cta:hover {
    background: var(--gold-light);
}

/* Optional: Make the new buttons slightly different */
#goToCover,
#goToToc {
    font-size: 0.9rem;
    padding: 0.2rem 0.5rem;
}

/* ============================================================
   TOP BAR - CLEAN WITH SVG ICONS
   ============================================================ */

.ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
    color: var(--text);
    transition: all var(--transition);
    line-height: 1.6;
    min-width: 32px;
    min-height: 28px;
}

.ctrl-btn svg {
    flex-shrink: 0;
    stroke: var(--text);
    transition: stroke var(--transition);
}

.ctrl-btn:hover {
    background: var(--gold);
    color: #fff;
    border-color: var(--gold);
}

.ctrl-btn:hover svg {
    stroke: #fff;
}

.ctrl-btn:active {
    transform: scale(0.95);
}

/* Dark mode active state */
.ctrl-btn.dark-active {
    background: var(--primary-dark);
    color: #fff;
    border-color: var(--primary-dark);
}

[data-theme="dark"] .ctrl-btn.dark-active {
    background: var(--gold);
    color: #1A202C;
    border-color: var(--gold);
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .ctrl-btn {
        font-size: 0.6rem;
        padding: 0.15rem 0.4rem;
        min-width: 28px;
        min-height: 24px;
    }
    .ctrl-btn svg {
        width: 16px;
        height: 16px;
    }
}

@media (max-width: 480px) {
    .ctrl-btn {
        font-size: 0.55rem;
        padding: 0.1rem 0.3rem;
        min-width: 24px;
        min-height: 22px;
        border-radius: 3px;
    }
    .ctrl-btn svg {
        width: 14px;
        height: 14px;
    }
    .top-bar-right {
        gap: 0.15rem;
    }
}

/* Navigation buttons with SVG arrows */
.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--primary-dark);
    color: #fff;
    border: none;
    padding: 0.6rem 1.4rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
}

.nav-btn svg {
    flex-shrink: 0;
    stroke: #fff;
}

.nav-btn:hover:not(:disabled) {
    background: var(--gold);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(214, 158, 46, 0.3);
}

.nav-btn:hover:not(:disabled) svg {
    stroke: #fff;
}

.nav-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

/* Cover CTA button with SVG */
.cover-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--primary-dark);
    color: #fff;
    border: none;
    padding: 0.9rem 2.5rem;
    border-radius: 50px;
    cursor: pointer;
    margin-top: 2.5rem;
    transition: all var(--transition);
    box-shadow: 0 4px 20px rgba(26, 54, 93, 0.25);
}

.cover-cta svg {
    flex-shrink: 0;
    stroke: #fff;
}

.cover-cta:hover {
    background: var(--gold);
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(214, 158, 46, 0.4);
}

.cover-cta:hover svg {
    stroke: #fff;
}

[data-theme="dark"] .cover-cta {
    background: var(--gold);
    color: #1A202C;
}

[data-theme="dark"] .cover-cta svg {
    stroke: #1A202C;
}

[data-theme="dark"] .cover-cta:hover {
    background: var(--gold-light);
}

/* Nav position text */
.nav-position {
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-light);
    letter-spacing: 0.02em;
    padding: 0 0.5rem;
}