/* ==========================================================================
   Netzhi theme — main stylesheet (no external fonts or assets)
   ========================================================================== */

:root {
	--bg: #f4f6f9;
	--surface: #ffffff;
	--surface-2: #f7f8fa;
	--text: #1f2329;
	--text-2: #4e5969;
	--muted: #86909c;
	--border: #e5e8ee;
	--border-strong: #d4d9e1;
	--primary: #1d6ef2;
	--primary-hover: #155ad1;
	--primary-soft: #eaf2ff;
	--code-bg: #f2f4f7;
	--pre-bg: #1f2430;
	--pre-text: #e6e9ef;
	--shadow: 0 1px 2px rgba(16, 24, 40, .04);
	--radius: 12px;
	--radius-sm: 8px;
	--header-h: 60px;
	--font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "Helvetica Neue", Arial, sans-serif;
	--mono: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;
	color-scheme: light;
}

[data-theme="dark"] {
	--bg: #0f1115;
	--surface: #171a21;
	--surface-2: #1d2129;
	--text: #e6e8eb;
	--text-2: #b4bac4;
	--muted: #858d99;
	--border: #262b34;
	--border-strong: #343a45;
	--primary: #5b94ff;
	--primary-hover: #7aa8ff;
	--primary-soft: #1a2740;
	--code-bg: #222731;
	--pre-bg: #12151b;
	--pre-text: #e6e9ef;
	--shadow: none;
	color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #0f1115;
		--surface: #171a21;
		--surface-2: #1d2129;
		--text: #e6e8eb;
		--text-2: #b4bac4;
		--muted: #858d99;
		--border: #262b34;
		--border-strong: #343a45;
		--primary: #5b94ff;
		--primary-hover: #7aa8ff;
		--primary-soft: #1a2740;
		--code-bg: #222731;
		--pre-bg: #12151b;
		--pre-text: #e6e9ef;
		--shadow: none;
		color-scheme: dark;
	}
}

