:root {
    /* ═══════════════════════════════════════════════════════════════
       COLOR PALETTE (11 colors - DO NOT MODIFY)
       ═══════════════════════════════════════════════════════════════ */
    --rust: #c45a28;
    --gold: #d4a84b;
    --cream: #e8dcc4;
    --tan: #c49a6c;
    --sienna: #a05a32;
    --chocolate: #7a4428;
    --slate: #3d4a52;
    --plum: #4a3a4c;
    --charcoal: #3c4a42;
    --olive: #b4a864;
    --bronze: #7a5c34;

    /* ═══════════════════════════════════════════════════════════════
       SPACING SCALE (4px base unit)
       ═══════════════════════════════════════════════════════════════ */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;
    --space-12: 48px;

    /* ═══════════════════════════════════════════════════════════════
       TYPOGRAPHY SCALE
       ═══════════════════════════════════════════════════════════════ */
    --text-xs: 0.65em;
    --text-sm: 0.75em;
    --text-base: 0.9em;
    --text-md: 0.95em;
    --text-lg: 1em;
    --text-xl: 1.2em;

    /* ═══════════════════════════════════════════════════════════════
       LETTER SPACING
       ═══════════════════════════════════════════════════════════════ */
    --tracking-tight: 0.5px;
    --tracking-normal: 1px;
    --tracking-wide: 2px;
    --tracking-wider: 3px;
    --tracking-widest: 4px;

    /* ═══════════════════════════════════════════════════════════════
       SEMANTIC COLOR ROLES
       ═══════════════════════════════════════════════════════════════ */
    --color-primary: var(--gold);
    --color-secondary: var(--bronze);
    --color-text-primary: var(--cream);
    --color-text-secondary: var(--tan);
    --color-text-muted: var(--charcoal);
    --color-text-hint: rgba(196, 154, 108, 0.78); /* Increased for WCAG AA contrast */
    --color-border-primary: var(--bronze);
    --color-border-secondary: var(--charcoal);

    /* ═══════════════════════════════════════════════════════════════
       SURFACE COLORS
       ═══════════════════════════════════════════════════════════════ */
    --surface-base: rgba(0, 0, 0, 0.18);
    --surface-elevated: rgba(60, 74, 66, 0.24);
    --surface-inset: rgba(0, 0, 0, 0.5);
    --surface-panel: rgba(10, 12, 11, 0.32);

    /* ═══════════════════════════════════════════════════════════════
       SHADOWS
       ═══════════════════════════════════════════════════════════════ */
    --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-inset: inset 0 3px 8px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(0, 0, 0, 0.5), 0 0 1px rgba(212, 168, 75, 0.3);

    /* ═══════════════════════════════════════════════════════════════
       SAFE ZONES (for tech overlay collision prevention)
       ═══════════════════════════════════════════════════════════════ */
    --safe-corner-inset: 48px;       /* Distance from edge for corner markers */
    --safe-corner-offset: 12px;      /* Offset from frame edge */
    --overlay-z-index: 2;            /* Below controls (z:10), above background */
}

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

#galaxy-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

#galaxy-bg canvas {
    width: 100%;
    height: 100%;
}

/* ═══════════════════════════════════════════════════════════════
   GLOBAL FOCUS STYLES (Accessibility)
   ═══════════════════════════════════════════════════════════════ */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove default outline for mouse users, keep for keyboard */
:focus:not(:focus-visible) {
    outline: none;
}

body {
    font-family: 'Courier New', monospace;
    background: #000;
    color: var(--cream);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

/* ═══════════════════════════════════════════════════════════════
   SKIP LINK (Accessibility)
   ═══════════════════════════════════════════════════════════════ */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gold);
    color: #000;
    padding: var(--space-3) var(--space-4);
    font-family: 'Turret Road', sans-serif;
    font-weight: 700;
    text-decoration: none;
    z-index: 10000;
    border-radius: 0 0 4px 4px;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid var(--cream);
    outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   LOADING INDICATOR
   ═══════════════════════════════════════════════════════════════ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--charcoal);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: loading-spin 1s linear infinite;
}

.loading-text {
    margin-top: 16px;
    color: var(--gold);
    font-family: 'Turret Road', sans-serif;
    font-size: 0.9em;
    letter-spacing: 2px;
}

@keyframes loading-spin {
    to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════
   MAIN CONTAINER
   ═══════════════════════════════════════════════════════════════ */
#ref-view {
    width: 100%;
    max-width: 100%;
}

.ref-sheet {
    width: 1400px;
    max-width: 100%;
    margin: 0 auto; /* Center horizontally */

    /* Deeper backdrop effect */
    background: var(--surface-base);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);

    /* Technical border treatment */
    border: 1px solid var(--color-border-primary);
    border-radius: 4px;

    /* Outer glow for presence */
    box-shadow: var(--shadow-glow);

    position: relative;
    overflow: hidden; /* Contain the letter glitch background */
}

