
/* Reset & Base */
:root {
    --bg-color: #fdfbf7;
    --text-color: #4a4a4a;
    --accent-pink: #f4dcd6;
    --accent-blue: #d6e4f4;
    --accent-yellow: #f4f0d6;
    --link-color: #d46b6b;
    --border-radius: 12px;
    
    /* Typography Variables */
    --base-font-size: 18px;
    --line-height: 1.8;
    --font-main: 'Zen Maru Gothic', 'Helvetica Neue', sans-serif;
    
    /* Theme Variables */
    --panel-bg: #fff;
    --panel-text: #333;
    --panel-border: #eee;
    --card-shadow: 8px 8px 0 rgba(0,0,0,0.05);
}

/* Dark Theme */
body.theme-dark {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --accent-pink: #4a3b3b;
    --accent-blue: #3b4a5a;
    --accent-yellow: #4a4a3b;
    --link-color: #ff8a80;
    --panel-bg: #2d2d2d;
    --panel-text: #e0e0e0;
    --panel-border: #444;
    --card-shadow: 8px 8px 0 rgba(0,0,0,0.3);
}

/* Sepia Theme */
body.theme-sepia {
    --bg-color: #f4ecd8;
    --text-color: #5b4636;
    --accent-pink: #e6d0b3;
    --accent-blue: #d0e6d8;
    --accent-yellow: #e6e0b3;
    --link-color: #a05a46;
    --panel-bg: #f9f4e6;
    --panel-text: #5b4636;
    --panel-border: #dcc8a8;
}

body {
    font-family: var(--font-main);
    font-size: var(--base-font-size);
    line-height: var(--line-height);
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    background-image: radial-gradient(var(--text-color) 0.5px, transparent 0.5px); /* Adjusted for dark mode visibility */
    background-size: 20px 20px;
    background-blend-mode: overlay; /* Helps with contrast */
    transition: background-color 0.3s, color 0.3s;
}

/* Ensure background pattern is subtle */
body.theme-dark {
    background-image: radial-gradient(#333 1px, transparent 1px);
}

a {
    color: var(--link-color);
    text-decoration: none;
    transition: opacity 0.2s;
}

a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Layout */
.container {
    max-width: 1000px; /* Slightly wider for grid */
    margin: 0 auto;
    padding: 0 20px;
}

/* Header & Nav */
header {
    background: var(--panel-bg); /* Use panel bg for header in dark mode */
    border-bottom: 2px dashed var(--panel-border);
    padding: 20px 0;
    margin-bottom: 40px;
    box-shadow: 0 4px 0 rgba(0,0,0,0.02);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: all 0.3s ease;
}

header.scrolled {
    padding: 10px 0;
    background: rgba(255, 255, 255, 0.95); /* Slight transparency */
    backdrop-filter: blur(10px);
    border-bottom-style: solid;
}

body.theme-dark header.scrolled {
    background: rgba(45, 45, 45, 0.95);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.logo h1 {
    margin: 0;
    font-size: 1.8em;
    color: var(--text-color);
    transition: font-size 0.3s ease;
}

header.scrolled .logo h1 {
    font-size: 1.4em;
}

.logo p {
    margin: 0;
    color: var(--text-color);
    opacity: 0.7;
    font-size: 0.8em;
    transition: all 0.3s ease;
    max-height: 20px;
    overflow: hidden;
}

header.scrolled .logo p {
    opacity: 0;
    max-height: 0;
    margin: 0;
}

/* Dropdown Menu */
.top-nav {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-link {
    color: var(--text-color);
    font-weight: bold;
    font-size: 16px;
    padding: 10px 15px;
    border-radius: 20px;
    transition: background 0.2s;
}

.nav-link:hover {
    background-color: var(--accent-yellow);
    text-decoration: none;
    opacity: 1;
    color: #333; /* Always dark text on yellow bg */
}

/* Buy Me a Coffee Button */
.bmc-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.bmc-btn {
    display: flex;
    align-items: center;
    background-color: #FFDD00;
    color: #333;
    border-radius: 50px;
    padding: 10px;
    font-weight: bold;
    font-size: 14px;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    max-width: 40px;
    overflow: hidden;
    white-space: nowrap;
    box-sizing: border-box;
}

.bmc-btn:hover, .bmc-btn:focus {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    max-width: 200px;
    padding-right: 20px;
    text-decoration: none;
    opacity: 1;
}

.bmc-icon {
    width: 20px;
    height: 20px;
    min-width: 20px;
    margin-right: 0;
    transition: margin-right 0.3s ease;
}

.bmc-btn:hover .bmc-icon, .bmc-btn:focus .bmc-icon {
    margin-right: 8px;
}

.bmc-btn span {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.bmc-btn:hover span, .bmc-btn:focus span {
    opacity: 1;
}

/* Search Container */
.search-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

#search-input {
    padding: 8px 35px 8px 15px;
    border-radius: 20px;
    border: 2px solid var(--panel-border);
    font-family: inherit;
    font-size: 0.9em;
    width: 200px;
    transition: all 0.2s;
    background: var(--panel-bg);
    color: var(--text-color);
}

#search-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 8px rgba(214, 228, 244, 0.5);
    width: 250px;
}

#search-clear {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: #999;
    font-size: 1.2em;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    display: none;
}

#search-clear:hover {
    color: var(--text-color);
}

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

