/* ================================
   FOLKLORE THEORIES DESIGN SYSTEM
   World-Class CSS Variables & Components
================================ */

/* ================================
   CSS RESET & BASE STYLES 
================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* ================================
   DESIGN TOKENS 
================================ */
:root {
    /* Color System */
    --primary: #1a1625;
    --secondary: #2d1b3d;
    --accent: #c9a96e;
    --accent-light: #f4e8d0;
    --accent-dark: #b8966b;
    --text-primary: #ffffff;
    --text-secondary: #b8b4c7;
    --text-muted: #8a8394;
    --surface: rgba(255, 255, 255, 0.08);
    --surface-hover: rgba(255, 255, 255, 0.12);
    --surface-active: rgba(255, 255, 255, 0.16);
    --border: rgba(255, 255, 255, 0.1);
    --border-focus: rgba(201, 169, 110, 0.4);
    --error: #ff6b6b;
    --success: #51cf66;
    --warning: #ffd43b;
    --info: #74c0fc;
    
    /* Archive-Specific Colors */
    --archive-primary: #2d3748;
    --archive-secondary: #4a5568;
    --archive-accent: #c9a96e;
    --archive-surface: rgba(45, 55, 72, 0.1);
    --archive-glow: rgba(201, 169, 110, 0.4);
    --theory-bg: rgba(26, 32, 44, 0.95);
    --evidence-highlight: #f6ad55;
    --connection-line: #63b3ed;
    
    /* Typography */
    --font-display: 'Playfair Display', serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    
    /* Font Weights */
    --weight-light: 300;
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-bold: 700;
    --weight-extrabold: 800;
    
    /* Font Sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;
    --text-6xl: 3.75rem;
    
    /* Line Heights */
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;
    --leading-loose: 2;
    
    /* Spacing System (8pt grid) */
    --space-px: 1px;
    --space-0: 0;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-20: 5rem;
    --space-24: 6rem;
    --space-32: 8rem;
    --space-40: 10rem;
    --space-48: 12rem;
    --space-56: 14rem;
    --space-64: 16rem;
    
    /* Semantic Spacing */
    --space-xs: var(--space-2);
    --space-sm: var(--space-4);
    --space-md: var(--space-6);
    --space-lg: var(--space-8);
    --space-xl: var(--space-12);
    --space-2xl: var(--space-16);
    --space-3xl: var(--space-24);
    
    /* Border Radius */
    --radius-none: 0;
    --radius-sm: 0.125rem;
    --radius-base: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-2xl: 1rem;
    --radius-3xl: 1.5rem;
    --radius-full: 9999px;
    
    /* Semantic Radius */
    --radius-button: var(--radius-lg);
    --radius-card: var(--radius-xl);
    --radius-modal: var(--radius-2xl);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-base: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px rgba(0, 0, 0, 0.25);
    --shadow-inner: inset 0 2px 4px rgba(0, 0, 0, 0.06);
    
    /* Animations */
    --transition-none: none;
    --transition-all: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-default: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 100ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Z-Index Scale */
    --z-hide: -1;
    --z-base: 0;
    --z-docked: 10;
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-banner: 1030;
    --z-overlay: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-skiplink: 1070;
    --z-toast: 1080;
    --z-tooltip: 1090;
    
    /* Breakpoints (for reference in JS) */
    --breakpoint-sm: 640px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;
    --breakpoint-2xl: 1536px;
}

body {
    font-family: var(--font-body);
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--text-primary);
    line-height: var(--leading-normal);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ================================
   UTILITY CLASSES 
================================ */

/* Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

.container-sm {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

.container-lg {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

.section {
    padding: var(--space-3xl) 0;
}

.section-sm {
    padding: var(--space-2xl) 0;
}

.section-lg {
    padding: var(--space-32) 0;
}

/* Flexbox */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.flex-wrap {
    flex-wrap: wrap;
}

.items-center {
    align-items: center;
}

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-start {
    justify-content: flex-start;
}

.justify-end {
    justify-content: flex-end;
}

/* Grid */
.grid {
    display: grid;
}

.grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

.grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gap-4 {
    gap: var(--space-4);
}

