:root {
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-text: #1a1a2e;
    --color-text-muted: #6c757d;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-border: #e2e8f0;
    --color-accent: #f0f4ff;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --max-width: 1280px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.7;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    padding-top: var(--safe-top);
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}
a:hover { color: var(--color-primary-hover); }

/* ============================================
   HEADER
   ============================================ */
.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    min-height: 52px;
    flex-wrap: nowrap;
}

.site-logo {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-text);
    flex-shrink: 0;
}
.site-logo:hover { color: var(--color-primary); }

/* Mobile menu toggle */
.menu-toggle-input { display: none; }
.menu-toggle-btn { display: none; }

.header-nav-group {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.site-nav { display: flex; gap: 1.25rem; align-items: center; }
.site-nav a {
    color: var(--color-text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.25rem 0;
}
.site-nav a:hover { color: var(--color-primary); }

.search-form { display: flex; gap: 0.4rem; }
.search-form input[type="text"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 180px;
    min-height: 40px;
}
.search-form input[type="text"]:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.search-form button {
    padding: 0.5rem 0.75rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
    min-height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.search-form button:hover { background: var(--color-primary-hover); }
.search-form button:active { transform: scale(0.96); }

/* ============================================
   MAIN CONTAINER
   ============================================ */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 1.5rem 1.5rem;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 2rem;
}

/* ============================================
   POST CARDS
   ============================================ */
.post-list { display: flex; flex-direction: column; gap: 1.25rem; }

.post-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
}
.post-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}
.post-card h2 { font-size: 1.2rem; margin-bottom: 0.4rem; line-height: 1.4; }
.post-card h2 a { color: var(--color-text); }
.post-card h2 a:hover { color: var(--color-primary); }

.post-meta {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 0.6rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.post-excerpt {
    color: var(--color-text-muted);
    font-size: 0.93rem;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.post-tags { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.6rem; }

.tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--color-accent);
    color: var(--color-primary);
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    min-height: 28px;
    line-height: 1.6;
}
.tag:hover { background: var(--color-primary); color: white; }

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar { display: flex; flex-direction: column; gap: 1.25rem; }

.sidebar-section {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.sidebar-section h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--color-accent);
}

.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.category-list { list-style: none; }
.category-list li {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--color-border);
}
.category-list li:last-child { border-bottom: none; }
.category-list a {
    display: flex;
    justify-content: space-between;
    color: var(--color-text);
    min-height: 36px;
    align-items: center;
}
.category-list .count { color: var(--color-text-muted); font-size: 0.85rem; }

/* ============================================
   ARTICLE
   ============================================ */
.article {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 2rem 2.5rem;
    box-shadow: var(--shadow);
    max-width: 100%;
    width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

.article-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--color-border);
}
.article-header h1 { font-size: 1.75rem; line-height: 1.3; margin-bottom: 0.6rem; }

.article-body { font-size: 1.02rem; line-height: 1.8; }
.article-body h1, .article-body h2, .article-body h3 { margin-top: 1.75rem; margin-bottom: 0.6rem; }
.article-body h2 { font-size: 1.4rem; }
.article-body h3 { font-size: 1.2rem; }
.article-body p { margin-bottom: 1.1rem; }
.article-body ul, .article-body ol { margin-bottom: 1.1rem; padding-left: 1.5rem; }
.article-body li { margin-bottom: 0.25rem; }

.article-body code {
    background: var(--color-accent);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.88em;
    word-break: break-all;
}

.article-body pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 1.1rem;
    -webkit-overflow-scrolling: touch;
    font-size: 0.88rem;
}
.article-body pre code { background: none; padding: 0; color: inherit; word-break: normal; }

.article-body blockquote {
    border-left: 4px solid var(--color-primary);
    padding: 0.6rem 1rem;
    margin-bottom: 1.1rem;
    background: var(--color-accent);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.article-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    display: block;
    margin: 1rem 0;
}

.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.1rem;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.article-body th, .article-body td {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
}
.article-body th { background: var(--color-accent); font-weight: 600; }

.article-footer {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}

/* ============================================
   SEARCH PAGE
   ============================================ */
.search-page .search-form { margin-bottom: 1.5rem; }
.search-page .search-form input[type="text"] {
    width: 100%;
    max-width: 500px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    min-height: 48px;
}
.search-page .search-form button {
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    min-height: 48px;
}

.search-results { display: flex; flex-direction: column; gap: 0.75rem; }

