/* ============================================================
   Finite Context, Real Memory — Single-file interactive essay
   Base CSS: Variables, reset, utilities
   Audience: senior/principal/director/head roles + curious intellectuals.
   ============================================================ */

:root {
    /* Dark theme (default) - editorial systems palette */
    --bg0: #0e1216;
    --bg1: #141a1f;
    --bg2: #1b232b;
    --bg3: #212d36;

    --card: rgba(234, 240, 244, 0.04);
    --card2: rgba(234, 240, 244, 0.08);
    --card3: rgba(234, 240, 244, 0.14);
    --stroke: rgba(170, 183, 193, 0.24);
    --stroke2: rgba(170, 183, 193, 0.38);
    --stroke3: rgba(170, 183, 193, 0.56);

    --text: #eaf0f4;
    --muted: #aab7c1;
    --faint: rgba(170, 183, 193, 0.72);
    --ghost: rgba(170, 183, 193, 0.46);

    /* Semantic accents */
    --accent: #63a7ff;
    --accent2: #d98e5f;
    --accent3: #78b587;
    --accent4: #d86b6b;
    --accent5: #93a5b5;

    --accent-glow: rgba(99, 167, 255, 0.24);
    --accent2-glow: rgba(217, 142, 95, 0.2);
    --accent3-glow: rgba(120, 181, 135, 0.2);

    --danger: #d86b6b;
    --warn: #d98e5f;
    --success: #78b587;

    --mono: "IBM Plex Mono", "SF Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --sans: "Manrope", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
    --serif: "Source Serif 4", "Iowan Old Style", "Baskerville", Georgia, "Times New Roman", serif;
    --display: "Fraunces", "Instrument Serif", "Iowan Old Style", Georgia, serif;

    --radius: 16px;
    --radius2: 24px;
    --radius-sm: 10px;
    --radius-xs: 6px;

    --shadow: 0 8px 26px rgba(2, 8, 14, 0.28);
    --shadow2: 0 18px 44px rgba(2, 8, 14, 0.34);
    --shadow-glow: 0 0 30px rgba(99, 167, 255, 0.14);

    --maxw: 1520px;
    --maxw-narrow: 980px;

    --lh: 1.82;
    --lh-tight: 1.5;
    --ease: cubic-bezier(.23, 1, .32, 1);
    --ease-out: cubic-bezier(.16, 1, .3, 1);
    --ease-in-out: cubic-bezier(.65, 0, .35, 1);

    --c-system: rgba(99, 167, 255, 0.72);
    --c-conv: rgba(147, 165, 181, 0.62);
    --c-retr: rgba(120, 181, 135, 0.68);
    --c-tools: rgba(217, 142, 95, 0.65);
    --c-user: rgba(170, 183, 193, 0.62);
    --c-resp: rgba(216, 107, 107, 0.58);

    --fg: #eaf0f4;
}

[data-theme="light"] {
    --bg0: #f4f1ea;
    --bg1: #ece7de;
    --bg2: #e2dbd0;
    --bg3: #d7cfc3;

    --card: rgba(255, 255, 255, 0.72);
    --card2: rgba(255, 255, 255, 0.88);
    --card3: rgba(255, 255, 255, 0.95);
    --stroke: rgba(196, 184, 166, 0.7);
    --stroke2: rgba(196, 184, 166, 0.86);
    --stroke3: rgba(145, 127, 102, 0.62);

    --text: #1c252c;
    --muted: #51626d;
    --faint: rgba(81, 98, 109, 0.72);
    --ghost: rgba(81, 98, 109, 0.46);

    --accent: #2f6fb2;
    --accent2: #b66c3c;
    --accent3: #3e7a4e;
    --accent4: #a84444;
    --accent5: #6a7a86;

    --accent-glow: rgba(47, 111, 178, 0.2);
    --accent2-glow: rgba(182, 108, 60, 0.18);
    --accent3-glow: rgba(62, 122, 78, 0.2);

    --danger: #a84444;
    --warn: #b66c3c;
    --success: #3e7a4e;

    --shadow: 0 6px 18px rgba(52, 44, 33, 0.08);
    --shadow2: 0 14px 32px rgba(52, 44, 33, 0.14);
    --shadow-glow: 0 0 24px rgba(47, 111, 178, 0.14);

    --c-system: rgba(47, 111, 178, 0.58);
    --c-conv: rgba(106, 122, 134, 0.52);
    --c-retr: rgba(62, 122, 78, 0.55);
    --c-tools: rgba(182, 108, 60, 0.56);
    --c-user: rgba(81, 98, 109, 0.46);
    --c-resp: rgba(168, 68, 68, 0.52);

    --fg: #1c252c;
}