.hidden {
    display: none !important;
}

#no-results {
    text-align: center;
    padding: 40px;
    background: var(--panel-bg);
    border-radius: var(--border-radius);
    border: 2px dashed var(--panel-border);
    margin-bottom: 20px;
    color: var(--text-color);
}

.dropbtn {
    background-color: var(--accent-blue);
    color: var(--text-color);
    padding: 10px 20px;
    font-size: 16px;
    border: none;
    cursor: pointer;
    border-radius: 20px;
    font-family: inherit;
    font-weight: bold;
    transition: background 0.2s;
}

.dropbtn:hover {
    background-color: var(--accent-pink);
    color: #333;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: var(--panel-bg);
    min-width: 250px;
    box-shadow: 0px 8px 24px rgba(0,0,0,0.15);
    z-index: 1;
    border-radius: 12px;
    padding: 15px;
    border: 2px solid var(--panel-border);
    max-height: 400px;
    overflow-y: auto;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-content li {
    list-style: none;
    margin-bottom: 5px;
}

.dropdown-content a {
    color: var(--text-color);
    padding: 8px 12px;
    text-decoration: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.dropdown-content a:hover {
    background-color: var(--accent-yellow);
    color: #333;
    text-decoration: none;
}

.cat-count {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.8em;
    color: #888;
}

.view-all-cats {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--panel-border);
}

.view-all-cats a {
    font-weight: bold;
    color: var(--link-color);
    justify-content: center;
}

/* Main Layout */
.main-layout {
    display: block;
}

/* Main Content - Card Style for Single Post */
.card {
    background: var(--panel-bg);
    padding: 50px;
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    border: 1px solid var(--panel-border);
    margin-bottom: 30px;
    position: relative;
    transition: background 0.3s, border-color 0.3s;
}

/* Post Grid System */
.post-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    margin: 30px 0;
}

