/* ==========================================================================
   1. Root Variables & Base Styles
   ========================================================================== */

:root {
    --text-primary: #2c2c2c;
    --text-secondary: #666666;
    --accent: #ff6b6b;
    --accent-dark: #b90a00;
    --background: #fffef9;
    --surface: #ffffff;
    --border-light: #f0f0f0;
    --shadow-light: rgba(0, 0, 0, 0.05);
    --shadow-medium: rgba(0, 0, 0, 0.1);
    --gradient-warm: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
}

/* --- Dark Mode Variables --- */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #e8e8e8;
        --text-secondary: #b8b8b8;
        --background: #1a1a1a;
        --surface: #2a2a2a;
        --border-light: #3a3a3a;
        --shadow-light: rgba(0, 0, 0, 0.3);
        --shadow-medium: rgba(0, 0, 0, 0.5);
    }
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.8;
    color: var(--text-primary);
    background: var(--background);
    font-weight: 400;
}

/* ==========================================================================
   2. Decorative Elements & Overall Layout
   ========================================================================== */

/* Hide unwanted decorative elements for this theme */
.corner,
.window,
.statusbar {
    display: none;
}

.wrapper {
    max-width: 60vw;
    margin: 0 auto;
    padding: 6rem 2rem;
    min-height: 100vh;
}

/* Style for dynamically loaded markdown pages */
#content:not(:has(.page-main)) {
    padding-top: 2rem;
}

.separator {
    border: none;
    height: 1px;
    background: var(--border-light);
    margin: 4rem 0;
    position: relative;
}

.separator::after {
    content: '✦';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--background);
    color: var(--accent);
    padding: 0 1rem;
    font-size: 1.2rem;
}

/* ==========================================================================
   3. Controls, Navigation & Progress Bar
   ========================================================================== */

.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: var(--gradient-warm);
    z-index: 1002;
    transition: width 0.1s ease;
}

.controls {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.button,
.dropdown-trigger {
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border-light);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px var(--shadow-light);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 600;
}

.button:hover,
.dropdown-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-medium);
    border-color: var(--accent);
}

.dropdown {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 5px);
    min-width: 160px;
    background: var(--surface);
    box-shadow: 0 8px 16px var(--shadow-medium);
    padding: 8px;
    z-index: 1;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    margin-top: 0.1rem;
    overflow: auto;
    max-height: 400px;
}

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

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.dropdown-item:hover {
    background-color: var(--border-light);
}

/* ==========================================================================
   4. Main Page: Header, Categories & Grid
   ========================================================================== */

.header {
    text-align: center;
    margin-bottom: 2rem;
}

.title-main {
    font-size: 3.5rem;
    font-weight: 200;
    margin-bottom: 1rem;
    position: relative;
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin: 0;
}

.header-decoration-top, .header-decoration-bottom {
    display: none; /* Replaced by separator style */
}

.category {
    margin-top: 3rem;
}

.title-category {
    font-size: 1.8rem;
    font-weight: 300;
    margin-bottom: 2rem;
    padding-left: 1.5rem;
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.title-category .title-count {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

.title-category::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

.category-infographics a {
    text-decoration: none;
    color: inherit;
}
.category-infographics a:hover .title-text {
    color: var(--accent);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

/* ==========================================================================
   5. Main Page: Blog Card
   ========================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--shadow-light);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(255, 107, 107, 0.15);
}

.card-decoration {
    display: none; /* Not used in this theme */
}

.card-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

.card-path {
    font-size: 0.8rem;
    font-family: 'SF Mono', 'Monaco', monospace;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.card-meta {
    margin-top: auto;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.card-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

.button-read {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-dark);
    background: var(--accent-light);
    border: none;
}

.button-read:hover {
    background: var(--accent);
    color: var(--surface);
}

/* ==========================================================================
   6. Main Page: Footer & Messages
   ========================================================================== */

.footer {
    text-align: center;
    margin-top: 2rem;
    color: var(--text-secondary);
}

.message {
    text-align: center;
    padding: 3rem;
    font-style: italic;
    color: var(--text-secondary);
    border-radius: 8px;
}

.message-error {
    color: #dc3545;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
}

/* ==========================================================================
   7. Content Page (from Markdown) Typography & Elements
   ========================================================================== */

#content h1 {
    font-size: 3rem;
    margin: 0 0 3rem 0;
    position: relative;
    font-weight: 200;
    text-align: left;
}

#content h1:first-child {
    text-align: center;
}

#content h1::after {
    content: '';
    position: absolute;
    bottom: -1rem;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: var(--gradient-warm);
    border-radius: 2px;
}
#content h1:not(:first-child)::after {
    left: 0;
    transform: none;
}

