/* ==========================================================================
   CSS Variables - Military/War Theme
   ========================================================================== */
:root {
    /* Colors */
    --color-bg-dark: #0a0b0d;
    --color-bg-panel: #14161a;
    --color-bg-lighter: #1d2026;

    --color-primary: #8a9a5b;
    /* Camo Green */
    --color-primary-dark: #556b2f;
    --color-primary-glow: rgba(102, 0, 255, 0.4);

    --color-accent: #cc3300;
    /* Alert / Fire Red */
    --color-accent-dark: #990000;

    --color-text-main: #e2e4e9;
    --color-text-muted: #8b92a5;

    --color-border: #2a2e37;
    --color-border-glow: rgba(138, 154, 91, 0.2);

    /* Typography */
    --font-heading: 'Heebo', sans-serif;
    --font-body: 'Rubik', sans-serif;

    /* Layout */
    --max-width: 900px;
    --border-radius: 4px;
    --transition-fast: 0.2s ease;
}

/* ==========================================================================
   Base
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--color-bg-dark);
    color: var(--color-text-main);
    font-family: var(--font-body);
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
    /* subtle CRT scanline effect */
    background-image: linear-gradient(rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 4px, 3px 100%;
}

/* Noise overlay for gritty texture */
#noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.04;
    background: url('data:image/svg+xml;utf8,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)"/%3E%3C/svg%3E');
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    color: white;
    font-weight: 700;
    line-height: 1.2;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

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

button {
    cursor: pointer;
    font-family: var(--font-heading);
}

/* ==========================================================================
   Typography & Utilities
   ========================================================================== */