.post-card {
    background: var(--panel-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--panel-border);
    box-shadow: 4px 4px 0 rgba(0,0,0,0.03);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.post-card:hover {
    transform: translateY(-5px);
    box-shadow: 8px 8px 0 rgba(0,0,0,0.08);
    border-color: var(--link-color);
}

.post-card-content {
    padding: 25px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.post-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    color: #888;
    margin-bottom: 15px;
}

.meta-cat {
    background: var(--accent-blue);
    padding: 2px 8px;
    border-radius: 4px;
    color: #555;
    font-weight: bold;
}

.post-card-title {
    color: var(--text-color);
    text-decoration: none;
    margin-bottom: 10px;
}

.post-card-title h3 {
    margin: 0;
    font-size: 1.3em;
    line-height: 1.4;
}

.post-card-title:hover {
    color: var(--link-color);
}

.post-card-excerpt {
    font-size: 0.95em;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 20px;
    flex-grow: 1;
    line-height: 1.6;
}

.post-card-footer {
    border-top: 1px dashed var(--panel-border);
    padding-top: 15px;
    font-size: 0.85em;
    color: #999;
    display: flex;
    justify-content: flex-end;
}

/* Categories Grid Page */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.category-card {
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    border-radius: var(--border-radius);
    padding: 20px;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.category-card:hover {
    background: var(--accent-yellow);
    border-color: var(--accent-yellow);
    transform: scale(1.05);
    text-decoration: none;
}

.category-card h3 {
    margin: 0 0 10px 0;
    font-size: 1.2em;
    color: #333;
}

.category-count {
    background: rgba(0,0,0,0.1);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9em;
    color: #666;
}

.category-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px dashed var(--panel-border);
}

.category-header h2 {
    font-size: 2em;
    margin-bottom: 10px;
}

.category-header p {
    color: #888;
}

.btn-secondary {
    display: inline-block;
    padding: 10px 25px;
    background: transparent;
    border: 2px solid var(--link-color);
    color: var(--link-color);
    border-radius: 25px;
    font-weight: bold;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--link-color);
    color: #fff;
    text-decoration: none;
}

/* Back Button */
.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: var(--accent-pink);
    color: #555;
    border: none;
    padding: 6px 15px;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.85em;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
    visibility: visible;
}

.back-btn:hover {
    background: #eecbc3;
    transform: translateX(-3px);
    box-shadow: 2px 2px 0 rgba(0,0,0,0.05);
}

.back-btn:disabled {
    background: #eee;
    color: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.back-btn .icon {
    font-size: 1.1em;
}

@media (max-width: 600px) {
    .back-btn {
        position: static;
        margin-bottom: 20px;
        display: inline-flex;
    }
}

.category-tag {
    display: inline-block;
    background: var(--accent-yellow);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: bold;
    color: #666;
    margin-bottom: 10px;
}

/* Article Content Typography */
.content h1, .content h2, .content h3 {
    color: var(--text-color);
    margin-top: 1.5em;
}

.content p {
    margin-bottom: 1.5em;
    font-size: 1em; /* Relative to base-font-size */
}

.content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    border: 4px solid var(--panel-bg);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: block;
    margin: 20px auto;
}

.content blockquote {
    border-left: 4px solid var(--accent-pink);
    margin: 20px 0;
    padding-left: 20px;
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05); /* Transparent bg */
    padding: 15px 20px;
    border-radius: 0 8px 8px 0;
    opacity: 0.9;
}

.content code {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: var(--link-color);
}

.content pre {
    background: #2d2d2d;
    color: #ccc;
    padding: 20px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 20px 0;
}

.content pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

/* Article List in Categories (Legacy fallback) */
.article-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.article-list li {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px dashed var(--panel-border);
}

.article-list li:last-child {
    border-bottom: none;
}

.article-list a {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-color);
    display: block;
    padding: 5px 0;
}

.article-list a:hover {
    color: var(--link-color);
    padding-left: 5px;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 60px;
    padding: 40px 0;
    color: #999;
    border-top: 1px solid var(--panel-border);
}

/* Responsive */
@media (max-width: 850px) {
    .header-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .top-nav {
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }

    .search-container {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    #search-input, #search-input:focus {
        width: 100%;
        max-width: 300px;
    }
}

@media (max-width: 600px) {
    .header-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .card {
        padding: 20px;
    }
    
    .post-grid {
        grid-template-columns: 1fr; /* Single column on mobile */
    }
    
    .categories-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* --- View Toggle (Grid/List) --- */
.view-toggle-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
    gap: 10px;
}

.view-toggle-btn {
    background: transparent;
    border: 1px solid var(--panel-border);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    color: var(--text-color);
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.view-toggle-btn span {
    font-size: 1.1em;
}

.view-toggle-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #555;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.view-toggle-btn:hover {
    background: var(--accent-yellow);
    border-color: var(--accent-yellow);
}

