:root {
    /* Base Variables */
    --padding-sm: 8px;
    --padding-md: 16px;
    --padding-lg: 24px;
    --border-radius: 12px;
    --font-primary: 'Segoe UI', system-ui, sans-serif;

    /* Default Colors (Fallback) */
    --bg-color: #f0f0f0;
    --card-bg: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --accent: #4F46E5;
    --border: #e0e0e0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-color);
    color: var(--text-primary);
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: none;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

/* Header & Hamburger */
.app-header {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
    /* above cards, below modals */
}

.icon-btn {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

/* Sidebar Styling */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: var(--card-bg);
    z-index: 401;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    left: 0;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.sidebar-nav {
    list-style: none;
    padding: 20px;
}

.sidebar-nav li {
    padding: 15px 0;
    font-size: 1.1rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.sidebar-nav li.hidden {
    display: none;
}

/* Bottom Sheet */
.bottom-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.bottom-sheet-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet {
    position: absolute;
    bottom: -100%;
    left: 0;
    width: 100%;
    background: var(--card-bg);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    padding: 20px;
    transition: bottom 0.3s ease;
    display: flex;
    flex-direction: column;
}

.bottom-sheet.open {
    bottom: 0;
}

.sheet-drag-handle {
    width: 40px;
    height: 5px;
    background: #ccc;
    border-radius: 3px;
    margin: 0 auto 15px auto;
}

.folder-list {
    list-style: none;
    margin: 15px 0;
    max-height: 40vh;
    overflow-y: auto;
}

.folder-list li {
    padding: 12px 15px;
    background: var(--bg-color);
    margin-bottom: 8px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    border: 1px solid var(--border);
}

.new-folder-area {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.new-folder-area input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.new-folder-area button {
    background: var(--accent);
    color: white;
    padding: 0 15px;
    border-radius: 10px;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
}

/* Snap Scrolling Container */
#feed-container {
    height: 100vh;
    width: 100%;
    overflow-y: scroll;
    /* The magic of IG Reels/TikTok scrolling */
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    /* Hide scrollbar for cleaner UI */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

#feed-container::-webkit-scrollbar {
    display: none;
}

/* Individual Card (Full Screen) */
.card-section {
    position: relative;
    height: 100vh;
    width: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--padding-md);
}

.card-inner {
    width: 100%;
    max-width: 450px;
    height: 90vh;
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: var(--padding-lg);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
    user-select: none;
    /* Prevent accidental text selection when double tapping */
}

/* markdown parsed content styling inside card */
.card-content {
    flex: 1;
}

.card-title {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 8px;
    line-height: 1.2;
}

.card-concept {
    font-size: 1.1rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border);
}

.card-detail {
    font-size: 1.05rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.card-detail ul,
.card-detail ol {
    margin-left: 20px;
    margin-bottom: 10px;
    margin-top: 10px;
}

.card-detail p {
    margin-bottom: 10px;
}

.card-keywords {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.keyword-badge {
    background-color: var(--bg-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid var(--border);
}

/* Interactions */
.doubt-animation {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 80px;
    pointer-events: none;
    z-index: 100;
    opacity: 0;
}

@keyframes popOut {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

.pop-anim {
    animation: popOut 0.8s ease-out forwards;
}

/* UI Overlays */
.fab-ai {
    position: fixed;
    bottom: 20px;
    right: 15px;
    width: 45px;
    height: 45px;
    border-radius: 25px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    z-index: 50;
    transition: transform 0.2s;
    border: none;
}

.fab-ai:hover,
.fab-ai:active {
    transform: scale(0.95);
}

.fab-ai.hidden {
    display: none;
}

/* AI Drawer Layer */
#ai-drawer {
    position: fixed;
    bottom: -100%;
    left: 0;
    width: 100%;
    height: 70vh;
    background: var(--card-bg);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
    z-index: 200;
    transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
}

.theme-win11 #ai-drawer {
    background: rgba(255, 255, 255, 0.5);
    /* increased opacity so text is readable */
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid rgba(255, 255, 255, 0.6);
}

#ai-drawer.open {
    bottom: 0;
}

.drawer-header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.ai-tabs {
    display: flex;
    gap: 8px;
}

.ai-tab {
    background: transparent;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 14px;
    border-radius: 20px;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-tab.active {
    background: var(--bg-color);
    color: var(--text-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.drawer-drag-handle {
    width: 40px;
    height: 5px;
    background: #ccc;
    border-radius: 3px;
    margin: 0 auto 10px auto;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background-color: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background-color: var(--bg-color);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.chat-input-area {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: 20px;
    outline: none;
    font-size: 1rem;
    background: var(--bg-color);
    color: var(--text-primary);
}

.chat-input-area button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0 20px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
}

/* Modal Overlay */
.auth-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
}

.auth-modal {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 350px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.auth-modal h3 {
    margin-bottom: 20px;
    text-align: center;
}

.auth-modal input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

.auth-modal button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.auth-modal-overlay.nav-modal {
    z-index: 600;
    /* Ensure auth modal overrides sidebar */
}

.nav-select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg-color);
    color: var(--text-primary);
}

/* -------------------------------------
   Collections & Phase 3 UI Additions
--------------------------------------*/

/* Bookmark Button on Card */
.bookmark-btn {
    position: absolute;
    bottom: 120px;
    right: 15px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.8);
    color: white;
    /* SVG uses currentColor */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    transition: transform 0.2s;
}

.bookmark-btn:active {
    transform: scale(0.9);
}

/* Collections Dashboard */
.collections-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-color);
    z-index: 200;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.collections-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    margin-top: 10px;
}

.collections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    overflow-y: auto;
}

.folder-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.folder-card:active {
    transform: scale(0.95);
}

.folder-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.folder-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.folder-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Review Mode Sticky Header */
.review-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    z-index: 150;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.review-title {
    font-weight: 700;
    font-size: 1.1rem;
}

.review-btn {
    background: var(--bg-color);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

.message {
    padding: 10px 15px;
    border-radius: 12px;
    max-width: 80%;
    margin-bottom: 10px;
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    /* Forces line breaks to render */
    word-break: break-word;
}