* {
    box-sizing: border-box;
    min-width: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    overflow-x: clip;
}

body {
    margin: 0;
    font-family: var(--serif);
    color: var(--text);
    background:
        radial-gradient(1400px 900px at 85% -10%, rgba(99, 167, 255, 0.08), transparent 62%),
        radial-gradient(1000px 700px at 10% 10%, rgba(217, 142, 95, 0.06), transparent 64%),
        linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 24%, var(--bg2) 68%, var(--bg3) 100%);
    min-height: 100vh;
    overflow-x: clip;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: var(--lh);
}

/* Enhanced grain / print texture */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: 0.035;
    mix-blend-mode: soft-light;
    background-image:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0px, rgba(255, 255, 255, 0.018) 1px, transparent 1px, transparent 3px),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.012) 0px, rgba(255, 255, 255, 0.012) 1px, transparent 1px, transparent 4px);
    filter: contrast(118%) brightness(0.98);
    transform: translateZ(0);
    z-index: 0;
}

[data-theme="light"] body::before {
    opacity: 0.025;
    mix-blend-mode: multiply;
    background-image:
        repeating-linear-gradient(0deg, rgba(60, 49, 34, 0.012) 0px, rgba(60, 49, 34, 0.012) 1px, transparent 1px, transparent 3px),
        repeating-linear-gradient(90deg, rgba(60, 49, 34, 0.01) 0px, rgba(60, 49, 34, 0.01) 1px, transparent 1px, transparent 4px);
}

::selection {
    background: rgba(99, 167, 255, 0.3);
    color: var(--text);
}

h1,
h2,
h3,
h4 {
    font-family: var(--display);
}

a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s var(--ease);
}

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

p {
    line-height: var(--lh);
    font-size: 1.06rem;
    margin: 0 0 1.75rem;
}

ul,
ol {
    margin: 1.5rem 0 1.75rem 1.75rem;
    padding: 0;
}

li {
    margin: 0.875rem 0;
    line-height: var(--lh);
    color: var(--muted);
}

@media (max-width: 768px) {
    p {
        margin: 0 0 1.5rem;
    }

    ul,
    ol {
        margin: 1.25rem 0 1.5rem 1.5rem;
    }
}

li::marker {
    color: var(--accent);
}

strong {
    color: var(--text);
    font-weight: 650;
}

em {
    color: var(--text);
    opacity: 0.95;
    font-style: italic;
}

code {
    font-family: var(--mono);
    font-size: 0.92em;
    background: var(--card2);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-xs);
    border: 1px solid var(--stroke);
}

kbd {
    font-family: var(--mono);
    font-size: 11px;
    padding: 4px 8px;
    border: 1px solid var(--stroke2);
    border-bottom-color: var(--stroke3);
    border-radius: var(--radius-xs);
    background: var(--card2);
    color: var(--muted);
    box-shadow: 0 3px 9px rgba(2, 8, 14, 0.2);
    transition: all 0.2s var(--ease);
}

kbd:hover {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    transform: translateY(-1px);
}

[data-theme="light"] kbd {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(145, 127, 102, 0.3);
    box-shadow: 0 2px 6px rgba(52, 44, 33, 0.12);
}

