/* ================================
   StudyNet AI — "Soft Editorial" Design System
   Typography: DM Serif Display + DM Sans
   Palette: Berry rose, deep navy, cool gray
   ================================ */

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

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

/* ================================
   LIGHT THEME (default)
   ================================ */
:root {
    /* Brand */
    --primary: #b04e84;
    --primary-hover: #9d2266;
    --primary-light: #f0dce8;
    --primary-glow: rgba(176, 78, 132, 0.18);
    --accent: #2c3346;
    --accent-light: #626776;

    /* Background & Surface */
    --background: #edeeef;
    --background-warm: #e4e5e7;
    --sidebar-background: #FFFFFF;
    --surface: #FFFFFF;
    --surface-hover: #f4f4f6;
    --surface-active: #eaebee;
    --surface-elevated: rgba(255, 255, 255, 0.92);
    --surface-code: #2c3346;
    --surface-muted: #e8e9ec;

    /* Text */
    --text-primary: #2c3346;
    --text-secondary: #626776;
    --text-tertiary: #a2a3ad;
    --text-on-primary: #FFFFFF;

    /* Border */
    --border: #d4d5da;
    --border-light: #e2e3e7;
    --border-focus: var(--primary);

    /* Chat */
    --chat-assistant-bg: #FFFFFF;
    --chat-assistant-border: #d4d5da;
    --chat-user-bg: var(--accent);
    --chat-user-border: var(--accent-light);

    /* Content */
    --content-bg: #f4f4f6;
    --content-hover-bg: #eaebee;
    --content-strong-start: var(--primary);
    --content-strong-end: var(--accent);
    --content-link-bg: rgba(176, 78, 132, 0.08);
    --content-link-border: rgba(176, 78, 132, 0.18);

    /* Table */
    --table-row-even: #f4f4f6;
    --table-row-hover: #eaebee;

    /* Code */
    --inline-code-bg: #e8e9ec;
    --inline-code-color: var(--accent);
    --inline-code-border: #d4d5da;

    /* Misc */
    --shadow-soft: 0 1px 3px rgba(44, 51, 70, 0.04), 0 4px 16px rgba(44, 51, 70, 0.06);
    --shadow-medium: 0 4px 24px rgba(44, 51, 70, 0.08), 0 1px 4px rgba(44, 51, 70, 0.04);
    --shadow-heavy: 0 8px 40px rgba(44, 51, 70, 0.12), 0 2px 8px rgba(44, 51, 70, 0.06);
    --shadow-glow: 0 0 0 3px var(--primary-glow);
    --overlay-bg: rgba(237, 238, 239, 0.92);
    --modal-overlay-bg: rgba(44, 51, 70, 0.4);
    --scrollbar-color: rgba(176, 78, 132, 0.2);
    --scrollbar-hover: rgba(176, 78, 132, 0.35);

    /* Sources */
    --source-bg: #e8eaf0;
    --source-color: #2c3346;
    --source-border: #cdd1db;
    --source-section-bg: #e8eaf0;
    --source-section-border: #cdd1db;
    --source-section-color: #2c3346;
    --source-link-color: #6b5b95;

    /* Loader */
    --loader-bg: rgba(255, 255, 255, 0.7);
    --loader-hover-bg: #FFFFFF;
    --step-icon-bg: #e8e9ec;
    --step-waiting-color: #c5c6cc;
    --step-completed-icon-bg: #626776;
    --step-completed-text: #626776;

    /* Toggle */
    --toggle-track: #d4d5da;
    --toggle-track-hover: #c0c1c8;
    --toggle-thumb: #FFFFFF;
    --toggle-thumb-shadow: rgba(44, 51, 70, 0.15);

    /* Modal */
    --modal-btn-secondary-bg: #e8e9ec;
    --modal-btn-secondary-hover: #d4d5da;

    /* Grain overlay opacity */
    --grain-opacity: 0.03;

    /* Radius system */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;
}

/* ================================
   DARK THEME
   ================================ */