/* LetterGlitch background container */
#letter-glitch-root {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════
   CORNER DECORATIONS
   ═══════════════════════════════════════════════════════════════ */
.corner-decoration {
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: var(--color-secondary);
    border-style: solid;
    z-index: 10;
    pointer-events: none;
}

/* Position corners flush with container edges */
.corner-tl { top: 4px; left: 4px; border-width: 2px 0 0 2px; }
.corner-tr { top: 4px; right: 4px; border-width: 2px 2px 0 0; }
.corner-bl { bottom: 4px; left: 4px; border-width: 0 0 2px 2px; }
.corner-br { bottom: 4px; right: 4px; border-width: 0 2px 2px 0; }

/* ═══════════════════════════════════════════════════════════════
   COORDINATE MARKERS (anchored to frame corners, not content)
   ═══════════════════════════════════════════════════════════════ */
.coord-marker {
    position: absolute;
    font-family: 'Courier New', monospace;
    font-size: var(--text-xs);
    color: var(--color-secondary);
    letter-spacing: var(--tracking-wide);
    opacity: 0.6;
    pointer-events: none;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.9);
    z-index: var(--overlay-z-index);
}

/* Position markers adjacent to corner decorations, outside content areas */
/* Corner decorations are at 8px inset; markers sit just inside the L-bracket */
/* Top-left hidden: title occupies that space by design */
.coord-tl {
    display: none;
}
.coord-tr {
    top: var(--safe-corner-offset);
    right: var(--safe-corner-inset);
}
.coord-bl {
    bottom: var(--safe-corner-offset);
    left: var(--safe-corner-inset);
}
.coord-br {
    bottom: var(--safe-corner-offset);
    right: var(--safe-corner-inset);
}

/* ═══════════════════════════════════════════════════════════════
   FRAME BRACKETS (for images)
   ═══════════════════════════════════════════════════════════════ */
.frame-bracket {
    position: absolute;
    width: 16px;
    height: 16px;
    border-color: var(--color-primary);
    border-style: solid;
    z-index: 5;
    opacity: 0.5;
    pointer-events: none;
}

.frame-bracket-tl { top: 8px; left: 8px; border-width: 1px 0 0 1px; }
.frame-bracket-tr { top: 8px; right: 8px; border-width: 1px 1px 0 0; }
.frame-bracket-bl { bottom: 8px; left: 8px; border-width: 0 0 1px 1px; }
.frame-bracket-br { bottom: 8px; right: 8px; border-width: 0 1px 1px 0; }

/* ═══════════════════════════════════════════════════════════════
   HEADER (Enhanced with Technical Details)
   ═══════════════════════════════════════════════════════════════ */
.ref-header {
    padding: 24px var(--space-8) var(--space-6) 4px;
    border-bottom: 1px solid var(--color-border-primary);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
    z-index: 1;
}

/* Tick marks along header bottom */
.ref-header::before {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 56px;
    right: 56px;
    height: 1px;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 56px,
        var(--charcoal) 56px,
        var(--charcoal) 60px
    );
    opacity: 0.4;
}

/* Center accent mark */
.ref-header::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 1px;
    background: var(--color-primary);
    opacity: 0.6;
}

.title-section {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    z-index: 10; /* Above overlay markers */
    position: relative;
}

#fuzzy-title-root {
    margin-left: -50px; /* Compensate for canvas internal margin */
    line-height: 0;
    min-height: 55px; /* Reserve space for 48px font to prevent CLS */
    contain: layout; /* Isolate layout from affecting other elements */
}

#fuzzy-title-root canvas {
    display: block;
    /* Reserve space to prevent CLS - matches FuzzyText output for "Entropy" at 48px */
    min-width: 380px;
    min-height: 55px;
}

.subtitle {
    font-family: 'Turret Road', sans-serif;
    font-size: 0.8em;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--tan);
    margin-top: 10px;
    margin-left: 30px; /* Align with visual "E" in FuzzyText canvas (pixel-measured) */
    padding-top: 10px;
    border-top: 1px solid var(--charcoal);
}

.header-right {
    display: flex;
    align-items: center;
    align-self: center; /* Vertically center in header */
    gap: 20px;
    z-index: 10; /* Above overlay markers */
    position: relative;
}

/* Header label - data readout style */
.header-label {
    text-align: right;
    padding: var(--space-2) var(--space-3);
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--color-border-secondary);
    border-left: 2px solid var(--color-secondary);
    position: relative;
}

/* Corner notch on header label */
.header-label::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 5px;
    background: linear-gradient(135deg, transparent 50%, var(--charcoal) 50%);
}

.label-main {
    font-family: 'Turret Road', sans-serif;
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: var(--tracking-normal);
}