#content h2 {
    font-size: 1.8rem;
    margin: 4rem 0 2rem 0;
    position: relative;
    padding-left: 1.5rem;
}

#content h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

#content h3 { font-size: 1.4rem; margin: 3rem 0 1.5rem 0; color: var(--text-secondary); }
#content h4, #content h5, #content h6 { font-size: 1.1rem; margin: 2rem 0 1rem 0; color: var(--text-secondary); text-transform: uppercase; }

#content p { margin: 2rem 0; font-size: 1rem; line-height: 1.9; }

#content a {
    color: var(--accent);
    text-decoration: none;
    position: relative;
    transition: all 0.3s ease;
    font-weight: 500;
}

#content a:hover { color: var(--accent-dark); }
#content a::after { content: ''; position: absolute; width: 0; height: 2px; bottom: -2px; left: 50%; background: var(--accent); transition: all 0.3s ease; transform: translateX(-50%); }
#content a:hover::after { width: 100%; }

#content ul, #content ol { margin: 2.5rem 0; padding-left: 1rem; }
#content li { margin: 1rem 0; position: relative; padding-left: 2rem; list-style: none; }
#content ul li::before { content: ''; position: absolute; left: 0; top: 0.7em; width: 8px; height: 8px; background: var(--accent); border-radius: 50%; transform: translateY(-50%); }

#content blockquote {
    margin: 3rem 0;
    padding: 2rem;
    background: linear-gradient(135deg, #f8f9ff 0%, #fff8f8 100%);
    border-radius: 12px;
    position: relative;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--text-secondary);
    border-left: 4px solid var(--accent);
}

#content code { background: #ffe0e0; color: var(--accent-dark); padding: 0.3rem 0.6rem; border-radius: 6px; font-family: 'SF Mono', 'Monaco', monospace; font-size: 0.85rem; }
#content pre { background: #2a2a2a; color: #f0f0f0; padding: 2rem; border-radius: 12px; overflow-x: auto; margin: 3rem 0; box-shadow: 0 8px 32px var(--shadow-medium); }
#content pre code { background: transparent; color: inherit; padding: 0; }

#content table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 3rem 0; background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: 0 4px 20px var(--shadow-light); }
#content th, #content td { padding: 1rem 1.5rem; text-align: left; border-bottom: 1px solid var(--border-light); }
#content th { background: #fafafa; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
#content tr:last-child td { border-bottom: none; }

#content img {
    max-width: 100%;
    height: auto;
    border-radius: 16px;
    margin: 3rem auto;
    display: block;
    box-shadow: 0 12px 40px var(--shadow-light);
    transition: all 0.4s ease;
    cursor: pointer;
}

#content img:hover { transform: translateY(-4px); box-shadow: 0 20px 60px var(--shadow-medium); }

/* ==========================================================================
   8. Image Modal
   ========================================================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.modal.modal-open {
    display: flex;
}

.modal-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
}

@media (prefers-color-scheme: dark) {
    .modal-overlay {
        background: rgba(0, 0, 0, 0.9);
    }
}

.modal-container {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    z-index: 1;
    text-align: center;
}

.modal-content .image {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 16px;
    box-shadow: 0 24px 80px var(--shadow-medium);
}

.modal-close {
    position: absolute;
    top: -45px;
    right: -15px;
    background: var(--surface);
    border: none;
    color: var(--text-primary);
    font-size: 2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px var(--shadow-light);
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.1);
}

.modal-content .image-caption {
    color: var(--text-secondary);
    margin-top: 1rem;
    font-style: italic;
}

.spinner {
    border: 4px solid var(--border-light);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: auto;
}

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


/* ==========================================================================
   9. Responsive Design
   ========================================================================== */
@media (max-width: 1024px) {
    .wrapper { max-width: 85vw; }
}

@media (max-width: 768px) {
    .wrapper { max-width: 95vw; padding: 4rem 1.5rem; }
    #content h1, .title-main { font-size: 2.5rem; }
    .grid { grid-template-columns: 1fr; }
}