.gap-6 {
    gap: var(--space-6);
}

.gap-8 {
    gap: var(--space-8);
}

/* Text Alignment */
.text-left {
    text-align: left;
}

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

.text-right {
    text-align: right;
}

/* Visibility */
.hidden {
    display: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ================================
   TYPOGRAPHY SYSTEM 
================================ */
.heading-1 {
    font-family: var(--font-display);
    font-size: clamp(var(--text-4xl), 5vw, var(--text-6xl));
    font-weight: var(--weight-bold);
    line-height: var(--leading-tight);
    letter-spacing: -0.02em;
    margin-bottom: var(--space-md);
}

.heading-2 {
    font-family: var(--font-display);
    font-size: clamp(var(--text-3xl), 4vw, var(--text-5xl));
    font-weight: var(--weight-semibold);
    line-height: var(--leading-snug);
    margin-bottom: var(--space-md);
}

.heading-3 {
    font-family: var(--font-display);
    font-size: clamp(var(--text-2xl), 3vw, var(--text-4xl));
    font-weight: var(--weight-medium);
    line-height: var(--leading-snug);
    margin-bottom: var(--space-sm);
}

.heading-4 {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--weight-medium);
    line-height: var(--leading-snug);
    margin-bottom: var(--space-sm);
}

.heading-5 {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    line-height: var(--leading-snug);
    margin-bottom: var(--space-xs);
}

.heading-6 {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--weight-medium);
    line-height: var(--leading-snug);
    margin-bottom: var(--space-xs);
}

.body-2xl {
    font-size: var(--text-2xl);
    font-weight: var(--weight-regular);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
}

.body-xl {
    font-size: var(--text-xl);
    font-weight: var(--weight-regular);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
}

.body-lg {
    font-size: var(--text-lg);
    font-weight: var(--weight-regular);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
}

.body {
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    color: var(--text-secondary);
    line-height: var(--leading-normal);
}

.body-sm {
    font-size: var(--text-sm);
    font-weight: var(--weight-regular);
    color: var(--text-muted);
    line-height: var(--leading-normal);
}

.body-xs {
    font-size: var(--text-xs);
    font-weight: var(--weight-regular);
    color: var(--text-muted);
    line-height: var(--leading-normal);
}

.gradient-text {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

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

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

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

/* ================================
   COMPONENT SYSTEM 
================================ */

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: var(--space-lg);
    backdrop-filter: blur(20px);
    transition: var(--transition-default);
}

.card:hover {
    background: var(--surface-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.card-sm {
    padding: var(--space-md);
}

.card-lg {
    padding: var(--space-xl);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-button);
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition-default);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: var(--primary);
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface);
    color: var(--text-primary);
}

.btn-accent {
    background: var(--accent);
    color: var(--primary);
}

.btn-accent:hover {
    background: var(--accent-dark);
    transform: translateY(-2px);
}

.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: var(--text-lg);
}

.btn-xl {
    padding: var(--space-5) var(--space-10);
    font-size: var(--text-xl);
}

/* Form Elements */
.input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-base);
    transition: var(--transition-default);
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(201, 169, 110, 0.1);
}

.input::placeholder {
    color: var(--text-muted);
}

.textarea {
    resize: vertical;
    min-height: 120px;
}

.select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

/* ================================
   LAYOUT COMPONENTS 
================================ */

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-sticky);
    background: rgba(26, 22, 37, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    transition: var(--transition-default);
}

.header.scrolled {
    background: rgba(26, 22, 37, 0.95);
    box-shadow: var(--shadow-lg);
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) 0;
}

.logo {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--weight-semibold);
    color: var(--accent);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: var(--space-lg);
    list-style: none;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: var(--weight-medium);
    transition: var(--transition-default);
}

.nav-link:hover {
    color: var(--accent);
}

/* Footer */
.footer {
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid var(--border);
}

/* ================================
   BACKGROUND EFFECTS 
================================ */
.bg-pattern {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-hide);
    opacity: 0.4;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(201, 169, 110, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(201, 169, 110, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 80%, rgba(201, 169, 110, 0.08) 0%, transparent 50%);
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(1deg); }
}