.label-sub {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    font-family: 'Courier New', monospace;
    letter-spacing: var(--tracking-wider);
    text-transform: uppercase;
    opacity: 0.95;
    text-shadow: 0 0 8px rgba(196, 154, 108, 0.25);
    margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   MAIN CONTENT GRID
   ═══════════════════════════════════════════════════════════════ */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1.8fr 1fr;
    border-bottom: 1px solid var(--color-border-secondary);
    position: relative;
    z-index: 1;
}

.column {
    padding: var(--space-3);
    border-right: 1px solid var(--color-border-secondary);
    position: relative;
}

/* Column top notch */
.column::before {
    content: '';
    position: absolute;
    top: 0;
    right: -1px;
    width: 8px;
    height: 1px;
    background: var(--color-secondary);
}

/* Column bottom notch */
.column::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -1px;
    width: 8px;
    height: 1px;
    background: var(--color-secondary);
}

.column:last-child {
    border-right: none;
}

.column:last-child::before,
.column:last-child::after {
    display: none;
}

.column.center {
    border-right: 1px solid var(--color-border-secondary);
}

/* ═══════════════════════════════════════════════════════════════
   SECTION BOXES (Raised/Mounted Panel Style)
   ═══════════════════════════════════════════════════════════════ */
.section-box {
    /* Background with higher opacity for readability over LetterGlitch */
    background: linear-gradient(
        135deg,
        rgba(10, 12, 11, 0.88) 0%,
        rgba(8, 12, 10, 0.92) 100%
    );
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    /* Border system - top highlight, darker sides */
    border: 1px solid var(--color-border-secondary);
    border-top-color: rgba(212, 168, 75, 0.25);
    border-left-color: rgba(122, 92, 52, 0.4);

    /* Elevation shadow with inner fill for stability */
    box-shadow:
        var(--shadow-elevated),
        0 1px 0 rgba(212, 168, 75, 0.08) inset,
        0 -1px 0 rgba(0, 0, 0, 0.4) inset,
        inset 0 0 12px rgba(0, 0, 0, 0.25);

    /* Spacing */
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);

    /* Subtle corner radius */
    border-radius: 2px;

    /* Backdrop effect - subtle, performant */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    /* Position for pseudo-elements */
    position: relative;
}

/* Corner notch on panel */
.section-box::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    height: 8px;
    background: linear-gradient(135deg, transparent 50%, var(--charcoal) 50%);
    pointer-events: none;
    opacity: 0.7;
}

/* Bottom-right accent tick */
.section-box::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 12px;
    height: 1px;
    background: var(--bronze);
    opacity: 0.25;
}

/* ═══════════════════════════════════════════════════════════════
   SECTION TITLES (Module Label Style)
   ═══════════════════════════════════════════════════════════════ */
.section-title {
    font-family: 'Turret Road', sans-serif;
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    min-height: 30px; /* Reserve space to prevent CLS when GlitchText mounts */
    color: var(--color-primary);

    /* Module label box styling */
    display: inline-block;
    background: linear-gradient(
        180deg,
        rgba(122, 92, 52, 0.2) 0%,
        rgba(0, 0, 0, 0.3) 100%
    );
    border: 1px solid var(--color-secondary);
    border-left: 3px solid var(--color-primary);
    padding: 6px 16px 6px 12px;
    margin-bottom: var(--space-4);

    /* Technical accent positioning */
    position: relative;
    overflow: visible; /* Allow GlitchText pseudo-elements to overflow */
}

/* Corner notch on label */
.section-title::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 6px;
    background: linear-gradient(135deg, transparent 50%, var(--charcoal) 50%);
}

/* Technical separator after label */
.section-title::after {
    content: '//';
    margin-left: 12px;
    color: var(--charcoal);
    font-weight: 400;
    opacity: 0.45;
    font-size: 0.85em;
}

/* Section body text */
.section-text {
    font-size: var(--text-md);
    color: var(--color-text-secondary);
    line-height: 1.65;
    opacity: 0.9;
}

/* ═══════════════════════════════════════════════════════════════
   FEATURE LISTS (Technical Bullet Style)
   ═══════════════════════════════════════════════════════════════ */
.feature-list {
    list-style: none;
    font-size: var(--text-md);
    color: var(--color-text-primary);
    line-height: 1.8;
    padding-left: var(--space-4);
}

.feature-list li {
    position: relative;
    padding-left: 20px;
    margin-bottom: var(--space-1);
}

/* Technical bullet - horizontal tick */
.feature-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.7em;
    width: 8px;
    height: 1px;
    background: var(--color-secondary);
}

/* Technical bullet - vertical tick */
.feature-list li::after {
    content: '';
    position: absolute;
    left: 0;
    top: calc(0.7em - 3px);
    width: 1px;
    height: 7px;
    background: var(--color-secondary);
}

/* Art placeholders - technical module awaiting content */
.art-placeholder {
    background: var(--surface-inset);
    border: 2px dashed var(--color-primary);
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-4);
    position: relative;
    box-shadow: var(--shadow-inset);
    opacity: 0.85;
}

