/* ===========================
   CODEX PAGE - THREE-COLUMN DOCS LAYOUT
   Left: Section nav (fixed)
   Center: Article content
   Right: On-page TOC (sticky)
   =========================== */

.codex-main {
    padding-top: 70px;
}

/* Hero */
.codex-hero {
    text-align: center;
    padding: 3rem 5% 2rem;
    background: var(--base);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.codex-hero h1 {
    font-family: var(--font-heading);
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: var(--accent-gold);
    margin-bottom: 0.4rem;
}

.codex-subtitle {
    font-family: var(--font-mono);
    font-size: 1.05rem;
    color: var(--text-dim);
    margin-bottom: 1.25rem;
}

.spoiler-notice {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(177, 18, 37, 0.1);
    border: 1px solid rgba(177, 18, 37, 0.25);
    padding: 0.5rem 1rem;
    max-width: 500px;
    margin: 0 auto;
}

.spoiler-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.spoiler-notice p {
    margin: 0;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    text-align: left;
}

/* ===========================
   THREE-COLUMN LAYOUT
   =========================== */
.codex-layout {
    display: flex;
    padding-left: 240px;
}

/* ===========================
   LEFT SIDEBAR - Fixed Nav
   =========================== */
.codex-sidebar-left {
    position: fixed;
    top: 70px;
    left: 0;
    bottom: 0;
    width: 240px;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    background: var(--base);
    z-index: 50;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 193, 10, 0.15) transparent;
}

.codex-sidebar-left::-webkit-scrollbar {
    width: 3px;
}
.codex-sidebar-left::-webkit-scrollbar-thumb {
    background: rgba(255, 193, 10, 0.15);
}

.codex-nav {
    padding: 1.5rem 0;
}

.codex-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.codex-nav li {
    margin: 0;
}

.nav-link {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.5rem 1.5rem;
    border-left: 2px solid transparent;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.nav-link:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.02);
}

.nav-link.active {
    color: var(--accent-gold);
    border-left-color: var(--accent-gold);
    background: rgba(255, 193, 10, 0.04);
    font-weight: 600;
}

/* ===========================
   MAIN CONTENT
   =========================== */
.codex-content {
    flex: 1;
    min-width: 0;
    max-width: 780px;
    padding: 2rem 3rem 4rem;
    margin: 0 auto;
}

/* ===========================
   RIGHT SIDEBAR - Page TOC
   =========================== */
.codex-sidebar-right {
    width: 200px;
    min-width: 200px;
    flex-shrink: 0;
}

.codex-page-toc {
    position: sticky;
    top: 90px;
    padding: 1.5rem 1rem 1.5rem 0;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 193, 10, 0.1) transparent;
}

.codex-page-toc::-webkit-scrollbar {
    width: 3px;
}
.codex-page-toc::-webkit-scrollbar-thumb {
    background: rgba(255, 193, 10, 0.1);
}

.codex-page-toc h3 {
    font-family: var(--font-heading);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
    padding-left: 0.75rem;
}

.codex-page-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.page-toc-link {
    display: block;
    color: rgba(255, 255, 255, 0.4);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 400;
    padding: 0.25rem 0.75rem;
    border-left: 2px solid transparent;
    margin-left: -1px;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.page-toc-link:hover {
    color: var(--text-muted);
}

.page-toc-link.active {
    color: var(--accent-gold);
    border-left-color: var(--accent-gold);
}

/* ===========================
   CONTENT STYLES
   =========================== */

.codex-intro {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.wiki-voice {
    background: rgba(255, 193, 10, 0.03);
    border-left: 3px solid var(--accent-gold);
    padding: 1rem 1.25rem;
    margin: 1.25rem 0;
}

.wiki-voice p {
    margin-bottom: 0.5rem;
    line-height: 1.7;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.wiki-voice p:last-child { margin-bottom: 0; }

.wiki-signature {
    color: var(--accent-gold);
    font-family: var(--font-heading);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: right;
    margin-top: 0.5rem !important;
    font-size: 0.8rem;
}

.codex-section {
    margin-bottom: 2.5rem;
    padding-top: 1rem;
    scroll-margin-top: 80px;
}

.codex-section h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--accent-gold);
    margin-bottom: 1.25rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid rgba(255, 193, 10, 0.12);
}

.codex-section h3 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-gold);
    margin: 1.75rem 0 0.6rem;
    scroll-margin-top: 80px;
}

