:root {
    --bg-color: #F8F5EB;
    --ink: #1C1B18;
    --paper: #FFFFFF;
    --folder-bg: #EAE6D7;
    --highlight: #E2F0CB;
    
    --font-serif: 'Fraunces', serif;
    --font-mono: 'Space Mono', monospace;
}

* {
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    background-image: radial-gradient(#d1cdbf 2px, transparent 2px);
    background-size: 24px 24px;
    color: var(--ink);
    font-family: var(--font-mono);
    margin: 0;
    padding: 0 20px 40px 20px;
    cursor: crosshair;
    overflow-x: hidden; /* Prevents floating writers from creating horizontal scrollbars */
}

/* Removed position: relative from .main-header so writers can break out of its 900px max-width boundary and use the full screen width */
.main-header {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 0 30px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Floating Writer Caricatures */
.floating-writer {
    position: absolute;
    width: 130px;
    height: 160px;
    object-fit: cover;
    z-index: 0; /* Changed to 0 so they sit behind the main content if they overlap */
    pointer-events: none; /* So they don't block clicks */
    
    /* Neo-brutalist / Newspaper Clipping Aesthetic */
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0px var(--ink);
    background-color: var(--paper);
    padding: 6px; /* White border like a retro photo */
    
    /* Make them look harsh, retro, and printed */
    filter: grayscale(100%) contrast(140%) brightness(1.1);
    mix-blend-mode: multiply; /* Lets the background grid show through the white areas */
}

.title-container {
    position: relative; /* This is the anchor point for the floating writers */
    z-index: 10;
    border: 3px solid var(--ink);
    background: var(--paper);
    padding: 20px 30px;
    box-shadow: 8px 8px 0px var(--ink);
    border-radius: 4px;
    margin-bottom: 30px;
    transform: rotate(-1deg);
    transition: transform 0.3s ease;
}

.title-container:hover {
    transform: rotate(0deg);
}

.cat-doodle {
    position: absolute;
    top: -45px;
    right: -20px;
    width: 100px;
    z-index: 10;
    filter: drop-shadow(4px 4px 0px rgba(0,0,0,0.1));
}

.zzz {
    animation: floatZ 3s infinite ease-in-out;
}
.zzz:nth-child(2) { animation-delay: 1.5s; }

.smoke {
    opacity: 0;
    animation: riseSmoke 4s infinite ease-out;
}

.smoke-1 {
    animation-delay: 0.5s;
}

.smoke-2 {
    animation-delay: 2.5s;
}

@keyframes riseSmoke {
    0% { transform: translateY(0) scale(0.8); opacity: 0; }
    20% { opacity: 0.6; }
    80% { opacity: 0.2; }
    100% { transform: translateY(-30px) scale(1.5); opacity: 0; }
}

@keyframes floatZ {
    0% { transform: translateY(0) scale(1); opacity: 0; }
    50% { transform: translateY(-10px) scale(1.2); opacity: 1; }
    100% { transform: translateY(-20px) scale(1.4); opacity: 0; }
}

h1 {
    font-family: var(--font-serif);
    font-size: 3rem;
    font-weight: 800;
    margin: 0 0 10px 0;
    letter-spacing: -2px;
    line-height: 1;
}

.subtitle {
    font-style: italic;
    font-family: var(--font-serif);
    font-size: 1rem;
    max-width: 500px;
    margin: 0 auto;
    color: #4a4a4a;
}

.search-box {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 500px;
    transform: rotate(1deg);
}

#searchInput {
    width: 100%;
    padding: 12px 20px;
    font-family: var(--font-mono);
    font-size: 1rem;
    border: 3px solid var(--ink);
    background: var(--paper);
    box-shadow: 4px 4px 0px #B5EAD7;
    border-radius: 0;
    outline: none;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#searchInput:focus {
    box-shadow: 6px 6px 0px #FF9AA2;
    transform: translateY(-2px) translateX(-2px);
}

.search-icon {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    pointer-events: none;
}

/* --- The System Layout (Neo-Retro OS) --- */
.system-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    gap: 30px;
    height: 75vh; /* Fixed height for the "OS" feel */
    min-height: 600px;
    position: relative;
    z-index: 10;
}

.pane-header {
    border-bottom: 3px solid var(--ink);
    padding: 10px 15px;
    background: var(--folder-bg);
}

.pane-header h2 {
    margin: 0;
    font-size: 1.1rem;
    text-transform: uppercase;
}

