/* =========================================================================
   goblog front-end stylesheet
   No framework: design tokens + a handful of components.
   Sections: tokens · base · layout · components · home · article · archive
             · tags/heatmap · reading · misc pages · responsive · print
   ========================================================================= */

/* ---------- 1. Design tokens ---------- */
:root {
    --bg: #ffffff;
    --bg-soft: #f6f8fa;
    --bg-elev: #ffffff;
    --bg-hover: #f3f6f4;
    --text: #1f2328;
    --text-2: #4d5761;
    --text-3: #8a939d;
    --border: #e7e9ec;
    --border-strong: #d5d9de;
    --accent: #209460;
    --accent-strong: #18784d;
    --accent-soft: rgba(32, 148, 96, 0.10);
    --accent-contrast: #ffffff;
    --link: #0b6bcb;
    --code-bg: #f6f8fa;
    --code-inline-bg: rgba(175, 184, 193, 0.22);
    --header-bg: rgba(255, 255, 255, 0.86);
    --overlay: rgba(15, 23, 42, 0.38);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 6px 24px rgba(16, 24, 40, 0.10);

    --radius: 10px;
    --radius-sm: 6px;
    --header-h: 60px;
    --container: 1080px;
    --narrow: 820px;
    --article: 780px;
    --gutter: 20px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono",
        "Noto Sans Mono CJK SC", monospace;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);

    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #1a1a2e;
    --bg-soft: #22223a;
    --bg-elev: #20203a;
    --bg-hover: #25253f;
    --text: #e4e6eb;
    --text-2: #b4b8c5;
    --text-3: #8286a0;
    --border: #2e2e48;
    --border-strong: #3d3d5c;
    --accent: #2ecc71;
    --accent-strong: #5fdb93;
    --accent-soft: rgba(46, 204, 113, 0.14);
    --accent-contrast: #0e1a14;
    --link: #6cb6ff;
    --code-bg: #161625;
    --code-inline-bg: rgba(255, 255, 255, 0.10);
    --header-bg: rgba(26, 26, 46, 0.86);
    --overlay: rgba(0, 0, 0, 0.55);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.45);

    color-scheme: dark;
}

/* ---------- 2. Base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow-wrap: break-word;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    line-height: 1.35;
    font-weight: 650;
}

p {
    margin: 0 0 1em;
}

a {
    color: var(--link);
    text-decoration: none;
}

img, svg, video {
    max-width: 100%;
}

img {
    height: auto;
    border: 0;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    touch-action: manipulation;
}

ul, ol {
    margin: 0;
    padding: 0;
}

::selection {
    background: var(--accent-soft);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 2000;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-contrast);
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
}

.text-center {
    text-align: center;
}

/* Inline SVG icons (tpl/default/icons.html) */
.icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    flex: none;
    vertical-align: -0.125em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------- 3. Layout ---------- */
.container {
    width: 100%;
    max-width: calc(var(--container) + var(--gutter) * 2);
    margin: 0 auto;
    padding-left: max(var(--gutter), var(--safe-left));
    padding-right: max(var(--gutter), var(--safe-right));
}

.container-narrow {
    max-width: calc(var(--narrow) + var(--gutter) * 2);
}

.site-main {
    flex: 1 0 auto;
    width: 100%;
    padding: 28px 0 56px;
}

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    padding-top: var(--safe-top);
    background: var(--header-bg);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
    transition: transform 0.28s ease, box-shadow 0.2s ease;
}

.site-header.is-scrolled {
    box-shadow: var(--shadow-sm);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    height: var(--header-h);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    margin-right: auto;
}

.brand-avatar {
    flex: none;
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--border);
    transition: transform 0.25s ease;
}

.brand-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand-name {
    color: var(--text);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-panel {
    display: flex;
    align-items: center;
    gap: 14px;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 2px;
}

.site-nav a {
    position: relative;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 15px;
    line-height: 1.4;
    white-space: nowrap;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.site-nav a[aria-current="page"] {
    color: var(--accent);
    font-weight: 600;
}

.header-search {
    position: relative;
    display: flex;
    align-items: center;
}

.header-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    display: grid;
    color: var(--text-3);
    font-size: 15px;
    transform: translateY(-50%);
    pointer-events: none;
}

.header-search-hint {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

html:not(.js) .header-search-hint {
    display: none;
}

.header-search input {
    width: 190px;
    height: 36px;
    padding: 0 58px 0 34px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-soft);
    font-size: 14px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: width 0.2s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.header-search input::placeholder {
    color: var(--text-3);
}

.header-search input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.header-search input:focus {
    border-color: var(--accent);
    background: var(--bg);
}

.js .header-search input {
    cursor: pointer;
}

kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 1px 6px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--bg-elev);
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 11.5px;
    line-height: 1.5;
    text-align: center;
    white-space: nowrap;
}

mark {
    padding: 0 1px;
    border-radius: 3px;
    background: rgba(255, 213, 79, 0.55);
    color: inherit;
}

[data-theme="dark"] mark {
    background: rgba(255, 213, 79, 0.32);
}

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

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-2);
    font-size: 19px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.rss-link {
    color: #f08c00;
}

.nav-toggle,
.search-toggle {
    display: none;
}

.nav-toggle-close {
    display: none;
}

/* Theme switch */
.theme-switch {
    position: relative;
    flex: none;
    width: 50px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 13px;
    background: #d8dde3;
    transition: background 0.3s;
    user-select: none;
}

.theme-switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    font-size: 13px;
    line-height: 1;
    pointer-events: none;
    transition: transform 0.3s;
}

.theme-switch-moon { display: none; }
[data-theme="dark"] .theme-switch { background: #364fc7; }
[data-theme="dark"] .theme-switch-knob { transform: translateX(24px); background: #1a1a2e; }
[data-theme="dark"] .theme-switch-sun { display: none; }
[data-theme="dark"] .theme-switch-moon { display: inline; }

/* Footer */
.site-footer {
    flex: none;
    padding: 22px 0 calc(22px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    color: var(--text-3);
    font-size: 13px;
    text-align: center;
}

.site-footer p {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px 18px;
    margin: 0;
}

.site-footer a {
    color: var(--text-2);
}

/* Reading progress bar */
#reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1100;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #209460, #2ecc71);
    pointer-events: none;
}

/* ---------- 4. Components ---------- */
.page-header {
    padding: 8px 0 22px;
}

.page-header h1 {
    font-size: 30px;
    letter-spacing: 0.01em;
}

.page-sub {
    margin: 8px 0 0;
    color: var(--text-3);
    font-size: 14px;
}

.page-sub span + span::before {
    content: "·";
    margin: 0 8px;
}

/* Chips: category filter, year navigation, reading filter */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 18px;
    padding: 0;
    list-style: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 4px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elev);
    color: var(--text-2);
    font-size: 14px;
    line-height: 1.3;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.chip small {
    color: var(--text-3);
    font-size: 12px;
}

.chip.is-active,
.chip.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-contrast);
}

.chip.is-active small,
.chip.active small {
    color: inherit;
    opacity: 0.85;
}

.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--accent-soft);
    color: var(--text-2);
    font-size: 14px;
}

.filter-bar strong {
    color: var(--text);
}

.filter-clear {
    flex: none;
    color: var(--accent-strong);
    font-weight: 600;
}

/* Pagination */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 28px;
}

.pager-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 42px;
    padding: 8px 18px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elev);
    color: var(--text);
    font-size: 15px;
    transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.pager-btn.is-hidden {
    visibility: hidden;
}