/* Inner border for technical depth */
.art-placeholder::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px solid rgba(212, 168, 75, 0.2);
    border-radius: 1px;
    pointer-events: none;
}

.art-placeholder.large {
    height: 350px;
}

.art-placeholder.small {
    height: 150px;
}

/* ═══════════════════════════════════════════════════════════════
   ART FRAMES (Inset/Recessed Panel Style)
   ═══════════════════════════════════════════════════════════════ */
.art-frame {
    position: relative;

    /* Inset border effect - darker top/left, lighter bottom/right */
    border: 2px solid var(--color-border-secondary);
    border-top-color: rgba(0, 0, 0, 0.6);
    border-left-color: rgba(0, 0, 0, 0.5);
    border-bottom-color: rgba(122, 92, 52, 0.4);
    border-right-color: rgba(122, 92, 52, 0.3);

    /* Deep inset shadow */
    box-shadow:
        var(--shadow-inset),
        inset 0 1px 3px rgba(0, 0, 0, 0.3),
        0 1px 0 rgba(212, 168, 75, 0.12);

    /* Dark background for images */
    background: var(--surface-inset);

    /* Tight corner radius */
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: var(--space-2);
    padding: 2px;
}

/* Small art frames */
.art-frame.small {
    border-width: 1px;
    border-top-color: rgba(0, 0, 0, 0.5);
    border-left-color: rgba(0, 0, 0, 0.4);
    border-bottom-color: rgba(122, 92, 52, 0.3);
    border-right-color: rgba(122, 92, 52, 0.25);
    box-shadow:
        inset 0 2px 6px rgba(0, 0, 0, 0.4),
        0 1px 0 rgba(212, 168, 75, 0.08);
    padding: 2px;
}

/* Large art frames get corner brackets */
.art-frame.large {
    border-width: 2px;
    padding: 4px;
    box-shadow:
        inset 0 4px 16px rgba(0, 0, 0, 0.6),
        inset 0 1px 4px rgba(0, 0, 0, 0.4),
        0 2px 0 rgba(212, 168, 75, 0.1);
}

.art-frame .ref-image {
    width: 100%;
    height: auto;
    display: block;
}

/* Reserve space for image placeholders to prevent CLS */
#main-ref-glitch-root {
    aspect-ratio: 2620 / 1904;
    width: 100%;
}

#entropy-icon-glitch-root {
    aspect-ratio: 1 / 1;
    width: 100%;
}

#artwork-3-glitch-root {
    aspect-ratio: 4096 / 1714;
    width: 100%;
}

#artwork-bottom-glitch-root {
    aspect-ratio: 4624 / 3389;
    width: 100%;
}

/* Artist credit badge */
.art-credit {
    position: absolute;
    bottom: 10px;
    right: 12px;
    font-size: var(--text-sm);
    font-family: 'Courier New', monospace;
    letter-spacing: var(--tracking-normal);
    color: var(--cream);
    background: rgba(0, 0, 0, 0.75);
    padding: 4px 10px;
    border-radius: 2px;
    border-left: 2px solid var(--bronze);
    z-index: 5;
    text-decoration: none;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.art-credit:hover {
    color: var(--gold);
    border-left-color: var(--gold);
}

.art-credit:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    color: var(--gold);
}

.placeholder-text {
    color: var(--color-text-hint);
    font-family: 'Turret Road', sans-serif;
    font-size: var(--text-base);
    letter-spacing: var(--tracking-widest);
    text-transform: uppercase;
}

/* Color palette */
.palette-container {
    border: 2px solid var(--bronze);
    border-radius: 4px;
    padding: 4px;
    overflow: hidden;
}

.palette-row {
    display: flex;
    height: 50px;
    overflow: hidden;
}

.color-chip {
    flex: 1;
    cursor: pointer;
    position: relative;
}

.color-chip:hover,
.color-chip:focus-visible {
    z-index: 10;
}

.color-chip:hover .swatch,
.color-chip:focus-visible .swatch {
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.8);
}

/* Focus state for accessibility */
.color-chip:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Active/pressed state */
.color-chip:active .swatch {
    box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.9);
}

