/* ==========================================================================
   inKnit Premium Design System
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root, [data-theme="light"] {
    /* Color Palette — Light (Default) */
    --primary: #7C3AED;
    --primary-hover: #6D28D9;
    --primary-light: #EDE9FE;
    --secondary: #EC4899;
    --bg-color: #F8FAFC;
    --surface: #FFFFFF;
    --text-main: #0F172A;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --navbar-bg: rgba(255, 255, 255, 0.8);
    --card-bg: #FFFFFF;
    --reader-bg: #F4F1EA;
}

[data-theme="dark"] {
    --primary: #A78BFA;
    --primary-hover: #8B5CF6;
    --primary-light: #2E1065;
    --secondary: #F472B6;
    --bg-color: #0F172A;
    --surface: #1E293B;
    --text-main: #F1F5F9;
    --text-muted: #94A3B8;
    --border: #334155;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --navbar-bg: rgba(15, 23, 42, 0.9);
    --card-bg: #1E293B;
    --reader-bg: #0F172A;
}

[data-theme="midnight"] {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-light: #1E1B4B;
    --secondary: #818CF8;
    --bg-color: #020617;
    --surface: #0F172A;
    --text-main: #E2E8F0;
    --text-muted: #7C85A3;
    --border: #1E293B;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7);
    --navbar-bg: rgba(2, 6, 23, 0.9);
    --card-bg: #0F172A;
    --reader-bg: #020617;
}

[data-theme="forest"] {
    --primary: #10B981;
    --primary-hover: #059669;
    --primary-light: #D1FAE5;
    --secondary: #34D399;
    --bg-color: #F0FDF4;
    --surface: #FFFFFF;
    --text-main: #14532D;
    --text-muted: #4D7C5E;
    --border: #BBF7D0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --navbar-bg: rgba(240, 253, 244, 0.9);
    --card-bg: #FFFFFF;
    --reader-bg: #ECFDF5;
}

[data-theme="rose"] {
    --primary: #F43F5E;
    --primary-hover: #E11D48;
    --primary-light: #FFE4E6;
    --secondary: #FB7185;
    --bg-color: #FFF1F2;
    --surface: #FFFFFF;
    --text-main: #4C0519;
    --text-muted: #9F1239;
    --border: #FECDD3;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --navbar-bg: rgba(255, 241, 242, 0.9);
    --card-bg: #FFFFFF;
    --reader-bg: #FFF1F2;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    background-image: radial-gradient(circle at 10% 20%, rgba(124, 58, 237, 0.03) 0%, transparent 20%),
                      radial-gradient(circle at 90% 80%, rgba(236, 72, 153, 0.03) 0%, transparent 20%);
    min-height: 100vh;
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1, h2, h3, h4, h5 {
    color: var(--text-main);
    font-weight: 600;
}

h1 { font-size: 2.25rem; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; }
p { color: var(--text-muted); }

/* ==========================================================================
   Components
   ========================================================================== */

/* Solid White Card (matching prototype) */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    padding: 24px;
    transition: var(--transition);
}

.glass-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(124, 58, 237, 0.39);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.23);
    transform: translateY(-1px);
}

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

.btn-outline:hover {
    background-color: var(--bg-color);
    border-color: var(--text-muted);
}

/* Inputs */
.input-group {
    margin-bottom: 16px;
}

.input-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-main);
}