.pager-info {
    color: var(--text-3);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 42px;
    padding: 8px 20px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--bg-elev);
    color: var(--text);
    font-size: 15px;
}

.btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-contrast);
}

.empty-state {
    padding: 72px 0;
    color: var(--text-3);
    text-align: center;
}

.empty-state h2 {
    margin-bottom: 8px;
    color: var(--text-2);
    font-size: 20px;
}

/* Floating action buttons (TOC, back to top) */
.fab-stack {
    position: fixed;
    right: calc(18px + var(--safe-right));
    bottom: calc(22px + var(--safe-bottom));
    z-index: 900;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fab {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-elev);
    color: var(--text-2);
    font-size: 20px;
    box-shadow: var(--shadow-md);
    transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease;
}

.fab[hidden] {
    display: none;
}

.fab.is-off {
    opacity: 0;
    transform: translateY(8px) scale(0.92);
    pointer-events: none;
}

.fab-toc {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

/* ---------- 5. Home: post list ---------- */
.post-list {
    display: flex;
    flex-direction: column;
}

.post-item {
    position: relative;
    margin: 0 -16px;
    padding: 20px 16px;
    border-radius: var(--radius);
    transition: background-color 0.15s ease;
}

.post-item + .post-item::before {
    content: "";
    position: absolute;
    top: 0;
    left: 16px;
    right: 16px;
    border-top: 1px solid var(--border);
}

.post-title {
    font-size: 21px;
    font-weight: 650;
    line-height: 1.45;
}

.post-title a {
    color: var(--text);
    transition: color 0.15s ease;
}

/* make the whole card clickable while keeping inner links usable */
.post-title a::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
}

.badge-top {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-right: 8px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 600;
    vertical-align: 3px;
}

.post-desc {
    margin: 8px 0 0;
    color: var(--text-2);
    font-size: 15px;
    line-height: 1.75;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
}

.post-meta {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 14px;
    margin-top: 12px;
    color: var(--text-3);
    font-size: 13px;
    pointer-events: none;
}

.post-meta a {
    pointer-events: auto;
}

.meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.meta-cat {
    display: inline-flex;
    align-items: center;
    padding: 1px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 600;
}

.meta-tags {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px 10px;
}

.meta-tag {
    color: var(--text-3);
}


/* Home: list + discovery sidebar */
.home-layout {
    max-width: calc(var(--narrow) + var(--gutter) * 2);
}

.home-main {
    min-width: 0;
}

.home-aside {
    display: none;
}

.post-item.is-selected {
    background: var(--bg-hover);
    box-shadow: inset 3px 0 0 var(--accent);
}

.widget {
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
}

.widget-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 0 0 12px;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
}

.widget-more {
    color: var(--text-3);
    font-size: 12.5px;
    font-weight: 400;
}

.widget-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    text-align: center;
}

.stat strong {
    display: block;
    color: var(--text);
    font-size: 20px;
    font-weight: 700;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
}

.stat span {
    color: var(--text-3);
    font-size: 12.5px;
}

.hot-list {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: none;
}

.hot-list a {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 8px;
    padding: 7px 0;
    color: var(--text-2);
    font-size: 14px;
    line-height: 1.5;
}

.hot-rank {
    color: var(--text-3);
    font-size: 13px;
    font-style: italic;
    font-weight: 700;
    text-align: center;
}

.hot-list li:nth-child(-n+3) .hot-rank {
    color: var(--accent);
}

.hot-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.hot-views {
    color: var(--text-3);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.widget-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-pill-sm {
    padding: 3px 10px;
    font-size: 13px;
}

.btn-block {
    display: flex;
    width: 100%;
}

/* Search palette */
.palette,
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh 16px 16px;
}

.palette-backdrop,
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

.palette {
    opacity: 0;
    transition: opacity 0.16s ease;
}

.palette.is-open {
    opacity: 1;
}

.palette-panel,
.modal-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 640px;
    max-height: min(72vh, 640px);
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-elev);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
}

.palette-panel {
    transform: translateY(-8px) scale(0.985);
    transition: transform 0.16s ease;
}

.palette.is-open .palette-panel {
    transform: none;
}

.palette-input-row {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px 0 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-3);
    font-size: 18px;
}

.palette-input-row input {
    flex: 1;
    min-width: 0;
    height: 54px;
    padding: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 16.5px;
    -webkit-appearance: none;
    appearance: none;
}

.palette-input-row input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.palette-esc {
    flex: none;
    padding: 6px 2px;
    border: 0;
    background: transparent;
    color: var(--accent-strong);
    font-size: 15px;
}

.palette-esc span {
    display: none;
}

.palette-results {
    flex: 1;
    min-height: 0;
    padding: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.palette-results[aria-busy="true"] {
    opacity: 0.6;
}

.palette-section + .palette-section {
    margin-top: 6px;
}

.palette-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px 6px;
    color: var(--text-3);
    font-size: 12.5px;
    font-weight: 600;
}

.palette-clear {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-3);
    font-size: 12.5px;
}

.palette-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 2px 10px 8px;
}

.palette-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text);
}

.palette-item.is-active {
    background: var(--accent-soft);
}

.palette-item-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.45;
}

.palette-item-snippet {
    color: var(--text-2);
    font-size: 13.5px;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.palette-item-meta {
    color: var(--text-3);
    font-size: 12px;
}

.palette-empty {
    padding: 44px 16px;
    color: var(--text-2);
    text-align: center;
}

.palette-empty small {
    display: block;
    margin-top: 6px;
    color: var(--text-3);
    font-size: 13px;
}

.palette-footer {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 40px;
    padding: 6px 14px;
    border-top: 1px solid var(--border);
    color: var(--text-3);
    font-size: 12.5px;
}

.palette-keys kbd {
    margin: 0 2px;
}

.palette-all {
    margin-left: auto;
    color: var(--accent-strong);
    font-weight: 600;
}

/* Generic modal (keyboard shortcut help) */
.modal-panel {
    max-width: 440px;
    padding: 6px 20px 18px;
    overflow-y: auto;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-right: -10px;
}

.modal-head h2 {
    font-size: 17px;
}

.shortcut-list {
    margin: 4px 0 0;
}

.shortcut-list > div {
    display: flex;
    align-items: baseline;
    gap: 14px;
    padding: 7px 0;
    border-bottom: 1px dashed var(--border);
}

.shortcut-list > div:last-child {
    border-bottom: 0;
}

.shortcut-list dt {
    flex: none;
    width: 86px;
}

.shortcut-list dd {
    margin: 0;
    color: var(--text-2);
    font-size: 14px;
}

/* ---------- 6. Article ---------- */
.article-layout {
    display: block;
    max-width: calc(var(--article) + var(--gutter) * 2);
}

.article-main {
    min-width: 0;
}

.article-header {
    padding: 8px 0 22px;
    margin-bottom: 26px;
    border-bottom: 1px solid var(--border);
}

.article-title {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: 0.005em;
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 18px;
    margin-top: 14px;
    color: var(--text-3);
    font-size: 14px;
}

.article-meta .item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.article-meta a {
    color: var(--text-2);
}

.article-meta .tags {
    flex-wrap: wrap;
    gap: 4px 10px;
}

.article-content {
    font-size: 16.5px;
    line-height: 1.85;
    min-height: 40vh;
}

.noscript-tip {
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--bg-soft);
    color: var(--text-2);
}

/* editor.md preview container: neutralise its own box styling */
#post-viewer.editormd-html-preview,
#page-viewer.editormd-html-preview {
    width: auto;
    padding: 0;
    overflow: visible;
    background: transparent;
    font-size: inherit;
    line-height: inherit;
}

