/* ---------- tokens ---------- */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #16202c;
  --muted: #5b6878;
  --border: #e2e7ee;
  --accent: #0a6ed1;
  --accent-strong: #0854a0;
  --accent-soft: #e6f1fc;
  --accent-2: #0d9488;
  --code-bg: #0f1724;
  --code-head: #172234;
  --code-text: #dbe4f0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-hover: 0 2px 4px rgba(16, 24, 40, .06), 0 12px 32px rgba(16, 24, 40, .10);
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1119;
    --surface: #111a26;
    --surface-2: #162131;
    --text: #e4eaf2;
    --muted: #93a1b3;
    --border: #223044;
    --accent: #4fa8ff;
    --accent-strong: #7cc0ff;
    --accent-soft: #12263d;
    --accent-2: #2dd4bf;
    --code-bg: #0a1018;
    --code-head: #111b29;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-hover: 0 8px 28px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1119;
  --surface: #111a26;
  --surface-2: #162131;
  --text: #e4eaf2;
  --muted: #93a1b3;
  --border: #223044;
  --accent: #4fa8ff;
  --accent-strong: #7cc0ff;
  --accent-soft: #12263d;
  --accent-2: #2dd4bf;
  --code-bg: #0a1018;
  --code-head: #111b29;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-hover: 0 8px 28px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
img { max-width: 100%; height: auto; }
.container { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) { .container { padding: 0 32px; } }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 16px; min-height: 64px; }
.brand { color: var(--text); font-size: 18px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { color: var(--accent); }
.main-nav { display: flex; gap: 2px; margin-left: 12px; }
.main-nav a { color: var(--muted); font-weight: 500; font-size: 15px; padding: 6px 11px; border-radius: 8px; white-space: nowrap; }
.main-nav a:hover { color: var(--text); background: var(--surface-2); }
.main-nav a[aria-current] { color: var(--text); background: var(--surface-2); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn, .lang-menu > summary {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  color: var(--text); cursor: pointer; font: 600 13px var(--font);
}
.icon-btn:hover, .lang-menu > summary:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: inline-flex; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: inline-flex; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}
.icon-btn span { display: inline-flex; }
.lang-menu { position: relative; }
.lang-menu > summary { list-style: none; }
.lang-menu > summary::-webkit-details-marker { display: none; }
.lang-list {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-hover);
}
.lang-list a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-size: 14px; }
.lang-list a:hover { background: var(--surface-2); }
.lang-list a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lang-code { font-family: var(--mono); font-size: 12px; color: var(--muted); width: 22px; }
/* Narrow screens: menu moves to its own scrollable row under the brand. */
@media (max-width: 960px) {
  .header-inner { flex-wrap: wrap; gap: 0 12px; padding-top: 10px; }
  .main-nav {
    order: 3; width: 100%; margin: 6px -16px 0; padding: 0 16px 8px;
    overflow-x: auto; scrollbar-width: none; width: calc(100% + 32px);
  }
  .main-nav::-webkit-scrollbar { display: none; }
  .main-nav a { padding: 6px 10px; font-size: 14px; }
}
@media (min-width: 768px) and (max-width: 960px) {
  .main-nav { margin: 6px -32px 0; padding: 0 32px 8px; width: calc(100% + 64px); }
}
@media (max-width: 560px) {
  .brand { font-size: 16px; }
}

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden;
  padding: 72px 0 56px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(900px 400px at 85% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(600px 300px at 0% 110%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 70%);
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.5), transparent 85%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.5), transparent 85%);
}
.hero .container { position: relative; }
.hero-art { display: none; position: absolute; pointer-events: none; }
@media (min-width: 1100px) {
  .hero-art { display: block; right: max(0px, calc((100vw - 1160px) / 2 - 40px)); bottom: -40px; width: 420px; }
  .hero h1, .hero-text { max-width: 640px; }
  .hero-tags { max-width: 640px; }
}
.kicker {
  display: inline-block; margin: 0 0 16px; padding: 4px 12px; border-radius: 999px;
  font: 600 12.5px var(--mono); letter-spacing: .03em;
  color: var(--accent); background: var(--accent-soft);
}
.hero h1 { font-size: clamp(30px, 5.2vw, 52px); line-height: 1.1; letter-spacing: -.03em; margin: 0 0 18px; max-width: 820px; }
.hero-text { font-size: clamp(16px, 2vw, 19px); color: var(--muted); max-width: 640px; margin: 0 0 24px; }