/* List View Styles */
.post-grid.view-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.post-grid.view-list .post-card {
    flex-direction: row;
    min-height: auto;
    align-items: center;
    padding: 0;
}

.post-grid.view-list .post-card-content {
    padding: 20px 25px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    width: 100%;
    text-align: left;
}

.post-grid.view-list .post-card-title {
    flex: 0 0 35%; /* Title width */
    margin-bottom: 0;
    font-size: 1.1em;
}

.post-grid.view-list .post-card-title h3 {
    font-size: 1.1em;
    margin: 0;
}

.post-grid.view-list .post-card-excerpt {
    flex: 1;
    margin-bottom: 0;
    color: #666;
    font-size: 0.9em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.post-grid.view-list .post-card-footer {
    border-top: none;
    padding-top: 0;
    flex: 0 0 auto;
    white-space: nowrap;
}

/* Mobile adjustments for List View */
@media (max-width: 768px) {
    .post-grid.view-list .post-card-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .post-grid.view-list .post-card-title {
        flex: 0 0 auto;
        width: 100%;
    }
    
    .post-grid.view-list .post-card-excerpt {
        width: 100%;
        -webkit-line-clamp: 3;
    }
    
    .post-grid.view-list .post-card-footer {
        width: 100%;
        text-align: right;
        margin-top: 5px;
    }
}


/* 1. Floating Action Button (FAB) */
.fab-menu-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--link-color);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    font-size: 24px;
    cursor: pointer;
    z-index: 2000;
    transition: transform 0.3s, background-color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-menu-btn:hover {
    transform: scale(1.1);
    background-color: #e57373;
}

/* 2. Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    right: -320px; /* Hidden by default */
    width: 300px;
    height: 100vh;
    background-color: var(--panel-bg);
    box-shadow: -4px 0 15px rgba(0,0,0,0.1);
    z-index: 1999;
    padding: 20px;
    overflow-y: auto;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--panel-text);
    border-left: 1px solid var(--panel-border);
}

.settings-panel.active {
    right: 0;
}

.settings-panel h3 {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--panel-border);
}

.setting-group {
    margin-bottom: 25px;
}

.setting-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
    font-size: 0.9em;
}

.btn-group {
    display: flex;
    gap: 10px;
}

.btn-group button {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--panel-border);
    background: transparent;
    color: var(--panel-text);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-group button.active {
    background: var(--link-color);
    color: #fff;
    border-color: var(--link-color);
}

.btn-group button:hover {
    border-color: var(--link-color);
}

input[type="range"] {
    width: 100%;
    cursor: pointer;
}

/* 3. Reading Progress Bar */
.reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 4px;
    background-color: var(--link-color);
    z-index: 2001; /* Above header */
    transition: width 0.1s;
}

/* 4. Bookmarks */
#bookmark-list {
    list-style: none;
    padding: 0;
    margin-top: 10px;
}

#bookmark-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: rgba(0,0,0,0.03);
    margin-bottom: 5px;
    border-radius: 6px;
}

#bookmark-list a {
    flex-grow: 1;
    font-size: 0.9em;
    color: var(--panel-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bm-date {
    font-size: 0.7em;
    color: #888;
}

.bm-delete {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 5px;
}

.bm-delete:hover {
    color: red;
}

#add-bookmark-btn {
    width: 100%;
    padding: 8px;
    background: var(--accent-blue);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    color: #555;
    transition: background 0.2s;
}

#add-bookmark-btn:hover {
    background: #c4d9f0;
}

/* 5. Table of Contents */
.toc-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 10px;
    background: rgba(0,0,0,0.02);
}

.toc-link {
    display: block;
    padding: 4px 0;
    font-size: 0.9em;
    color: var(--panel-text);
    text-decoration: none;
}

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

.toc-h2 {
    font-weight: bold;
}

.toc-h3 {
    padding-left: 15px;
    font-size: 0.85em;
}