.btn {
    background: var(--color-bg-lighter);
    color: var(--color-text-main);
    border: 1px solid var(--color-border);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn:hover {
    background: var(--color-border);
    border-color: var(--color-primary);
    box-shadow: 0 0 10px var(--color-border-glow);
}

.btn.active {
    background: var(--color-primary-dark);
    color: white;
    border-color: var(--color-primary);
}


.hidden {
    display: none !important;
}

/* ==========================================================================
   Header
   ========================================================================== */
.main-header {
    background-color: #000;
    border-bottom: 2px solid var(--color-primary);
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
}

.header-content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.target-icon {
    font-size: 2.5rem;
    color: var(--color-accent);
    /* Pulse animation representing radar/target */
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.logo-area h1 {
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: 1px;
    margin-bottom: 0.2rem;
    text-shadow: 0 0 10px rgba(204, 51, 0, 0.4);
}

.subtitle {
    color: var(--color-primary);
    font-size: 0.9rem;
    font-family: var(--font-heading);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.author-info {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    background: rgba(255, 255, 255, 0.05);
}

.warning-tape {
    background: #ffcc00;
    color: #000;
    font-weight: 900;
    font-family: var(--font-heading);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 3px;
    display: flex;
    justify-content: space-around;
    padding: 3px 0;
    overflow: hidden;
    white-space: nowrap;
    border-bottom: 2px solid #000;
    /* Diagonal stripes */
    background-image: repeating-linear-gradient(-45deg,
            transparent,
            transparent 20px,
            rgba(0, 0, 0, 0.1) 20px,
            rgba(0, 0, 0, 0.1) 40px);
}

/* ==========================================================================
   Main Layout
   ========================================================================== */
.app-container {
    max-width: var(--max-width);
    margin: 2rem auto;
    padding: 0 1rem;
    min-height: 60vh;
}

.view {
    animation: fadeIn 0.4s ease forwards;
}

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

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

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 1rem;
    margin-bottom: 2rem;
    position: relative;
    z-index: 2;
}

.section-header h2 {
    font-size: 1.5rem;
    color: var(--color-text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-header h2 i {
    color: var(--color-primary);
}

/* ==========================================================================
   Navigation Sections
   ========================================================================== */
.nav-section {
    margin-bottom: 3rem;
}

.abstract-section {
    border-bottom: 4px double var(--color-border);
    padding-bottom: 2rem;
    margin-bottom: 3rem;
}

/* --- Abstract card --- */
.abstract-card {
    background:
        radial-gradient(ellipse at 30% 50%, rgba(204, 51, 0, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(138, 154, 91, 0.06) 0%, transparent 50%),
        linear-gradient(170deg, #1a1c21 0%, #0d0e10 40%, #0a0b0d 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 2.5rem 2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: abstract-glow 4s ease-in-out infinite;
}

@keyframes abstract-glow {
    0%, 100% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 15px rgba(204, 51, 0, 0.08); }
    50%      { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 25px rgba(204, 51, 0, 0.18), 0 0 60px rgba(204, 51, 0, 0.06); }
}

/* HUD corner brackets */
.abstract-card::before,
.abstract-card::after {
    content: '';
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: var(--color-accent);
    border-style: solid;
    opacity: 0.6;
    transition: opacity 0.3s ease;
    z-index: 3;
}

.abstract-card::before {
    top: 10px;
    right: 10px;
    border-width: 2px 2px 0 0;
}

.abstract-card::after {
    bottom: 10px;
    left: 10px;
    border-width: 0 0 2px 2px;
}

.abstract-card:hover::before,
.abstract-card:hover::after {
    opacity: 1;
}

/* Scanline overlay */
.abstract-scanline {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(255, 255, 255, 0.015) 2px,
        rgba(255, 255, 255, 0.015) 4px
    );
    pointer-events: none;
    z-index: 1;
}

/* Accent line at the top of the card */
.abstract-accent-line {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--color-accent) 20%, var(--color-accent) 80%, transparent);
    z-index: 2;
}

.abstract-body {
    position: relative;
    z-index: 2;
}

.abstract-content {
    max-width: 100%;
}

.abstract-badge {
    position: relative;
    z-index: 2;
    display: inline-block;
    background: rgba(204, 51, 0, 0.15);
    color: var(--color-accent);
    padding: 4px 14px;
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 900;
    letter-spacing: 1px;
    text-transform: uppercase;
    border: 1px solid rgba(204, 51, 0, 0.3);
    border-radius: 2px;
    margin-bottom: 1.25rem;
}

/* Large icon watermark */
.abstract-icon {
    position: absolute;
    bottom: -10px;
    left: 15px;
    font-size: 7rem;
    color: rgba(204, 51, 0, 0.06);
    z-index: 1;
    pointer-events: none;
    transition: color 0.3s ease;
}

.abstract-card:hover .abstract-icon {
    color: rgba(204, 51, 0, 0.1);
}

@media (hover: hover) {
    .abstract-card:hover {
        border-color: var(--color-accent);
        transform: translateY(-3px);
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.7), 0 0 30px rgba(204, 51, 0, 0.15);
        animation: none;
    }
}

.abstract-card h3 {
    font-size: 1.8rem;
    margin-bottom: 0.75rem;
    color: white;
    font-weight: 900;
}

.abstract-card p {
    font-size: 1.1rem;
    line-height: 1.7;
    color: var(--color-text-muted);
    max-width: 600px;
}

.read-more {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.25rem;
    color: var(--color-accent);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    transition: all 0.3s ease;
}

.abstract-card:hover .read-more {
    color: white;
    gap: 0.7rem;
}

@media (max-width: 550px) {
    .abstract-card {
        padding: 2rem 1.5rem;
    }

    .abstract-card h3 {
        font-size: 1.4rem;
    }

    .abstract-card p {
        font-size: 1rem;
    }

    .abstract-icon {
        font-size: 5rem;
    }
}

/* ==========================================================================
   Carousel
   ========================================================================== */
.carousel-section {
    margin-bottom: 3rem;
}

.carousel-wrapper {
    position: relative;
}

.carousel-viewport {
    overflow: hidden;
    padding-top: 10px;
    margin-top: -10px;
    position: relative;
    z-index: 0;
}

.carousel-track {
    display: flex;
    gap: 1rem;
    transition: transform 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

.carousel-nav {
    display: flex;
    gap: 0.5rem;
    position: relative;
    z-index: 1;
}

.carousel-arrow {
    background: var(--color-bg-lighter);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
    cursor: pointer;
    padding: 0;
    position: relative;
    touch-action: manipulation;
}

.carousel-arrow::after {
    content: '';
    position: absolute;
    inset: -8px;
}

@media (hover: hover) {
    .carousel-arrow:hover {
        border-color: var(--color-primary);
        background: var(--color-border);
        box-shadow: 0 0 12px var(--color-border-glow);
    }
}

.carousel-arrow:disabled {
    opacity: 0.2;
    cursor: default;
    pointer-events: none;
}

.carousel-dots {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.carousel-dot {
    width: 24px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
    border: none;
    padding: 0;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.carousel-dot::after {
    content: '';
    position: absolute;
    inset: -10px -4px;
}

.carousel-dot.active {
    background: var(--color-accent);
    width: 32px;
}

.carousel-dot:hover:not(.active) {
    background: var(--color-text-muted);
}

/* ==========================================================================
   Chapter Cards
   ========================================================================== */
.chapter-card {
    background-color: var(--color-bg-panel);
    background-size: cover;
    background-position: center;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

/* Cards inside carousel: width set by JS via CSS variable */
.carousel-track .chapter-card {
    flex: 0 0 var(--card-width, 30%);
    min-width: 0;
    opacity: 0.6;
    transition: all var(--transition-fast), opacity 0.45s ease;
}

.carousel-track .chapter-card.carousel-visible {
    opacity: 1;
}

@media (hover: hover) {
    .chapter-card:hover {
        border-color: var(--color-primary);
        transform: translateY(-4px);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    }
}

/* Gradient overlay for thumbnail cards */
.chapter-card.has-thumbnail::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(10, 11, 13, 0.95) 20%, rgba(10, 11, 13, 0.5) 60%, rgba(10, 11, 13, 0.2) 100%);
    z-index: 1;
}

/* Grid pattern for cards without thumbnail */
.chapter-card:not(.has-thumbnail)::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(138, 154, 91, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(138, 154, 91, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

.card-chapter-num {
    position: absolute;
    top: 15px;
    left: 15px;
    font-family: var(--font-heading);
    font-size: 3.5rem;
    font-weight: 900;
    color: rgba(138, 154, 91, 0.15);
    line-height: 1;
    z-index: 2;
}

.card-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--color-accent);
    color: white;
    padding: 3px 10px;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
    z-index: 2;
}

.card-body {
    padding: 1rem 1.25rem 2.5rem;
    display: flex;
    flex-direction: column;
    margin-top: auto;
    position: relative;
    z-index: 2;
}

.card-body .card-date {
    position: absolute;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-accent);
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 700;
    z-index: 2;
}

.card-body h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.card-body p {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 900px) {
    .chapter-card {
        min-height: 240px;
    }
}

@media (max-width: 550px) {
    .carousel-arrow {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }
}

/* ==========================================================================
   Reactions Grid (scattered layout)
   ========================================================================== */
.reactions-section {
    margin-top: 3rem;
}

.reactions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.reactions-grid .chapter-card {
    min-height: 200px;
}

.reactions-grid .chapter-card .card-badge {
    background: var(--color-primary-dark);
}

/* ==========================================================================
   Reader View
   ========================================================================== */
.reader-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.reader-meta {
    display: flex;
    gap: 1.5rem;
    color: var(--color-text-muted);
    font-family: var(--font-heading);
    font-size: 0.9rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chapter-content {
    background: var(--color-bg-panel);
    padding: 2rem 2.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

@media (max-width: 600px) {
    .chapter-content {
        padding: 1.5rem 1rem;
    }
}

/* Markdown Styles within Reader */
.chapter-content h1 {
    font-size: 2.2rem;
    margin-bottom: 1.5rem;
    color: white;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0.5rem;
}

.chapter-content h2 {
    font-size: 1.8rem;
    margin: 2rem 0 1rem;
    color: var(--color-text-main);
}

.chapter-content h3 {
    font-size: 1.4rem;
    margin: 1.5rem 0 1rem;
}

.chapter-content p {
    margin-bottom: 1.2rem;
    font-size: 1.1rem;
    line-height: 1.8;
    text-align: justify;
}

.chapter-content blockquote {
    border-right: 4px solid var(--color-accent);
    /* RTL border */
    padding-right: 1.5rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: var(--color-text-muted);
    background: rgba(204, 51, 0, 0.05);
    padding: 1rem 1.5rem;
    border-radius: 2px;
    text-align: justify;
}

.chapter-content ul,
.chapter-content ol {
    margin-bottom: 1.2rem;
    padding-right: 2rem;
}

.chapter-content li {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    text-align: justify;
}

.chapter-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    margin: 1rem 0;
}

.chapter-content hr {
    border: 0;
    border-bottom: 1px solid var(--color-border);
    margin: 2rem 0;
}


/* ==========================================================================
   Skeleton Placeholders
   ========================================================================== */

/* Wave animation container */
.placeholder-wave {
    -webkit-mask-image: linear-gradient(
        130deg,
        #000 55%,
        rgba(0, 0, 0, 0.3) 75%,
        #000 95%
    );
    mask-image: linear-gradient(
        130deg,
        #000 55%,
        rgba(0, 0, 0, 0.3) 75%,
        #000 95%
    );
    -webkit-mask-size: 200% 100%;
    mask-size: 200% 100%;
    animation: placeholder-wave 1.8s linear infinite;
}

@keyframes placeholder-wave {
    100% {
        -webkit-mask-position: -200% 0%;
        mask-position: -200% 0%;
    }
}

/* Individual placeholder bar */
.placeholder {
    display: inline-block;
    background: var(--color-border);
    border-radius: 3px;
    min-height: 0.8em;
    vertical-align: middle;
    opacity: 0.5;
}

/* Skeleton abstract card */
.skeleton-abstract {
    background: linear-gradient(170deg, #1a1c21 0%, #0d0e10 40%, #0a0b0d 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 2.5rem 2rem;
    position: relative;
    overflow: hidden;
}

.skeleton-abstract .placeholder-badge {
    width: 90px;
    height: 24px;
    margin-bottom: 1.25rem;
}

.skeleton-abstract .placeholder-title {
    width: 60%;
    height: 1.6rem;
    margin-bottom: 0.75rem;
}

.skeleton-abstract .placeholder-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}

.skeleton-abstract .placeholder-link {
    width: 120px;
    height: 0.9rem;
    margin-top: 1rem;
}

/* Skeleton chapter card */
.skeleton-card {
    background-color: var(--color-bg-panel);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

.skeleton-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(138, 154, 91, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(138, 154, 91, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

.skeleton-card .placeholder-badge-bar {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 50px;
    height: 20px;
    z-index: 2;
}

.skeleton-card .placeholder-num {
    position: absolute;
    top: 15px;
    left: 15px;
    width: 40px;
    height: 3rem;
    opacity: 0.15;
    z-index: 2;
}

.skeleton-card .skeleton-card-body {
    padding: 1rem 1.25rem 2.5rem;
    display: flex;
    flex-direction: column;
    margin-top: auto;
    position: relative;
    z-index: 2;
    gap: 0.5rem;
}

.skeleton-card .placeholder-date {
    position: absolute;
    bottom: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 0.8rem;
    z-index: 2;
}

/* Skeleton cards inside carousel track */
.carousel-track .skeleton-card {
    flex: 0 0 var(--card-width, 30%);
    min-width: 0;
    opacity: 0.6;
}

/* Skeleton cards inside reactions grid */
.reactions-grid .skeleton-card {
    min-height: 200px;
}

/* Skeleton reader content */
.skeleton-reader {
    padding: 1rem 0;
}

.skeleton-reader .placeholder-h1 {
    width: 70%;
    height: 2rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0.5rem;
}

.skeleton-reader .placeholder-paragraph {
    margin-bottom: 1.2rem;
}

.skeleton-reader .placeholder-paragraph .placeholder {
    height: 1rem;
    margin-bottom: 0.5rem;
    display: block;
}

.skeleton-reader .placeholder-h2 {
    width: 45%;
    height: 1.5rem;
    margin: 2rem 0 1rem;
}

.skeleton-reader .placeholder-blockquote {
    border-right: 4px solid var(--color-border);
    padding: 1rem 1.5rem;
    margin: 1.5rem 0;
    background: rgba(204, 51, 0, 0.03);
    border-radius: 2px;
}

.skeleton-reader .placeholder-blockquote .placeholder {
    height: 1rem;
    margin-bottom: 0.5rem;
    display: block;
    opacity: 0.3;
}

@media (max-width: 900px) {
    .skeleton-card {
        min-height: 240px;
    }
}

@media (max-width: 550px) {
    .skeleton-abstract {
        padding: 2rem 1.5rem;
    }
}

/* ==========================================================================
   Loading State
   ========================================================================== */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--color-primary);
    font-family: var(--font-heading);
    font-size: 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading i {
    font-size: 2rem;
}

/* ==========================================================================
   Footer
   ========================================================================== */
footer {
    text-align: center;
    padding: 2rem 1rem;
    border-top: 1px solid var(--color-border);
    margin-top: 4rem;
    background: #000;
    color: var(--color-text-muted);
    font-family: var(--font-heading);
    font-size: 0.9rem;
}

.disclaimer {
    color: var(--color-accent);
    margin-top: 0.5rem;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

/* --- Footer Contact --- */
.footer-contact-links {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.footer-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: 1.1rem;
    width: 36px;
    height: 36px;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.footer-link:hover {
    color: var(--color-text-main);
    border-color: var(--color-primary);
    background: rgba(138, 154, 91, 0.1);
    box-shadow: 0 0 10px var(--color-border-glow);
}

/* ==========================================================================
   Header About Button
   ========================================================================== */
.header-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.header-icon-btn:hover {
    color: var(--color-text-main);
    border-color: var(--color-primary);
    background: rgba(138, 154, 91, 0.1);
    box-shadow: 0 0 10px var(--color-border-glow);
}

/* ==========================================================================
   About Modal
   ========================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalBackdropIn 0.25s ease;
    padding: 1rem;
}

@keyframes modalBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-box {
    position: relative;
    background: var(--color-bg-panel);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 2.5rem 2rem;
    max-width: 550px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9), 0 0 30px rgba(204, 51, 0, 0.1);
    animation: modalBoxIn 0.3s ease;
}

@keyframes modalBoxIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-box h2 {
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 1rem;
}

.modal-box h2 i {
    color: var(--color-primary);
}

.modal-box h3 {
    font-size: 1.1rem;
    margin: 1.5rem 0 0.75rem;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.modal-box p {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.modal-credits {
    text-align: center;
}

.modal-credits a {
    color: var(--color-text-muted);
    margin-right: 0.3rem;
    font-size: 1.1rem;
    transition: color var(--transition-fast);
}

.modal-credits a:hover {
    color: var(--color-text-main);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.6rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast);
    line-height: 1;
}

.modal-close:hover {
    color: var(--color-text-main);
    background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 550px) {
    .modal-box {
        padding: 2rem 1.5rem;
    }
}

/* ==========================================================================
   Chapter Navigation (Prev / Next / Scroll-to-top)
   ========================================================================== */

/* --- Desktop: floating circles on outer background --- */
.chapter-nav-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-bg-lighter);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000; /* above #noise-overlay (9999) */
    transition: all var(--transition-fast);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* RTL: prev (right/start side), next (left/end side) */
.chapter-nav-prev {
    right: calc((100vw - var(--max-width)) / 2 / 2 - 24px);
}

.chapter-nav-next {
    left: calc((100vw - var(--max-width)) / 2 / 2 - 24px);
}

@media (hover: hover) {
    .chapter-nav-btn:hover {
        border-color: var(--color-primary);
        color: var(--color-text-main);
        background: var(--color-border);
        box-shadow: 0 0 14px var(--color-border-glow);
    }
}

.chapter-nav-btn.hidden {
    display: none !important;
}

/* --- Mobile top bar: rectangles pinned to top --- */
.chapter-nav-bar {
    position: sticky;
    top: 0;
    z-index: 10000; /* above #noise-overlay (9999) */
    display: none; /* overridden by media query */
    justify-content: space-between;
    gap: 0.5rem;
    background: var(--color-bg-dark);
    border-bottom: 1px solid var(--color-border);
    padding: 0.5rem;
    margin: -0.5rem -1rem 1rem -1rem;
}

.chapter-nav-bar-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: var(--color-bg-lighter);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chapter-nav-bar-btn:active {
    background: var(--color-border);
}

.chapter-nav-home-btn {
    flex: 0 0 auto;
    padding: 0.5rem 1rem;
    color: var(--color-primary);
}

.chapter-nav-bar-btn.hidden {
    display: flex !important; /* override generic .hidden to keep layout space */
    visibility: hidden;
}

/* --- Scroll-to-top button --- */
.scroll-to-top-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem; /* "start" in RTL */
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--color-bg-lighter);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000; /* above #noise-overlay (9999) */
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
}

.scroll-to-top-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

.scroll-to-top-btn.pinned {
    position: absolute;
    bottom: auto;
    /* transition only opacity when pinned, not position jumps */
    transition: opacity 0.3s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

@media (hover: hover) {
    .scroll-to-top-btn:hover {
        border-color: var(--color-primary);
        color: var(--color-text-main);
        background: var(--color-border);
        box-shadow: 0 0 14px var(--color-border-glow);
    }
}

/* --- Responsive: switch to mobile bar when not enough outer space --- */
/* When viewport <= max-width + ~140px (70px per side for circle + margin) */
@media (max-width: 1040px) {
    .chapter-nav-btn {
        display: none !important;
    }

    .chapter-nav-bar:not(.hidden) {
        display: flex;
    }

    /* Toolbar back button redundant on mobile — home is in nav bar */
    .back-btn {
        display: none !important;
    }
}