/* ---------- Base ---------- */

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

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

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.7 var(--font);
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--primary); }
img, svg { vertical-align: middle; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { color: var(--text); }
button { font: inherit; color: inherit; cursor: pointer; }

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

.screen-reader-text {
	position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
	overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link:focus {
	clip: auto; width: auto; height: auto; margin: 0; z-index: 100; top: 8px; left: 8px;
	padding: 8px 14px; background: var(--surface); color: var(--primary); border-radius: var(--radius-sm); box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

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

.icon { flex: none; }

/* ---------- Header ---------- */

.site-header {
	position: sticky; top: 0; z-index: 50;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 32px; height: var(--header-h); }

.brand { display: flex; align-items: center; gap: 10px; flex: none; color: var(--text); }
.brand:hover { color: var(--text); }
.brand-mark { color: var(--primary); }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.custom-logo { max-height: 36px; width: auto; }

.nav .menu { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.nav .menu a {
	display: block; padding: 7px 12px; border-radius: var(--radius-sm);
	color: var(--text-2); font-size: 15px; white-space: nowrap;
}
.nav .menu a:hover { color: var(--primary); background: var(--primary-soft); }
.nav .current-menu-item > a, .nav .current-menu-parent > a, .nav .current-post-ancestor > a { color: var(--primary); font-weight: 600; }

.header-tools { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.icon-btn {
	display: inline-grid; place-items: center; width: 38px; height: 38px;
	border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--primary); }
.menu-btn { display: none; }

.when-dark { display: none; }
[data-theme="dark"] .when-light { display: none; }
[data-theme="dark"] .when-dark { display: inline; }
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .when-light { display: none; }
	:root:not([data-theme="light"]) .when-dark { display: inline; }
}

.search-panel { border-top: 1px solid var(--border); padding: 14px 0; background: var(--surface); }

.search-form {
	position: relative; display: flex; align-items: center; gap: 8px; max-width: 640px;
}
.search-form .icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search-field {
	flex: 1; min-width: 0; height: 42px; padding: 0 12px 0 40px;
	border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
	background: var(--surface); color: var(--text); font: inherit; font-size: 15px;
}
.search-field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-submit, .btn {
	display: inline-flex; align-items: center; justify-content: center; height: 42px; padding: 0 18px;
	border: 0; border-radius: var(--radius-sm); background: var(--primary); color: #fff; font-size: 15px; white-space: nowrap;
}
.search-submit:hover, .btn:hover { background: var(--primary-hover); color: #fff; }

/* ---------- Layout ---------- */

.site-main { padding: 24px 0 48px; min-height: calc(100vh - var(--header-h) - 120px); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.content { min-width: 0; display: grid; gap: 16px; align-content: start; }
.sidebar { display: grid; gap: 16px; align-content: start; align-self: stretch; }
.content > *, .sidebar > * { min-width: 0; } /* let wide code/tables scroll instead of widening the column */

.panel {
	background: var(--surface); border: 1px solid var(--border);
	border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel-head {
	display: flex; align-items: center; justify-content: space-between;
	padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.panel-title {
	position: relative; margin: 0; padding-left: 12px; font-size: 16px; font-weight: 600; line-height: 1.5;
}
.panel-title::before {
	content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px; border-radius: 2px; background: var(--primary);
}

/* ---------- Post list ---------- */

.post-item { display: flex; gap: 20px; padding: 20px; }
.post-item + .post-item { border-top: 1px solid var(--border); }

.post-thumb {
	flex: 0 0 224px; aspect-ratio: 16 / 9; overflow: hidden;
	border-radius: var(--radius-sm); background: var(--surface-2);
}
.post-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.post-item:hover .post-thumb img { transform: scale(1.03); }

.post-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.post-title { margin: 0 0 8px; font-size: 18px; font-weight: 600; line-height: 1.5; }
.post-title a {
	display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.post-excerpt {
	margin: 0 0 12px; color: var(--text-2); font-size: 14px; line-height: 1.75;
	display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.post-meta {
	display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
	margin-top: auto; color: var(--muted); font-size: 13px; line-height: 1.6;
}
.meta-item { display: inline-flex; align-items: center; gap: 4px; }
.post-cat {
	display: inline-block; padding: 1px 8px; border-radius: 4px;
	background: var(--primary-soft); color: var(--primary); font-size: 12px; line-height: 20px;
}
.post-cat:hover { background: var(--primary); color: #fff; }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty .search-form { margin: 16px auto 0; }

.archive-head { padding: 20px 24px; }
.archive-title { margin: 0; font-size: 20px; line-height: 1.5; }
.archive-desc { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.pagination {
	display: flex; justify-content: center; flex-wrap: wrap; gap: 6px;
	padding: 16px 20px 20px; border-top: 1px solid var(--border);
}
.page-numbers {
	display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 10px;
	border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-2); font-size: 14px;
}
a.page-numbers:hover { border-color: var(--primary); color: var(--primary); }
.page-numbers.current { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-numbers.dots { border-color: transparent; }

/* ---------- Sidebar widgets ---------- */


.mini-list { margin: 0; padding: 6px 0; list-style: none; counter-reset: mini; }
.mini-list li { display: grid; gap: 2px; padding: 10px 20px; }
.mini-list li + li { border-top: 1px dashed var(--border); }
.mini-list a {
	font-size: 14px; line-height: 1.6; color: var(--text);
	display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.mini-list a:hover { color: var(--primary); }
.mini-list time { color: var(--muted); font-size: 12px; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 20px; }
.tag-cloud a {
	padding: 3px 10px; border-radius: 6px; background: var(--surface-2);
	color: var(--text-2); font-size: 13px !important; line-height: 1.6;
}
.tag-cloud a:hover { background: var(--primary-soft); color: var(--primary); }

.widget ul { margin: 0; padding: 8px 20px 12px; list-style: none; }
.widget ul li { padding: 6px 0; font-size: 14px; }
.widget > *:not(.panel-head) { max-width: 100%; }

/* ---------- Breadcrumb ---------- */

.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { color: var(--border-strong); }

/* ---------- Article ---------- */

.article { padding: 32px 40px 36px; }
.article-head { margin-bottom: 20px; }
.article-title { margin: 0 0 14px; font-size: 28px; font-weight: 700; line-height: 1.45; letter-spacing: .01em; }

.toc-inline {
	display: none; margin: 0 0 24px; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.toc-inline summary {
	display: flex; align-items: center; gap: 6px; padding: 10px 14px; cursor: pointer;
	font-weight: 600; list-style: none;
}
.toc-inline summary::-webkit-details-marker { display: none; }
.toc-inline[open] summary { border-bottom: 1px solid var(--border); }

.toc-list { margin: 0; padding: 8px; list-style: none; }
.toc-list a {
	display: block; padding: 6px 12px; border-radius: 6px;
	color: var(--text-2); font-size: 14px; line-height: 1.55;
}
.toc-list a:hover { color: var(--primary); background: var(--surface-2); }
.toc-list .lvl-3 a { padding-left: 26px; font-size: 13px; }
.toc-list a.is-active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }

.toc-panel { position: sticky; top: calc(var(--header-h) + 20px); }
.toc-panel .toc-list { max-height: calc(100vh - var(--header-h) - 120px); overflow-y: auto; }

/* ---------- Entry content typography ---------- */

.entry-content { font-size: 16px; line-height: 1.9; overflow-wrap: break-word; }
.entry-content > *:first-child { margin-top: 0; }
.entry-content p { margin: 0 0 1.2em; }
.entry-content h2 {
	margin: 2em 0 .8em; padding-left: 12px; border-left: 4px solid var(--primary);
	font-size: 21px; line-height: 1.45;
}
.entry-content h3 { margin: 1.7em 0 .7em; font-size: 18px; line-height: 1.5; }
.entry-content h4 { margin: 1.5em 0 .6em; font-size: 16px; }
.entry-content a {
	color: var(--primary); text-decoration: underline; text-underline-offset: 3px;
	text-decoration-thickness: 1px; text-decoration-color: color-mix(in srgb, var(--primary) 40%, transparent);
}
.entry-content a:hover { text-decoration-color: currentColor; }
.entry-content strong { font-weight: 600; color: var(--text); }
.entry-content ul, .entry-content ol { margin: 0 0 1.2em; padding-left: 1.5em; }
.entry-content li { margin: .35em 0; }
.entry-content li::marker { color: var(--muted); }
.entry-content blockquote {
	margin: 1.5em 0; padding: 12px 18px; border-left: 4px solid var(--border-strong);
	border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); color: var(--text-2);
}
.entry-content blockquote p:last-child { margin-bottom: 0; }
.entry-content hr { margin: 2em 0; border: 0; border-top: 1px solid var(--border); }
.entry-content img { border-radius: var(--radius-sm); }
.entry-content figure { margin: 1.6em 0; }
.entry-content figcaption, .entry-content .wp-element-caption {
	margin-top: 8px; color: var(--muted); font-size: 13px; text-align: center;
}

.entry-content code {
	padding: .15em .4em; border: 1px solid var(--border); border-radius: 4px;
	background: var(--code-bg); font-family: var(--mono); font-size: .875em;
}
.entry-content pre {
	position: relative; margin: 1.5em 0; padding: 16px 18px; overflow-x: auto;
	border-radius: var(--radius-sm); background: var(--pre-bg); color: var(--pre-text);
	font-family: var(--mono); font-size: 13.5px; line-height: 1.7; tab-size: 4;
}
.entry-content pre code { padding: 0; border: 0; background: none; color: inherit; font-size: inherit; }
.copy-btn {
	position: absolute; top: 8px; right: 8px; padding: 2px 10px;
	border: 1px solid rgba(255,255,255,.14); border-radius: 6px;
	background: rgba(255,255,255,.06); color: #c9d1d9; font-size: 12px; line-height: 22px;
	opacity: 0; transition: opacity .15s ease;
}
.entry-content pre:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
@media (hover: none) { .copy-btn { opacity: 1; } }

.table-wrap, .entry-content .wp-block-table {
	margin: 1.5em 0; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.entry-content table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.7; }
.entry-content th, .entry-content td {
	padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top;
}
.entry-content th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.entry-content tr > :first-child { min-width: 5.5em; }
.entry-content tr:last-child td { border-bottom: 0; }
.entry-content td + td, .entry-content th + th { border-left: 1px solid var(--border); }

/* ---------- Tags, post navigation ---------- */

.article-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 32px; }
.article-tags a {
	padding: 3px 10px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); font-size: 13px;
}
.article-tags a:hover { background: var(--primary-soft); color: var(--primary); }

.post-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.post-nav-item { display: grid; gap: 4px; padding: 16px 20px; }
.post-nav-item.is-next { text-align: right; }
.post-nav-label { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; }
.post-nav-item.is-next .post-nav-label { justify-content: flex-end; }
.post-nav-title {
	font-size: 15px; font-weight: 500; line-height: 1.6;
	display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.related .mini-list { display: grid; grid-template-columns: 1fr 1fr; padding: 4px 0; }
.related .mini-list li + li { border-top: 0; }
.related .mini-list li { border-bottom: 1px dashed var(--border); }
.related .mini-list li:nth-last-child(-n+2):nth-child(odd),
.related .mini-list li:last-child { border-bottom: 0; }

/* ---------- 404 ---------- */

.not-found { max-width: 640px; margin: 24px auto; padding: 48px 32px; text-align: center; }
.not-found-code { margin: 0; color: var(--primary); font-size: 56px; font-weight: 700; line-height: 1; }
.not-found-title { margin: 16px 0 8px; font-size: 22px; }
.not-found-text { margin: 0 0 24px; color: var(--muted); }
.not-found .search-form { margin: 0 auto 20px; }

/* ---------- Footer ---------- */

.site-footer { border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px; }
.footer-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; padding-top: 24px; padding-bottom: 24px; }
.footer-brand p { margin: 0; line-height: 1.8; }
.footer-copy a { color: var(--text-2); font-weight: 600; }
.footer-links .menu { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0; padding: 0; list-style: none; }
.footer-links a { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); }
.footer-links a:hover { color: var(--primary); }

.to-top {
	position: fixed; right: 20px; bottom: 24px; z-index: 40;
	display: grid; place-items: center; width: 42px; height: 42px;
	border: 1px solid var(--border); border-radius: 50%; background: var(--surface); color: var(--text-2);
	box-shadow: 0 4px 12px rgba(16, 24, 40, .08);
	opacity: 0; visibility: hidden; transform: translateY(8px); transition: all .2s ease;
}
.to-top.is-visible { opacity: 1; visibility: visible; transform: none; }
.to-top:hover { color: var(--primary); border-color: var(--primary); }

/* ---------- Responsive ---------- */

@media (max-width: 1024px) {
	.layout { grid-template-columns: minmax(0, 1fr); }
	.toc-panel { display: none; }
	.toc-inline { display: block; }
	.sidebar { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
}

@media (max-width: 860px) {
	.header-inner { gap: 12px; }
	.menu-btn { display: inline-grid; }
	.nav {
		position: absolute; top: var(--header-h); left: 0; right: 0;
		display: none; background: var(--surface); border-bottom: 1px solid var(--border);
		box-shadow: 0 8px 16px rgba(16, 24, 40, .06);
	}
	.nav.is-open { display: block; }
	.nav .menu { flex-direction: column; gap: 2px; padding: 8px 12px 12px; }
	.nav .menu a { padding: 10px 12px; }
}

@media (max-width: 640px) {
	:root { --header-h: 56px; }
	.container { padding: 0 14px; }
	.site-main { padding: 14px 0 32px; }
	.layout, .content, .sidebar { gap: 12px; }
	.brand-name { font-size: 18px; }
	.post-item { gap: 14px; padding: 16px; }
	.post-thumb { flex-basis: 112px; }
	.post-title { font-size: 16px; margin-bottom: 6px; }
	.post-excerpt { display: none; }
	.post-meta { gap: 4px 12px; font-size: 12px; }
	.article { padding: 22px 18px 26px; }
	.article-title { font-size: 22px; }
	.entry-content { font-size: 16px; line-height: 1.85; }
	.entry-content h2 { font-size: 19px; }
	.entry-content h3 { font-size: 17px; }
	.entry-content pre { margin-left: -18px; margin-right: -18px; border-radius: 0; }
	.post-nav { grid-template-columns: 1fr; gap: 12px; }
	.post-nav-item.is-next { text-align: left; }
	.post-nav-item.is-next .post-nav-label { justify-content: flex-start; }
	.related .mini-list { grid-template-columns: 1fr; }
	.related .mini-list li { border-bottom: 1px dashed var(--border); }
	.related .mini-list li:last-child { border-bottom: 0; }
	.search-submit { padding: 0 14px; }
	.footer-inner { flex-direction: column; align-items: flex-start; }
	.to-top { right: 14px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

@media print {
	.site-header, .sidebar, .post-nav, .related, .to-top, .site-footer, .toc-inline { display: none !important; }
	body { background: #fff; }
	.panel { border: 0; box-shadow: none; }
	.layout { display: block; }
}