.article-content .markdown-body {
    overflow: visible;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: inherit;
    line-height: inherit;
}

.article-content .markdown-body > *:first-child {
    margin-top: 0 !important;
}

.article-content .markdown-body p,
.article-content .markdown-body ul,
.article-content .markdown-body ol,
.article-content .markdown-body blockquote,
.article-content .markdown-body table,
.article-content .markdown-body pre {
    margin-top: 0;
    margin-bottom: 1.15em;
}

.article-content .markdown-body h1,
.article-content .markdown-body h2,
.article-content .markdown-body h3,
.article-content .markdown-body h4,
.article-content .markdown-body h5,
.article-content .markdown-body h6 {
    position: relative;
    margin: 1.9em 0 0.8em;
    padding-bottom: 0;
    border-bottom: 0;
    color: var(--text);
    font-weight: 700;
    line-height: 1.4;
}

.article-content .markdown-body h1 { font-size: 1.6em; }
.article-content .markdown-body h2 { font-size: 1.42em; padding-bottom: 0.35em; border-bottom: 1px solid var(--border); }
.article-content .markdown-body h3 { font-size: 1.24em; }
.article-content .markdown-body h4 { font-size: 1.1em; }
.article-content .markdown-body h5 { font-size: 1em; }
.article-content .markdown-body h6 { font-size: 0.95em; color: var(--text-2); }

.article-content .markdown-body a {
    color: var(--link);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, var(--link) 35%, transparent);
    text-underline-offset: 3px;
    overflow-wrap: anywhere;
}

.article-content .markdown-body a.reference-link {
    text-decoration: none;
}

.article-content .markdown-body strong {
    color: var(--text);
    font-weight: 700;
}

.article-content .markdown-body ul,
.article-content .markdown-body ol {
    padding-left: 1.6em;
}

.article-content .markdown-body li {
    margin: 0.3em 0;
}

.article-content .markdown-body li > p {
    margin-bottom: 0.5em;
}

.article-content .markdown-body blockquote {
    margin-left: 0;
    margin-right: 0;
    padding: 10px 16px;
    border-left: 4px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--bg-soft);
    color: var(--text-2);
    font-size: inherit;
    font-style: normal;
}

.article-content .markdown-body blockquote > :last-child {
    margin-bottom: 0;
}

.article-content .markdown-body hr {
    height: 0;
    margin: 2em 0;
    border: 0;
    border-top: 1px solid var(--border);
    background: none;
}

.article-content .markdown-body img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.2em auto;
    border-radius: var(--radius-sm);
    background: transparent;
}

.article-content .markdown-body img.emoji {
    display: inline-block;
    margin: 0 2px;
    border-radius: 0;
}

/* inline code */
.article-content .markdown-body code {
    margin: 0 2px;
    padding: 0.15em 0.4em;
    border: 0;
    border-radius: 5px;
    background: var(--code-inline-bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.875em;
    overflow-wrap: anywhere;
}

/* code blocks */
.code-block-wrapper {
    position: relative;
    margin: 0 0 1.15em;
}

.article-content .markdown-body pre,
.article-content .markdown-body pre.prettyprint {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--code-bg);
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.65;
    white-space: pre;
    word-wrap: normal;
    tab-size: 4;
}

.article-content .markdown-body pre code {
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: inherit;
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
}

.article-content .markdown-body pre ol.linenums {
    margin: 0;
    padding-left: 2.6em;
    color: var(--text-3);
}

.article-content .markdown-body pre ol.linenums li {
    margin: 0;
    padding-left: 10px;
    border-left: 1px solid var(--border);
    list-style-type: decimal;
    background: none;
    line-height: inherit;
    white-space: pre;
}

.article-content .markdown-body pre ol.linenums li code {
    white-space: pre;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    min-height: 28px;
    padding: 2px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elev);
    color: var(--text-2);
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.15s ease, border-color 0.15s ease;
}

.code-block-wrapper:hover .copy-btn,
.copy-btn:focus-visible {
    opacity: 1;
}

.copy-btn.copied {
    opacity: 1;
    border-color: var(--accent);
    color: var(--accent);
}

/* tables scroll horizontally instead of breaking the page */
.table-wrapper {
    margin: 0 0 1.15em;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.article-content .markdown-body .table-wrapper table {
    display: table;
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    font-size: 0.92em;
}

.article-content .markdown-body table th,
.article-content .markdown-body table td {
    padding: 9px 14px;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    white-space: normal;
    min-width: 72px;
}

.article-content .markdown-body table th:last-child,
.article-content .markdown-body table td:last-child {
    border-right: 0;
}

.article-content .markdown-body table tr:last-child td {
    border-bottom: 0;
}

.article-content .markdown-body table th {
    background: var(--bg-soft);
    color: var(--text);
    font-weight: 650;
    white-space: nowrap;
}

.article-content .markdown-body table tr,
.article-content .markdown-body table thead tr {
    border-top: 0;
    background: transparent;
}

.article-content .markdown-body table tr:nth-child(2n) {
    background: color-mix(in srgb, var(--bg-soft) 60%, transparent);
}

.article-content .markdown-body iframe,
.article-content .markdown-body video {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 1.2em auto;
    border: 0;
    border-radius: var(--radius);
}

.article-content .markdown-body iframe {
    aspect-ratio: 16 / 9;
    height: auto;
}

.article-content .markdown-body kbd {
    border-color: var(--border-strong);
    background: var(--bg-soft);
    color: var(--text);
    box-shadow: inset 0 -1px 0 var(--border-strong);
}

.article-content .markdown-body abbr {
    background: transparent;
}



/* Article pieces that used to come from editormd.preview.css. Server-rendered
   articles do not load that stylesheet any more. */
.article-content .markdown-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    border-spacing: 0;
    /* keep CJK phrases together: a wide table scrolls sideways inside its
       wrapper instead of squeezing every cell into one-character lines */
    word-break: keep-all;
}

.article-content .markdown-body ul { list-style: disc; }
.article-content .markdown-body ul ul { list-style: circle; }
.article-content .markdown-body ul ul ul { list-style: square; }
.article-content .markdown-body ol { list-style: decimal; }

.article-content .markdown-body ul ul,
.article-content .markdown-body ul ol,
.article-content .markdown-body ol ol,
.article-content .markdown-body ol ul {
    margin-top: 0.3em;
    margin-bottom: 0.3em;
}

.article-content .markdown-body li.task-list-item {
    list-style: none;
    margin-left: -1.3em;
}

.task-list-item-checkbox {
    margin: 0 0.5em 0 0;
    vertical-align: -1px;
    accent-color: var(--accent);
}

/* GitHub-style breathing room inside inline code */
.article-content .markdown-body code::before,
.article-content .markdown-body code::after {
    content: "\00a0";
    letter-spacing: -0.2em;
}

.article-content .markdown-body pre code::before,
.article-content .markdown-body pre code::after {
    content: normal;
}

.article-content .markdown-body em {
    font-style: italic;
}

.article-content .markdown-body del {
    color: var(--text-3);
}

.article-content .markdown-body dl dt {
    margin-top: 1em;
    font-weight: 700;
}

.article-content .markdown-body dl dd {
    margin: 0.3em 0 0 1.4em;
    color: var(--text-2);
}

.article-content .markdown-body sup {
    font-size: 0.75em;
    line-height: 0;
}

.article-content .markdown-body .footnotes {
    margin-top: 2.5em;
    color: var(--text-2);
    font-size: 0.9em;
}