.color-chip::after {
    content: attr(data-hex);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background: rgba(0, 0, 0, 0.85);
    color: var(--cream);
    font-family: monospace;
    font-size: 0.7em;
    padding: 4px 8px;
    border-radius: 3px;
    border: 1px solid var(--bronze);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.color-chip:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

.color-chip .swatch {
    height: 100%;
    width: calc(100% + 25px);
    transform: skewX(-20deg);
    margin-left: -12px;
    transition: box-shadow 0.2s ease;
}

.color-chip:first-child .swatch {
    margin-left: -30px;
    width: calc(100% + 55px);
}

.color-chip .hex {
    display: none;
}

.palette-labels {
    display: flex;
    margin-top: 8px;
    padding: 0 5px;
}

.palette-labels span {
    flex: 1;
    text-align: center;
    font-size: 0.6em;
    color: var(--bronze);
    font-family: monospace;
    cursor: pointer;
    transition: color 0.15s ease;
}

.palette-labels span:hover {
    color: var(--gold);
}

.palette-hint {
    text-align: center;
    font-size: var(--text-sm);
    color: var(--color-text-hint);
    margin-top: var(--space-4);
    font-style: italic;
    font-family: 'Courier New', monospace;
    letter-spacing: var(--tracking-tight);
}

/* ═══════════════════════════════════════════════════════════════
   FOOTER (Enhanced with Technical Details)
   ═══════════════════════════════════════════════════════════════ */
.ref-footer {
    padding: var(--space-4) var(--space-6);
    font-size: var(--text-sm);
    font-family: 'Courier New', monospace;
    color: var(--color-secondary);
    text-align: center;
    letter-spacing: var(--tracking-normal);
    position: relative;
    z-index: 10; /* Above overlay markers */
    width: 100%;
    background: rgba(10, 14, 12, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-top: 1px solid var(--color-border-secondary);
}

/* Center tick decoration above footer (xkcd 303 homage) */
.ref-footer::before {
    content: '[ ∴ ]';
    position: absolute;
    left: 50%;
    top: -8px;
    transform: translateX(-50%);
    font-size: var(--text-xs);
    color: var(--color-secondary);
    background: rgba(0, 0, 0, 0.8);
    padding: 0 var(--space-2);
    letter-spacing: 2px;
    opacity: 0.7;
}

/* Side accent lines */
.ref-footer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: var(--space-8);
    right: var(--space-8);
    height: 1px;
    background: linear-gradient(
        90deg,
        var(--charcoal) 0%,
        transparent 30%,
        transparent 70%,
        var(--charcoal) 100%
    );
    opacity: 0.3;
    z-index: -1;
}

/* Effects Toggle */
.effects-toggle {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--color-secondary);
    border-radius: 4px;
    padding: 6px 12px;
    color: var(--color-primary);
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.effects-toggle:hover {
    border-color: var(--color-primary);
    background: rgba(212, 168, 75, 0.08);
}

/* Focus state for accessibility */
.effects-toggle:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* OFF state - intentionally styled, still legible */
.effects-toggle.disabled {
    color: var(--color-text-hint);
    border-color: var(--charcoal);
    background: rgba(0, 0, 0, 0.5);
}

.effects-toggle.disabled:hover {
    border-color: var(--color-secondary);
    color: var(--color-text-secondary);
}

.effects-toggle .toggle-icon {
    font-size: 1.1em;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* ON state - animated sparkle */
.effects-toggle:not(.disabled) .toggle-icon {
    animation: sparkle 2s infinite;
    text-shadow: 0 0 6px rgba(212, 168, 75, 0.5);
}

/* OFF state icon - dimmed but visible */
.effects-toggle.disabled .toggle-icon {
    opacity: 0.5;
}

@keyframes sparkle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Reduced motion: disable animation */
@media (prefers-reduced-motion: reduce) {
    .effects-toggle:not(.disabled) .toggle-icon {
        animation: none;
    }
}

/* Tablet Responsive */
@media (max-width: 1100px) {
    /* Switch to single column when viewport narrows */
    .main-content {
        grid-template-columns: 1fr;
    }

    .column {
        border-right: none;
        border-bottom: 1px solid var(--charcoal);
    }

    .column:last-child {
        border-bottom: none;
    }

    .column.center {
        order: -1;
        border-right: none;
    }

    /* Push coord markers tighter to corners on narrower screens */
    .coord-marker {
        opacity: 0.5;
    }

    .coord-tl,
    .coord-bl {
        left: var(--safe-corner-offset);
    }

    .coord-tr,
    .coord-br {
        right: var(--safe-corner-offset);
    }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE (Performance-Optimized)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 700px) {
    body {
        padding: 10px;
        align-items: flex-start;
        padding-top: 15px;
    }

    .ref-sheet {
        border-radius: 0;
        border-left: none;
        border-right: none;
        box-shadow: none; /* Remove glow on mobile */
    }

    /* Hide decorative elements for performance */
    .corner-decoration,
    .coord-marker,
    .frame-bracket {
        display: none;
    }

    /* Simplify header */
    .ref-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
        padding: var(--space-4) var(--space-6);
    }

    /* Remove header pseudo-element decorations */
    .ref-header::before,
    .ref-header::after {
        display: none;
    }

    .header-label {
        text-align: left;
        align-self: flex-start;
        /* Simplify to minimal border */
        background: transparent;
        border: none;
        border-left: 2px solid var(--color-primary);
        padding: var(--space-1) var(--space-3);
    }

    .header-label::before {
        display: none;
    }

    #fuzzy-title-root {
        margin-left: -45px; /* Pull title left to align with edge on mobile */
        min-height: 40px; /* Reserve space for 32px font to prevent CLS */
        contain: layout; /* Isolate layout from affecting other elements */
    }

    #fuzzy-title-root canvas {
        /* Reserve space for "Entropy" at 32px mobile font */
        min-width: 260px;
        min-height: 40px;
    }

    .main-content {
        grid-template-columns: 1fr;
    }

    .column {
        padding: var(--space-4);
        border-right: none;
        border-bottom: 1px solid var(--color-border-secondary);
    }

    /* Remove column notches */
    .column::before,
    .column::after {
        display: none;
    }

    .column:last-child {
        border-bottom: none;
    }

    .column.center {
        order: -1;
        border-right: none;
    }

    .column:first-child {
        border-right: none;
    }

    /* Simplify section boxes - no backdrop-filter for performance */
    .section-box {
        background: rgba(10, 14, 12, 0.9);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        border-top-color: var(--color-border-secondary);
        border-left-color: var(--color-border-secondary);
        padding: var(--space-3) var(--space-4);
        margin-bottom: var(--space-4);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }

    .section-box::before,
    .section-box::after {
        display: none;
    }

    /* Simplify section titles - mobile module label */
    .section-title {
        font-size: var(--text-base);
        background: transparent;
        border: none;
        border-left: 2px solid var(--color-primary);
        border-bottom: 1px solid var(--color-border-secondary);
        padding: var(--space-1) 0 var(--space-2) var(--space-3);
        min-height: 26px; /* Reserve space to prevent CLS */
    }

    .section-title::before,
    .section-title::after {
        display: none;
    }

    .section-text {
        font-size: var(--text-base);
    }

    .feature-list {
        font-size: var(--text-base);
        padding-left: var(--space-3);
    }

    /* Simplify feature list bullets */
    .feature-list li::after {
        display: none;
    }

    /* Touch targets - minimum 44x44px for mobile accessibility */
    .effects-toggle,
    .nav-link {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 16px;
    }

    .art-credit {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 10px 12px;
    }

    .lightbox-close {
        min-height: 44px;
        min-width: 44px;
    }

    /* Simplify art frames */
    .art-frame {
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
    }

    /* Simplify art placeholders */
    .art-placeholder {
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
    }

    .art-placeholder::before {
        display: none;
    }

    .art-placeholder.large {
        height: 250px;
    }

    .art-placeholder.small {
        height: 120px;
    }

    .palette-row {
        height: 40px;
    }

    .palette-hint {
        font-size: var(--text-xs);
    }

    /* Simplify footer */
    .ref-footer {
        padding: var(--space-3) var(--space-4);
        font-size: var(--text-sm);
    }

    .ref-footer::before,
    .ref-footer::after {
        display: none;
    }

    .subtitle {
        font-size: var(--text-sm);
        letter-spacing: var(--tracking-wide);
        margin-left: 0; /* Flush left on mobile */
    }

    .label-main {
        font-size: var(--text-lg);
    }

    .label-sub {
        font-size: var(--text-sm);
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .ref-header {
        padding: var(--space-3) var(--space-4);
    }

    .column {
        padding: var(--space-3);
    }

    .section-box {
        padding: var(--space-2) var(--space-3);
    }

    .color-chip .hex {
        display: none;
    }

    .palette-hint {
        font-size: var(--text-xs);
    }

    /* Prevent nav buttons from being clipped on very small screens */
    .nav-link,
    .effects-toggle {
        flex-shrink: 0;
        padding: 6px 10px;
        font-size: 0.8em;
    }

    .header-right {
        gap: var(--space-2);
        flex-wrap: wrap;
    }

    /* Hide header label on very small screens to make room for buttons */
    .header-label {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════
   NAVIGATION LINK (Header nav between pages)
   ═══════════════════════════════════════════════════════════════ */
.nav-link {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--color-secondary);
    border-radius: 4px;
    padding: 6px 12px;
    color: var(--color-primary);
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.nav-link:hover {
    border-color: var(--color-primary);
    background: rgba(212, 168, 75, 0.08);
}

.nav-link:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.nav-icon {
    font-size: 1.1em;
}

.nav-label {
    letter-spacing: var(--tracking-normal);
}

/* ═══════════════════════════════════════════════════════════════
   GALLERY VIEW
   ═══════════════════════════════════════════════════════════════ */
.gallery-view {
    width: 1400px;
    max-width: 100%;
    min-height: 100vh;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    background: var(--surface-base);
    border-left: 1px solid var(--color-border-primary);
    border-right: 1px solid var(--color-border-primary);
    position: relative;
}

.gallery-title {
    font-family: 'Turret Road', sans-serif;
    font-size: 2.5em;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: var(--tracking-wider);
    margin: 0;
    background: linear-gradient(90deg, var(--gold), var(--rust), var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gallery-content {
    padding: var(--space-6);
    min-height: 60vh;
    position: relative;
    z-index: 1;
}

/* ═══════════════════════════════════════════════════════════════
   MASONRY GRID
   ═══════════════════════════════════════════════════════════════ */
.masonry-container {
    width: 100%;
}

.masonry-item {
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    transition: opacity 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
                transform 0.5s cubic-bezier(0.165, 0.84, 0.44, 1),
                box-shadow 0.3s ease;
}

.masonry-item-visible {
    opacity: 1 !important;
    transform: translateY(0) !important;
}

.masonry-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.masonry-item-visible:hover {
    transform: translateY(-4px) !important;
}

.gallery-item-wrapper {
    position: relative;
    background: var(--surface-inset);
    border: 1px solid var(--color-border-secondary);
    border-radius: 4px;
    overflow: hidden;
    min-height: 200px; /* Prevent CLS while media loads */
}

.gallery-item-wrapper:hover {
    border-color: var(--color-secondary);
}

.gallery-image {
    width: 100%;
    display: block;
    min-height: 200px; /* Reserve space before load */
    object-fit: cover;
}

.gallery-item-credit {
    position: absolute;
    bottom: 8px;
    right: 8px;
    font-size: var(--text-xs);
    font-family: 'Courier New', monospace;
    color: var(--cream);
    background: rgba(0, 0, 0, 0.75);
    padding: 3px 8px;
    border-radius: 2px;
    border-left: 2px solid var(--bronze);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.gallery-item-wrapper:hover .gallery-item-credit {
    opacity: 1;
}

.gallery-item-credit a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.gallery-item-credit a:hover {
    color: var(--gold);
    border-bottom-color: var(--gold);
}

/* ═══════════════════════════════════════════════════════════════
   GALLERY EMPTY/LOADING STATES
   ═══════════════════════════════════════════════════════════════ */
.gallery-loading,
.gallery-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    text-align: center;
}

.empty-message {
    background: var(--surface-panel);
    border: 1px dashed var(--color-secondary);
    border-radius: 8px;
    padding: var(--space-8) var(--space-12);
    max-width: 500px;
}

.empty-message h2 {
    font-family: 'Turret Road', sans-serif;
    color: var(--color-primary);
    margin-bottom: var(--space-4);
    letter-spacing: var(--tracking-wide);
}

.empty-message p {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
}

.empty-message code {
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 8px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    color: var(--gold);
}

.empty-hint {
    font-size: var(--text-sm);
    color: var(--color-text-hint);
    font-style: italic;
}

/* ═══════════════════════════════════════════════════════════════
   SPA CONTAINERS
   ═══════════════════════════════════════════════════════════════ */
#app-views {
    display: none;
}

#app-views:has(.gallery-view) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 100;
    overflow-y: auto;
}

.spa-controller {
    width: 100%;
    min-height: 100vh;
}

/* letter-glitch-transition-container allows content to expand */
.letter-glitch-transition-container {
    width: 100%;
    min-height: 100%;
}

/* ═══════════════════════════════════════════════════════════════
   GALLERY RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
    .gallery-content {
        padding: var(--space-4);
    }
}

@media (max-width: 700px) {
    .gallery-view {
        width: 100%;
        padding: 10px;
        border-left: none;
        border-right: none;
        min-height: 100vh;
    }

    .gallery-view .ref-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
        padding: var(--space-4);
    }

    .gallery-view .header-right {
        width: 100%;
        justify-content: flex-start;
        gap: var(--space-3);
    }

    .gallery-title {
        font-size: 1.8em;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .gallery-content {
        padding: var(--space-3);
    }

    .empty-message {
        padding: var(--space-6);
        margin: var(--space-4);
    }

    .masonry-item {
        margin-bottom: var(--space-3);
    }
}

/* ═══════════════════════════════════════════════════════════════
   EDEX-UI LOADING INTERFACE
   Cyberpunk terminal-style loading experience for gallery
   ═══════════════════════════════════════════════════════════════ */

/* Portal container rendered at body level to escape stacking contexts */
#edex-loading-portal {
    position: fixed;
    inset: 0;
    z-index: 10000; /* Above transition canvas (9999) */
    pointer-events: none;
}

.edex-loading-container {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000; /* Above transition canvas (9999) so loading overlays the scramble */
    pointer-events: none;
}

.edex-loading-container.edex-loading--fading {
    opacity: 0;
    transition: opacity 800ms ease-out;
}

.edex-loading-panel {
    width: min(400px, 90vw);
    padding: 20px 24px;
    background: rgba(6, 8, 7, 0.96);
    border: 1px solid var(--color-secondary);
    border-left: 3px solid var(--gold);
    font-family: 'Courier New', monospace;
    position: relative;
    box-shadow:
        0 0 40px rgba(212, 168, 75, 0.15),
        0 0 80px rgba(0, 0, 0, 0.8),
        inset 0 0 60px rgba(0, 0, 0, 0.4);
}

/* Scanline overlay */
.edex-loading-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.12) 2px,
        rgba(0, 0, 0, 0.12) 4px
    );
    pointer-events: none;
    z-index: 1;
}