[data-theme="light"] kbd:hover {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

/* ============================================================
   Utilities - Enhanced spacing scale
   ============================================================ */

/* Text utilities */
.text-muted {
    color: var(--muted);
}

.text-faint {
    color: var(--faint);
}

.text-ghost {
    color: var(--ghost);
}

.text-xs {
    font-size: 12px;
}

.text-sm {
    font-size: 13.5px;
}

.text-14 {
    font-size: 14px;
}

.text-11 {
    font-size: 11px;
}

.text-warn {
    color: var(--warn);
}

.text-danger {
    color: var(--danger);
}

.text-accent {
    color: var(--accent);
}

.text-accent2 {
    color: var(--accent2);
}

.text-accent3 {
    color: var(--accent3);
}

.text-success {
    color: var(--success);
}

/* Opacity utilities */
.opacity-90 {
    opacity: 0.9;
}

.opacity-75 {
    opacity: 0.75;
}

.opacity-70 {
    opacity: 0.7;
}

.opacity-50 {
    opacity: 0.5;
}

.opacity-30 {
    opacity: 0.3;
}

/* Line height */
.lh-17 {
    line-height: 1.7;
}

.lh-tight {
    line-height: 1.5;
}

.lh-loose {
    line-height: 2;
}

/* Font weights */
.fw-500 {
    font-weight: 500;
}

.fw-600 {
    font-weight: 600;
}

.fw-700 {
    font-weight: 700;
}

.fw-800 {
    font-weight: 800;
}

.fw-900 {
    font-weight: 900;
}

/* Spacing utilities - 4px base grid */
.mt-0 {
    margin-top: 0 !important;
}

.mt-4 {
    margin-top: 4px;
}

.mt-8 {
    margin-top: 8px;
}

.mt-6 {
    margin-top: 6px;
}

.mt-10 {
    margin-top: 10px;
}

.mt-12 {
    margin-top: 12px;
}

.mt-16 {
    margin-top: 16px;
}

.mt-20 {
    margin-top: 20px;
}

.mt-24 {
    margin-top: 24px;
}

.mt-32 {
    margin-top: 32px;
}

.mt-40 {
    margin-top: 40px;
}

.mt-48 {
    margin-top: 48px;
}

.mt-64 {
    margin-top: 64px;
}

.mb-0 {
    margin-bottom: 0 !important;
}

.mb-4 {
    margin-bottom: 4px;
}

.mb-8 {
    margin-bottom: 8px;
}

.mb-12 {
    margin-bottom: 12px;
}

.mb-16 {
    margin-bottom: 16px;
}

.mb-20 {
    margin-bottom: 20px;
}

.mb-24 {
    margin-bottom: 24px;
}

.mb-32 {
    margin-bottom: 32px;
}

.mb-40 {
    margin-bottom: 40px;
}

.mb-48 {
    margin-bottom: 48px;
}

.mb-64 {
    margin-bottom: 64px;
}

.mx-4 {
    margin-left: 4px;
    margin-right: 4px;
}

.mx-6 {
    margin: 0 6px;
}

.mx-8 {
    margin-left: 8px;
    margin-right: 8px;
}

.mx-12 {
    margin-left: 12px;
    margin-right: 12px;
}

.ml-4 {
    margin-left: 4px;
}

.ml-8 {
    margin-left: 8px;
}

.ml-12 {
    margin-left: 12px;
}

.mr-4 {
    margin-right: 4px;
}

.mr-8 {
    margin-right: 8px;
}

.my-4 {
    margin-top: 4px;
    margin-bottom: 4px;
}

.my-8 {
    margin-top: 8px;
    margin-bottom: 8px;
}

.my-10 {
    margin: 10px 0;
}

.my-12 {
    margin-top: 12px;
    margin-bottom: 12px;
}

.my-16 {
    margin-top: 16px;
    margin-bottom: 16px;
}

.my-24 {
    margin-top: 24px;
    margin-bottom: 24px;
}

/* Padding utilities */
.p-4 {
    padding: 4px;
}

.p-8 {
    padding: 8px;
}

.p-12 {
    padding: 12px;
}

.p-16 {
    padding: 16px;
}

.p-20 {
    padding: 20px;
}

.p-24 {
    padding: 24px;
}

.p-32 {
    padding: 32px;
}

.p-40 {
    padding: 40px;
}

.p-48 {
    padding: 48px;
}

.p-64 {
    padding: 64px;
}

.px-4 {
    padding-left: 4px;
    padding-right: 4px;
}

.px-8 {
    padding-left: 8px;
    padding-right: 8px;
}

.px-12 {
    padding-left: 12px;
    padding-right: 12px;
}

.px-16 {
    padding-left: 16px;
    padding-right: 16px;
}

.px-24 {
    padding-left: 24px;
    padding-right: 24px;
}

.px-32 {
    padding-left: 32px;
    padding-right: 32px;
}

.px-48 {
    padding-left: 48px;
    padding-right: 48px;
}

.py-4 {
    padding-top: 4px;
    padding-bottom: 4px;
}

.py-8 {
    padding-top: 8px;
    padding-bottom: 8px;
}

.py-12 {
    padding-top: 12px;
    padding-bottom: 12px;
}

.py-16 {
    padding-top: 16px;
    padding-bottom: 16px;
}

.py-24 {
    padding-top: 24px;
    padding-bottom: 24px;
}

.py-32 {
    padding-top: 32px;
    padding-bottom: 32px;
}

.py-48 {
    padding-top: 48px;
    padding-bottom: 48px;
}

/* Gap utilities */
.gap-4 {
    gap: 4px;
}

.gap-8 {
    gap: 8px;
}

.gap-12 {
    gap: 12px;
}

.gap-14 {
    gap: 14px;
}

.gap-16 {
    gap: 16px;
}

.gap-20 {
    gap: 20px;
}

.gap-24 {
    gap: 24px;
}

.gap-32 {
    gap: 32px;
}

/* Display utilities */
.block {
    display: block;
}

.inline-block {
    display: inline-block;
}

.inline {
    display: inline;
}

.flex {
    display: flex;
}

.grid {
    display: grid;
}

.hidden {
    display: none;
}

/* Layout utilities */
.scroll-x {
    overflow-x: auto;
}

.scroll-y {
    overflow-y: auto;
}

/* Component utilities */
.pad-14 {
    padding: 14px;
}

.min-h-60 {
    min-height: 60px;
}

.is-hidden {
    display: none !important;
}

.invisible {
    visibility: hidden;
}

/* Typography utilities */
.mono-meta {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--faint);
    letter-spacing: 0.02em;
}