.input-field {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: var(--transition);
    background-color: var(--surface);
    color: var(--text-main);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

/* ==========================================================================
   Layouts
   ========================================================================== */

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 40px;
    background: var(--navbar-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Auth Container */
.auth-container {
    min-height: calc(100vh - 70px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-modal {
    width: 100%;
    max-width: 420px;
}

.social-login {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.social-btn {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
}

.social-btn:hover {
    background: var(--bg-color);
}

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

.animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--surface);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-lg);
    border-radius: 8px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.success {
    border-left-color: #10B981;
}

.toast.success .toast-icon {
    color: #10B981;
}

.toast.error {
    border-left-color: #EF4444;
}

.toast.error .toast-icon {
    color: #EF4444;
}

.toast-message {
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.95rem;
}

/* Toggle Switch Component */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #CBD5E1; border-radius: 24px; transition: 0.3s; }
.toggle-knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: white; border-radius: 50%; transition: 0.3s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-switch input:checked + .toggle-track + .toggle-knob { transform: translateX(20px); }

/* ==========================================================================
   Spoiler Alert & Click-to-Reveal System
   ========================================================================== */

/* Inline Spoiler text (Instagram-style blurry block) */
.spoiler-inline {
    filter: blur(5px);
    background-color: rgba(139, 92, 246, 0.12);
    color: var(--text-main, #1e293b) !important;
    cursor: pointer;
    border-radius: 4px;
    padding: 1px 5px;
    user-select: none;
    transition: filter 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
    font-family: inherit;
    display: inline-block;
}
.spoiler-inline:hover {
    filter: blur(3px);
    background-color: rgba(139, 92, 246, 0.2);
}
.spoiler-inline.revealed {
    filter: none !important;
    background-color: rgba(124, 58, 237, 0.15) !important;
    color: var(--text-main) !important;
    user-select: text;
}

/* Premium Card-Level Spoiler Blur & Inline Toggle System */
.spoiler-card-container {
    position: relative;
    display: block;
    width: 100%;
    margin: 16px 0;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(139, 92, 246, 0.2);
    padding: 20px 24px;
    box-sizing: border-box;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.03);
}
.spoiler-card-container:hover {
    border-color: rgba(139, 92, 246, 0.45);
    background: rgba(255, 255, 255, 0.6);
    box-shadow: 0 10px 40px rgba(139, 92, 246, 0.08);
}
.spoiler-blur-active {
    filter: blur(12px);
    opacity: 0.15;
    pointer-events: none;
    user-select: none;
    transition: filter 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
}
.spoiler-blur-active.revealed {
    filter: none !important;
    opacity: 1 !important;
    pointer-events: auto;
    user-select: text;
}

/* Force expanded preview view when revealed (override line-clamps) */
.thread-preview.revealed {
    display: block !important;
    -webkit-line-clamp: unset !important;
    overflow: visible !important;
}

.spoiler-toggle-btn {
    background: linear-gradient(135deg, #7C3AED 0%, #A855F7 100%);
    color: white !important;
    padding: 8px 20px;
    border-radius: 30px;
    font-size: 0.8rem;
    font-weight: 700;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    margin-bottom: 12px;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.3);
    outline: none;
    letter-spacing: 0.3px;
}
.spoiler-toggle-btn:hover {
    background: linear-gradient(135deg, #6D28D9 0%, #9333EA 100%);
    transform: translateY(-2.5px);
    box-shadow: 0 8px 22px rgba(124, 58, 237, 0.45);
}
.spoiler-toggle-btn:active {
    transform: translateY(0);
}

/* ==========================================================================
   Mobile Responsiveness (Phone & Tablet Friendly Overrides)
   ========================================================================== */

@media (max-width: 768px) {
    /* Global layout & margins */
    body {
        font-size: 0.95rem;
    }
    
    /* Responsive navbar wrapper */
    .navbar {
        padding: 12px 16px !important;
        flex-wrap: wrap !important;
        gap: 12px !important;
        height: auto !important;
    }
    
    .navbar > div {
        width: 100% !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .navbar > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100% !important;
        gap: 10px !important;
    }
    
    .navbar > div:last-child {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
    }

    .logo {
        font-size: 1.25rem !important;
    }

    /* Swipeable, scrollable horizontal navigation bar */
    .nav-links {
        margin-left: 0 !important;
        gap: 16px !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        padding: 4px 0 8px 0 !important;
        width: 100% !important;
        display: flex !important;
        scrollbar-width: none !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .nav-links::-webkit-scrollbar {
        display: none !important;
    }

    /* Search bar stretches to 100% on mobile */
    .search-bar-nav {
        width: 100% !important;
        margin: 6px 0 !important;
        order: 10 !important; /* Forces search to wrap below button group */
    }

    /* Button and dropdown styling on mobile */
    .navbar .btn-primary {
        padding: 8px 14px !important;
        font-size: 0.8rem !important;
        margin-right: 8px !important;
    }

    /* Headers, containers & banners */
    .dashboard-container,
    .lib-container,
    .forum-container,
    .story-container {
        margin: 16px auto !important;
        padding: 0 12px 40px !important;
    }

    .welcome-section,
    .lib-header,
    .community-banner {
        padding: 24px 16px !important;
        border-radius: 12px !important;
        margin-bottom: 20px !important;
    }

    .welcome-section h1,
    .lib-header h1,
    .community-banner h1,
    .story-header h1 {
        font-size: 1.5rem !important;
    }

    .welcome-section p,
    .lib-header p,
    .community-banner p {
        font-size: 0.85rem !important;
    }

    /* Tab bars become swipe-scrollable */
    .category-bar,
    .genre-tabs,
    .genre-grid,
    .lib-tabs,
    .tab-bar {
        justify-content: flex-start !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        flex-wrap: nowrap !important;
        padding-bottom: 8px !important;
        scrollbar-width: none !important;
        -webkit-overflow-scrolling: touch !important;
        width: 100% !important;
        display: flex !important;
        gap: 8px !important;
    }
    
    .category-bar::-webkit-scrollbar,
    .genre-tabs::-webkit-scrollbar,
    .genre-grid::-webkit-scrollbar,
    .lib-tabs::-webkit-scrollbar,
    .tab-bar::-webkit-scrollbar {
        display: none !important;
    }

    .cat-card,
    .genre-tab,
    .genre-card,
    .lib-tab,
    .tab-btn {
        flex: 0 0 auto !important;
        min-width: unset !important;
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
    }

    /* Grid layouts resize and display fewer columns on mobile */
    .continue-reading-grid {
        grid-template-columns: 1fr !important;
    }

    .rec-grid.list-view,
    .story-grid,
    .genre-card-grid,
    .trending-grid,
    .folders-grid {
        grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)) !important;
        gap: 12px !important;
    }

    /* List Views wrap to columns */
    .rec-grid.list-view .rec-card,
    .story-grid.list-view .lib-card {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    .story-grid.list-view .lib-card-actions {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Discussion Rows */
    .forum-search-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        padding: 12px !important;
        margin-bottom: 20px !important;
    }

    .new-disc-btn {
        width: 100% !important;
        justify-content: center !important;
    }

    .sort-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }

    /* Thread cards inside forums */
    .thread-card {
        padding: 14px !important;
    }

    .thread-card-inner {
        gap: 12px !important;
    }

    .thread-avatar {
        width: 36px !important;
        height: 36px !important;
        font-size: 0.9rem !important;
    }

    .thread-footer {
        flex-wrap: wrap !important;
        gap: 8px !important;
        font-size: 0.75rem !important;
    }

    /* Reading layout and floating sidebars */
    .reading-layout {
        flex-direction: column !important;
    }

    .chapter-sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        height: 100vh !important;
        width: 270px !important;
        z-index: 1000 !important;
        box-shadow: 4px 0 15px rgba(0,0,0,0.2) !important;
        margin-left: -270px !important;
    }

    .chapter-sidebar.collapsed {
        margin-left: -270px !important;
    }

    .chapter-sidebar:not(.collapsed) {
        margin-left: 0 !important;
    }

    .sidebar-toggle {
        left: 0 !important;
    }

    .sidebar-toggle.shifted {
        left: 270px !important;
    }

    .reader-main {
        padding: 24px 12px 60px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .reader-content {
        font-size: 1.12rem !important;
        line-height: 1.75 !important;
    }

    /* Inline paragraph comments on mobile */
    .para-wrap {
        padding-right: 36px !important;
        position: relative !important;
    }

    .para-comment-trigger {
        right: 0 !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        opacity: 0.85 !important;
        width: 26px !important;
        height: 26px !important;
        font-size: 0.72rem !important;
    }

    /* Preview Overlays & Modals */
    .preview-card {
        padding: 20px 16px !important;
        width: 92% !important;
    }

    .preview-card > div:first-child {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 14px !important;
    }

    #previewCoverContainer {
        width: 110px !important;
        height: 165px !important;
    }

    .preview-card div[style*="justify-content: flex-end"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .preview-card button,
    .preview-card a {
        width: 100% !important;
        text-align: center !important;
    }

    .forum-modal-content {
        padding: 20px 16px !important;
    }

    /* Moderator nav links scrollable on mobile */
    .mod-nav-links {
        justify-content: flex-start !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        flex-wrap: nowrap !important;
        padding-bottom: 8px !important;
        scrollbar-width: none !important;
        -webkit-overflow-scrolling: touch !important;
        width: 100% !important;
        display: flex !important;
        gap: 8px !important;
    }
    .mod-nav-links::-webkit-scrollbar {
        display: none !important;
    }
    .mod-nav-link {
        flex: 0 0 auto !important;
    }
    .rec-grid:not(.list-view) .rec-card {
        flex: 0 0 160px !important;
        width: 160px !important;
    }
}

@media (max-width: 480px) {
    /* Micro scales for very small phones */
    .logo {
        font-size: 1.15rem !important;
    }
    
    .rec-grid,
    .story-grid,
    .genre-card-grid,
    .trending-grid,
    .folders-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
    }
}
/* Custom Popout Modals */
.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.custom-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.custom-modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform 0.2s ease;
    text-align: center;
}
.custom-modal-overlay.active .custom-modal-box {
    transform: scale(1);
}
.custom-modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 12px;
}
.custom-modal-message {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 24px;
}
.custom-modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