/* CRT flicker effect */
.edex-loading-panel::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        rgba(212, 168, 75, 0.03) 0%,
        transparent 50%,
        rgba(212, 168, 75, 0.02) 100%
    );
    animation: edex-flicker 4s infinite;
    pointer-events: none;
    z-index: 2;
}

@keyframes edex-flicker {
    0%, 100% { opacity: 1; }
    92% { opacity: 1; }
    93% { opacity: 0.8; }
    94% { opacity: 1; }
    97% { opacity: 0.9; }
    98% { opacity: 1; }
}

/* Corner brackets */
.edex-corner {
    position: absolute;
    width: 10px;
    height: 10px;
    border-color: var(--gold);
    border-style: solid;
    opacity: 0.7;
    z-index: 3;
}

.edex-corner--tl { top: 4px; left: 4px; border-width: 2px 0 0 2px; }
.edex-corner--tr { top: 4px; right: 4px; border-width: 2px 2px 0 0; }
.edex-corner--bl { bottom: 4px; left: 4px; border-width: 0 0 2px 2px; }
.edex-corner--br { bottom: 4px; right: 4px; border-width: 0 2px 2px 0; }

/* Header row */
.edex-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    position: relative;
    z-index: 3;
}

.edex-module-name {
    font-size: 0.75em;
    color: var(--gold);
    letter-spacing: 2px;
    text-transform: uppercase;
    text-shadow: 0 0 8px rgba(212, 168, 75, 0.5);
}