.ref-list {
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--muted);
}

.ref-list p {
    margin-bottom: 20px;
}

.ref-list p:last-child {
    margin-bottom: 0;
}

/* Enhanced highlight utilities */
.highlight-warn {
    background: rgba(255, 201, 61, 0.12);
    padding: 0 4px;
    border-radius: 4px;
    border-bottom: 2px solid var(--warn);
}

.highlight-danger {
    background: rgba(255, 95, 109, 0.1);
    padding: 0 4px;
    border-radius: 4px;
    border-bottom: 2px solid var(--danger);
}

.highlight-accent {
    background: rgba(94, 231, 223, 0.1);
    padding: 0 4px;
    border-radius: 4px;
    border-bottom: 2px solid var(--accent);
}

/* Byline styles */
.byline {
    font-size: 16px;
    color: var(--muted);
    margin: 0 0 28px;
    letter-spacing: 0.01em;
    font-weight: 500;
    font-family: var(--sans);
}

.byline-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.byline-link:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.byline-meta {
    font-size: 14px;
    opacity: 0.7;
    font-weight: 400;
}

/* Skip link */
.skip {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.skip:focus {
    left: 16px;
    top: 16px;
    width: auto;
    height: auto;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--stroke3);
    background: var(--card3);
    color: var(--text);
    z-index: 9999;
    font-weight: 600;
    box-shadow: var(--shadow2);
}

/* SVG panel */
.svg-panel {
    border-radius: var(--radius);
    border: 1px solid var(--stroke);
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
}

[data-theme="light"] .svg-panel {
    background: rgba(248, 249, 250, 0.95);
    border-color: rgba(0, 0, 0, 0.15);
}

/* Focus visible styles */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    body::before {
        animation: none;
    }
}
