/* One stylesheet for every page. Plain CSS, no build step. */

/* Chinese pages only. Georgia comes first in the stack for its Latin letters,
   but it would also claim these characters:
   - quotes, dashes and the ellipsis, which Georgia draws for Latin text
     (“够用” cramped, —— broken in two, …… sitting low); Songti has CJK forms.
   - digits, which Georgia draws as old-style figures that rise and fall next
     to 汉字; Iowan Old Style / Charter have even-height ones.
   Where these fonts are missing (Windows, Linux), Georgia is used as before.
   The faces don't cover the space character, so line metrics still come from Georgia. */
@font-face {
  font-family: "zh-punct";
  src: local("Songti SC Regular"), local("STSongti-SC-Regular");
  unicode-range: U+2014, U+2018-2019, U+201C-201D, U+2026;
}

@font-face {
  font-family: "zh-punct";
  font-weight: 700;
  src: local("Songti SC Bold"), local("STSongti-SC-Bold");
  unicode-range: U+2014, U+2018-2019, U+201C-201D, U+2026;
}

@font-face {
  font-family: "zh-digits";
  src: local("Iowan Old Style Roman"), local("IowanOldStyle-Roman"), local("Charter Roman"), local("Charter-Roman");
  unicode-range: U+0030-0039;
}

@font-face {
  font-family: "zh-digits";
  font-weight: 700;
  src: local("Iowan Old Style Bold"), local("IowanOldStyle-Bold"), local("Charter Bold"), local("Charter-Bold");
  unicode-range: U+0030-0039;
}

:root {
  --bg: #fcfcfa;
  --fg: #1f1f1d;
  --muted: #6b6a65;
  --rule: #e4e3de;
  --img-bg: #efeee9;
  --link: #1d4ed8;
  --link-hover: #1e3a8a;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --fg: #e7e5de;
    --muted: #9a988f;
    --rule: #2c2b28;
    --img-bg: #22211e;
    --link: #7aa2f7;
    --link-hover: #a9c4ff;
  }
}

/* Users who ask the OS for more contrast get pure black/white. */
@media (prefers-contrast: more) {
  :root {
    --bg: #fff;
    --fg: #000;
    --muted: #3d3c38;
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --fg: #fff;
    --muted: #c8c6be;
  }
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable; /* no sideways jump between short and long pages */
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* 36rem ≈ 34 汉字 / ~70 Latin characters per line. `ch` is unreliable for CJK. */
body {
  max-width: 36rem;
  margin: 4.5rem auto;
  padding: 0 1.5rem;
  background: var(--bg);
  color: var(--fg);
  font-size: 1.0625rem;
  overflow-wrap: break-word;
  text-autospace: normal; /* small gap between 汉字 and Latin/digits */
  text-rendering: optimizeLegibility;
}

/* Language-specific type: Chinese needs looser leading than Latin text. */
body:lang(zh) {
  font-family: "zh-punct", "zh-digits", Georgia, "Songti SC", "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", serif;
  line-height: 1.8;
}

body:lang(en) {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  line-height: 1.65;
}

/* Chinese has no italics: the browser would slant 汉字 mechanically.
   Use emphasis dots under the characters instead (着重号, GB/T 15834). */
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;
}

main p {
  hyphens: auto;
}

.archive-intro:lang(zh) {
  text-wrap: wrap;
}

/* Site header: name on the left, language switch on the right. */
header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 3rem;
  font-size: 0.9375rem;
  line-height: 1.5rem; /* fixed: same height and baseline in zh and en */
}

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

/* Taller tap target (≥ 24px) without moving anything:
   vertical padding on an inline box doesn't affect layout. */
header a,
footer a {
  padding-block: 0.25rem;
}

header a:hover {
  text-decoration: underline;
}

header h1 {
  font: inherit;
  letter-spacing: normal;
  margin: 0;
}

header nav {
  display: flex;
  gap: 1.25rem;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.3;
  font-weight: 600;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h2 {
  font-size: 1.25rem;
  line-height: 1.4;
  font-weight: 600;
  margin: 2.5rem 0 1rem;
  text-wrap: balance;
}

h1, h2, p, li, figure {
  scroll-margin-top: 2.5rem;
}

p {
  margin: 0 0 1.25rem;
  text-wrap: pretty;
}

time,
.meta {
  color: var(--muted);
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

.meta {
  margin: 0 0 2.5rem;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--link-hover);
}

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

ul,
ol {
  padding-left: 1.25rem;
  margin: 1.25rem 0;
}

li {
  margin-bottom: 0.45rem;
}

/* Post list on the index: date column + title. */
ul.posts {
  list-style: none;
  padding: 0;
}

ul.posts li {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
}

ul.posts time {
  flex: none;
  min-width: 6.5em;
}

@media screen and (max-width: 40rem) {
  ul.posts li {
    flex-wrap: wrap;
    gap: 0 0.75rem;
  }

  ul.posts time {
    min-width: 5em;
  }

  ul.posts:lang(en) time {
    min-width: 3.5em;
  }

  ul.posts a {
    flex: 1 1 8em;
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

/* Language links on the root page. */
ul.langs {
  list-style: none;
  padding: 0;
}

ul.posts a {
  text-decoration: none;
}

ul.posts a:hover {
  text-decoration: underline;
}

blockquote {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875em;
}

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2.5rem 0;
}

/* Images.
   width/height attributes on <img> reserve space before load (no layout shift);
   the background shows a quiet placeholder while the file arrives. */
figure {
  margin: 2rem 0;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
  background: var(--img-bg);
  border-radius: 2px;
}

/* Reserve the final size before image metadata arrives, including the
   height-limited width of a portrait. Keep small originals at native size. */
@media screen {
  img[width][height] {
    width: min(100%, calc(var(--iw) * 1px), calc(85vh * var(--iw) / var(--ih)));
  }
}

figure a {
  display: block;
}

figcaption {
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.6;
  text-align: center;
}

/* Optional: let a figure break out of the text column on wide screens. */
@media (min-width: 62rem) {
  figure.wide {
    width: 56rem;
    margin-left: calc((36rem - 56rem) / 2);
  }
}

footer {
  margin-top: 4rem;
  color: var(--muted);
  font-size: 0.875rem;
}

@media print {
  :root {
    color-scheme: light;
    --bg: #fff;
    --fg: #000;
    --muted: #505050;
  }
  html {
    scroll-behavior: auto;
  }

  body {
    max-width: none;
    margin: 0;
    padding: 0;
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  header,
  footer {
    display: none;
  }

  header:has(h1) {
    display: block;
    margin-bottom: 1rem;
  }

  header nav {
    display: none;
  }

  a {
    color: #000;
  }

  figure {
    break-inside: avoid;
  }

  figure.wide {
    width: auto;
    margin-left: 0;
  }
}