/* ================================
   ANIMATIONS & INTERACTIONS 
================================ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

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

.animate-fade-in {
    animation: fadeInUp 0.8s ease-out;
}

.animate-fade-in-down {
    animation: fadeInDown 0.8s ease-out;
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* ================================
   RESPONSIVE DESIGN 
================================ */
@media (max-width: 1024px) {
    .container {
        padding: 0 var(--space-sm);
    }
    
    .grid-cols-2 {
        grid-template-columns: 1fr;
    }
    
    .grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    
    .grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    .section {
        padding: var(--space-2xl) 0;
    }
    
    .nav-links {
        display: none;
    }
    
    .btn {
        width: 100%;
        max-width: 280px;
    }
    
    .grid-cols-3 {
        grid-template-columns: 1fr;
    }
    
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 0 var(--space-4);
    }
    
    .heading-1 {
        font-size: var(--text-4xl);
    }
    
    .heading-2 {
        font-size: var(--text-3xl);
    }
}

/* ================================
   LOADING STATES 
================================ */
.loading {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
}

.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top: 2px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ================================
   NOTIFICATION SYSTEM 
================================ */
.notification {
    position: fixed;
    bottom: var(--space-lg);
    left: var(--space-lg);
    max-width: 350px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-toast);
    animation: slideInLeft 0.5s ease-out;
}

.notification.real {
    border-left: 4px solid var(--accent);
    background: rgba(201, 169, 110, 0.1);
}

.notification.success {
    border-left: 4px solid var(--success);
    background: rgba(81, 207, 102, 0.1);
}

.notification.error {
    border-left: 4px solid var(--error);
    background: rgba(255, 107, 107, 0.1);
}

.notification.warning {
    border-left: 4px solid var(--warning);
    background: rgba(255, 212, 59, 0.1);
}

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

/* Focus styles */
.btn:focus-visible,
.input:focus-visible,
.nav-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: rgba(255, 255, 255, 0.3);
        --surface: rgba(255, 255, 255, 0.15);
        --text-secondary: #e0e0e0;
    }
}

/* Dark mode support (already dark, but for completeness) */
@media (prefers-color-scheme: dark) {
    /* Already using dark theme */
}

/* ================================
   ARCHIVE COMPONENTS
================================ */

/* Theory Cards */
.theory-card {
    background: var(--theory-bg);
    border-radius: var(--radius-2xl);
    border: 2px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    transition: all var(--transition);
    position: relative;
    cursor: pointer;
}

.theory-card:hover {
    transform: translateY(-8px);
    border-color: var(--archive-accent);
    box-shadow: 0 20px 40px rgba(201, 169, 110, 0.2);
}

/* Confidence Meter */
.confidence-meter {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.confidence-bar {
    width: 80px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    background: linear-gradient(90deg, #f56565, #fbbf24, #48bb78);
    transition: width var(--transition);
}

/* Evidence Preview */
.evidence-preview {
    background: rgba(246, 173, 85, 0.1);
    border-left: 4px solid var(--evidence-highlight);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
}

.evidence-title {
    font-weight: var(--weight-semibold);
    color: var(--evidence-highlight);
    margin-bottom: var(--space-2);
}

/* Modal Content */
.modal-content {
    background: var(--theory-bg);
    border-radius: var(--radius-2xl);
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    border: 2px solid var(--archive-accent);
    position: relative;
}

.modal-header {
    padding: var(--space-8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    background: var(--theory-bg);
    z-index: 10;
}

/* Clickable Context */
.clickable-context {
    display: inline-block;
    color: var(--archive-accent);
    text-decoration: underline;
    cursor: pointer;
    transition: all var(--transition);
}

.clickable-context:hover {
    color: #fbbf24;
    text-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

/* Visualization Containers */
.viz-container {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-xl);
    padding: var(--space-4);
    margin: var(--space-4) 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.connection-web {
    height: 250px;
    width: 100%;
}

/* Analysis Sections */
.analysis-section {
    margin-bottom: var(--space-8);
}

.section-title {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--archive-accent);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.analysis-content {
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
}