.codex-section p {
    line-height: 1.75;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
    font-size: 1rem;
}

.codex-section li {
    font-size: 1rem;
    line-height: 1.75;
}

.section-intro {
    font-family: var(--font-mono);
    color: var(--text-dim);
    font-size: 0.85rem;
}

.codex-feature { margin-bottom: 1rem; }

.codex-feature h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-color);
    margin-bottom: 0.3rem;
}

.codex-entry,
.bestiary-entry {
    background: var(--base-light);
    padding: 1.1rem 1.25rem;
    margin-bottom: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-left: 3px solid rgba(255, 255, 255, 0.06);
}

.codex-entry h3,
.bestiary-entry h3 {
    margin-top: 0;
    font-size: 1rem;
}

.entry-meta {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 0.6rem;
}

.entry-meta span {
    font-weight: 600;
    color: var(--text-muted);
}

.codex-flavor {
    color: var(--text-dim);
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

.codex-section blockquote {
    border-left: 3px solid var(--accent-red);
    padding: 0.5rem 0.85rem;
    margin: 0.6rem 0;
    font-family: var(--font-mono);
    font-style: italic;
    color: rgba(255, 255, 255, 0.6);
    background: rgba(177, 18, 37, 0.03);
    font-size: 0.9rem;
    line-height: 1.6;
}

.character-card {
    background: var(--base-light);
    padding: 1.1rem 1.25rem;
    margin-bottom: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-left: 3px solid rgba(255, 193, 10, 0.15);
}

.character-card h4 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent-gold);
    margin-bottom: 0.4rem;
}

.character-card.npc { border-left-color: rgba(255, 255, 255, 0.08); }

.character-portrait {
    float: right;
    width: 120px;
    height: auto;
    margin: 0 0 0.75rem 1rem;
    border: 1px solid rgba(255, 193, 10, 0.1);
}

@media (max-width: 480px) {
    .character-portrait {
        float: none;
        display: block;
        width: 100px;
        margin: 0 auto 0.75rem;
    }
}

.character-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 0.6rem;
}

.codex-table-wrapper {
    overflow-x: auto;
    margin: 0.75rem 0 1.25rem;
}

.codex-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.codex-table th {
    text-align: left;
    padding: 0.4rem 0.6rem;
    font-family: var(--font-heading);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-gold);
    border-bottom: 2px solid rgba(255, 193, 10, 0.12);
    font-size: 0.82rem;
}

.codex-table td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    vertical-align: top;
    line-height: 1.5;
    color: var(--text-muted);
}

.codex-table td:first-child {
    white-space: nowrap;
    width: 1%;
    color: var(--text-color);
}

.codex-table tr:hover td { background: rgba(255, 193, 10, 0.02); }

.codex-list {
    padding-left: 1.25rem;
    margin: 0.6rem 0;
}

.codex-list li {
    margin-bottom: 0.35rem;
    line-height: 1.6;
    color: var(--text-muted);
    font-size: 1rem;
}

.codex-glossary dt {
    font-family: var(--font-heading);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-gold);
    margin-top: 0.75rem;
    font-size: 0.82rem;
}

.codex-glossary dt:first-child { margin-top: 0; }

