/* ===== Variables ===== */
:root {
    --bg: #ffffff;
    --bg-secondary: #f9fafb;
    --text: #111827;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --card-bg: #ffffff;
    --card-hover: #f3f4f6;
    --header-bg: #ffffff;
    --tab-active-bg: #111827;
    --tab-active-color: #ffffff;
    --tab-bg: transparent;
    --tab-color: #6b7280;
    --link: #2563eb;
    --code-bg: #f3f4f6;
    --blockquote-border: #e5e7eb;
    --blockquote-bg: #f9fafb;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-secondary: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --card-bg: #1e293b;
    --card-hover: #334155;
    --header-bg: #0f172a;
    --tab-active-bg: #f1f5f9;
    --tab-active-color: #0f172a;
    --tab-bg: transparent;
    --tab-color: #94a3b8;
    --link: #60a5fa;
    --code-bg: #1e293b;
    --blockquote-border: #334155;
    --blockquote-bg: #1e293b;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.2s, color 0.2s;
}

/* ===== Home Header ===== */
.home-header {
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    position: sticky;
    top: 0;
    z-index: 100;
}
.home-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.home-logo {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 0;
}
.logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #374151;
    font-size: 14px;
    font-weight: 700;
    margin-right: 8px;
    flex-shrink: 0;
    font-family: "Georgia", serif;
    letter-spacing: 0;
}
[data-theme="dark"] .logo-mark {
    background: #374151;
    color: #d1d5db;
}
.logo-mark.sm {
    width: 22px;
    height: 22px;
    font-size: 12px;
    border-radius: 50%;
    margin-right: 6px;
}
.home-tagline {
    color: var(--text-secondary);
    font-size: 14px;
    margin-left: 16px;
}

/* ===== Tabs ===== */
.tabs-wrapper {
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    position: sticky;
    top: 65px;
    z-index: 99;
}
.tabs {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab {
    padding: 10px 16px;
    border: none;
    background: var(--tab-bg);
    color: var(--tab-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    white-space: nowrap;
    transition: all 0.15s;
}
.tab:hover {
    color: var(--text);
    background: var(--bg-secondary);
}
.tab.active {
    background: var(--tab-active-bg);
    color: var(--tab-active-color);
}

/* ===== Cards ===== */
.cards-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}
.cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    max-width: 640px;
}
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
}
.card:hover {
    background: var(--card-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
[data-theme="dark"] .card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.card-cat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.cat-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
[data-theme="dark"] .cat-pill {
    opacity: 0.9;
}
.cat-pill.small {
    padding: 1px 8px;
    font-size: 11px;
}
.card-date {
    font-size: 13px;
    color: var(--text-secondary);
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 8px;
    word-break: break-word;
    overflow-wrap: break-word;
}
.card-excerpt {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.no-articles {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* ===== Article View ===== */
.article-header {
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    position: sticky;
    top: 0;
    z-index: 100;
}
.article-header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    position: relative;
    justify-content: space-between;
}
.btn-back {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
}
.btn-back:hover {
    background: var(--bg-secondary);
}
.reader-logo {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: color 0.15s;
}
.btn-icon:hover {
    color: var(--text);
}

/* Article content layout */
.article-content-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 40px;
    padding: 0 24px;
}
.article-content {
    flex: 1;
    min-width: 0;
    max-width: 800px;
    padding: 32px 0 60px;
}

/* Article meta */
.article-meta {
    margin-bottom: 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.meta-date {
    color: var(--text-secondary);
    font-size: 14px;
}
.article-title {
    width: 100%;
    font-size: 28px;
    font-weight: 700;
    line-height: 1.3;
    margin-top: 8px;
}

/* ===== Reader (Markdown) ===== */
.reader {
    font-size: 16px;
    line-height: 1.75;
}
.reader h1 { font-size: 26px; font-weight: 700; margin: 32px 0 16px; }
.reader h2 { font-size: 22px; font-weight: 600; margin: 28px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.reader h3 { font-size: 18px; font-weight: 600; margin: 24px 0 10px; }
.reader p { margin: 12px 0; }
.reader ul, .reader ol { margin: 12px 0; padding-left: 24px; }
.reader li { margin: 4px 0; }
.reader a { color: var(--link); text-decoration: none; }
.reader a:hover { text-decoration: underline; }
.reader img { max-width: 100%; border-radius: 8px; margin: 16px 0; }
.reader code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}
.reader pre {
    background: var(--code-bg);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 16px 0;
}
.reader pre code {
    background: none;
    padding: 0;
    font-size: 14px;
}
.reader blockquote {
    border-left: 3px solid var(--blockquote-border);
    background: var(--blockquote-bg);
    padding: 12px 16px;
    margin: 16px 0;
    border-radius: 0 8px 8px 0;
}
.reader table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}
.reader th, .reader td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.reader th {
    background: var(--bg-secondary);
    font-weight: 600;
}

/* ===== TOC ===== */
.toc {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 60px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    padding-top: 32px;
}
.toc-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
#toc-nav a {
    display: block;
    padding: 4px 0;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    line-height: 1.4;
    transition: color 0.15s;
}
#toc-nav a:hover,
#toc-nav a.active {
    color: var(--text);
}
#toc-nav a.toc-h3 {
    padding-left: 12px;
}