.search-result {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.search-result h3 { margin-bottom: 0.25rem; font-size: 1.1rem; }
.search-result .snippet { color: var(--color-text-muted); font-size: 0.93rem; line-height: 1.5; }
.search-result .snippet mark { background: #fef3c7; padding: 0.1rem 0.2rem; border-radius: 2px; }
.search-result-meta { font-size: 0.83rem; color: var(--color-text-muted); margin-top: 0.4rem; }

/* ============================================
   FOOTER
   ============================================ */
.site-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    padding-bottom: calc(1.5rem + var(--safe-bottom));
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin-top: 2rem;
    border-top: 1px solid var(--color-border);
}

/* ============================================
   LISTING PAGES
   ============================================ */
.listing-header { margin-bottom: 1.5rem; }
.listing-header h1 { font-size: 1.6rem; }
.listing-header p { color: var(--color-text-muted); margin-top: 0.4rem; }

/* ============================================
   404
   ============================================ */
.not-found { text-align: center; padding: 3rem 1rem; }
.not-found h1 { font-size: 4rem; color: var(--color-text-muted); margin-bottom: 0.75rem; }
.not-found p { color: var(--color-text-muted); font-size: 1.05rem; margin-bottom: 1.5rem; }

/* ============================================
   BUTTON
   ============================================ */
.btn {
    display: inline-block;
    padding: 0.65rem 1.5rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 44px;
    line-height: 1.4;
    text-align: center;
}
.btn:hover { background: var(--color-primary-hover); color: white; }
.btn:active { transform: scale(0.97); }

/* ============================================
   RESPONSIVE: TABLET (max-width: 900px)
   ============================================ */
@media (max-width: 900px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .sidebar-section { flex: 1; min-width: 200px; }
}

/* ============================================
   RESPONSIVE: MOBILE (max-width: 640px)
   ============================================ */
@media (max-width: 640px) {
    body { font-size: 15px; }

    .header-inner { padding: 0 0.75rem; }

    /* Show hamburger */
    .menu-toggle-btn {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        cursor: pointer;
        align-items: center;
        order: 3;
        -webkit-tap-highlight-color: transparent;
    }
    .menu-toggle-btn span {
        display: block;
        width: 22px;
        height: 2px;
        background: var(--color-text);
        border-radius: 2px;
        transition: transform 0.3s, opacity 0.3s;
    }

    .menu-toggle-input:checked ~ .menu-toggle-btn span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }
    .menu-toggle-input:checked ~ .menu-toggle-btn span:nth-child(2) {
        opacity: 0;
    }
    .menu-toggle-input:checked ~ .menu-toggle-btn span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* Collapsible nav */
    .header-nav-group {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
        z-index: 99;
    }

    .menu-toggle-input:checked ~ .header-nav-group {
        display: flex;
    }

    .site-nav {
        flex-direction: column;
        gap: 0;
        width: 100%;
    }
    .site-nav a {
        display: block;
        padding: 0.75rem 0.5rem;
        border-bottom: 1px solid var(--color-border);
        font-size: 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    .site-nav a:last-child { border-bottom: none; }

    .search-form {
        width: 100%;
    }
    .search-form input[type="text"] {
        flex: 1;
        width: 100%;
        min-height: 44px;
        font-size: 1rem;
    }
    .search-form button { min-height: 44px; min-width: 48px; }

    .container { padding: 1rem 0.75rem; }

    .post-card { padding: 1rem; }
    .post-card h2 { font-size: 1.1rem; }
    .post-excerpt { font-size: 0.9rem; }

    .article { padding: 1.25rem; }
    .article-header h1 { font-size: 1.4rem; }
    .article-body { font-size: 0.97rem; }
    .article-body pre { padding: 0.75rem; font-size: 0.82rem; }
    .article-body th, .article-body td { padding: 0.5rem; font-size: 0.88rem; }

    .sidebar { flex-direction: column; }
    .sidebar-section { min-width: unset; }

    .listing-header h1 { font-size: 1.35rem; }

    .not-found h1 { font-size: 3rem; }
    .not-found p { font-size: 0.95rem; }

    .search-page .search-form input[type="text"] {
        max-width: 100%;
    }
}

/* ============================================
   RESPONSIVE: SMALL PHONE (max-width: 380px)
   ============================================ */
@media (max-width: 380px) {
    body { font-size: 14px; }

    .site-logo { font-size: 1.15rem; }

    .container { padding: 0.75rem 0.5rem; }

    .post-card { padding: 0.85rem; }
    .post-card h2 { font-size: 1.05rem; }

    .article { padding: 1rem; }
    .article-header h1 { font-size: 1.25rem; }

    .tag { font-size: 0.72rem; padding: 0.15rem 0.45rem; }
}

/* ============================================
   RESPONSIVE: LARGE DESKTOP (min-width: 1200px)
   ============================================ */
@media (min-width: 1200px) {
    :root { --max-width: 1280px; }

    .content-grid {
        grid-template-columns: 1fr 320px;
        gap: 2.5rem;
    }

    .article { padding: 3rem; }
    .article-header h1 { font-size: 2.25rem; }
}

/* ============================================
   LANDSCAPE PHONE
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .site-header { position: relative; }
    .container { padding-top: 1rem; }
}

/* ============================================
   PWA / STANDALONE MODE
   ============================================ */
@media (display-mode: standalone) {
    .site-header {
        padding-top: calc(0.75rem + var(--safe-top));
    }
}

/* ============================================
   TOUCH DEVICE HINTS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    .post-card:hover {
        transform: none;
        box-shadow: var(--shadow);
    }
    a, button, .tag, .btn {
        -webkit-tap-highlight-color: rgba(37,99,235,0.1);
    }
}

/* ============================================
   PRINT
   ============================================ */
@media print {
    .site-header, .site-footer, .sidebar, .search-form,
    .menu-toggle-btn, .btn, .post-tags { display: none; }
    .content-grid { grid-template-columns: 1fr; }
    .article { box-shadow: none; padding: 0; max-width: 100%; }
    body { font-size: 12pt; color: #000; background: #fff; }
}
/* ============================================
   PASSWORD GATE
   ============================================ */
.password-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 2rem 1rem;
}

.password-gate-inner {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow);
}

.password-gate-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    line-height: 1;
}

.password-gate-inner h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.password-gate-hint {
    color: var(--color-text-muted);
    font-size: 0.92rem;
    margin-bottom: 1.5rem;
}

.password-gate-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 0.6rem 1rem;
    font-size: 0.88rem;
    margin-bottom: 1rem;
}

.password-gate-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.password-gate-form input[type="password"] {
    flex: 1;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
    min-height: 44px;
}

.password-gate-form input[type="password"]:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.password-gate-back {
    color: var(--color-text-muted);
    font-size: 0.88rem;
}

/* Lock icon in post listings */
.lock-icon {
    font-size: 0.75em;
    vertical-align: middle;
    margin-left: 0.3rem;
    opacity: 0.7;
}