.codex-glossary dd {
    margin-left: 0;
    margin-bottom: 0.15rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    line-height: 1.5;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.codex-afterword { margin-bottom: 1.5rem; }

.codex-cta {
    text-align: center;
    padding: 1.5rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.codex-cta p {
    color: var(--text-dim);
    margin-bottom: 1rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

/* ===========================
   INDEX GRID (Landing Page)
   =========================== */
.codex-index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.codex-index-card {
    display: block;
    background: var(--base-light);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-left: 3px solid rgba(255, 193, 10, 0.15);
    padding: 1.25rem 1.5rem;
    text-decoration: none;
    transition: all 0.2s ease;
}

.codex-index-card:hover {
    border-left-color: var(--accent-gold);
    background: rgba(255, 193, 10, 0.03);
    transform: translateY(-2px);
}

.codex-index-card h3 {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-gold);
    margin-bottom: 0.4rem;
}

.codex-index-card p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin: 0;
}

@media (max-width: 768px) {
    .codex-index-grid {
        grid-template-columns: 1fr;
    }
}

/* ===========================
   NEWSLETTER
   =========================== */
.codex-newsletter {
    padding: 3rem 5%;
    background: var(--base-light);
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.codex-newsletter .newsletter-container {
    max-width: 500px;
    margin: 0 auto;
}

.codex-newsletter .newsletter-container h2 {
    font-family: var(--font-heading);
    font-size: clamp(1.3rem, 2.5vw, 1.8rem);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--accent-gold);
    margin-bottom: 0.5rem;
}

.codex-newsletter .newsletter-container > p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.codex-newsletter .newsletter-inline {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.codex-newsletter .newsletter-inline input {
    flex: 1;
    padding: 0.7rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--base);
    color: var(--text-color);
    font-family: var(--font-body);
    font-size: 0.9rem;
}

.codex-newsletter .newsletter-inline input:focus {
    outline: none;
    border-color: var(--accent-gold);
}

.codex-newsletter .newsletter-inline button {
    padding: 0.7rem 1.25rem;
    background: var(--accent-gold);
    color: var(--base);
    border: none;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s ease;
    clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}

.codex-newsletter .newsletter-inline button:hover {
    background: var(--text-color);
}

.codex-newsletter .privacy-notice {
    font-size: 0.7rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

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

/* Hide right TOC on medium screens */
@media (max-width: 1100px) {
    .codex-sidebar-right {
        display: none;
    }

    .codex-content {
        padding: 2rem 2.5rem 3rem;
    }
}

/* Collapse left sidebar on mobile */
@media (max-width: 768px) {
    .codex-layout {
        padding-left: 0;
        flex-direction: column;
    }

    .codex-sidebar-left {
        position: sticky;
        top: 70px;
        left: auto;
        bottom: auto;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        overflow-x: auto;
        overflow-y: hidden;
    }

    .codex-nav {
        padding: 0;
    }

    .codex-nav ul {
        display: flex;
        flex-wrap: nowrap;
        padding: 0.5rem 1rem;
        gap: 0.25rem;
    }

    .codex-nav li { margin: 0; }

    .nav-link {
        padding: 0.4rem 0.75rem;
        font-size: 0.75rem;
        border-left: none;
        border-bottom: 2px solid transparent;
        white-space: nowrap;
        flex-shrink: 0;
        background: rgba(255, 255, 255, 0.02);
    }

    .nav-link:hover {
        border-bottom-color: rgba(255, 193, 10, 0.3);
        background: rgba(255, 255, 255, 0.04);
    }

    .nav-link.active {
        border-left-color: transparent;
        border-bottom-color: var(--accent-gold);
        background: rgba(255, 193, 10, 0.06);
    }

    .codex-content {
        padding: 1.5rem 5% 3rem;
    }

    .codex-hero {
        padding: 2rem 4% 1.5rem;
    }

    .codex-hero h1 {
        font-size: 1.6rem;
        letter-spacing: 2px;
    }

    .codex-section h2 { font-size: 1.25rem; }
    .codex-section h3 { font-size: 0.95rem; }

    .codex-entry,
    .bestiary-entry,
    .character-card {
        padding: 0.9rem 1rem;
    }

    .character-card h4 { font-size: 1rem; }

    .character-meta {
        flex-direction: column;
        gap: 0.15rem;
    }

    .codex-table td:first-child { white-space: normal; }
}

@media (max-width: 480px) {
    .codex-main { padding-top: 60px; }

    .codex-sidebar-left { top: 60px; }

    .codex-hero {
        padding: 1.5rem 3% 1rem;
    }

    .codex-hero h1 { font-size: 1.3rem; }
    .codex-subtitle { font-size: 0.95rem; }

    .nav-link {
        font-size: 0.7rem;
        padding: 0.35rem 0.6rem;
    }

    .codex-content {
        padding: 1.25rem 3% 2rem;
    }

    .codex-section h2 { font-size: 1.1rem; }

    .spoiler-notice { padding: 0.4rem 0.75rem; }
}