/* Sidebar Directory */
.directory-pane {
    width: 300px;
    background: var(--paper);
    border: 3px solid var(--ink);
    box-shadow: 8px 8px 0px var(--ink);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.folder-tree {
    list-style: none;
    padding: 15px;
    margin: 0;
    overflow-y: auto;
    flex-grow: 1;
}

.tree-section {
    font-size: 0.8rem;
    color: #888;
    margin: 20px 0 5px 5px;
    font-weight: bold;
    letter-spacing: 1px;
}

.tree-item {
    padding: 8px 10px;
    margin-bottom: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    transition: background 0.1s, border 0.1s;
}

.tree-item:hover {
    background: var(--folder-bg);
}

.tree-item.active {
    background: var(--highlight);
    border: 2px dashed var(--ink);
    font-weight: bold;
}

.tree-item.active .folder-icon {
    content: "📂"; /* Emulate open folder visually if possible, or just rely on CSS */
}

.tree-section.collapsible {
    cursor: pointer;
    user-select: none;
    transition: color 0.1s;
}

.tree-section.collapsible:hover {
    color: var(--ink);
}

.collapse-icon {
    display: inline-block;
    width: 12px;
    font-weight: bold;
}

.folder-group {
    display: block;
    overflow: hidden;
}

.folder-group.collapsed {
    display: none;
}

/* Main Content Area */
.content-pane {
    flex-grow: 1;
    background: var(--paper);
    border: 3px solid var(--ink);
    box-shadow: 8px 8px 0px var(--ink);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.window-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.window-stats {
    font-size: 0.9rem;
    color: #555;
}

.folder-contents {
    padding: 30px;
    overflow-y: auto;
    flex-grow: 1;
    
    /* Grid layout for the cards inside the folder */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    grid-auto-rows: max-content;
    gap: 30px;
}

/* Custom Scrollbar for Panes */
::-webkit-scrollbar {
    width: 14px;
}
::-webkit-scrollbar-track {
    background: var(--paper);
    border-left: 2px solid var(--ink);
}
::-webkit-scrollbar-thumb {
    background: var(--ink);
    border: 2px solid var(--paper);
}

/* --- Cards (Same Neo-brutalist aesthetic, slightly smaller) --- */
.fragment-card {
    background: var(--paper);
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0px var(--card-shadow, var(--ink));
    padding: 20px;
    position: relative;
    border-radius: 4px;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    /* Cards stay within grid flow, no random rotations here to keep folder neat */
}

.fragment-card:hover {
    transform: translateY(-4px) translateX(-4px); 
    box-shadow: 10px 10px 0px var(--card-shadow, var(--ink));
    z-index: 5;
}

.card-cat-container {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 30px;
    z-index: 2;
    pointer-events: none;
}

.card-cat {
    width: 100%;
    height: 100%;
    filter: drop-shadow(2px 2px 0px rgba(0,0,0,0.1));
}

.card-header {
    border-bottom: 2px dashed var(--ink);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.card-header h2 {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 5px 0;
    line-height: 1.1;
}

.card-header h3 {
    font-size: 0.85rem;
    font-weight: 400;
    margin: 0;
    color: #555;
}

.card-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.tag-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.tag {
    border: 2px solid var(--ink);
    padding: 2px 8px;
    font-size: 0.65rem;
    text-transform: uppercase;
    font-weight: bold;
    border-radius: 20px;
}

.read-tag { background-color: #C7CEEA; }
.unread-tag { background-color: #FFDAC1; }
.lang-tag { background-color: #E2F0CB; }
.rating-tag { background-color: #FFB7B2; }

.meta-data p {
    margin: 4px 0;
    font-size: 0.8rem;
}

.notes-doodle {
    margin-top: 15px;
    padding: 10px;
    background: #FFF9C4; 
    border: 2px solid var(--ink);
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 0.95rem;
    transform: rotate(-1deg);
}
.notes-doodle p { margin: 0; }
@media (max-width: 900px) {
    /* 1. Hide the decorative elements that clutter small screens */
    .floating-writer {
        display: none !important;
    }
    .cat-doodle {
        width: 70px;
        top: -30px;
        right: -10px;
    }

    /* 2. Fix header sizing for mobile */
    .main-header {
        padding: 20px 0 15px 0;
    }
    h1 {
        font-size: 2.2rem;
        letter-spacing: -1px;
    }
    .subtitle {
        font-size: 0.9rem;
    }
    .title-container {
        padding: 15px 20px;
        margin-bottom: 20px;
        box-shadow: 4px 4px 0px var(--ink);
    }
    
    /* 3. Make search bar more compact */
    .search-box {
        transform: rotate(0deg);
    }
    #searchInput {
        padding: 10px 15px;
        font-size: 0.9rem;
        box-shadow: 3px 3px 0px #B5EAD7;
    }

    /* 4. Completely restructure the "OS System" layout into a stacked mobile app view */
    .system-container {
        flex-direction: column;
        height: auto;
        min-height: auto;
        gap: 15px;
    }

    /* 5. Turn the sidebar into a compact, scrollable horizontal menu */
    .directory-pane {
        width: 100%;
        height: auto;
        box-shadow: 4px 4px 0px var(--ink);
    }
    
    .pane-header h2 {
        font-size: 0.9rem;
    }

    /* Make the folder tree scroll horizontally instead of a massive vertical list */
    .folder-tree {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 10px;
        white-space: nowrap;
        gap: 10px;
        /* Smooth scrolling on iOS */
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }

    /* Hide the text headers like "BY LANGUAGE" to save space */
    .tree-section {
        display: none;
    }
    
    .folder-group {
        display: contents; /* Flattens groups so they flow horizontally */
    }

    .tree-item {
        scroll-snap-align: start;
        margin: 0;
        padding: 6px 12px;
        border: 2px solid var(--ink);
        background: var(--paper);
        border-radius: 20px;
        font-size: 0.8rem;
    }
    
    .tree-item.active {
        background: var(--highlight);
        border: 2px solid var(--ink);
    }

    /* 6. Expand the content pane to take up remaining height */
    .content-pane {
        height: 60vh; /* Give it a good chunk of the screen so internal scroll works */
        box-shadow: 4px 4px 0px var(--ink);
    }
    
    .folder-contents {
        padding: 15px;
        grid-template-columns: 1fr; /* 1 card per row on mobile */
        gap: 15px;
    }
    
    .fragment-card {
        padding: 15px;
        box-shadow: 4px 4px 0px var(--card-shadow, var(--ink));
    }
    .fragment-card:hover {
        transform: translateY(-2px) translateX(-2px); 
        box-shadow: 6px 6px 0px var(--card-shadow, var(--ink));
    }
    .card-header h2 {
        font-size: 1.2rem;
    }
    .card-cat-container {
        top: -25px;
        width: 50px;
    }
}