/* Article footer */
.article-footer {
    margin-top: 40px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    color: var(--text-secondary);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .toc { display: none; }
    .article-content-wrapper { padding: 0 16px; }
}
@media (max-width: 640px) {
    .home-header-inner { padding: 16px; }
    .home-logo { font-size: 20px; }
    .home-tagline { display: none; }
    .tabs { padding: 0 16px; }
    .cards-container { padding: 12px; }
    .card { padding: 16px; }
    .article-header-inner { padding: 10px 16px; }
    .article-content { padding: 20px 0 40px; }
    .article-title { font-size: 24px; }
    .reader { font-size: 15px; }
    .reader-logo { display: none; }
}

/* ===== Font Size Control ===== */
.reader.font-small { font-size: 14px; }
.reader.font-medium { font-size: 16px; }
.reader.font-large { font-size: 18px; }
.reader.font-xlarge { font-size: 20px; }

.reader.font-small h1 { font-size: 24px; }
.reader.font-small h2 { font-size: 20px; }
.reader.font-small h3 { font-size: 16px; }

.reader.font-large h1 { font-size: 28px; }
.reader.font-large h2 { font-size: 24px; }
.reader.font-large h3 { font-size: 20px; }
.reader.font-large p, .reader.font-large li { line-height: 1.8; }

.reader.font-xlarge h1 { font-size: 30px; }
.reader.font-xlarge h2 { font-size: 26px; }
.reader.font-xlarge h3 { font-size: 22px; }
.reader.font-xlarge p, .reader.font-xlarge li { line-height: 1.85; }

.font-size-label {
    font-size: 11px;
    color: var(--text-secondary);
    pointer-events: none;
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}
.btn-icon-wrap { position: relative; display: inline-flex; }
.btn-icon-wrap:hover .font-size-label { opacity: 1; }

.article-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===== Card Stats ===== */
.card-stats {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}
.stat-item svg {
    width: 14px;
    height: 14px;
}

/* ===== Article Actions ===== */
.article-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 24px 0;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.article-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-right: auto;
}
.article-stats .stat-item { gap: 5px; }
.article-stats .stat-item svg { width: 15px; height: 15px; }
.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.action-btn:hover {
    color: var(--text);
    border-color: var(--text-secondary);
}
.action-btn svg { width: 16px; height: 16px; }
.action-btn.like-btn:hover:not(.liked) {
    color: #ef4444;
    border-color: #ef4444;
}
.action-btn.liked {
    background: #fef2f2;
    border-color: #ef4444;
    color: #ef4444;
    cursor: default;
}
[data-theme="dark"] .action-btn.liked {
    background: #451a1a;
}
.action-btn.share-btn:hover {
    color: #3b82f6;
    border-color: #3b82f6;
}

/* ===== Comments ===== */
.comments-section {
    margin-top: 40px;
    padding-top: 28px;
    border-top: 2px solid var(--border);
}
.comments-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}
.comment-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
}
.comment-form input,
.comment-form textarea {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    resize: vertical;
}
.comment-form input:focus,
.comment-form textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.comment-form-footer {
    display: flex;
    justify-content: flex-end;
}
.comment-submit {
    padding: 8px 20px;
    background: var(--tab-active-bg);
    color: var(--tab-active-color);
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}
.comment-submit:hover { opacity: 0.85; }
.comment-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.comments-list { }
.comment-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.comment-item:last-child { border-bottom: none; }
.comment-item.new-anim {
    animation: fadeSlide 0.3s ease;
}
@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}
.comment-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.comment-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.comment-nick {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.comment-time {
    font-size: 12px;
    color: var(--text-secondary);
}
.comment-body {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    padding-left: 38px;
    white-space: pre-wrap;
    word-break: break-word;
}
.no-comments {
    text-align: center;
    padding: 24px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: var(--tab-active-bg);
    color: var(--tab-active-color);
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 13px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