.edex-status {
    font-size: 0.7em;
    color: var(--rust);
    letter-spacing: 1px;
    animation: edex-blink 1s steps(1) infinite;
}

@keyframes edex-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* Progress bar container */
.edex-progress-container {
    position: relative;
    height: 6px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--charcoal);
    margin-bottom: 12px;
    overflow: hidden;
    z-index: 3;
}

/* Progress bar fill */
.edex-progress-bar {
    height: 100%;
    background: linear-gradient(
        90deg,
        var(--rust) 0%,
        var(--gold) 50%,
        var(--rust) 100%
    );
    background-size: 200% 100%;
    animation: edex-shimmer 2s linear infinite;
    box-shadow:
        0 0 10px var(--gold),
        0 0 20px rgba(212, 168, 75, 0.4),
        inset 0 0 4px rgba(255, 255, 255, 0.3);
    transition: width 0.15s ease-out;
}

@keyframes edex-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* Progress bar glow trail */
.edex-progress-container::after {
    content: '';
    position: absolute;
    top: -2px;
    bottom: -2px;
    right: 0;
    width: 40px;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(212, 168, 75, 0.3)
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.edex-progress-container:has(.edex-progress-bar[style*="width"]:not([style*="width: 0"]))::after {
    opacity: 1;
}

/* Percentage display */
.edex-percentage {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--gold);
    text-align: center;
    margin-bottom: 12px;
    letter-spacing: 2px;
    text-shadow:
        0 0 10px rgba(212, 168, 75, 0.6),
        0 0 20px rgba(212, 168, 75, 0.3);
    font-family: 'Turret Road', 'Courier New', monospace;
    position: relative;
    z-index: 3;
}