[data-theme="dark"] {
    --primary: #c76b9c;
    --primary-hover: #b04e84;
    --primary-light: #3d2838;
    --primary-glow: rgba(199, 107, 156, 0.2);
    --accent: #9f9fb8;
    --accent-light: #7a7a96;

    --background: #2c3346;
    --background-warm: #343b50;
    --sidebar-background: #343b50;
    --surface: #3a4258;
    --surface-hover: #444c64;
    --surface-active: #4e5670;
    --surface-elevated: rgba(58, 66, 88, 0.95);
    --surface-code: #1e2333;
    --surface-muted: #3a4258;

    --text-primary: #edeeef;
    --text-secondary: #9f739b;
    --text-tertiary: #626776;
    --text-on-primary: #FFFFFF;

    --border: #4a5270;
    --border-light: #3f475e;
    --border-focus: var(--primary);

    --chat-assistant-bg: #3a4258;
    --chat-assistant-border: #4a5270;
    --chat-user-bg: #b04e84;
    --chat-user-border: #9d2266;

    --content-bg: #3a4258;
    --content-hover-bg: #444c64;
    --content-strong-start: #c76b9c;
    --content-strong-end: #9f9fb8;
    --content-link-bg: rgba(199, 107, 156, 0.15);
    --content-link-border: rgba(199, 107, 156, 0.25);

    --table-row-even: #343b50;
    --table-row-hover: #444c64;

    --inline-code-bg: #3a4258;
    --inline-code-color: #9f9fb8;
    --inline-code-border: #4a5270;

    --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.15), 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-medium: 0 4px 24px rgba(0, 0, 0, 0.25), 0 1px 4px rgba(0, 0, 0, 0.15);
    --shadow-heavy: 0 8px 40px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-glow: 0 0 0 3px var(--primary-glow);
    --overlay-bg: rgba(44, 51, 70, 0.92);
    --modal-overlay-bg: rgba(0, 0, 0, 0.55);
    --scrollbar-color: rgba(199, 107, 156, 0.2);
    --scrollbar-hover: rgba(199, 107, 156, 0.35);

    --source-bg: #343b50;
    --source-color: #9f9fb8;
    --source-border: #4a5270;
    --source-section-bg: #343b50;
    --source-section-border: #4a5270;
    --source-section-color: #9f9fb8;
    --source-link-color: #c76b9c;

    --loader-bg: rgba(58, 66, 88, 0.8);
    --loader-hover-bg: #3a4258;
    --step-icon-bg: #343b50;
    --step-waiting-color: #4a5270;
    --step-completed-icon-bg: #2A6E4A;
    --step-completed-text: #5ABA7E;

    --toggle-track: #4a5270;
    --toggle-track-hover: #5a6280;
    --toggle-thumb: #edeeef;
    --toggle-thumb-shadow: rgba(0, 0, 0, 0.3);

    --modal-btn-secondary-bg: #444c64;
    --modal-btn-secondary-hover: #4a5270;

    --grain-opacity: 0.04;
}

/* ================================
   BODY & BASE
   ================================ */
body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv11', 'ss01';
    letter-spacing: -0.01em;
}

/* Grain texture overlay on body */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    opacity: var(--grain-opacity);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 128px 128px;
}

.hidden {
    display: none;
}

/* Skip to main content */
.skip-to-content {
    position: absolute;
    left: -9999px;
    top: 8px;
    z-index: 9999;
    padding: 12px 24px;
    background: var(--accent);
    color: var(--text-on-primary);
    font-weight: 600;
    border-radius: var(--radius-md);
    text-decoration: none;
    box-shadow: var(--shadow-medium);
    font-family: 'DM Sans', sans-serif;
}

.skip-to-content:focus {
    left: 16px;
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-color);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}

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

@keyframes revealTitle {
    from { opacity: 0; transform: translateY(20px) scale(0.97); filter: blur(4px); }
    to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

@keyframes revealSubtle {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes floatIn {
    from { opacity: 0; transform: translateY(30px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

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

@keyframes slideInFromRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInFromLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes typingPulse {
    0%, 60%, 100% { transform: scale(1); opacity: 0.4; }
    30% { transform: scale(1.3); opacity: 1; }
}

@keyframes slideInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.95) translateY(-12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 var(--primary-glow); }
    50% { box-shadow: 0 0 0 8px transparent; }
}

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

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes messageSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes rainbow {
    0% { background-position: 0%; }
    100% { background-position: 200%; }
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

/* ================================
   UTILITY CLASSES
   ================================ */
.font-display {
    font-family: 'DM Serif Display', Georgia, 'Times New Roman', serif;
}

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