/* ============================================================
   Microblog – Minimalist Stylesheet
   ============================================================ */

/* ── Reset & Base ──────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    color: #222;
    background: #fafafa;
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: #222;
    text-decoration: none;
}

a:hover {
    color: #555;
}

img {
    display: block;
    max-width: 100%;
    height: auto;
}

/* ── Layout ────────────────────────────────────────────── */
.container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 0 20px;
}

.container-wide {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
}

.main-layout {
    display: flex;
    gap: 40px;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
}

.posts-container {
    flex: 1;
    max-width: 600px;
}

/* ── Header ────────────────────────────────────────────── */
.site-header {
    border-bottom: 1px solid #eee;
    padding: 28px 0;
}

.site-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.site-header h1 a {
    color: #111;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-row nav a {
    margin-left: 18px;
    font-size: 0.9rem;
    color: #666;
}

.header-row nav a:hover {
    color: #111;
}

/* ── Posts ──────────────────────────────────────────────── */
.post {
    padding: 28px 0;
    border-bottom: 1px solid #eee;
    scroll-margin-top: 20px;
    transition: background-color 0.3s ease;
}

.post.highlight-post {
    background-color: #fffde7;
    margin: 0 -20px;
    padding-left: 20px;
    padding-right: 20px;
    border-radius: 8px;
}

.post-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #eee;
}

.post-header .post-time {
    margin: 0;
    font-size: 0.85rem;
    color: #888;
}

.post-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: #888;
    padding: 4px 10px;
    background: #f5f5f5;
    border-radius: 4px;
    transition: all 0.15s;
    text-decoration: none;
}

.post-link:hover {
    color: #6366f1;
    background: #eef2ff;
}

.link-icon {
    font-size: 0.9rem;
    font-weight: 600;
}

.post-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
}

.permalink {
    font-size: 0.85rem;
    color: #aaa;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}

.permalink:hover {
    color: #666;
    background: #f0f0f0;
}

.share-btn {
    font-size: 0.85rem;
    color: #555;
    background: #f5f5f5;
    border: 1px solid #ddd;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.share-btn:hover {
    background: #e8e8e8;
    border-color: #ccc;
}

.single-post {
    padding-top: 20px;
}

.post-content {
    font-size: 1rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-word;
}

.post-image {
    margin-top: 16px;
}

.post-image img {
    border-radius: 8px;
}

.post-time {
    display: block;
    margin-top: 12px;
    font-size: 0.8rem;
    color: #999;
}

.post-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
}

.delete-link {
    font-size: 0.8rem;
    color: #c00;
}

.delete-link:hover {
    color: #900;
}

.edit-link {
    font-size: 0.8rem;
    color: #0066cc;
}

.edit-link:hover {
    color: #004499;
}

.post-actions {
    display: flex;
    gap: 12px;
}

.current-image {
    margin: 12px 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: #666;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* ── Pagination ────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 32px 0;
}

.page-link {
    font-size: 0.9rem;
    color: #444;
    padding: 6px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    transition: background 0.15s;
}

.page-link:hover {
    background: #f0f0f0;
    color: #111;
}

.page-info {
    font-size: 0.85rem;
    color: #999;
}

/* ── Login ─────────────────────────────────────────────── */
.login-box {
    max-width: 360px;
    margin: 60px auto;
}

.login-box h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 24px;
}

/* ── Forms ─────────────────────────────────────────────── */
label {
    display: block;
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 6px;
    margin-top: 16px;
}

input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.95rem;
    font-family: inherit;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    color: #222;
    outline: none;
    transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    border-color: #aaa;
}

textarea {
    resize: vertical;
    min-height: 100px;
}

input[type="file"] {
    font-size: 0.9rem;
    color: #555;
}

.btn {
    display: inline-block;
    margin-top: 20px;
    padding: 10px 28px;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    color: #fff;
    background: #222;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn:hover {
    background: #444;
}

/* ── Messages ──────────────────────────────────────────── */
.error-msg {
    color: #c00;
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.success-msg {
    color: #0a7e3c;
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 60px 0;
    font-size: 0.95rem;
}

/* ── Post Form (Admin) ─────────────────────────────────── */
.post-form {
    margin-bottom: 32px;
}

hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 32px 0;
}

h2 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 8px;
    margin-top: 24px;
}

/* ── Footer ────────────────────────────────────────────── */
.site-footer {
    margin-top: auto;
    padding: 24px 0;
    text-align: center;
    font-size: 0.8rem;
    color: #bbb;
    border-top: 1px solid #eee;
}

/* ── Editor Toolbar ────────────────────────────────────── */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    margin-top: 8px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: 0.85rem;
    font-family: inherit;
    color: #444;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.toolbar-btn:hover {
    background: #e8e8e8;
    border-color: #ccc;
}

.toolbar-btn.active {
    background: #222;
    color: #fff;
    border-color: #222;
}