/* Current file display */
.edex-current-file {
    font-size: 0.65em;
    color: var(--tan);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    z-index: 3;
}

.edex-current-file::before {
    content: '>';
    color: var(--gold);
    margin-right: 6px;
    animation: edex-cursor 0.8s steps(1) infinite;
}

@keyframes edex-cursor {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Stats row */
.edex-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.6em;
    color: var(--charcoal);
    letter-spacing: 1px;
    text-transform: uppercase;
    border-top: 1px solid var(--charcoal);
    padding-top: 8px;
    margin-top: 4px;
    position: relative;
    z-index: 3;
}

.edex-stats-value {
    color: var(--bronze);
}

/* Data stream decoration */
.edex-stream {
    position: absolute;
    left: -3px;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 60%;
    background: linear-gradient(
        180deg,
        transparent 0%,
        var(--gold) 20%,
        var(--gold) 80%,
        transparent 100%
    );
    opacity: 0.4;
    animation: edex-stream 2s ease-in-out infinite;
}

@keyframes edex-stream {
    0%, 100% { height: 30%; opacity: 0.3; }
    50% { height: 70%; opacity: 0.6; }
}

/* Mobile adjustments */
@media (max-width: 500px) {
    .edex-loading-panel {
        width: calc(100vw - 40px);
        padding: 16px 20px;
    }

    .edex-percentage {
        font-size: 1.5em;
    }

    .edex-module-name {
        font-size: 0.65em;
    }
}
