/*
 * Blog pages (/blog/): static HTML built from blog/posts/*.md, no JS. The shell copies the SPA's geometry —
 * the rail outside a 28 px-rounded mountain scene («昼夜» design spec) — and the content is variant C of the
 * reviewed prototype (apps/site/blog/prototype.html): a card stream for the index, a sticky side rail with the
 * table of contents beside the prose card for a post. Colours are tokens; day unless /blog-theme.js says night (the
 * account's theme, mirrored by the site).
 */
:root {
  --ground: #eaf0f4;
  --card: #f7fafb;
  --raise: #ffffff;
  --ink: #162a44;
  --stone: #5c6b80;
  --hair: #d3dde5;
  --accent: #1f6782;
  --on-accent: #ffffff;
  --link: #1a5a73;
  --glass: rgba(247, 250, 251, 0.74);
  --glass-edge: rgba(255, 255, 255, 0.85);
  --shadow: 0 18px 44px rgba(22, 42, 68, 0.12);
  --rail-shadow: 0 10px 30px -12px rgba(22, 42, 68, 0.25);
  --halo: 0 0 6px var(--ground), 0 0 2px var(--ground);
  --art: url("/assets/mountains-day.webp");
  --shade: linear-gradient(90deg, rgba(234, 240, 244, 0.62), rgba(234, 240, 244, 0.28) 50%, rgba(234, 240, 244, 0.16));
  --serif: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --sans: "Noto Sans SC", "PingFang SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[data-theme="night"] {
  --ground: #0f1d1f;
  --card: #172a2b;
  --raise: #1f3637;
  --ink: #eceee3;
  --stone: #97a79f;
  --hair: #2d4442;
  --accent: #e3b45f;
  --on-accent: #2b2210;
  --link: #e3b45f;
  --glass: rgba(15, 29, 31, 0.76);
  --glass-edge: rgba(227, 180, 95, 0.22);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
  --rail-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.5);
  --halo: 0 1px 2px rgba(0, 0, 0, 0.55);
  --art: url("/assets/mountains-night.webp");
  --shade: linear-gradient(90deg, rgba(15, 29, 31, 0.84), rgba(15, 29, 31, 0.56) 50%, rgba(15, 29, 31, 0.26));
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* The SPA's .page (src/styles.css): the start padding holds the rail (72 px) and its 18 px gap to the scene. */
body {
  --gutter: clamp(16px, 3vw, 48px);
  min-height: 100vh; padding-block: 24px; padding-inline: calc(var(--gutter) + 90px) var(--gutter);
  font: 15px/1.7 var(--sans); background: var(--ground); color: var(--ink);
  /* The SPA's .page token (#182): two thin rings around the avatar, resolved per theme. */
  --avatar-rings: 0 0 0 2px var(--glass-edge), 0 0 0 3.5px color-mix(in srgb, var(--accent) 45%, transparent);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2 { font-family: var(--serif); font-weight: 600; text-wrap: balance; }
time { color: var(--stone); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 1px 8px; border: 1px solid var(--hair); border-radius: 999px; font-size: 12px; color: var(--stone); }

/* --- rail (same geometry as the SPA) ----------------------------------------------------------- */
.rail {
  position: fixed; z-index: 10; top: 50%; transform: translateY(-50%);
  inset-inline-start: calc(var(--gutter) + max(0px, (100% - 2 * var(--gutter) - 1530px) / 2));
  width: 72px; padding: 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  border: 1px solid var(--glass-edge); border-radius: 36px; background: var(--glass);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); box-shadow: var(--rail-shadow);
}
/* Signed in or out, as the SPA shows it (src/styles.css, #182; public/blog-identity.js draws the signed-in state).
   The rules from .rail-top to .rail nav a.signed-in are the SPA's, word for word: test/blog-shell-parity.test.ts. */