.toolbar-btn code {
    font-family: monospace;
    font-size: 0.75rem;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: #ddd;
    margin: 0 6px;
}

.post-form textarea {
    border-radius: 0 0 6px 6px;
}

/* ── Preview Area ──────────────────────────────────────── */
.content-preview {
    margin-top: 12px;
    padding: 16px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
}

.preview-label {
    font-size: 0.75rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.preview-content {
    font-size: 1rem;
    line-height: 1.8;
    word-break: break-word;
}

/* ── Rich Text Styles ──────────────────────────────────── */
.post-content strong {
    font-weight: 600;
}

.post-content em {
    font-style: italic;
}

.post-content del {
    text-decoration: line-through;
    color: #888;
}

.post-content code {
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: 0.9em;
    padding: 2px 6px;
    background: #f0f0f0;
    border-radius: 4px;
    color: #c7254e;
}

.preview-content strong {
    font-weight: 600;
}

.preview-content em {
    font-style: italic;
}

.preview-content del {
    text-decoration: line-through;
    color: #888;
}

.preview-content code {
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: 0.9em;
    padding: 2px 6px;
    background: #f0f0f0;
    border-radius: 4px;
    color: #c7254e;
}

/* ── KaTeX Styles ──────────────────────────────────────── */
.katex-block {
    display: block;
    margin: 16px 0;
    text-align: center;
    overflow-x: auto;
}

.katex-inline {
    display: inline;
}

.katex-error {
    color: #c00;
    font-size: 0.85rem;
    font-style: italic;
}

/* Adjust KaTeX font size */
.katex {
    font-size: 1.1em;
}

/* ── Code Block Styles (Luogu/Codeforces Style) ───────── */
.code-block {
    margin: 16px 0;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    overflow: hidden;
    background: #f6f8fa;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #e9ecef;
    border-bottom: 1px solid #e1e4e8;
}

.code-lang {
    font-size: 0.75rem;
    font-weight: 600;
    color: #586069;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.copy-btn {
    font-size: 0.75rem;
    padding: 4px 10px;
    color: #444;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.copy-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.code-block pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    background: #f6f8fa;
}

.code-block code {
    font-family: "JetBrains Mono", "SF Mono", Monaco, "Cascadia Code", "Consolas", monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    tab-size: 4;
}

/* Inline code */
.inline-code {
    font-family: "JetBrains Mono", "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: 0.9em;
    padding: 2px 6px;
    background: #f0f0f0;
    border-radius: 4px;
    color: #c7254e;
}

.post-content code.inline-code,
.preview-content code.inline-code {
    font-family: "JetBrains Mono", "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: 0.9em;
    padding: 2px 6px;
    background: #f0f0f0;
    border-radius: 4px;
    color: #c7254e;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }
    
    .tags-sidebar {
        order: -1;
        position: static;
        width: 100%;
        border-left: none;
        padding-left: 0;
        margin-bottom: 24px;
    }
    
    .tag-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .tag-list li {
        margin-bottom: 0;
    }
}

@media (max-width: 640px) {
    .container,
    .container-wide,
    .main-layout {
        padding: 0 16px;
    }

    .site-header {
        padding: 20px 0;
    }

    .post {
        padding: 22px 0;
    }

    .login-box {
        margin: 40px auto;
    }
    
    .editor-toolbar {
        flex-wrap: wrap;
    }
    
    .toolbar-btn {
        min-width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }
}

/* ── Tags Sidebar ──────────────────────────────────────── */
.tags-sidebar {
    width: 200px;
    flex-shrink: 0;
    padding-left: 20px;
    border-left: 1px solid #eee;
    margin-top: 28px;
}

.tags-sidebar h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tag-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tag-list li {
    margin-bottom: 6px;
}

.tag-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 0.85rem;
    color: #555;
    background: #f5f5f5;
    border-radius: 4px;
    transition: all 0.15s;
}

.tag-list a:hover {
    background: #e8e8e8;
    color: #222;
}

.tag-list a.active {
    background: #222;
    color: #fff;
}

.tag-count {
    font-size: 0.75rem;
    color: #888;
    background: #fff;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.tag-list a.active .tag-count {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* ── Post Tags ─────────────────────────────────────────── */
.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.tag {
    display: inline-block;
    font-size: 0.75rem;
    padding: 3px 10px;
    background: #e9f0f5;
    color: #3a6d8c;
    border-radius: 12px;
    transition: all 0.15s;
}

a.tag:hover {
    background: #d0e3f0;
    color: #2a5570;
}

/* ── Tag Filter Notice ─────────────────────────────────── */
.tag-filter-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f0f7ff;
    border: 1px solid #d0e3f0;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.clear-filter {
    font-size: 0.85rem;
    color: #c00;
    padding: 4px 10px;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.clear-filter:hover {
    background: #fee;
    border-color: #c00;
}