/* ---------- posts ---------- */
.section { padding: 48px 16px 72px; }
@media (min-width: 768px) { .section { padding: 56px 32px 88px; } }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 20px; }
.post-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.post-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.post-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.post-card-link { display: flex; flex-direction: column; height: 100%; padding: 24px; color: var(--text); }
.post-card-link:hover { color: var(--text); }
.post-card h3 { font-size: 20px; line-height: 1.3; letter-spacing: -.01em; margin: 10px 0 8px; }
.post-card p { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.read-more { margin-top: auto; padding-top: 12px; font-weight: 600; font-size: 14px; color: var(--accent); }
.post-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font: 500 12px var(--mono); padding: 3px 9px; border-radius: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------- article ---------- */
.article-layout { padding-top: 32px; padding-bottom: 88px; }
.article { min-width: 0; max-width: 780px; }
@media (min-width: 1080px) {
  .article-layout.has-toc { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 56px; }
}
.back-link { display: inline-block; font-size: 14px; font-weight: 500; margin-bottom: 20px; color: var(--muted); }
.back-link:hover { color: var(--accent); }
.article-header { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.article-header h1 { font-size: clamp(28px, 4.4vw, 42px); line-height: 1.15; letter-spacing: -.025em; margin: 10px 0 14px; }
.lead { font-size: 19px; color: var(--muted); margin: 0 0 18px; }

.toc { display: none; }
@media (min-width: 1080px) { .toc { display: block; } }
.toc-inner { position: sticky; top: 96px; max-height: calc(100vh - 120px); overflow: auto; padding-left: 16px; border-left: 1px solid var(--border); }
.toc-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 0 0 10px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a { display: block; padding: 4px 0; font-size: 13.5px; line-height: 1.4; color: var(--muted); }
.toc a:hover, .toc a.active { color: var(--accent); }
.toc .toc-3 a { padding-left: 12px; font-size: 13px; }

/* prose */
.prose { font-size: 17px; }
.prose > * + * { margin-top: 1.1em; }
.prose p, .prose ul, .prose ol { margin-bottom: 0; }
.prose h2 { font-size: 26px; letter-spacing: -.02em; line-height: 1.25; margin: 2em 0 .2em; }
.prose h3 { font-size: 20px; letter-spacing: -.01em; margin: 1.6em 0 .2em; }
.prose h2, .prose h3 { position: relative; }
.prose .anchor { position: absolute; left: -1em; width: 1em; opacity: 0; color: var(--muted); font-weight: 400; }
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.prose li + li { margin-top: .35em; }
.prose strong { font-weight: 650; }
.prose :not(pre) > code {
  font-family: var(--mono); font-size: .86em; padding: .15em .4em; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.prose blockquote {
  margin-left: 0; margin-right: 0; padding: 14px 18px; border-left: 4px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 10px 10px 0; color: var(--text);
}
.prose blockquote > :first-child { margin-top: 0; }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.5em 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; }
.prose th, .prose td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.prose tr:last-child td { border-bottom: 0; }
.prose kbd {
  font: 500 .8em var(--mono); padding: .1em .45em; border-radius: 6px;
  border: 1px solid var(--border); border-bottom-width: 2px; background: var(--surface);
}

.callout { padding: 12px 16px; border-radius: 10px; margin-bottom: 24px; font-size: 15px; }
.callout-info { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }

/* code blocks */
.code-block { margin: 1.4em 0; border-radius: 12px; overflow: hidden; background: var(--code-bg); border: 1px solid color-mix(in srgb, var(--border) 40%, #000); }
.code-block figcaption {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px 8px 16px; background: var(--code-head); border-bottom: 1px solid rgba(255,255,255,.06);
}
.code-file { font: 500 12.5px var(--mono); color: #9fb0c6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy-btn {
  flex: none; font: 600 12px var(--font); color: #c8d4e3; background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1); border-radius: 7px; padding: 4px 10px; cursor: pointer;
}
.copy-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.copy-btn.done { color: #5eead4; border-color: rgba(94,234,212,.4); }
.code-block pre { margin: 0; padding: 16px 18px; overflow-x: auto; font: 13.5px/1.65 var(--mono); color: var(--code-text); tab-size: 2; }
.code-block code { font: inherit; }

/* Prism tokens (dark code surface in both themes) */
.token.comment, .token.prolog { color: #6b7d95; font-style: italic; }
.token.string, .token.string-template, .token.char { color: #a5e3a0; }
.token.keyword { color: #7cb7ff; }
.token.builtin, .token.class-name { color: #ffcb6b; }
.token.function, .token.annotation { color: #f0a6ff; }
.token.number, .token.boolean { color: #ffab70; }
.token.operator, .token.punctuation { color: #9fb0c6; }
.token.variable, .token.property, .token.attr-name { color: #5eead4; }
.token.tag { color: #7cb7ff; }

/* screenshots */
.shot { margin: 1.6em 0; }
.shot img { display: block; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.shot figcaption { margin-top: 10px; font-size: 14px; color: var(--muted); text-align: center; }
.shot-ph {
  display: grid; place-items: center; aspect-ratio: 16 / 8; border-radius: 12px;
  border: 2px dashed var(--border); color: var(--muted);
  background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 12px, var(--surface-2) 12px, var(--surface-2) 24px);
}

.hero-small { padding: 48px 0 40px; }
.hero-small h1 { font-size: clamp(30px, 4.6vw, 44px); }
.hero-small .hero-text { margin-bottom: 0; }
.empty-state {
  padding: 40px 24px; text-align: center; color: var(--muted);
  border: 2px dashed var(--border); border-radius: var(--radius);
}

/* ---------- 404 / misc ---------- */
.not-found h1 { font-size: 40px; margin: 8px 0; letter-spacing: -.02em; }
.lang-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.btn { display: inline-block; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 500; font-size: 14px; }
.btn:hover { border-color: var(--accent); }

/* ---------- search ---------- */
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.section-head .section-title { margin: 0; }
.search-box {
  display: flex; align-items: center; gap: 8px; width: min(100%, 320px); height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--muted);
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: 15px var(--font); }
.post-card[hidden] { display: none; }

/* ---------- reading progress ---------- */
.read-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 30; pointer-events: none; }
.read-progress span {
  display: block; height: 100%; transform-origin: 0 50%; transform: scaleX(0);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ---------- share / related ---------- */
.share { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 48px 0 0; padding-top: 24px; border-top: 1px solid var(--border); }
.share-label { font-weight: 600; font-size: 14px; margin-right: 4px; }
.share-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 500 13.5px var(--font); cursor: pointer;
}
.share-btn:hover { border-color: var(--accent); color: var(--accent); }
.share-btn.done { color: var(--accent-2); border-color: var(--accent-2); }
.related { margin-top: 48px; }
.related .post-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.related .post-card p, .related .post-card .tags { display: none; }
.related .post-card h3 { font-size: 17px; }

/* ---------- forms ---------- */
.form-card {
  display: grid; gap: 16px; padding: 24px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.form-card h3, .form-card h1 { margin: 0; font-size: 19px; }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.form-card label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.form-card input, .form-card textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: 15px/1.5 var(--font);
}
.form-card textarea { resize: vertical; min-height: 120px; }
.form-card input:focus, .form-card textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-card .hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.form-status { margin: 0; font-size: 14px; }
.form-status.ok { color: var(--accent-2); font-weight: 600; }
.form-status.error { color: #e5484d; font-weight: 600; }
.btn { cursor: pointer; font-family: var(--font); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0b1119; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #0b1119; } }
.btn-danger { color: #e5484d; }
.btn-danger:hover { border-color: #e5484d; }
.btn:disabled { opacity: .6; cursor: default; }
.contact-form { max-width: 760px; }
.muted { color: var(--muted); }

/* ---------- comments ---------- */
.comments { margin-top: 56px; }
.comments h2 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 16px; }
.comment-count { color: var(--muted); font-weight: 500; font-size: .8em; }
.comment-list { display: grid; gap: 12px; margin-bottom: 24px; }
/* Scoped to the list: Prism also uses the class "comment" for code comments. */
.comment-list > .comment { padding: 16px 18px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.comment-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 14px; }
.comment-head time { color: var(--muted); margin-left: auto; font-size: 13px; }
.comment-list > .comment p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.avatar {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 700; font-size: 13px;
}

/* ---------- admin ---------- */
.admin-badge { font: 600 12.5px var(--mono); padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.login-card { max-width: 420px; margin: 40px auto; }
.password-card { max-width: 480px; }
.admin .header-actions { gap: 12px; font-size: 14px; }
.admin-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.admin-tabs button {
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font: 500 14px var(--font); cursor: pointer;
}
.admin-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); font-weight: 600; }
.admin-tabs span:not(:empty) { margin-left: 4px; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; }
.admin-list { display: grid; gap: 12px; }
.admin-card { display: grid; gap: 8px; padding: 18px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.admin-card.unread { border-left: 4px solid var(--accent); }
.admin-card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; font-size: 14px; }
.admin-post { font-weight: 600; font-size: 14.5px; }
.admin-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-actions, .admin-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

/* ---------- footer ---------- */
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.footer-links a { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.footer-links a:hover { color: var(--accent); }
.site-footer { border-top: 1px solid var(--border); padding: 28px 0; color: var(--muted); font-size: 14px; }
.footer-inner { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }
