/* style.css: hand-written. Light tokens, redefined for dark; all text meets WCAG AA. */
:root {
  --bg: #faf8f3; --surface: #f1ede4; --text: #1f2328; --muted: #5d5850; --rule: #e2dcd0; --rule-strong: #8f887c;
  --accent: #b0392b; --accent-soft: #b0392b24; --mark: #f6e2a4;
  /* Traditional Chinese serifs, then sans fallbacks: iOS has no TC serif and Android rarely does,
     so headings there fall back to a sans with a real bold instead of a random serif */
  --serif: "Noto Serif TC", "Source Han Serif TC", "Noto Serif CJK TC", "Songti TC", "PMingLiU", "PingFang TC", "Microsoft JhengHei", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --gutter: 1.25rem; --line: 1px solid var(--rule);
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  --bg: #17181b; --surface: #222327; --text: #ebe6dd; --muted: #a9a398; --rule: #35373c; --rule-strong: #6b6d74;
  --accent: #f0907a; --accent-soft: #f0907a38; --mark: #4a3b15; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b; --surface: #222327; --text: #ebe6dd; --muted: #a9a398; --rule: #35373c; --rule-strong: #6b6d74;
    --accent: #f0907a; --accent-soft: #f0907a38; --mark: #4a3b15;
  }
}
/* Chinese: the CJK font first, so …… —— “ ” and · are full-width and sit where they belong */
html:lang(zh) { --sans: "PingFang TC", "Noto Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
/* English, for a whole page or a passage inside a Chinese page: Latin fonts first */
:root:lang(en), [lang|="en"] {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif TC", "Songti TC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang TC", "Microsoft JhengHei", sans-serif;
}

/* Base */
*, ::before, ::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html:lang(zh) { line-break: strict; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1.0625rem/1.85 var(--sans); overflow-wrap: break-word; }
:where([lang|="en"]:not(:root)) { font-family: var(--sans); }
body:lang(en), .notfound:lang(en), .prose [lang|="en"] { line-height: 1.65; }
@supports (text-autospace: normal) {
  html { text-autospace: normal; }
  :is(pre, code, kbd, samp) { text-autospace: no-autospace; } /* keep code on its monospace grid */
}
@supports (text-spacing-trim: trim-start) { html:lang(zh) { text-spacing-trim: trim-start; } }
h1, h2, h3, h4 { text-wrap: balance; }
/* Chinese headings break at punctuation and spaces, never inside a word such as 文章 */
html:lang(zh) :is(h1, h2, h3, h4, .nav-title) { word-break: keep-all; overflow-wrap: anywhere; }
/* No fake bold where the Chinese serif has no bold face (PMingLiU on Windows) */
html:lang(zh) :is(h1, h2, h3, .site-name, .nav-title) { font-synthesis-weight: none; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: .22em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
main:focus { outline: none; }
::selection { background: var(--accent-soft); }
img, svg, video { max-width: 100%; height: auto; }
.wrap { max-width: calc(40rem + 2 * var(--gutter)); margin-inline: auto; padding-inline: var(--gutter); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; top: 0; left: var(--gutter); z-index: 10; padding-inline: 1rem; background: var(--text); color: var(--bg); transform: translateY(-110%); }
.skip-link:focus { transform: none; }
.tagline, .section-title, .post-date, .post-summary, .note, .empty, .lede, .post-meta, .archive-list time, .count,
.nav-label, .site-footer, .prose blockquote, .prose caption, .prose figcaption, .prose small { color: var(--muted); }
.post-date, .post-meta, .archive-list time, .archive-year h2, .count, .prose ol > li::marker { font-variant-numeric: tabular-nums; }
.post-date, .post-meta, .archive-list time, .count, .site-footer, .lang-switch { font-size: .875rem; }
.eyebrow, .tags, .nav-label { font-size: .8125rem; }
.more, .translation, .note { font-size: .9375rem; }
.post-title, .post-summary, .translation, .footer-inner p { margin: 0; }
/* English names and titles do not need the letter-spacing that suits Chinese */
html:lang(en) :is(.site-name, .hero h1, .page-header :is(h1, h2), .post-header h1) { letter-spacing: 0; }

/* Header: every control is 44px+ tall. The site name and the tools share the first row;
   the nav has a row of its own below 48rem and sits between them on wider screens. */
.site-header { border-bottom: var(--line); }
.header-inner { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 1rem; padding-block: .5rem; }
.tools { grid-area: 1 / 2; }
.site-nav { grid-area: 2 / 1 / 3 / 3; }
@media (min-width: 48rem) {
  .header-inner { grid-template-columns: auto minmax(0, 1fr) auto; }
  .site-nav { grid-area: 1 / 2; justify-self: end; }
  .tools { grid-area: 1 / 3; }
}
@media (max-width: 47.99rem) {
  .site-nav ul { margin-inline: -.55rem; }
}
.site-nav ul, .post-list, .archive-list, .tag-index, .tags { margin: 0; padding: 0; list-style: none; }
.site-nav ul, .tools, .lang-switch, .post-meta, .tags, .tag-index, .footer-inner { display: flex; flex-wrap: wrap; align-items: center; }
.skip-link, .site-name, .site-nav a, .lang-switch > *, .more a, .translation a, .site-footer a, .tags a, .tag-index a { display: inline-flex; align-items: center; gap: .3em; min-height: 44px; text-decoration: none; }
.site-name, .post-title a, .archive-list a, .tag-index a, .nav-title { color: var(--text); }
.site-name { justify-self: start; gap: .6rem; font: 600 1.125rem/1.3 var(--serif); letter-spacing: .05em; }
.site-name::before { content: ""; flex: none; width: .75rem; height: .75rem; border-radius: 2px; background: var(--accent); }
.site-nav a { padding-inline: .55rem; color: var(--muted); font-size: .9375rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text); }
.site-nav a[aria-current="page"] { text-decoration: underline 2px var(--accent); text-underline-offset: .5em; }
.lang-switch { color: var(--muted); }
.lang-switch > a { justify-content: center; min-width: 44px; }
.lang-current { padding-inline: .35rem; color: var(--text); font-weight: 600; }
.theme-toggle { display: none; }
.js .theme-toggle { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.theme-toggle:hover { background: var(--surface); color: var(--text); }
/* The icon follows the theme itself, which is known before the first paint; aria-pressed is
   only set once the page has loaded. A moon in light mode, a sun in dark mode. */
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* Post lists: dates get a column on wide screens */
.hero { padding-block: 3.5rem .5rem; }
.hero h1 { margin: 0; font: 600 clamp(2rem, 1.5rem + 2.4vw, 2.75rem)/1.25 var(--serif); letter-spacing: .04em; }
.tagline { margin: .75rem 0 0; }
.hero::after { content: ""; display: block; width: 2.5rem; height: 2px; margin-top: 2rem; background: var(--accent); }
.section-title { margin: 2.25rem 0 0; font: 600 .8125rem/1.5 var(--sans); letter-spacing: .14em; text-transform: uppercase; }
.post-item { display: grid; padding-block: 1.25rem .25rem; border-bottom: var(--line); }
.post-item > * { min-width: 0; }
.post-date { order: -1; }
.post-title { font: 600 1.3125rem/1.45 var(--serif); }
.post-title a { display: inline-block; padding-block: .45rem; text-decoration: none; }
.post-title a:hover, .archive-list a:hover, .tag-index a:hover, .post-nav a:hover .nav-title, .site-footer a:hover { color: var(--accent); }
/* Tag links: 44px wide targets, with the text where it would be without the padding */
.tags { column-gap: 0; margin-inline: -.625rem; }
.tags a, .site-footer a { padding-inline: .625rem; }
.tags a:hover, .more a:hover, .translation a:hover, .lang-switch a:hover { text-decoration: underline; }
@media (min-width: 48rem) {
  .post-item { grid-template-columns: 9.5rem minmax(0, 1fr); column-gap: 1.5rem; }
  .post-item > * { grid-column: 2; }
  .post-item > .post-date { grid-column: 1; grid-row: 1; padding-top: .65rem; }
}
.more { margin: 1.25rem 0 0; }
.note { margin: 1.5rem 0 0; padding: .75rem 1rem; border-inline-start: 2px solid var(--accent); background: var(--surface); }
.badge { margin-inline-start: .5rem; padding: 0 .4em; border: 1px solid; border-radius: 3px; color: var(--accent); font: 600 .75rem/1.6 var(--sans); vertical-align: .2em; }

/* Page and post headers */
.page-header, .post-header { padding-block: 3rem 1.25rem; }
.page-header :is(h1, h2), .post-header h1 { margin: 0; font: 600 clamp(1.75rem, 1.35rem + 1.8vw, 2.375rem)/1.3 var(--serif); letter-spacing: .02em; }
.eyebrow { margin: 0 0 .5rem; color: var(--accent); letter-spacing: .14em; text-transform: uppercase; }
.lede { margin: .5rem 0 0; }
.post-meta { column-gap: 1.25rem; margin-top: .75rem; }

/* Archive and tags */
.archive-year h2 { margin: 2.25rem 0 .5rem; font: 600 1.25rem/1.4 var(--serif); }
.archive-list li { display: grid; grid-template-columns: 7rem minmax(0, 1fr); column-gap: 1rem; align-items: baseline; border-top: var(--line); }
.archive-list a { display: flex; align-items: center; min-height: 44px; padding-block: .25rem; text-decoration: none; }
.tag-index { gap: .6rem; margin-top: .5rem; }
/* Outlines that mark a control (chips, details, keys) use the stronger rule: 3:1 or more */
.tag-index a { gap: .5rem; padding-inline: 1rem; border: 1px solid var(--rule-strong); border-radius: 999px; }
.tag-index a:hover { border-color: var(--accent); }

/* Long words (file names, identifiers, URLs) wrap instead of widening the page */
.prose, .post-title, .page-header h1, .post-header h1, .site-name, .archive-list a, .tags a, .tag-index a, .post-nav a, .nav-title { overflow-wrap: anywhere; }

/* Long-form text */
.prose > * { margin-block: 0; }
.prose > * + * { margin-top: 1.15em; }
.prose :is(p, li, figcaption, blockquote) { text-wrap: pretty; }
/* English needs a shorter line than Chinese; code, tables and figures keep the full width */
html:lang(en) .prose > :is(p, ul, ol, blockquote, details, h2, h3, h4) { max-width: 34rem; }
.prose h2 { margin-top: 2.2em; font: 600 1.5rem/1.4 var(--serif); }
.prose h3 { margin-top: 1.9em; font: 600 1.25rem/1.45 var(--serif); }
.prose h4 { margin-top: 1.7em; font: 600 1.0625rem/1.5 var(--sans); }
.prose :is(h2, h3, h4) + * { margin-top: .6em; }
.prose h2::before { content: ""; display: inline-block; width: .38em; height: .38em; margin-inline-end: .5em; vertical-align: .2em; background: var(--accent); }
.prose :is(ul, ol) { padding-inline-start: 1.6em; }
.prose li + li, .prose li > :is(ul, ol) { margin-top: .35em; }
.prose ul > li::marker { color: var(--accent); }
.prose ol > li::marker { color: var(--muted); }
.prose blockquote { margin-inline: 0; padding-inline-start: 1.25em; border-inline-start: 2px solid var(--accent); font-family: var(--serif); }
.prose blockquote > * { margin: 0; }
.prose blockquote > * + * { margin-top: .6em; }
.prose :is(code, kbd, samp, pre) { font-family: var(--mono); font-size: .875em; }
.prose :not(pre) > code { padding: .1em .35em; border-radius: 3px; background: var(--surface); }
.prose pre { padding: .9rem 1.1rem; overflow-x: auto; border: var(--line); border-radius: 4px; background: var(--surface); line-height: 1.6; tab-size: 4; overflow-wrap: normal; }
.prose pre code { font-size: inherit; }
.prose kbd { padding: .05em .4em; border: 1px solid var(--rule-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); font-size: .8em; white-space: nowrap; }
.prose mark { padding: 0 .15em; border-radius: 2px; background: var(--mark); color: var(--text); }
.prose hr { margin-block: 2.5em; border: 0; color: var(--accent); text-align: center; }
.prose hr::after { content: "· · ·"; letter-spacing: .5em; margin-inline-end: -.5em; font-size: 1.5em; }
.prose table { width: 100%; border-collapse: collapse; font-size: .9375em; overflow-wrap: normal; }
/* Wide tables scroll inside <div class="table-wrap" role="region" aria-label="..." tabindex="0"> */
.table-wrap { overflow-x: auto; }
.prose caption { caption-side: bottom; padding-top: .6em; font-size: .875em; text-align: start; }
.prose :is(th, td) { padding: .5em .8em; border-bottom: var(--line); text-align: start; vertical-align: top; }
.prose thead th { border-bottom-color: var(--muted); white-space: nowrap; }
.prose figure { margin-inline: 0; }
.prose figure img { display: block; border-radius: 4px; }
.prose figcaption { margin-top: .6em; font-size: .875em; }
.prose details { padding-inline: 1rem; border: 1px solid var(--rule-strong); border-radius: 4px; }
.prose summary { padding-block: .55rem; cursor: pointer; font-weight: 600; }
.prose details[open] > summary { margin-bottom: .75rem; border-bottom: var(--line); }
.prose details > :last-child { margin-bottom: 1rem; }
.prose :is(small, .note) { font-size: .875em; }
/* zh emphasis: dots under the text (著重號); other italics stay upright instead of fake-slanted */
.prose em:lang(zh) { font-style: normal; -webkit-text-emphasis: filled dot; text-emphasis: filled dot; -webkit-text-emphasis-position: under right; text-emphasis-position: under right; }
.prose :is(i, cite, dfn, var, address):lang(zh) { font-style: normal; }
/* Bright images are toned down a little in dark mode */
:root[data-theme="dark"] .prose img { filter: brightness(.9); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .prose img { filter: brightness(.9); }
}

/* Footers */
.post-footer { margin-top: 3.5rem; padding-top: 1.25rem; border-top: var(--line); }
.post-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1.5rem; }
.post-nav a { display: block; padding-block: .5rem; text-decoration: none; }
.post-nav .next { grid-column: 2; text-align: end; }
.nav-label { display: block; letter-spacing: .06em; }
.nav-title { font-family: var(--serif); font-weight: 600; }
.notfound + .notfound { border-top: var(--line); }
.site-footer { margin-top: 4rem; padding-block: .75rem 2rem; border-top: var(--line); }
.footer-inner { column-gap: 1.5rem; }
.footer-inner a { margin-inline: -.625rem; }
.site-footer a { color: inherit; text-decoration: underline; text-underline-offset: .25em; }

@media (max-width: 30rem) {
  :root { --gutter: 1rem; }
  .archive-list li, .post-nav { grid-template-columns: minmax(0, 1fr); }
  .post-nav .next { grid-column: auto; text-align: start; }
}
/* Smooth scrolling only when nobody asked to reduce motion */
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

@media print {
  :root:root:root { --bg: #fff; --surface: #f3f3f3; --text: #000; --muted: #444; --rule: #bbb; --rule-strong: #888; --accent: #000; --mark: #eee; }
  .site-header, .site-footer, .skip-link, .post-nav, .translation, .more { display: none; }
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; }
  .prose pre { white-space: pre-wrap; }
  .prose img { filter: none; }
  .prose :is(pre, figure, blockquote, tr) { break-inside: avoid; }
}