.rail-top { display: grid; flex: none; width: 44px; height: 44px; }
.rail-top > * { grid-area: 1 / 1; }
.rail-avatar {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font: 600 19px var(--serif);
  box-shadow: var(--avatar-rings); text-decoration: none; padding: 0; border: 0; cursor: pointer;
}
.rail-avatar:focus-visible { outline-offset: 5px; }
.tab-avatar {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font: 600 11px var(--serif); box-shadow: var(--avatar-rings);
  margin-block: -2px;
}
.rail nav a.signed-in { display: none; }
/* A painted avatar (src/avatars.ts): the painting, no letter. After .rail-avatar and .tab-avatar, as in the SPA. */
.has-paint { background-color: var(--card); background-repeat: no-repeat; color: transparent; font-size: 0; }
/* The blog's emblem is a link home; the SPA's is an image. */
.rail-mark { display: block; width: 44px; height: 44px; }
.rail-mark img { display: block; width: 44px; height: 44px; }
.rail nav, .rail-tools { display: grid; gap: 4px; width: 100%; padding-top: 10px; border-top: 1px solid var(--hair); }
.rail nav a, .rail-lang {
  display: grid; justify-items: center; gap: 2px; width: 58px; min-height: 52px; margin: 0 auto; padding: 6px 0;
  border: 0; border-radius: 14px; background: transparent; color: var(--ink); font-size: 11px; line-height: 1.2; cursor: pointer;
}
.rail nav a:hover, .rail-lang:hover, .rail-lang[aria-expanded="true"], .rail nav a[aria-current="page"] {
  color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); text-decoration: none;
}
.rail nav svg { width: 20px; height: 20px; }
/* The language button: the current language's short form, one line (src/styles.css .rail-lang). */
.rail-lang { place-content: center; font: 600 15px/1 var(--sans); letter-spacing: 0.04em; }
.lang-short:lang(zh), .lang-short:lang(ja), .lang-short:lang(ko), .lang-short:lang(ar) { font-size: 17px; letter-spacing: 0; }
@media (max-height: 620px) and (min-width: 761px) { .rail { top: 24px; transform: none; } }

