:root {
    --bg: #fbf5ee; /* parchment */
    --surface: #fffaf3;
    --ink: #4b2e18; /* dark brown */
    --muted: #7a5a43;
    --accent: #d9762a; /* burnt orange */
    --accent-2: #ffb86b;
    --card: #fffdf8;
    --border: rgba(75,46,24,0.08);
    --shadow: 0 8px 30px rgba(75,46,24,0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Merriweather", "Noto Serif SC", "Times New Roman", serif;
}

body {
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 6vw 80px;
}

.site-header {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 6vw 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-mark {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: linear-gradient(135deg,var(--accent),var(--accent-2));
    display: inline-grid;
    place-items: center;
    box-shadow: var(--shadow);
}

.brand-mark[src] {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: cover;
}

.brand h1 {
    font-size: 1.8rem;
    margin-bottom: 4px;
}

.brand p {
    color: var(--muted);
}

.site-nav {
    display: flex;
    gap: 20px;
}

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

.admin-link {
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
}

/* Dark theme overrides when body has .dark */
body.dark {
    --bg: #17120f;
    --surface: #1b1613;
    --ink: #f6efe8;
    --muted: #cdbdae;
    --accent: #ff9a3c;
    --accent-2: #ffcf9a;
    --card: #161213;
    --border: rgba(255,255,255,0.04);
    background: #0f0d0c;
}

/* Ensure key blocks use card color and readable text in dark mode */
body.dark .hero-card,
body.dark .post-card,
body.dark .work-card,
body.dark .about,
body.dark .saved-content,
body.dark .contact {
    background: var(--card);
    color: var(--ink);
    border-color: var(--border);
}

body.dark .hero-card .meta,
body.dark .post-meta,
body.dark .saved-header,
body.dark .small,
body.dark .brand p,
body.dark .search-box .hint {
    color: var(--muted);
}

body.dark .site-nav a { color: var(--muted); }
body.dark .work-card .thumb { background: rgba(255,255,255,0.02); }

/* Make buttons clear in dark mode */
body.dark .button { color: #061225; }
body.dark .button.ghost { color: var(--accent); border-color: rgba(255,255,255,0.06); }

/* Mobile / header adjustments */
@media (max-width: 720px) {
    .site-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .site-header .brand { order: 1; display:flex; justify-content:space-between; width:100%; }
    .site-header .header-actions { order: 2; width:100%; display:flex; justify-content:flex-end; }
    .site-header .site-nav { order: 3; width:100%; display:flex; flex-wrap:wrap; gap:8px; }

    .hero { grid-template-columns: 1fr; }
    .hero-card .meta { flex-direction: column; gap:6px; }

    .post-grid { grid-template-columns: 1fr; }
    .works-grid { grid-template-columns: 1fr; }

    .work-actions { display:flex; gap:8px; width:100%; }
    .work-actions .button { flex:1; }
}

/* Smooth theme transition */
* {
    transition: background-color 220ms ease, color 220ms ease, border-color 220ms ease;
}

.site-nav a {
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    padding: 6px 10px;
}

.site-nav a:hover {
    color: var(--accent);
}

.hero {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 32px;
    margin: 32px 0 40px;
    align-items: center;
}

.hero-text h2 {
    font-size: clamp(2rem, 3vw, 2.8rem);
    margin-bottom: 16px;
}

.hero-text p {
    color: var(--muted);
    line-height: 1.8;
}

.hero-actions {
    margin-top: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.hero-card {
    background: var(--card);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.hero-card h3 {
    margin-bottom: 10px;
}

.hero-card .meta {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Ensure long titles/excerpts wrap on small screens */
.hero-card h3,
.hero-card p,
.post-card h3,
.post-card p {
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 0 24px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.chip {
    border: 1px solid transparent;
    background: transparent;
    border-radius: 999px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--muted);
}

.chip.active {
    background: linear-gradient(90deg, rgba(217,118,42,0.12), rgba(255,184,107,0.06));
    color: var(--ink);
    font-weight: 700;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 16px;
}

.search-box input {
    border: none;
    outline: none;
    font-size: 0.9rem;
    background: transparent;
}

.search-box .hint {
    font-size: 0.8rem;
    color: var(--muted);
}

.post-grid {
    margin-top: 28px;
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.post-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 16px;
    min-height: 200px;
}

.post-card h3 {
    margin-bottom: 8px;
}

.post-card p {
    color: var(--muted);
    line-height: 1.6;
}

.post-meta {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.85rem;
}

.save-btn {
    align-self: flex-start;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--accent);
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
}

.button {
    border: none;
    background: var(--accent);
    color: #fff;
    padding: 10px 20px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
}

.button.ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.about {
    margin: 48px 0 24px;
    padding: 24px;
    background: var(--card);
    border-radius: 20px;
    border: 1px solid var(--border);
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.about p {
    color: var(--muted);
    line-height: 1.7;
}

.about ul {
    list-style: none;
    display: grid;
    gap: 8px;
    color: var(--muted);
}

.newsletter {
    margin-top: 24px;
    padding: 18px;
    background: linear-gradient(90deg, rgba(217,118,42,0.06), rgba(255,184,107,0.03));
    border-radius: 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.newsletter-form {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.newsletter-form input {
    border-radius: 999px;
    border: 1px solid var(--border);
    padding: 10px 16px;
    min-width: 220px;
}

/* Contact form styles */
.contact {
    margin-top: 24px;
    padding: 24px;
    background: linear-gradient(180deg, rgba(79,125,93,0.04), transparent);
    border-radius: 16px;
    border: 1px solid var(--border);
}

.contact-form {
    display: grid;
    gap: 12px;
    margin-top: 12px;
}

.contact-form input,
.contact-form textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    resize: vertical;
}

.contact-form button {
    width: fit-content;
}

.form-success {
    font-size: 0.95rem;
    color: var(--accent);
    margin-top: 8px;
}

footer {
    text-align: center;
    padding: 32px 6vw 40px;
    color: var(--muted);
}

.saved-panel {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.saved-panel.active {
    display: flex;
}

.saved-content {
    background: var(--card);
    border-radius: 12px;
    padding: 18px;
    width: min(680px, 96%);
    box-shadow: var(--shadow);
}

.saved-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.saved-content ul {
    list-style: none;
    display: grid;
    gap: 12px;
    color: var(--muted);
}

/* Works grid */
.works {
    margin-top: 28px;
}

.works-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 12px;
}

.work-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.01), rgba(255,255,255,0.005));
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}

.work-card .thumb {
    width: 100%;
    height: 120px;
    border-radius: 8px;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.02);
}

.work-card .thumb img {
    width: 64px;
    height: 64px;
}

.work-actions {
    margin-top: 6px;
}

/* Work modal */
.work-modal {
    position: fixed;
    inset: 0;
    background: rgba(2,6,23,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.work-modal.active { display: flex; }

.work-modal .modal-content {
    width: min(900px, 98%);
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
    border-radius: 12px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.work-modal .modal-body { margin-top: 12px; color: var(--muted); }

.close-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

@media (max-width: 720px) {
    .site-header {
        flex-direction: column;
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .site-nav {
        flex-wrap: wrap;
    }

    .search-box {
        width: 100%;
        justify-content: space-between;
    }
}

/* 更细粒度的手机适配 */
@media (max-width: 520px) {
    .site-header {
        padding: 20px 6vw 12px;
    }
    .brand h1 { font-size: 1.25rem; }
    .brand p { display: none; }
    .header-actions { width: 100%; justify-content: flex-end; }

    .hero {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .hero-text h2 { font-size: 1.4rem; }
    .hero-card { padding: 14px; border-radius: 10px; }

    .post-grid { grid-template-columns: 1fr; gap: 12px; }
    .works-grid { grid-template-columns: 1fr; gap: 12px; }

    .work-card .thumb { height: 100px; }
    .work-card .thumb img { width: 48px; height: 48px; }

    .button { width: 100%; padding: 12px; }
    .save-btn { width: auto; }

    .search-box { margin-top: 8px; }
}

/* Mobile-first refinements: larger touch targets, spacing, contrast */
@media (max-width: 520px) {
    html, body { -webkit-text-size-adjust: 100%; }
    body { font-size: 16px; }

    .site-header {
        position: sticky;
        top: 0;
        background: var(--surface);
        padding: 14px 6vw;
        z-index: 60;
        border-bottom: 1px solid var(--border);
    }

    .brand-mark { width: 48px; height:48px; }
    .brand h1 { font-size: 1.1rem; }

    .hero { gap: 12px; margin: 20px 0; }
    .hero-text h2 { font-size: 1.6rem; }
    .hero-text p { font-size: 0.98rem; line-height: 1.6; }

    .post-grid { grid-template-columns: 1fr; }
    .post-card { padding: 18px; min-height: auto; border-radius: 12px; }
    .post-card h3 { font-size: 1.05rem; }
    .post-card p { font-size: 0.98rem; color: var(--muted); }

    .work-card { padding: 14px; border-radius: 12px; }
    .work-card h3 { font-size: 1rem; }

    .work-actions { display:flex; flex-direction:column; gap:10px; width:100%; }
    .work-actions .button { width:100%; padding:12px; }

    .search-box input { font-size: 0.95rem; padding: 10px; }

    .saved-content { width: 96%; padding: 16px; }

    /* Improve contrast for muted text in dark mode */
    body.dark .post-card p,
    body.dark .hero-card p,
    body.dark .small { color: rgba(246,239,232,0.86); }
}

/* Mobile card refinements: stronger separation, subtle shadow, larger touch targets */
@media (max-width: 520px) {
    .post-card, .work-card {
        box-shadow: 0 6px 18px rgba(11,6,4,0.06);
        border: 1px solid rgba(75,46,24,0.06);
        padding: 18px;
        margin-bottom: 14px;
        border-radius: 14px;
        touch-action: manipulation;
    }

    .post-card .post-meta { margin-top: 12px; }
    .work-card .thumb { height: 120px; display:flex; align-items:center; justify-content:center; }
    .work-card .thumb img { width: 64px; height:64px; }

    /* focus-visible for keyboard users */
    .button:focus, .nav-toggle:focus, .theme-toggle:focus, .chip:focus {
        outline: 3px solid rgba(217,118,42,0.14);
        outline-offset: 2px;
    }
}

/* Mobile nav toggle (hidden by default on small screens) */
@media (max-width: 720px) {
    /* 在移动端完全隐藏导航（不展示折叠菜单） */
    .site-nav { display: none !important; width: 100%; }
    /* 隐藏所有用于显示/切换导航的按钮 */
    .nav-toggle { display: none !important; }
    .site-header .brand { width:100%; }
}

@media (max-width: 520px) {
    .nav-toggle { padding: 10px; }
    .site-nav a { padding: 12px 8px; display:block; }
}

/* 移动端增大暗黑模式按钮并让其更显眼 */
@media (max-width: 720px) {
    .theme-toggle {
        padding: 10px 14px;
        font-size: 1.2rem;
        border-radius: 12px;
        min-width: 48px;
        height: 44px;
        display: inline-grid;
        place-items: center;
    }
}

@media (max-width: 520px) {
    .theme-toggle {
        padding: 12px 16px;
        font-size: 1.25rem;
        min-width: 52px;
        height: 48px;
    }
    /* admin 页面的主题按钮也同样放大 */
    #themeToggle2 { padding: 12px 16px; font-size: 1.25rem; min-width:52px; height:48px; }
}
