:root {
    /* Colors - Dark Theme (Default) */
    --bg-body: #121212;
    --bg-surface: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-color: #bb86fc;
    --accent-hover: #9965f4;
    --border-color: #333;
    --code-bg: #1e1e1e;

    /* Spacing */
    --container-width: 1100px;
    /* Increased for sidebar */
    --header-height: 60px;
    --spacing-unit: 1rem;
}

/* Light Theme Variables */
body.light-theme {
    --bg-body: #f5f5f5;
    --bg-surface: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --accent-color: #6200ee;
    --accent-hover: #3700b3;
    --border-color: #e0e0e0;
    --code-bg: #f8f8f8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    /* Disable mobile tap highlight */
}

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

/* Ripple Effect */
.ripple {
    position: absolute;
    border-radius: 50%;
    transform: scale(0);
    animation: ripple 0.6s linear;
    background-color: rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Ensure elements with ripple are relative and clip overflow */
.btn,
.button,
.icon-btn,
.tag,
.filter-tag,
.page-link,
.attachment-download-btn,
.post-preview,
.tag-cloud-item,
.side-post-card {
    position: relative;
    overflow: hidden;
}

/* Header */
.site-header {
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: var(--container-width);
    margin: 0 auto;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--spacing-unit);
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-accent {
    color: var(--accent-color);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

body.light-theme .icon-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Main Content */
.main-content {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 2rem var(--spacing-unit);
    min-height: calc(100vh - var(--header-height) - 60px);
}

/* Hero Section */
.hero-section {
    text-align: center;
    margin-bottom: 3rem;
}

.hero-section h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.hero-section p {
    color: var(--text-secondary);
}

/* Layout Grid */
.layout-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 900px) {
    .layout-container {
        grid-template-columns: 1fr 300px;
    }
}

/* Sidebar Widgets */
.sidebar-widget {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.sidebar-widget h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

/* Responsive Utils */
.mobile-only {
    display: block;
}

.desktop-only {
    display: none;
}

@media (min-width: 900px) {
    .mobile-only {
        display: none !important;
    }

    .desktop-only {
        display: block !important;
    }
}

/* Post List */
.post-preview {
    background-color: var(--bg-surface);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
    transition: transform 0.2s;
    cursor: pointer;
}

.post-preview:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
}

.post-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.post-preview h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.post-preview p {
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Post Page */
.post-header {
    margin-bottom: 2rem;
    text-align: center;
}

.post-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.post-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.post-date {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.tag {
    /* Base tag style, color set dynamically via CSS Var or JS */
    background-color: var(--tag-bg, rgba(187, 134, 252, 0.1));
    color: var(--tag-fg, var(--accent-color));
    border: 1px solid var(--tag-border, transparent);
    padding: 0.1rem 0.6rem;
    border-radius: 100px;
    font-size: 0.85rem;
    display: inline-block;
    transition: all 0.2s;
}

body.light-theme .tag {
    --tag-bg: rgba(98, 0, 238, 0.1);
}

/* Markdown Body */
.markdown-body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    color: var(--text-primary);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.markdown-body p {
    margin-bottom: 1.2rem;
}

.markdown-body a {
    color: var(--accent-color);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1.2rem;
    padding-left: 1.5rem;
}

.markdown-body li {
    margin-bottom: 0.4rem;
}

.markdown-body blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1rem;
    color: var(--text-secondary);
    margin: 1.5rem 0;
    background-color: rgba(187, 134, 252, 0.05);
    padding: 1rem;
    border-radius: 0 4px 4px 0;
}

body.light-theme .markdown-body blockquote {
    background-color: rgba(98, 0, 238, 0.05);
}

.markdown-body img,
.markdown-body video,
.iframe-container {
    max-width: 100%;
    border-radius: 8px;
    margin: 1.5rem 0;
    display: block;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.markdown-body code {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
}

body.light-theme .markdown-body code {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Code Blocks (Mac Style) */
.code-block-container {
    background-color: #1e1e1e !important;
    /* Always dark for code */
    border-radius: 8px;
    margin: 1.5rem 0;
    overflow: hidden;
    border: 1px solid #333;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: #252526;
    border-bottom: 1px solid #333;
}

.mac-buttons {
    display: flex;
    gap: 6px;
}

.mac-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.mac-btn.red {
    background-color: #ff5f56;
}

.mac-btn.yellow {
    background-color: #ffbd2e;
}

.mac-btn.green {
    background-color: #27c93f;
}

.code-lang {
    font-family: sans-serif;
    font-size: 0.8rem;
    color: #888;
    text-transform: uppercase;
}

.code-block-container pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
}

.code-block-container code {
    background-color: transparent !important;
    padding: 0;
    color: #d4d4d4;
}

.copy-code-btn {
    background: transparent;
    border: 1px solid #444;
    color: #ccc;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.copy-code-btn:hover {
    background: #333;
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

/* Responsive */
@media (max-width: 600px) {
    .post-title {
        font-size: 1.6rem;
    }

    .header-container {
        padding: 0 1rem;
    }

    .main-content {
        padding: 1.5rem 1rem;
    }
}

/* Alerts / Callouts */
.alert {
    border-left: 4px solid;
    padding: 1rem;
    margin: 1.5rem 0;
    border-radius: 0 8px 8px 0;
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.alert-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-transform: capitalize;
}

.alert-icon {
    font-size: 1.2rem;
}

.alert-content p {
    margin-bottom: 0;
}

/* Alert Colors */
.alert-note {
    border-color: #2196f3;
    background-color: rgba(33, 150, 243, 0.1);
}

.alert-note .alert-title {
    color: #2196f3;
}

.alert-tip {
    border-color: #00c853;
    background-color: rgba(0, 200, 83, 0.1);
}

.alert-tip .alert-title {
    color: #00c853;
}

.alert-important {
    border-color: #9c27b0;
    background-color: rgba(156, 39, 176, 0.1);
}

.alert-important .alert-title {
    color: #9c27b0;
}

.alert-warning {
    border-color: #ff9800;
    background-color: rgba(255, 152, 0, 0.1);
}

.alert-warning .alert-title {
    color: #ff9800;
}

.alert-caution {
    border-color: #f44336;
    background-color: rgba(244, 67, 54, 0.1);
}

.alert-caution .alert-title {
    color: #f44336;
}


/* --- Search & Filters --- */
.search-container {
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.05);
    /* Light translucent bg */
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 0.5rem 1rem;
    transition: border-color 0.2s, background-color 0.2s;
}

.search-container:focus-within {
    border-color: var(--accent-color);
    background-color: rgba(255, 255, 255, 0.1);
}

.search-icon {
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

#search-input,
#search-input-mobile {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    font-family: inherit;
    min-width: 0;
    /* Fix flex overflow */
}

input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 2rem;
}

.filter-tag {
    /* Uses new color logic */
    color: white;
    /* Always white text for contrast on colored bg */
    padding: 0.3rem 0.8rem;
    border-radius: 100px;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: opacity 0.2s;
    /* background-color set via JS */
}

.filter-tag:hover {
    opacity: 0.9;
}

.filter-remove {
    font-size: 1rem;
    font-weight: 700;
}

/* --- Pagination --- */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 3rem;
    margin-bottom: 3rem;
}

.page-link,
.page-current {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s;
}

.page-link {
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
}

.page-link:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.page-current {
    background-color: var(--accent-color);
    color: white;
    cursor: default;
}

/* --- Archives & Tags Sections --- */
.archives-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.archive-year-group {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.archive-year-group:last-child {
    border-bottom: none;
}

.archive-year-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--accent-color);
    display: block;
    text-decoration: none;
}

.archive-year-title:hover {
    text-decoration: underline;
}

.archive-months {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.archive-month-link {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.archive-month-link:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag-cloud-item {
    font-size: 0.85rem;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    background-color: var(--bg-body);
    /* color/border set dynamically via JS usually, or fallback */
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
}

/* Hover effects for tags will likely need JS override or specific specificity */
.tag-cloud-item:hover {
    opacity: 0.8;
}

/* --- Sidebar & Post List Additions --- */
.section-divider {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 3rem 0;
}

.related-posts-section,
.new-posts-section {
    margin-bottom: 3rem;
}

.related-posts-section h3,
.new-posts-section h3 {
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--accent-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.side-post-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.side-post-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: var(--text-primary);
    height: 100%;
}

.side-post-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
}

.side-post-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.side-post-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* Social Share Buttons */
.share-buttons {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.share-label {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.share-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    color: white;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: opacity 0.2s;
}

.share-btn:hover {
    opacity: 0.8;
}

.share-btn-twitter {
    background-color: #000000;
    border: 1px solid #333;
}

.share-btn-facebook {
    background-color: #1877f2;
}

.share-btn-line {
    background-color: #06c755;
}

body.light-theme .share-btn-twitter {
    background-color: #000000;
    color: white;
}