/* --- the language menu (src/styles.css .rail-menu, .lang-menu) ---------------------------------- */
.glass {
  border: 1px solid var(--glass-edge); border-radius: 18px;
  background: var(--glass); -webkit-backdrop-filter: blur(18px) saturate(1.15); backdrop-filter: blur(18px) saturate(1.15);
  box-shadow: var(--shadow);
}
.rail-menu {
  position: fixed; z-index: 25; inset-block-start: var(--menu-top, 96px); inset-inline-start: var(--menu-start, 96px);
  width: 300px; max-width: calc(100vw - 24px); padding: 6px; display: grid; gap: 2px;
  background: color-mix(in srgb, var(--card) 93%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(1.1); backdrop-filter: blur(24px) saturate(1.1);
}
.menu-list { display: grid; }
.menu-item {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border: 0; border-radius: 12px;
  background: transparent; color: var(--ink); font-size: 14px; text-decoration: none; text-align: start; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.menu-item[aria-checked="true"] { color: var(--accent); }
.lang-menu { width: 232px; max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; }
.lang-item { justify-content: space-between; width: 100%; min-height: 40px; font-family: inherit; }

/* --- the rounded mountain scene --------------------------------------------------------------- */
.scene {
  position: relative; max-width: 1440px; min-height: calc(100vh - 48px); margin: 0 auto;
  background: var(--art) center / cover no-repeat;
  border-radius: 28px; overflow: clip; box-shadow: var(--shadow);
}
.scene::before { content: ""; position: absolute; inset: 0; background: var(--shade); pointer-events: none; }
.content { position: relative; z-index: 1; margin-inline-start: clamp(28px, 3.4vw, 52px); padding-block: 24px 32px; padding-inline-end: clamp(20px, 4vw, 56px); }
.brand-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; min-height: 64px; }
/* The SPA's brand (src/styles.css; the same parity test): signed in, the emblem sits before the name. */
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark { flex: none; display: block; width: 52px; height: 52px; }
.brand-text { display: grid; gap: 2px; text-shadow: var(--halo); }
.brand-text strong { font: 600 21px var(--serif); }
.brand-text small { font: 500 12px var(--serif); letter-spacing: 0.06em; color: var(--ink); }
/* The blog colours its links; the SPA's links inherit, so the brand's name is ink in both. */
.brand-row .brand { color: var(--ink); }
/* The SPA's inner-page heading (src/styles.css .page-head, .lede). */
.page-head { padding: 32px 0 8px; }
.page-head h1 { margin: 0; font-size: clamp(32px, 3.6vw, 44px); letter-spacing: 0.06em; text-shadow: var(--halo); }
.lede {
  max-width: 48ch; margin: 18px 0 0; font-size: 16px; line-height: 1.72;
  color: color-mix(in srgb, var(--ink) 85%, transparent); text-shadow: var(--halo); text-wrap: pretty;
}

/* --- index: the card stream -------------------------------------------------------------------- */
.cards { margin-block: 24px 64px; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; max-width: 980px; }
.card {
  display: block; overflow: hidden; border: 1px solid var(--glass-edge); border-radius: 18px;
  background: var(--glass); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: var(--shadow); color: var(--ink);
}
.card:hover { text-decoration: none; transform: translateY(-2px); transition: transform 0.18s; }
.card .thumb { height: 100px; background: var(--art) 14% 58% / 210% auto; border-bottom: 1px solid var(--glass-edge); }
.card:nth-child(3n + 2) .thumb { background-position: 60% 30%; }
.card:nth-child(3n) .thumb { background-position: 85% 80%; }
.card-body { padding: 16px 18px 18px; }
.card .post-title { font-size: 17px; margin: 6px 0 8px; }
.card .post-desc { color: var(--stone); font-size: 13.5px; line-height: 1.65; }

/* --- post: sticky side rail + prose card -------------------------------------------------------- */
.post-layout { margin-block: 24px 64px; display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; max-width: 1040px; align-items: start; }
.side {
  position: sticky; top: 24px; border: 1px solid var(--glass-edge); border-radius: 18px;
  background: var(--glass); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: var(--shadow); padding: 18px; font-size: 13.5px;
}
.side h2 { font-family: var(--sans); font-size: 12.5px; font-weight: 600; letter-spacing: 0.12em; color: var(--stone); margin: 14px 0 6px; }
.side ul { list-style: none; }
.side li { padding: 3px 0; line-height: 1.5; }
.article-card {
  border: 1px solid var(--glass-edge); border-radius: 18px;
  background: var(--glass); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: var(--shadow); padding: 36px 44px;
}
.meta-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.article-card .post-title-main { font-size: 30px; line-height: 1.4; }

/* --- prose -------------------------------------------------------------------------------------- */
.prose { margin-top: 24px; }
/* Tutorial video (blog plan 2026-10-22): full card width, 16:9, our own footage only. */
.post-video { margin: 20px 0 0; }
.post-video video { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: 12px; background: #0b1112; }
.prose h2 { font-size: 21px; margin: 32px 0 12px; }
.prose h3 { font-size: 17px; margin: 26px 0 10px; }
.prose p { line-height: 1.85; margin: 14px 0; font-size: 15.5px; }
.prose ul, .prose ol { padding-inline-start: 1.4em; line-height: 1.85; font-size: 15.5px; }
.prose li { margin: 5px 0; }
.prose blockquote { border-inline-start: 3px solid var(--accent); padding: 2px 0 2px 14px; color: var(--stone); margin: 16px 0; }
.prose code { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 4px; padding: 1px 5px; font-size: 0.92em; }
.prose pre { background: var(--card); border: 1px solid var(--hair); border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 16px 0; }
.prose pre code { background: none; padding: 0; }
.prose img { max-width: 100%; border-radius: 10px; }
.prose hr { border: 0; border-top: 1px solid var(--hair); margin: 28px 0; }

.foot { margin-top: 48px; padding-top: 14px; border-top: 1px solid var(--hair); color: var(--stone); font-size: 12.5px; line-height: 1.7; text-shadow: var(--halo); }
.foot a { color: inherit; text-underline-offset: 3px; }

/* --- phones: the rail becomes the bottom tab bar, as on the SPA ---------------------------------- */
@media (max-width: 760px) {
  body { padding: 0; }
  .rail {
    top: auto; bottom: 0; inset-inline-start: 0; inset-inline-end: 0; transform: none; width: auto; flex-direction: row; justify-content: space-between;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px)); border-radius: 0; border-width: 1px 0 0;
  }
  .rail-top { display: none; }
  .rail nav a.signed-in { display: grid; }
  .rail nav, .rail-tools { display: flex; padding: 0; border: 0; width: auto; }
  .rail nav a, .rail-lang { width: 56px; min-height: 48px; }
  .scene { min-height: 100vh; border-radius: 0; }
  .rail-menu {
    inset-block-start: auto; inset-block-end: calc(72px + env(safe-area-inset-bottom, 0px));
    inset-inline: 12px; width: auto; max-width: none;
  }
  .lang-menu { max-height: calc(100dvh - 72px - env(safe-area-inset-bottom, 0px) - 24px); }
  /* Seven tabs across a phone (src/styles.css, the second 760 px block). */
  .rail { padding-inline: 4px; gap: 0; }
  .rail nav { flex: 1; justify-content: space-around; min-width: 0; gap: 0; }
  .rail nav a, .rail-lang { width: 44px; min-width: 0; }
  .rail-tools { gap: 0; }
  .rail nav a span { font-size: 10px; overflow-wrap: anywhere; }
  .content { margin-inline-start: 0; padding-inline: 20px; padding-bottom: 96px; }
  .post-layout { grid-template-columns: 1fr; }
  .side { position: static; order: 2; }
}
@media (prefers-reduced-motion: reduce) {
  .card:hover { transform: none; transition: none; }
}
