:root {
    --cyan: #00f3ff;
    --green: #4fffa8;
    --magenta: #d946ef;
    --red: #ff3333;
    --panel: rgba(3, 10, 13, 0.9);
    --line: rgba(0, 243, 255, 0.28);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    min-height: 100vh;
    margin: 0;
    color: #d8eef0;
    background:
        radial-gradient(circle at 75% 15%, rgba(79, 255, 168, 0.12), transparent 32rem),
        radial-gradient(circle at 10% 85%, rgba(217, 70, 239, 0.08), transparent 28rem),
        #030305;
    font-family: 'Share Tech Mono', monospace;
}

.codex-noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.16;
    background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0, 243, 255, 0.07) 4px);
}

.codex-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 96px;
    padding: 1.25rem clamp(1rem, 4vw, 4rem);
    background: rgba(0, 0, 0, 0.86);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.codex-eyebrow {
    color: var(--cyan);
    font-size: 0.68rem;
    letter-spacing: 0.2em;
}

.codex-header h1 {
    margin: 0.3rem 0 0;
    color: var(--green);
    font-family: 'Cinzel Decorative', serif;
    font-size: clamp(1.45rem, 4vw, 2.5rem);
    text-shadow: 0 0 24px rgba(79, 255, 168, 0.35);
}

.codex-return {
    padding: 0.65rem 0.85rem;
    color: var(--cyan);
    border: 1px solid var(--line);
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-decoration: none;
}

.codex-return:hover,
.codex-return:focus-visible {
    border-color: var(--cyan);
    background: rgba(0, 243, 255, 0.1);
    outline: none;
}

.codex-shell {
    position: relative;
    display: grid;
    grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
    gap: 1.25rem;
    width: min(1400px, 100%);
    margin: 0 auto;
    padding: 1.25rem;
}

.codex-sidebar,
.codex-record {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 0 30px rgba(0, 243, 255, 0.05);
}

.codex-sidebar {
    position: sticky;
    top: 116px;
    align-self: start;
    max-height: calc(100vh - 136px);
    padding: 1rem;
    overflow-y: auto;
}

.codex-sidebar label {
    display: block;
    margin-bottom: 0.55rem;
    color: rgba(0, 243, 255, 0.7);
    font-size: 0.62rem;
    letter-spacing: 0.12em;
}

#codex-search {
    width: 100%;
    margin-bottom: 1rem;
    padding: 0.7rem;
    color: #fff;
    background: #020507;
    border: 1px solid var(--line);
    font: inherit;
    outline: none;
}

#codex-search:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
}

.codex-category {
    margin: 1rem 0 0.35rem;
    color: var(--magenta);
    font-size: 0.65rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.codex-entry {
    display: block;
    width: 100%;
    padding: 0.65rem 0.7rem;
    color: #9cb3b5;
    background: transparent;
    border: 0;
    border-left: 2px solid transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.codex-entry:hover,
.codex-entry.active {
    color: #fff;
    background: rgba(0, 243, 255, 0.08);
    border-left-color: var(--cyan);
}

.codex-record {
    min-height: calc(100vh - 136px);
    padding: clamp(1rem, 4vw, 3rem);
}

.record-status {
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    color: rgba(79, 255, 168, 0.7);
    border-bottom: 1px solid rgba(79, 255, 168, 0.18);
    font-size: 0.66rem;
    letter-spacing: 0.14em;
}

.codex-content {
    max-width: 900px;
    line-height: 1.75;
}

.codex-content h1,
.codex-content h2,
.codex-content h3 {
    color: #fff;
    font-family: 'Cinzel Decorative', serif;
    line-height: 1.25;
}

.codex-content h1 {
    color: var(--green);
    font-size: clamp(1.8rem, 5vw, 3.25rem);
}

.codex-content h2 {
    margin-top: 2.5rem;
    padding-bottom: 0.45rem;
    color: var(--cyan);
    border-bottom: 1px solid var(--line);
}

.codex-content a {
    color: var(--cyan);
}

.codex-content .restricted-record-link {
    position: relative;
    color: #ff7777;
    text-decoration-color: rgba(255, 51, 51, 0.65);
    text-decoration-style: dashed;
    text-shadow: 0 0 8px rgba(255, 51, 51, 0.35);
}

.codex-content .restricted-record-link::after {
    content: ' // WITHHELD';
    color: var(--red);
    font-size: 0.68em;
    letter-spacing: 0.12em;
}

.codex-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}

.codex-content th,
.codex-content td {
    padding: 0.55rem 0.75rem;
    border: 1px solid rgba(0, 243, 255, 0.18);
    text-align: left;
}

.codex-content th {
    color: var(--cyan);
    background: rgba(0, 243, 255, 0.06);
}

.codex-content img {
    max-width: 100%;
    height: auto;
}

.codex-toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 20;
    max-width: calc(100vw - 2rem);
    padding: 0.85rem 1rem;
    color: #fff;
    background: rgba(30, 0, 0, 0.94);
    border: 1px solid var(--red);
    box-shadow: 0 0 24px rgba(255, 51, 51, 0.25);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
}

body.watcher-channel .codex-header,
body.watcher-channel .codex-record,
body.watcher-channel .codex-sidebar {
    border-color: rgba(217, 70, 239, 0.4);
}

body.watcher-channel .codex-noise {
    opacity: 0.28;
    animation: codex-flicker 4s steps(2) infinite;
}

body.clearance-denied .codex-record {
    border-color: var(--red);
    box-shadow: inset 0 0 38px rgba(255, 51, 51, 0.08), 0 0 24px rgba(255, 51, 51, 0.2);
    animation: clearance-denied 0.34s steps(2) 2;
}

body.clearance-denied .record-status {
    color: var(--red);
    border-bottom-color: rgba(255, 51, 51, 0.45);
}

@keyframes clearance-denied {
    0%, 100% { transform: translateX(0); filter: none; }
    25% { transform: translateX(-4px); filter: saturate(1.8); }
    50% { transform: translateX(5px); filter: hue-rotate(18deg); }
    75% { transform: translateX(-2px); filter: saturate(1.4); }
}

@keyframes codex-flicker {
    0%, 92%, 100% { transform: translate(0); filter: none; }
    94% { transform: translate(2px, -1px); filter: hue-rotate(70deg); }
    96% { transform: translate(-3px, 1px); filter: hue-rotate(-40deg); }
}

@media (max-width: 760px) {
    .codex-header {
        align-items: flex-start;
        min-height: 86px;
        padding: 0.85rem 1rem;
    }

    .codex-return {
        padding: 0.55rem;
        font-size: 0.58rem;
    }

    .codex-shell {
        grid-template-columns: 1fr;
        padding: 0.65rem;
    }

    .codex-sidebar {
        position: static;
        max-height: none;
    }

    #codex-navigation {
        display: flex;
        gap: 0.4rem;
        overflow-x: auto;
    }

    .codex-category {
        display: none;
    }

    .codex-entry {
        flex: 0 0 auto;
        width: auto;
        border-bottom: 2px solid transparent;
        border-left: 0;
    }

    .codex-entry.active {
        border-bottom-color: var(--cyan);
    }

    .codex-record {
        min-height: 60vh;
        padding: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