/* prettify tokens, light theme (dark overrides live in section 13) */
.pln { color: #24292f; }
.str, .atv { color: #0a6c2f; }
.kwd, .tag { color: #a31571; }
.com { color: #6e7781; font-style: italic; }
.typ, .atn, .dec, .var { color: #8250df; }
.lit { color: #0550ae; }
.pun, .opn, .clo { color: #57606a; }
.fun { color: #953800; }

ol.linenums {
    margin-top: 0;
    margin-bottom: 0;
}

/* editor.md decorations we do not use */
.article-content .markdown-body .header-link {
    display: none;
}

/* "copy link to this section" */
.heading-anchor {
    display: inline-grid;
    place-items: center;
    width: 1.5em;
    height: 1.5em;
    margin-left: 0.25em;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    font-size: 0.72em;
    vertical-align: middle;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.article-content .markdown-body a.heading-anchor {
    color: var(--text-3);
    text-decoration: none;
}

.heading-anchor:focus-visible {
    opacity: 1;
}

/* offline fallback page (served by the service worker) */
.offline .offline-icon {
    margin: 0 0 8px;
    font-size: 52px;
    line-height: 1;
}

.offline .offline-tip,
.offline .offline-empty {
    max-width: 34em;
    margin: 0 auto 18px;
    color: var(--text-2);
}

.offline-list {
    max-width: 34em;
    margin: 0 auto 22px;
    padding: 0;
    list-style: none;
    text-align: left;
}

.offline-list li + li {
    border-top: 1px solid var(--border);
}

.offline-list a {
    display: block;
    padding: 11px 6px;
    color: var(--text);
    overflow-wrap: anywhere;
}

/* notices */
.notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 0 24px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14.5px;
    line-height: 1.7;
}

.notice .icon {
    margin-top: 0.3em;
}

.notice-outdated {
    border: 1px solid rgba(240, 140, 0, 0.35);
    background: rgba(240, 140, 0, 0.09);
    color: #94560a;
}

[data-theme="dark"] .notice-outdated {
    color: #f3c27b;
}

/* code block extras */
.code-lang {
    position: absolute;
    top: 9px;
    right: 14px;
    z-index: 1;
    padding: 0 6px;
    border-radius: 4px;
    background: var(--code-bg); /* long first lines run underneath the label */
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: 11.5px;
    letter-spacing: 0.04em;
    line-height: 26px;
    pointer-events: none;
    user-select: none;
    transition: opacity 0.15s ease;
}

.article-content .markdown-body .is-prose pre,
.article-content .markdown-body .is-prose pre code,
.article-content .markdown-body .is-prose pre ol.linenums li,
.article-content .markdown-body .is-prose pre ol.linenums li code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.code-block-wrapper.is-collapsed pre {
    max-height: var(--collapsed-h, 560px);
    overflow-y: hidden;
}

.code-block-wrapper.is-collapsed::after {
    content: "";
    position: absolute;
    left: 1px;
    right: 1px;
    bottom: 37px;
    height: 72px;
    background: linear-gradient(to bottom, transparent, var(--code-bg));
    pointer-events: none;
}

.code-expand {
    display: block;
    width: 100%;
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--bg-soft);
    color: var(--text-2);
    font-size: 13px;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.article-content .markdown-body .is-collapsible pre,
.article-content .markdown-body .is-collapsible pre.prettyprint {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* article footer: license, share, neighbours, related */
.article-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px 24px;
    margin-top: 40px;
    padding: 16px 18px;
    border-radius: var(--radius);
    background: var(--bg-soft);
    font-size: 13.5px;
}

.article-license {
    min-width: 0;
    flex: 1 1 320px;
    color: var(--text-2);
}

.article-license p {
    margin: 0;
    overflow-wrap: anywhere;
}

.article-license p + p {
    margin-top: 4px;
}

.license-label {
    margin-right: 10px;
    color: var(--text-3);
}

.article-actions {
    display: flex;
    gap: 10px;
}

.btn-sm {
    min-height: 36px;
    padding: 5px 14px;
    font-size: 13.5px;
}

.post-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 28px;
}

.post-nav-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.post-nav-item.is-empty {
    visibility: hidden;
}

.post-nav-next {
    align-items: flex-end;
    text-align: right;
}

.post-nav-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-3);
    font-size: 12.5px;
}

.post-nav-title {
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.section-title {
    margin: 0 0 14px;
    font-size: 19px;
    font-weight: 700;
}

.related {
    margin-top: 44px;
}

.related-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.related-list a {
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: 100%;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--bg-soft);
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.related-title {
    color: var(--text);
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.5;
}

.related-meta {
    color: var(--text-3);
    font-size: 12.5px;
}

/* TOC reading percentage */
.toc-progress {
    margin-left: auto;
    color: var(--text-3);
    font-size: 12px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(28px + var(--safe-bottom));
    z-index: 1500;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: min(92vw, 420px);
    padding: 10px 16px;
    border-radius: 999px;
    background: #24292f;
    color: #fff;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, 12px);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

[data-theme="dark"] .toast {
    background: #e4e6eb;
    color: #1a1a2e;
}

.toast.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.toast-action {
    flex: none;
    padding: 4px 12px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 13px;
    font-weight: 600;
}

[data-theme="dark"] .toast-action {
    background: #209460;
    color: #fff;
}

.toast-close {
    display: grid;
    place-items: center;
    flex: none;
    width: 26px;
    height: 26px;
    margin-right: -6px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    opacity: 0.7;
}

/* Lightbox */
.article-content .markdown-body img.is-zoomable {
    cursor: zoom-in;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    flex-direction: column;
    background: rgba(10, 12, 20, 0.94);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.lightbox.is-open {
    opacity: 1;
}

.lightbox-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: calc(56px + var(--safe-top)) 12px 8px;
    overflow: hidden;
    cursor: zoom-out;
}

.lightbox-stage img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    cursor: zoom-in;
    user-select: none;
    -webkit-user-drag: none;
}

.lightbox.is-zoomed .lightbox-stage {
    display: block;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.lightbox.is-zoomed .lightbox-stage img {
    max-width: none;
    max-height: none;
    cursor: zoom-out;
}

.lightbox-caption {
    flex: none;
    display: flex;
    justify-content: center;
    gap: 12px;
    min-height: 40px;
    padding: 8px 16px calc(12px + var(--safe-bottom));
    color: rgba(255, 255, 255, 0.78);
    font-size: 13px;
    text-align: center;
}

.lightbox-counter {
    font-variant-numeric: tabular-nums;
}

.lightbox-btn {
    position: absolute;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 22px;
    transition: background-color 0.15s ease;
}

.lightbox-close {
    top: calc(8px + var(--safe-top));
    right: calc(10px + var(--safe-right));
}

.lightbox-prev,
.lightbox-next {
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-prev { left: calc(10px + var(--safe-left)); }
.lightbox-next { right: calc(10px + var(--safe-right)); }

/* Table of contents */
.article-aside {
    display: none;
}

.toc-container {
    font-size: 13.5px;
    line-height: 1.5;
}

.toc-container .toc-title {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.toc-container ul {
    margin: 0;
    padding: 0;
    list-style: none;
    border-left: 1px solid var(--border);
}

.toc-container li {
    margin: 0;
}

.toc-container a {
    display: block;
    margin-left: -1px;
    padding: 5px 0 5px 14px;
    border-left: 2px solid transparent;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.toc-container a.active {
    border-left-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.toc-container .toc-level-1 a { padding-left: 28px; }
.toc-container .toc-level-2 a { padding-left: 42px; }
.toc-container .toc-level-3 a { padding-left: 56px; }
.toc-container .toc-level-4 a { padding-left: 70px; }

.toc-overlay {
    position: fixed;
    inset: 0;
    z-index: 1190;
    background: var(--overlay);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.toc-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.toc-sheet-handle {
    display: none;
}

/* Comments */
.comments {
    margin-top: 48px;
    padding-top: 28px;
    border-top: 1px solid var(--border);
    min-height: 120px;
}

/* ---------- 7. Archive ---------- */
.archive-year {
    margin-bottom: 34px;
}

.archive-year-title {
    position: sticky;
    top: calc(var(--header-h) + var(--safe-top));
    z-index: 5;
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin: 0 0 6px;
    padding: 10px 0;
    background: var(--bg);
    color: var(--accent);
    font-size: 24px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.archive-year-title small {
    color: var(--text-3);
    font-size: 13px;
    font-weight: 400;
}

.archive-posts {
    list-style: none;
    margin: 0;
    padding: 0 0 0 18px;
    border-left: 2px solid var(--border);
}

.archive-post-item {
    position: relative;
    display: flex;
    align-items: baseline;
    gap: 14px;
    padding: 9px 0;
}

.archive-post-item::before {
    content: "";
    position: absolute;
    left: -24px;
    top: 1.15em;
    width: 10px;
    height: 10px;
    border: 2px solid var(--bg);
    border-radius: 50%;
    background: var(--border-strong);
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.archive-post-date {
    flex: none;
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.archive-post-link {
    color: var(--text);
    font-size: 16px;
    line-height: 1.6;
}

/* ---------- 8. Tags + heatmap ---------- */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 0 0 8px;
    padding: 0;
    list-style: none;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elev);
    color: var(--text-2);
    line-height: 1.35;
    transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.tag-count {
    min-width: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--bg-soft);
    color: var(--text-3);
    font-size: 12px;
    line-height: 18px;
    text-align: center;
}

.section-card {
    margin-top: 32px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
}

.gh-heatmap-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    margin-bottom: 14px;
}

.gh-heatmap-header h2 {
    color: var(--text-2);
    font-size: 15px;
    font-weight: 600;
}

.gh-heatmap-year-select {
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 14px;
}

.gh-heatmap-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    scrollbar-width: thin;
}

.gh-heatmap-body {
    width: max-content;
    min-width: 100%;
}

.gh-heatmap-months {
    position: relative;
    height: 16px;
    margin: 0 0 4px 26px;
    color: var(--text-3);
    font-size: 11px;
}

.gh-heatmap-months span {
    position: absolute;
    top: 0;
    white-space: nowrap;
}

.gh-heatmap-graph {
    display: flex;
}

.gh-heatmap-weekdays {
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 26px;
}

.gh-heatmap-weekdays span {
    height: var(--cell, 13px);
    color: var(--text-3);
    font-size: 10px;
    line-height: var(--cell, 13px);
}

.gh-heatmap-grid {
    display: flex;
    gap: 3px;
}

.gh-heatmap-col {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.gh-heatmap-cell {
    width: var(--cell, 13px);
    height: var(--cell, 13px);
    border-radius: 3px;
}

.gh-heatmap-cell[data-count]:not([data-count="0"]) {
    cursor: pointer;
}

.gh-heatmap-cell.is-selected {
    outline: 2px solid var(--text);
    outline-offset: 1px;
}

.gh-heatmap-level-0 { background-color: #ebedf0; }
.gh-heatmap-level-1 { background-color: #9be9a8; }
.gh-heatmap-level-2 { background-color: #40c463; }
.gh-heatmap-level-3 { background-color: #30a14e; }
.gh-heatmap-level-4 { background-color: #216e39; }

[data-theme="dark"] .gh-heatmap-level-0 { background-color: #2a2a44; }
[data-theme="dark"] .gh-heatmap-level-1 { background-color: #0e4429; }
[data-theme="dark"] .gh-heatmap-level-2 { background-color: #006d32; }
[data-theme="dark"] .gh-heatmap-level-3 { background-color: #26a641; }
[data-theme="dark"] .gh-heatmap-level-4 { background-color: #39d353; }

.gh-heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    margin-top: 10px;
    color: var(--text-3);
    font-size: 11px;
}

.gh-heatmap-legend span {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 3px;
}

.gh-heatmap-tooltip {
    position: fixed;
    z-index: 1300;
    display: none;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: #1b1f23;
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
}

.gh-heatmap-detail {
    display: none;
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--bg-soft);
}

.gh-heatmap-detail h3 {
    margin: 0 0 8px;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.gh-heatmap-detail ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.gh-heatmap-detail li {
    padding: 6px 0;
    border-bottom: 1px dashed var(--border);
}

.gh-heatmap-detail li:last-child {
    border-bottom: 0;
}

.gh-heatmap-detail a {
    color: var(--accent-strong);
    font-size: 14px;
}

.gh-heatmap-detail .detail-time,
.gh-heatmap-detail .detail-words {
    margin-left: 8px;
    color: var(--text-3);
    font-size: 12px;
}

/* ---------- 9. Reading list ---------- */
.year-section {
    margin-bottom: 40px;
}

.year-title {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
    color: var(--accent);
    font-size: 22px;
    font-weight: 700;
}

.year-title .year-stats {
    color: var(--text-3);
    font-size: 13px;
    font-weight: 400;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.book-card {
    display: flex;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.book-cover,
.book-cover-placeholder {
    flex: none;
    width: 80px;
    height: 114px;
    border-radius: 5px;
}

.book-cover {
    object-fit: cover;
    background: var(--bg-soft);
    box-shadow: var(--shadow-sm);
}

.book-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 13px;
    line-height: 1.3;
    text-align: center;
    word-break: break-all;
}

.book-info {
    flex: 1;
    min-width: 0;
}

.book-title {
    margin-bottom: 4px;
    color: var(--text);
    font-size: 16px;
    font-weight: 650;
    line-height: 1.4;
}

.book-author {
    margin-bottom: 6px;
    color: var(--text-3);
    font-size: 13px;
}

.book-meta {
    margin-bottom: 6px;
    color: var(--text-3);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.book-status-badge {
    display: inline-block;
    margin-bottom: 8px;
    padding: 1px 9px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.book-status-reading { background: #e8f5e9; color: #2e7d32; }
.book-status-finished { background: #e3f2fd; color: #1565c0; }
.book-status-wish { background: #fff3e0; color: #e65100; }
.book-status-dropped { background: #fce4ec; color: #c62828; }

[data-theme="dark"] .book-status-reading { background: rgba(46, 204, 113, 0.16); color: #6ee7a0; }
[data-theme="dark"] .book-status-finished { background: rgba(108, 182, 255, 0.16); color: #8cc8ff; }
[data-theme="dark"] .book-status-wish { background: rgba(255, 167, 38, 0.16); color: #ffc46b; }
[data-theme="dark"] .book-status-dropped { background: rgba(244, 114, 142, 0.16); color: #ff9db3; }

.book-progress-bar {
    height: 4px;
    margin: 8px 0;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
}

.book-progress-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s ease;
}

.book-progress-fill.reading { background: var(--accent); }
.book-progress-fill.finished { background: #1565c0; }

.book-rating {
    margin-bottom: 4px;
    color: #f5a623;
    font-size: 14px;
    letter-spacing: 1px;
}

.book-comment {
    margin-top: 6px;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.6;
}

/* ---------- 10. 404 ---------- */
.notfound {
    padding: 64px 0;
    text-align: center;
}

.notfound .notfound-code {
    margin: 0;
    background: linear-gradient(120deg, #209460, #2ecc71 60%, #7fe3a8);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-size: clamp(88px, 22vw, 160px);
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.04em;
}

.notfound h1 {
    margin-top: 12px;
    font-size: 22px;
}

.notfound p {
    margin: 10px 0 0;
    color: var(--text-3);
}

.notfound-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 28px;
}


/* ---------- 10b. Stats page ---------- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
}

.stat-card {
    padding: 16px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    text-align: center;
}

.stat-card strong {
    display: block;
    color: var(--accent);
    font-size: 24px;
    font-weight: 750;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
}

.stat-card span {
    color: var(--text-3);
    font-size: 12.5px;
}

.stats-fact {
    margin: 22px 0 0;
    color: var(--text-2);
    font-size: 15px;
}

.stats-fact strong {
    color: var(--text);
}

.stats-page .section-card {
    margin-top: 22px;
}

.card-title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    margin: 0 0 16px;
    font-size: 17px;
    font-weight: 700;
}

.card-title small {
    color: var(--text-3);
    font-size: 12.5px;
    font-weight: 400;
}

.chart-grid {
    display: grid;
    grid-template-columns: 7fr 12fr;
    gap: 24px;
}

.chart-caption {
    margin: 0 0 6px;
    color: var(--text-3);
    font-size: 12.5px;
    font-weight: 600;
}

.chart-grid + .chart-caption {
    margin-top: 20px;
}

.bar-chart {
    display: flex;
    align-items: stretch;
    gap: 6px;
    height: 150px;
}

.bar-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.bar {
    width: 100%;
    max-width: 44px;
    min-height: 0;
    border-radius: 5px 5px 2px 2px;
    background: linear-gradient(to top, var(--accent), color-mix(in srgb, var(--accent) 62%, #ffffff));
    transition: filter 0.15s ease;
}

.bar-value {
    color: var(--text-2);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.bar-label,
.bar-sub {
    flex: none;
    color: var(--text-3);
    font-size: 11.5px;
    line-height: 1.3;
    white-space: nowrap;
}

.bar-chart-years {
    height: 190px;
    gap: 14px;
}

.bar-chart-years .bar {
    max-width: 64px;
}

.bar-chart-hours {
    height: 110px;
    gap: 3px;
}

.bar-chart-hours .bar-label {
    font-size: 10px;
}

.bar-chart-hours .is-night .bar {
    background: linear-gradient(to top, #364fc7, #748ffc);
}

.stack-bar {
    display: flex;
    height: 16px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--bg-soft);
}

.stack-seg {
    display: block;
    height: 100%;
}

.seg-0 { background: #209460; }
.seg-1 { background: #4c6ef5; }
.seg-2 { background: #f59f00; }
.seg-3 { background: #e64980; }
.seg-4 { background: #15aabf; }
.seg-5 { background: #7950f2; }
.seg-6 { background: #82c91e; }
.seg-7 { background: #868e96; }

.stack-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 22px;
    margin: 14px 0 0;
    padding: 0;
    list-style: none;
    font-size: 14px;
}

.stack-legend li {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.stack-legend a {
    color: var(--text);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.legend-num {
    color: var(--text-3);
    font-size: 12.5px;
}

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

.rank-list a {
    position: relative;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14.5px;
    overflow: hidden;
}

.rank-bar {
    position: absolute;
    inset: 3px auto 3px 0;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
}

.rank-no,
.rank-title,
.rank-num {
    position: relative;
}

.rank-no {
    color: var(--text-3);
    font-style: italic;
    font-weight: 700;
    text-align: center;
}

.rank-list li:nth-child(-n+3) .rank-no {
    color: var(--accent);
}

.rank-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-num {
    color: var(--text-2);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

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

.facts li {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 14.5px;
}

.facts li:last-child {
    border-bottom: 0;
}

.fact-label {
    color: var(--text-3);
    font-size: 13px;
}

.fact-num {
    color: var(--text-2);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.time-progress {
    display: grid;
    gap: 12px;
}

.tp-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 56px;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.tp-label {
    color: var(--text-2);
}

.tp-bar {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--bg-soft);
}

.tp-bar i {
    display: block;
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #209460, #2ecc71);
    transition: width 0.8s ease;
}

.tp-value {
    color: var(--text-3);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

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

.otd-list li {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 5px 0;
    font-size: 14px;
    line-height: 1.5;
}

.otd-list time {
    flex: none;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 12.5px;
    font-weight: 600;
}

.otd-list a {
    color: var(--text);
}

a.widget-stats {
    color: inherit;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.badge-hot {
    margin-left: 6px;
    font-size: 0.8em;
    vertical-align: 1px;
}

/* like button */
.like-btn .icon {
    transition: transform 0.2s ease;
}

.like-btn.is-liked {
    border-color: #e64980;
    color: #e64980;
}

.like-btn.is-liked .icon {
    fill: currentColor;
    animation: like-pop 0.45s ease;
}

.like-count {
    min-width: 1ch;
    font-variant-numeric: tabular-nums;
}

@keyframes like-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.45); }
    100% { transform: scale(1); }
}

/* emoji bursts / confetti */
.burst-piece,
.rain-piece {
    position: fixed;
    z-index: 3000;
    pointer-events: none;
    user-select: none;
    will-change: transform, opacity;
}

.burst-piece {
    animation: burst-fly 1.2s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

.rain-piece {
    top: -40px;
    animation: rain-fall 3s linear forwards;
}

@keyframes burst-fly {
    from { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
    to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(1); opacity: 0; }
}

@keyframes rain-fall {
    from { transform: translateY(0) rotate(0deg); opacity: 1; }
    90% { opacity: 1; }
    to { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}

/* terminal on the 404 page */
.terminal {
    max-width: 520px;
    margin: 26px auto 0;
    overflow: hidden;
    border-radius: 10px;
    background: #1e2030;
    box-shadow: var(--shadow-md);
    text-align: left;
}

.terminal-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 12px;
    background: #2a2d42;
    color: #8f96b8;
    font-family: var(--font-mono);
    font-size: 11.5px;
}

.terminal-bar i {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #ff5f57;
}

.terminal-bar i:nth-child(2) { background: #febc2e; }
.terminal-bar i:nth-child(3) { background: #28c840; }

.terminal-bar span {
    margin-left: 8px;
}

.terminal-body {
    margin: 0;
    padding: 14px 16px 16px;
    overflow-x: auto;
    color: #c8d0f0;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.t-prompt { color: #2ecc71; }
.t-out { color: #9aa3c7; }
.t-out.t-err { color: #ff7a85; }

.t-cursor {
    animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

html:not(.js) .js-only {
    display: none;
}

/* ---------- 11. Hover (pointer devices only) ---------- */
@media (hover: hover) {
    .site-nav a:hover { color: var(--text); background: var(--bg-hover); }
    .site-nav a[aria-current="page"]:hover { color: var(--accent); }
    .icon-btn:hover { background: var(--bg-hover); color: var(--text); }
    .rss-link:hover { color: #f08c00; }
    .brand-avatar:hover { transform: rotate(-6deg) scale(1.06); }
    .brand-name:hover { color: var(--accent); }
    .site-footer a:hover { color: var(--accent); }
    .chip:hover { border-color: var(--accent); color: var(--accent); }
    .chip.is-active:hover, .chip.active:hover { color: var(--accent-contrast); }
    .filter-clear:hover { text-decoration: underline; }
    .pager-btn:hover { border-color: var(--accent); color: var(--accent); }
    .btn:hover { border-color: var(--accent); color: var(--accent); }
    .btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-contrast); }
    .fab:hover { color: var(--accent); transform: translateY(-2px); }
    .fab-toc:hover { color: var(--accent-contrast); }
    .post-item:hover { background: var(--bg-hover); }
    .post-item:hover + .post-item::before, .post-item:hover::before { border-color: transparent; }
    .post-item:hover .post-title a { color: var(--accent); }
    .meta-tag:hover { color: var(--accent); }
    .hot-list a:hover .hot-title { color: var(--accent); }
    a.widget-stats:hover { border-color: var(--accent); transform: translateY(-1px); }
    .otd-list a:hover, .rank-list a:hover .rank-title, .facts a:hover, .stack-legend a:hover, .stats-fact a:hover { color: var(--accent); }
    .bar-col:hover .bar { filter: brightness(1.1); }
    .like-btn:hover { border-color: #e64980; color: #e64980; }
    .widget-more:hover { color: var(--accent); }
    .palette-clear:hover { color: var(--accent); }
    .meta-cat:hover { background: var(--accent); color: var(--accent-contrast); }
    .article-meta a:hover { color: var(--accent); }
    .article-content .markdown-body a:hover { text-decoration-color: currentColor; }
    .toc-container a:hover { color: var(--text); }
    .toc-container a.active:hover { color: var(--accent); }
    .copy-btn:hover { border-color: var(--accent); color: var(--accent); }
    .code-block-wrapper:hover .code-lang { opacity: 0; }
    .code-expand:hover { color: var(--accent); background: var(--bg-hover); }
    h1:hover > .heading-anchor, h2:hover > .heading-anchor, h3:hover > .heading-anchor,
    h4:hover > .heading-anchor, h5:hover > .heading-anchor { opacity: 1; }
    .article-content .markdown-body a.heading-anchor:hover { color: var(--accent); background: var(--accent-soft); }
    .post-nav-item:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
    .post-nav-item:hover .post-nav-title { color: var(--accent); }
    .related-list a:hover { background: var(--accent-soft); transform: translateY(-1px); }
    .related-list a:hover .related-title { color: var(--accent-strong); }
    .lightbox-btn:hover { background: rgba(255, 255, 255, 0.24); }
    .toast-close:hover { opacity: 1; }
    .archive-post-link:hover { color: var(--accent); }
    .offline-list a:hover { color: var(--accent); }
    .archive-post-item:hover::before { background: var(--accent); transform: scale(1.2); }
    .tag-pill:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
    .book-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-strong); }
    .gh-heatmap-cell:hover { outline: 1.5px solid var(--text-2); outline-offset: -0.5px; }
}

/* touch devices cannot hover: keep the copy button and section anchors reachable */
@media (hover: none) {
    .footer-shortcuts { display: none; } /* no hardware keyboard, no shortcuts */
    .palette-keys { visibility: hidden; }
    .copy-btn { opacity: 0.9; }
    .code-block-wrapper.has-lang .code-lang { right: 64px; }
    .heading-anchor { opacity: 0.55; }
    .lightbox-prev, .lightbox-next { display: none; } /* swipe instead */
}

/* ---------- 12. Responsive ---------- */

/* Wide screens: article + sticky table of contents side by side */
@media (min-width: 1100px) {
    .home-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 288px;
        align-items: start;
        gap: 44px;
        max-width: calc(var(--container) + var(--gutter) * 2);
    }

    .home-aside {
        display: block;
        position: sticky;
        top: calc(var(--header-h) + 24px);
    }

    .article-layout.has-toc {
        display: grid;
        grid-template-columns: minmax(0, var(--article)) 240px;
        justify-content: space-between;
        gap: 48px;
        max-width: calc(var(--container) + var(--gutter) * 2);
    }

    .article-layout.has-toc .article-aside {
        display: block;
    }

    .article-aside .toc-container {
        position: sticky;
        top: calc(var(--header-h) + 24px);
        max-height: calc(100vh - var(--header-h) - 48px);
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        padding-right: 4px;
    }

    .fab-toc {
        display: none;
    }
}

/* Below that the TOC becomes a bottom sheet opened from a floating button */
@media (max-width: 1099.98px) {
    .toc-container.is-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1200;
        max-height: min(70vh, 560px);
        padding: 8px 20px calc(20px + var(--safe-bottom));
        overflow-y: auto;
        overscroll-behavior: contain;
        border-radius: 18px 18px 0 0;
        background: var(--bg-elev);
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
        font-size: 15px;
        transform: translateY(105%);
        visibility: hidden;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), visibility 0.3s;
    }

    .toc-container.is-sheet.mobile-visible {
        transform: none;
        visibility: visible;
    }

    .toc-container.is-sheet .toc-sheet-handle {
        display: block;
        width: 40px;
        height: 4px;
        margin: 4px auto 14px;
        border-radius: 2px;
        background: var(--border-strong);
    }

    .toc-container.is-sheet a {
        padding-top: 9px;
        padding-bottom: 9px;
        white-space: normal;
    }
}

/* Tablet / phone: collapsible navigation */
@media (max-width: 860px) {
    :root {
        --header-h: 56px;
    }

    .nav-toggle,
    .js .search-toggle {
        display: inline-grid;
    }

    /* the palette button replaces the form inside the menu when JS is on */
    .js .nav-panel .header-search {
        display: none;
    }

    .site-header.nav-open .nav-toggle-open { display: none; }
    .site-header.nav-open .nav-toggle-close { display: block; }

    .nav-panel {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column-reverse;
        align-items: stretch;
        gap: 12px;
        max-height: calc(100vh - var(--header-h));
        max-height: calc(100dvh - var(--header-h));
        padding: 14px max(var(--gutter), var(--safe-right)) 18px max(var(--gutter), var(--safe-left));
        overflow-y: auto;
        border-bottom: 1px solid var(--border);
        background: var(--bg);
        box-shadow: var(--shadow-md);
        opacity: 0;
        visibility: hidden;
        transform: translateY(-8px);
        transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    }

    .site-header.nav-open .nav-panel {
        opacity: 1;
        visibility: visible;
        transform: none;
    }

    .site-nav {
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
    }

    .site-nav a {
        padding: 12px 12px;
        font-size: 16px;
    }

    .site-nav a[aria-current="page"] {
        background: var(--accent-soft);
    }

    .header-search input,
    .header-search input:focus {
        width: 100%;
        height: 44px;
        font-size: 16px; /* >= 16px: no zoom-on-focus in iOS Safari */
    }

    .icon-btn {
        width: 42px;
        height: 42px;
    }

    /* Without JavaScript the toggle cannot work: show the panel inline instead. */
    html:not(.js) .nav-toggle { display: none; }
    html:not(.js) .header-inner { flex-wrap: wrap; height: auto; min-height: var(--header-h); }
    html:not(.js) .header-actions { order: 2; }
    html:not(.js) .nav-panel {
        position: static;
        order: 3;
        width: 100%;
        padding: 0 0 12px;
        border: 0;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
    }
    html:not(.js) .site-nav { flex-direction: row; flex-wrap: wrap; }

    /* hide on scroll down, show on scroll up (class toggled by enhance.js) */
    .site-header.is-hidden:not(.nav-open) {
        transform: translateY(-100%);
    }
}

@media (max-width: 640px) {
    :root {
        --gutter: 16px;
    }

    /* full-screen search on phones */
    .palette {
        padding: 0;
    }

    .palette-panel {
        max-width: none;
        height: 100%;
        max-height: none;
        padding-top: var(--safe-top);
        border: 0;
        border-radius: 0;
    }

    .palette-esc kbd {
        display: none;
    }

    .palette-esc span {
        display: inline;
    }

    .palette-footer {
        padding-bottom: calc(6px + var(--safe-bottom));
    }

    .site-main {
        padding: 18px 0 44px;
    }

    .brand-avatar {
        width: 36px;
        height: 36px;
    }

    .brand-name {
        font-size: 18px;
    }

    .rss-link {
        display: none;
    }

    .page-header {
        padding-bottom: 16px;
    }

    .page-header h1 {
        font-size: 25px;
    }

    /* category chips become a single swipeable row */
    .chips.chips-scroll {
        flex-wrap: nowrap;
        margin-left: calc(var(--gutter) * -1);
        margin-right: calc(var(--gutter) * -1);
        padding: 2px var(--gutter);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .chips.chips-scroll::-webkit-scrollbar {
        display: none;
    }

    .post-item {
        margin: 0 -8px;
        padding: 16px 8px;
    }

    .post-item + .post-item::before {
        left: 8px;
        right: 8px;
    }

    .post-title {
        font-size: 18.5px;
    }

    .post-desc {
        font-size: 14.5px;
    }

    .post-meta {
        gap: 4px 12px;
        font-size: 12.5px;
    }

    .meta-tags {
        display: none;
    }

    .pager-btn {
        padding: 8px 14px;
    }

    .article-header {
        padding-bottom: 16px;
        margin-bottom: 20px;
    }

    .article-title {
        font-size: 24px;
    }

    .article-meta {
        gap: 4px 14px;
        font-size: 13px;
    }

    .article-content {
        font-size: 16px;
        line-height: 1.8;
    }

    /* code blocks and tables run edge to edge for more room */
    .article-content .markdown-body pre,
    .table-wrapper {
        margin-left: calc(var(--gutter) * -1);
        margin-right: calc(var(--gutter) * -1);
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .article-content .markdown-body pre,
    .article-content .markdown-body pre.prettyprint {
        padding: 12px var(--gutter);
        border-left: 0;
        border-right: 0;
        font-size: 13px;
    }

    .article-content .markdown-body pre ol.linenums {
        padding-left: 2.2em;
    }

    .code-block-wrapper .copy-btn {
        right: 0;
    }

    .code-expand {
        width: auto;
        margin: 0 calc(var(--gutter) * -1);
        width: calc(100% + var(--gutter) * 2);
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    .code-block-wrapper.is-collapsed::after {
        left: calc(var(--gutter) * -1);
        right: calc(var(--gutter) * -1);
    }

    .article-footer {
        padding: 14px;
    }

    .post-nav,
    .related-list {
        grid-template-columns: 1fr;
    }

    .post-nav-item.is-empty {
        display: none;
    }

    .post-nav-next {
        align-items: flex-start;
        text-align: left;
    }

    .toast {
        bottom: calc(84px + var(--safe-bottom));
    }

    .article-content .markdown-body ul,
    .article-content .markdown-body ol {
        padding-left: 1.35em;
    }

    .archive-year-title {
        font-size: 21px;
    }

    .archive-post-item {
        gap: 10px;
    }

    .archive-post-link {
        font-size: 15px;
    }

    .section-card {
        padding: 16px;
    }

    .stat-cards {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .stat-card strong {
        font-size: 21px;
    }

    .chart-grid {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .bar-chart {
        gap: 4px;
    }

    .bar-chart-years {
        gap: 8px;
    }

    .bar-chart-hours {
        gap: 2px;
    }

    .bar-chart-hours .bar-col:nth-child(odd) .bar-label {
        visibility: hidden;
    }

    .facts li {
        grid-template-columns: 1fr auto;
    }

    .facts .fact-label {
        grid-column: 1 / -1;
        margin-bottom: -6px;
    }

    .article-actions {
        flex-wrap: wrap;
    }

    .book-grid {
        grid-template-columns: 1fr;
    }

    .tag-cloud {
        gap: 8px;
    }

    .fab-stack {
        right: calc(14px + var(--safe-right));
        bottom: calc(16px + var(--safe-bottom));
    }

    /* keep footer text clear of the floating buttons */
    .site-footer p {
        padding: 0 52px;
    }

    .footer-shortcuts {
        display: none;
    }
}

@media (max-width: 360px) {
    .brand-name {
        font-size: 16px;
    }

    .header-inner {
        gap: 8px;
    }
}

/* ---------- 13. Dark-mode code highlighting (prettify) ---------- */
[data-theme="dark"] .article-content .markdown-body img:not(.emoji) { opacity: 0.92; }
[data-theme="dark"] .prettyprint { background-color: var(--code-bg) !important; }
[data-theme="dark"] li.L0, [data-theme="dark"] li.L1, [data-theme="dark"] li.L2, [data-theme="dark"] li.L3,
[data-theme="dark"] li.L4, [data-theme="dark"] li.L5, [data-theme="dark"] li.L6, [data-theme="dark"] li.L7,
[data-theme="dark"] li.L8, [data-theme="dark"] li.L9 { background: none; }
[data-theme="dark"] .pln { color: #d4d7e0; }
[data-theme="dark"] .str { color: #a5d6a7; }
[data-theme="dark"] .kwd { color: #c792ea; }
[data-theme="dark"] .com { color: #7f849c; }
[data-theme="dark"] .typ { color: #82aaff; }
[data-theme="dark"] .lit { color: #f78c6c; }
[data-theme="dark"] .clo, [data-theme="dark"] .opn, [data-theme="dark"] .pun { color: #bbb; }
[data-theme="dark"] .tag { color: #f07178; }
[data-theme="dark"] .atn { color: #ffcb6b; }
[data-theme="dark"] .atv { color: #c3e88d; }
[data-theme="dark"] .dec { color: #f78c6c; }
[data-theme="dark"] .var, [data-theme="dark"] .fun { color: #82aaff; }

/* ---------- 14. Motion & print ---------- */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media print {
    :root {
        --bg: #fff;
        --text: #000;
        --text-2: #222;
        --text-3: #444;
        --border: #bbb;
        --code-bg: #f4f4f4;
    }

    .site-header, .site-footer, .skip-link, #reading-progress, .fab-stack, .toc-container, .toc-overlay,
    .article-aside, .comments, .copy-btn, .pager, .chips, .filter-bar, .article-actions, .post-nav, .related,
    .heading-anchor, .code-lang, .code-expand, .toast, .lightbox, .palette, .modal, .home-aside, .burst-piece, .rain-piece {
        display: none !important;
    }

    .code-block-wrapper.is-collapsed pre { max-height: none !important; }
    .code-block-wrapper.is-collapsed::after { display: none; }

    body { display: block; font-size: 11.5pt; }
    .site-main { padding: 0; }
    .container, .article-layout, .article-layout.has-toc { display: block; max-width: none; padding: 0; }
    .article-content .markdown-body a { color: #000; }
    .article-content .markdown-body pre { white-space: pre-wrap; overflow: visible; border: 1px solid #bbb; }
    .article-content .markdown-body pre code, .article-content .markdown-body pre ol.linenums li { white-space: pre-wrap; }
    .article-content .markdown-body pre, .article-content .markdown-body img, .table-wrapper, blockquote { break-inside: avoid; }
    h1, h2, h3, h4 { break-after: avoid; }
}
