/* ==========================================================================
   Fonts — Geist (sans) + JetBrains Mono, self-hosted, OFL licensed.
   Only Latin glyphs are bundled; CJK falls back to the system sans in --cjk.
   ========================================================================== */
@font-face {
  font-family: "Geist";
  src: url(/static/fonts/geist-latin-wght.woff2) format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist";
  src: url(/static/fonts/geist-latin-ext-wght.woff2) format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url(/static/fonts/jetbrains-mono-latin-wght.woff2) format("woff2");
  font-weight: 100 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url(/static/fonts/jetbrains-mono-latin-ext-wght.woff2) format("woff2");
  font-weight: 100 800;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "CJK Punct";
  src: local("PingFang SC"), local("PingFangSC-Regular"), local("Hiragino Sans"), local("HiraginoSans-W3"),
       local("Microsoft YaHei"), local("Microsoft YaHei UI"), local("Yu Gothic UI"), local("Meiryo"),
       local("Noto Sans CJK SC"), local("NotoSansCJKsc-Regular"), local("Source Han Sans SC");
  unicode-range: U+2014-2015, U+2018-2019, U+201C-201D, U+2026;
}

/* ==========================================================================
   Tokens — light by default; dark via OS preference or [data-theme="dark"]
   ========================================================================== */
:root {
  --bg: #f6f6f3;
  --bg-elev: #ffffff;
  --fg: #15171a;
  --fg-muted: #565d68;
  --fg-faint: #868c96;
  --line: #e3e3dd;
  --line-strong: #cdcdc5;
  --accent: #d1007b;
  --accent-fg: #ffffff;
  --accent-soft: rgba(209, 0, 123, 0.06);
  --chip: rgba(20, 22, 26, 0.055);
  --code-bg: #efefe9;
  --grid: rgba(20, 22, 26, 0.09);
  --grid-hi: rgba(255, 45, 149, 0.6);
  --glow: rgba(255, 45, 149, 0.16);
  --diffuse: rgba(255, 45, 149, 0.12);
  --shadow: rgba(20, 22, 26, 0.22);
  --warn: #a16207;
  --cover-opacity: 0.26;
  --cover-opacity-hover: 0.36;
  color-scheme: light;
  --radius: 10px;

  /* Sans-serif CJK fonts per language, so no glyph ever falls back to a serif (Song/Mincho) face. */
  --cjk: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei";
}
:lang(ja) {
  --cjk: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Source Han Sans JP", "Yu Gothic UI", "Meiryo UI", "Meiryo";
}
/* Re-resolved on every element carrying a lang attribute, so --cjk follows the content language. */
:root, [lang] {
  --font-sans: "Geist", var(--cjk), system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, var(--cjk), monospace;
}
/* In Chinese/Japanese text, dashes, quotes and ellipses come from the CJK font (full-width, centered). */
:root:is(:lang(zh), :lang(ja)),
[lang]:is(:lang(zh), :lang(ja)) {
  --font-sans: "CJK Punct", "Geist", var(--cjk), system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c0f;
    --bg-elev: #11151a;
    --fg: #e6e8eb;
    --fg-muted: #9ba3ad;
    --fg-faint: #69717b;
    --line: #1d232a;
    --line-strong: #2b333c;
    --accent: #b6f35c;
    --accent-fg: #0a0c0f;
    --accent-soft: rgba(182, 243, 92, 0.06);
    --chip: rgba(255, 255, 255, 0.06);
    --code-bg: #0e1216;
    --grid: rgba(255, 255, 255, 0.06);
    --grid-hi: rgba(182, 243, 92, 0.42);
    --glow: rgba(182, 243, 92, 0.12);
    --diffuse: rgba(182, 243, 92, 0.085);
    --shadow: rgba(0, 0, 0, 0.7);
    --warn: #facc15;
    --cover-opacity: 0.2;
    --cover-opacity-hover: 0.3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0c0f;
  --bg-elev: #11151a;
  --fg: #e6e8eb;
  --fg-muted: #9ba3ad;
  --fg-faint: #69717b;
  --line: #1d232a;
  --line-strong: #2b333c;
  --accent: #b6f35c;
  --accent-fg: #0a0c0f;
  --accent-soft: rgba(182, 243, 92, 0.06);
  --chip: rgba(255, 255, 255, 0.06);
  --code-bg: #0e1216;
  --grid: rgba(255, 255, 255, 0.06);
  --grid-hi: rgba(182, 243, 92, 0.42);
  --glow: rgba(182, 243, 92, 0.12);
  --diffuse: rgba(182, 243, 92, 0.085);
  --shadow: rgba(0, 0, 0, 0.7);
  --warn: #facc15;
  --cover-opacity: 0.2;
  --cover-opacity-hover: 0.3;
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
/* --header-h: height of the fixed header; base.html measures the real value before first paint. */
html { --header-h: 3.8rem; -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 1.25rem); }
body {
  margin: 0;
  min-height: 100vh;
  padding-top: var(--header-h);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.7 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
main { flex: 1; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }
::selection { background: var(--accent); color: var(--accent-fg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.wrap { width: 100%; max-width: 68rem; margin-inline: auto; padding-inline: 1.25rem; }
@media (min-width: 48rem) { .wrap { padding-inline: 2rem; } }
.mono { font-family: var(--font-mono); }
.muted { color: var(--fg-muted); }
.accent { color: var(--accent); }
.empty { color: var(--fg-faint); font-family: var(--font-mono); font-size: 0.85rem; }

.skip-link { position: absolute; left: 1rem; top: -3rem; z-index: 100; padding: 0.4rem 0.8rem; background: var(--accent); color: var(--accent-fg); border-radius: 6px; }
.skip-link:focus { top: 0.75rem; }

/* Dotted grid behind everything */
body::before {
  content: "";
  position: fixed;
  z-index: -1;
  pointer-events: none;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, var(--grid) 1px, transparent 0);
  background-size: 24px 24px;
  -webkit-mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, 0.35) 45%, transparent 85%);
  mask-image: linear-gradient(180deg, #000 0%, rgba(0, 0, 0, 0.35) 45%, transparent 85%);
}
/* Ambient light. A fixed light source sits at the top-right. With a mouse, main.js makes it
   brighter/wider (and lean) as the cursor approaches, and paints a diffuse reflection plus
   lit-up dots under the cursor, scaled by how much light reaches that point. */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.ambient-glow,
.ambient-diffuse {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  will-change: transform, opacity;
}
.ambient-glow {
  width: 46rem;
  height: 46rem;
  background: radial-gradient(closest-side, var(--glow), transparent);
  opacity: 0.72;
  transform: translate(calc(100vw - 10rem), 0) translate(-50%, -50%);
}
.ambient-diffuse {
  width: 24rem;
  height: 24rem;
  background: radial-gradient(closest-side, var(--diffuse), transparent);
  opacity: 0;
}
.ambient-grid {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, var(--grid-hi) 1px, transparent 0);
  background-size: 24px 24px;
  -webkit-mask-image: radial-gradient(9rem circle at var(--x, -50vw) var(--y, -50vh), #000, transparent);
  mask-image: radial-gradient(9rem circle at var(--x, -50vw) var(--y, -50vh), #000, transparent);
  opacity: 0;
}

/* ==========================================================================
   Header
   ========================================================================== */
/* Fixed rather than sticky: when the page rubber-bands at its top or bottom (trackpad, touch),
   the header stays put with the background instead of moving with the content. */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: saturate(150%) blur(12px);
  backdrop-filter: saturate(150%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; flex-wrap: wrap; align-items: center; column-gap: 2.25rem; min-height: 3.75rem; }
.logo { display: flex; align-items: center; min-width: 0; font-family: var(--font-mono); font-weight: 600; font-size: 0.92rem; letter-spacing: -0.01em; white-space: nowrap; }
.logo a { transition: color 0.15s; }
.logo-user { flex-shrink: 0; color: var(--accent); }
.logo-user:hover { color: var(--fg); }
.logo-sep { flex-shrink: 0; color: var(--fg-faint); }
/* Parent segments are slightly dimmed links (no underline); the current segment is full strength. */
/* When space runs out, clip the *start* of the path ("…/affective-touch") so the current page stays visible:
   the box is RTL (overflow/ellipsis on the left) while the path itself is an isolated LTR run. */
.logo-path { min-width: 0; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; color: var(--fg-muted); }
.logo-path > bdi { direction: ltr; unicode-bidi: isolate; }
.logo-path a:hover { color: var(--accent); }
.logo-path [aria-current] { color: var(--fg); }
.caret { flex-shrink: 0; display: inline-block; width: 0.55em; height: 1.05em; margin-left: 0.2em; background: var(--accent); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.nav { display: flex; gap: 1.6rem; font-family: var(--font-mono); font-size: 0.82rem; }
.nav a { display: inline-flex; align-items: baseline; gap: 0.45em; padding-block: 0.3rem; color: var(--fg-muted); border-bottom: 1px solid transparent; transition: color 0.15s, border-color 0.15s; }
.nav a:hover { color: var(--fg); }
.nav a[aria-current] { color: var(--fg); border-bottom-color: var(--accent); }
.nav-idx { font-size: 0.72em; color: var(--fg-faint); }
.nav a[aria-current] .nav-idx { color: var(--accent); }

.controls { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.theme-toggle { display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0; border: 1px solid var(--line-strong); border-radius: 7px; background: transparent; color: var(--fg-muted); cursor: pointer; transition: color 0.15s, border-color 0.15s; }
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { display: none; width: 1rem; height: 1rem; }
.theme-toggle[data-mode="system"] .i-system,
.theme-toggle[data-mode="light"] .i-light,
.theme-toggle[data-mode="dark"] .i-dark { display: block; }

/* Wide: one row; a long prompt path shrinks (with an ellipsis) instead of wrapping. */
@media (min-width: 60rem) {
  .header-inner { flex-wrap: nowrap; }
  .logo { flex: 0 1 auto; }
  .nav { flex: none; }
}
/* Header dropdowns (language, theme). main.js opens them on hover with a mouse; on touch the
   language menu opens on tap and the theme button just cycles. */
.hover-menu { position: relative; }
/* Same 2rem square as .theme-toggle. */
.lang-menu > summary {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--fg-muted);
  list-style: none;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.lang-menu > summary::-webkit-details-marker { display: none; }
.lang-menu > summary:hover,
.lang-menu[open] > summary,
.theme-menu.is-open > .theme-toggle { color: var(--accent); border-color: var(--accent); }
.lang-menu > summary svg { width: 1rem; height: 1rem; }
.menu-list {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 40;
  min-width: 9.5rem;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: 0 18px 36px -18px var(--shadow);
}
.menu-list[hidden] { display: none; }
/* Invisible bridge over the gap, so the pointer can travel from the button to the list. */
.menu-list::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 0.5rem; }
.menu-list :is(a, button) {
  display: flex; align-items: center; gap: 0.6rem; width: 100%;
  padding: 0.45rem 0.6rem; border: 0; border-radius: 6px; background: none;
  font: inherit; font-size: 0.86rem; color: var(--fg-muted); text-align: start; cursor: pointer;
}
.menu-list :is(a, button):hover { background: var(--chip); color: var(--fg); }
.menu-list [aria-current],
.menu-list [aria-current]:hover { color: var(--accent); }
.menu-list svg { flex: none; width: 0.95rem; height: 0.95rem; }
.lang-code { width: 1.3rem; font: 0.66rem var(--font-mono); color: var(--fg-faint); }

/* Narrower: prompt + controls on the first row, nav on the second. If the prompt path would be
   cut off, the script in base.html adds .is-stacked and the controls move down beside the nav. */
@media (max-width: 59.99rem) {
  .header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "logo controls" "nav nav";
    align-items: center;
    gap: 0.15rem 0.75rem;
    padding-block: 0.55rem 0.3rem;
  }
  .header-inner.is-stacked { grid-template-areas: "logo logo" "nav controls"; }
  .logo { grid-area: logo; }
  /* Never wraps: on very small screens the nav scrolls sideways instead. */
  .nav { grid-area: nav; gap: 1.1rem; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .controls { grid-area: controls; margin-left: 0; }
}
@media (max-width: 24rem) {
  .is-stacked .nav-idx { display: none; }
}

/* ==========================================================================
   Hero (home)
   ========================================================================== */
.hero { display: grid; gap: 2.5rem; align-items: end; padding-block: 4.5rem 2.5rem; }
/* Wide: the status panel spans from the top of the name to the bottom of the links row.
   .hero-main dissolves into the grid so its rows (eyebrow, name, tagline, links) are shared with
   the panel, which stretches over rows 2–4 and spreads its lines evenly over that height. */
@media (min-width: 56rem) {
  .hero { grid-template-columns: minmax(0, 1fr) 19rem; column-gap: 2.5rem; row-gap: 0; align-items: start; padding-block: 7rem 3.5rem; }
  .hero-main { display: contents; }
  .hero-main > * { grid-column: 1; }
  .status-panel { grid-column: 2; grid-row: 2 / 5; align-self: stretch; display: flex; flex-direction: column; }
  .status-panel dl { flex: 1; display: flex; flex-direction: column; }
  .status-panel dl div { flex: 1; align-items: center; }
}
.eyebrow { margin: 0 0 1rem; font-family: var(--font-mono); font-size: 0.82rem; color: var(--fg-muted); }
.hero-title { margin: 0; font-size: clamp(2.6rem, 7.5vw, 4.9rem); font-weight: 700; line-height: 1.02; letter-spacing: -0.04em; }
.hero-tagline { text-wrap: pretty; max-width: 36rem; margin: 1.25rem 0 0; font-size: clamp(1.05rem, 2vw, 1.22rem); line-height: 1.65; color: var(--fg-muted); }
.hero-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1.75rem 0 0; padding: 0; list-style: none; font-family: var(--font-mono); font-size: 0.78rem; }
.hero-links a { display: inline-block; padding: 0.35rem 0.75rem; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--fg-muted); transition: color 0.15s, border-color 0.15s; }
.hero-links a:hover { color: var(--accent); border-color: var(--accent); }

.status-panel {
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  box-shadow: 0 24px 48px -32px var(--shadow);
}
.panel-bar { display: flex; align-items: center; gap: 0.8rem; padding: 0.55rem 0.85rem; border-bottom: 1px solid var(--line); color: var(--fg-faint); font-size: 0.7rem; }
.dots { display: flex; gap: 0.35rem; }
.dots i { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--line-strong); }
.dots i:first-child { background: var(--accent); }
.status-panel dl { margin: 0; padding: 0.5rem 0.9rem 0.65rem; }
.status-panel dl div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.38rem 0; border-bottom: 1px dashed var(--line); }
.status-panel dl div:last-child { border-bottom: 0; }
.status-panel dt { color: var(--fg-muted); }
.status-panel dd { margin: 0; text-align: right; }

/* ==========================================================================
   Sections
   ========================================================================== */
.section { padding-block: 2.25rem; }
.section-tight { padding-bottom: 4rem; }
.section-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1.1rem; }
.section-head h2 { display: flex; align-items: baseline; gap: 0.65rem; margin: 0; font-size: 1.05rem; font-weight: 600; white-space: nowrap; }
.section-head::after { content: ""; order: 1; flex: 1; height: 1px; align-self: center; background: var(--line); }
.section-idx { font-family: var(--font-mono); font-size: 0.72rem; color: var(--accent); }
.section-more { order: 2; font-family: var(--font-mono); font-size: 0.78rem; color: var(--fg-muted); white-space: nowrap; }
.section-more:hover { color: var(--accent); }

.page-head { padding-block: 4rem 1.75rem; }
.page-head h1 { margin: 0; font-size: clamp(2.1rem, 5.5vw, 3.2rem); line-height: 1.1; letter-spacing: -0.035em; }
.page-head p:not(.eyebrow) { max-width: 40rem; margin: 0.8rem 0 0; color: var(--fg-muted); }
.page-head .mono { margin-left: 0.4rem; font-size: 0.78rem; color: var(--fg-faint); }
/* Page header with a portrait (front matter `photo`): text on the left, photo top-right.
   Narrow: the photo sits beside the eyebrow + title and the summary runs full width below. */
.page-head.has-photo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto auto 1fr;
  grid-template-areas: "eyebrow ." "title photo" "summary photo" "actions photo" ". photo";
  column-gap: 2rem;
}
.page-head.has-photo > .eyebrow { grid-area: eyebrow; align-self: start; }
.page-head.has-photo > h1 { grid-area: title; }
.page-head.has-photo > .page-summary { grid-area: summary; align-self: start; }
.page-head.has-photo > .actions { grid-area: actions; align-self: start; }
.page-head .actions { margin: 1.25rem 0 0; }
.page-photo {
  grid-area: photo;
  align-self: start;
  width: clamp(5.5rem, 22vw, 11rem);
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 36px -24px var(--shadow);
}
@media (max-width: 40rem) {
  .page-head.has-photo { column-gap: 1rem; }
}
.page-body { padding: 2rem 0 4.5rem; border-top: 1px solid var(--line); }
.page-body > * { max-width: 46rem; }

/* ==========================================================================
   Post list
   ========================================================================== */
.post-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.post-row { border-bottom: 1px solid var(--line); }
.post-link {
  position: relative;
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr) auto;
  grid-template-areas: "date main meta";
  align-items: baseline;
  gap: 0.25rem 1.5rem;
  padding: 1rem 0.75rem;
  transition: background 0.15s;
}
.post-link::before { content: ""; position: absolute; left: 0; top: 0.9rem; bottom: 0.9rem; width: 2px; background: var(--accent); transform: scaleY(0); transition: transform 0.2s; }
.post-link:hover { background: var(--accent-soft); }
.post-link:hover::before { transform: scaleY(1); }
.post-date { grid-area: date; font-family: var(--font-mono); font-size: 0.78rem; color: var(--fg-faint); }
.post-main { grid-area: main; }
.post-title { display: block; font-weight: 600; transition: color 0.15s; }
.post-link:hover .post-title { color: var(--accent); }
.post-summary { display: block; margin-top: 0.15rem; font-size: 0.92rem; color: var(--fg-muted); }
.post-meta { grid-area: meta; display: flex; align-items: center; gap: 0.5rem; font-family: var(--font-mono); font-size: 0.72rem; color: var(--fg-faint); white-space: nowrap; }
.badge { padding: 0 0.3rem; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 0.66rem; line-height: 1.5; }
@media (max-width: 40rem) {
  .post-link { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "date meta" "main main"; padding-inline: 0.5rem; }
}

.tag-filter { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 2.25rem; padding: 0; list-style: none; font-family: var(--font-mono); font-size: 0.76rem; }
.tag-filter a { display: inline-block; padding: 0.25rem 0.65rem; border: 1px solid var(--line); border-radius: 999px; color: var(--fg-muted); transition: color 0.15s, border-color 0.15s; }
.tag-filter a:hover { color: var(--fg); border-color: var(--fg-faint); }
.tag-filter a[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.tag-filter .count { margin-left: 0.35em; opacity: 0.6; }

.year-group { display: grid; gap: 0.4rem; margin-bottom: 2.5rem; }
@media (min-width: 56rem) { .year-group { grid-template-columns: 6rem minmax(0, 1fr); } }
.year-label { margin: 0; padding-top: 0.95rem; font-family: var(--font-mono); font-size: 0.85rem; font-weight: 500; color: var(--fg-faint); }

/* ==========================================================================
   Project cards
   ========================================================================== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr)); gap: 1rem; }
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg-elev) 72%, transparent);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 18px 36px -24px var(--shadow); }
/* First image of the project page as a faded backdrop; a wash from the top-left keeps text legible. */
.card.has-cover { isolation: isolate; overflow: hidden; }
.card-cover {
  position: absolute; inset: 0; z-index: -2;
  width: 100%; height: 100%; object-fit: cover;
  opacity: var(--cover-opacity); transition: opacity 0.3s;
}
.card.has-cover::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(160deg, color-mix(in srgb, var(--bg-elev) 55%, transparent), transparent 70%);
}
.card.has-cover:hover .card-cover { opacity: var(--cover-opacity-hover); }
.card.has-cover .chips li { background: color-mix(in srgb, var(--bg-elev) 70%, transparent); color: color-mix(in srgb, var(--fg) 45%, var(--fg-muted)); }
/* Over an image, step each text tone one notch toward --fg, with a soft halo in the card colour. */
.card.has-cover :is(.card-title, .card-summary, .card-top) { text-shadow: 0 0 10px var(--bg-elev), 0 0 2px color-mix(in srgb, var(--bg-elev) 60%, transparent); }
.card.has-cover .card-top,
.card.has-cover .card-arrow { color: var(--fg-muted); }
.card.has-cover:hover .card-arrow { color: var(--accent); }
.card.has-cover .card-summary { color: color-mix(in srgb, var(--fg) 55%, var(--fg-muted)); }
.card-top { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-faint); }
.card-status { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; }
.card-status::before { content: ""; display: inline-block; width: 0.45rem; height: 0.45rem; margin-right: 0.45rem; border-radius: 50%; background: var(--accent); vertical-align: 0.06em; }
.card-status[data-status="wip"]::before { background: var(--warn); }
.card-status[data-status="archived"]::before { background: var(--fg-faint); }
.card-status[data-status="completed"]::before { background: var(--fg-muted); }
.card-title { text-wrap: balance; margin: 0; padding-right: 1.5rem; font-size: 1.12rem; font-weight: 650; letter-spacing: -0.01em; }
.stretched::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.card-summary { flex: 1; margin: 0; font-size: 0.92rem; line-height: 1.6; color: var(--fg-muted); }
.card-arrow { position: absolute; right: 1.2rem; top: 2.85rem; color: var(--fg-faint); transition: transform 0.2s, color 0.2s; }
.card:hover .card-arrow { color: var(--accent); transform: translateX(3px); }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0; padding: 0; list-style: none; font-family: var(--font-mono); font-size: 0.68rem; }
.chips li { padding: 0.12rem 0.5rem; border-radius: 4px; background: var(--chip); color: var(--fg-muted); }

/* ==========================================================================
   Article
   ========================================================================== */
.article { padding-block: 3.5rem 4.5rem; }
.article-head h1 { max-width: 52rem; margin: 1.25rem 0 1rem; font-size: clamp(1.9rem, 4.6vw, 2.8rem); line-height: 1.15; letter-spacing: -0.03em; text-wrap: balance; }
.article-head .eyebrow + h1 { margin-top: 0; }
.lead { max-width: 46rem; margin: -0.25rem 0 1.25rem; font-size: 1.1rem; color: var(--fg-muted); }
.article-main { min-width: 0; max-width: 46rem; }
/* Break Japanese headings at phrase boundaries instead of mid-word (Chromium). */
:is(.hero-title, .page-head h1, .article-head h1, .card-title):lang(ja) { word-break: auto-phrase; }

/* Wide: TOC column on the left, sticky while reading. */
@media (min-width: 60rem) {
  .article-layout.has-toc { display: grid; grid-template-columns: 12.5rem minmax(0, 46rem); gap: 3.5rem; align-items: start; }
  .toc-toggle { display: none; }
  .toc {
    display: block;
    position: sticky;
    inset: auto;
    top: calc(var(--header-h) + 1.75rem);
    width: auto;
    height: auto;
    max-height: calc(100vh - 7rem);
    margin: 0;
    padding: 0;
    overflow: auto;
    border: 0;
    background: none;
    color: inherit;
  }
}
/* Narrow: floating button opens the TOC as a popover panel. */
@media (max-width: 59.99rem) {
  .toc-toggle {
    position: fixed;
    left: max(1rem, env(safe-area-inset-left, 0px));
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.95rem;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 12px 28px -14px var(--shadow);
    color: var(--fg);
    font: 500 0.78rem/1 var(--font-mono);
    cursor: pointer;
  }
  .toc-toggle:hover { border-color: var(--accent); color: var(--accent); }
  .toc-toggle svg { width: 1rem; height: 1rem; }
  .toc:popover-open {
    position: fixed;
    inset: auto auto calc(4.4rem + env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
    width: min(20rem, calc(100vw - 2rem));
    max-height: min(60vh, 28rem);
    margin: 0;
    padding: 1rem 1.1rem 1rem 1rem;
    overflow: auto;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--bg-elev);
    color: var(--fg);
    box-shadow: 0 24px 48px -20px var(--shadow);
  }
  .toc::backdrop { background: transparent; }
}
.toc-title { margin: 0 0 0.75rem; font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-faint); }
.toc ol { margin: 0; padding: 0; list-style: none; }
.toc > ol { border-left: 1px solid var(--line); }
.toc a { display: block; margin-left: -1px; padding: 0.3rem 0 0.3rem 0.9rem; border-left: 1px solid transparent; font-size: 0.85rem; line-height: 1.45; color: var(--fg-muted); transition: color 0.15s, border-color 0.15s; }
.toc ol ol a { padding-left: 1.8rem; font-size: 0.8rem; }
.toc a:hover { color: var(--fg); }
.toc a[aria-current] { color: var(--accent); border-left-color: var(--accent); }
.article-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: 0.78rem; color: var(--fg-faint); }
.tag { color: var(--accent); }
.license { display: inline-flex; align-items: center; color: var(--fg-muted); transition: color 0.15s; }
a.license:hover { color: var(--fg); }
.license-icons { display: inline-flex; gap: 0.2rem; }
.license-icons svg { width: 1.2em; height: 1.2em; fill: currentColor; }
.tag:hover { text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.5rem; }
.notice { margin: 0 0 2rem; padding: 0.75rem 1rem; border: 1px dashed var(--line-strong); border-radius: 8px; font-size: 0.9rem; color: var(--fg-muted); }
.notice::before { content: "i"; display: inline-grid; place-items: center; width: 1.1rem; height: 1.1rem; margin-right: 0.6rem; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font: 700 0.7rem/1 var(--font-mono); vertical-align: 0.1em; }

.btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.45rem 0.95rem; border: 1px solid var(--line-strong); border-radius: 7px; font-family: var(--font-mono); font-size: 0.78rem; color: var(--fg); transition: color 0.15s, border-color 0.15s, filter 0.15s; }
.btn:hover { color: var(--accent); border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { color: var(--accent-fg); filter: brightness(1.08); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 4rem; padding-top: 2rem; border-top: 1px solid var(--line); }
.pager a { display: block; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 8px; font-weight: 600; transition: border-color 0.15s; }
.pager a:hover { border-color: var(--accent); }
.pager .label { display: block; margin-bottom: 0.3rem; font-family: var(--font-mono); font-size: 0.7rem; font-weight: 400; color: var(--fg-faint); }
.pager .next { grid-column: 2; text-align: right; }
@media (max-width: 40rem) { .pager { grid-template-columns: 1fr; } .pager .next { grid-column: auto; } }

/* ==========================================================================
   Prose (rendered Markdown)
   ========================================================================== */
.prose {
  font-family: var(--font-sans);
  font-size: 1.04rem;
  line-height: 1.85;
  overflow-wrap: break-word;
}
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose table, .prose .codehilite, .prose figure { margin: 1.15em 0; }
.prose :is(h1, h2, h3, h4) { position: relative; margin: 2.4em 0 0.8em; line-height: 1.3; letter-spacing: -0.015em; }
.prose h1 { font-size: 1.6rem; }
.prose h2 { font-size: 1.32rem; }
.prose h3 { font-size: 1.15rem; }
.prose h4 { font-size: 1.02rem; }
/* Prompt-style chevron on top-level (#) headings, drawn with borders so it looks the same in every font. */
.prose h1::before {
  content: "";
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  margin: 0 0.6em 0.14em 0.04em;
  border-right: 0.12em solid var(--accent);
  border-bottom: 0.12em solid var(--accent);
  transform: rotate(-45deg);
  vertical-align: middle;
}
.prose .anchor { margin-left: 0.4em; font-family: var(--font-mono); font-weight: 400; color: var(--fg-faint); opacity: 0; transition: opacity 0.15s; text-decoration: none; }
.prose :is(h1, h2, h3, h4):hover .anchor, .prose .anchor:focus-visible { opacity: 1; }
.prose a:not(.anchor) { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 0.22em; }
.prose a:not(.anchor):hover { text-decoration-color: var(--accent); }
.prose strong { font-weight: 650; }
/* Math (KaTeX): wide display formulas scroll sideways instead of overflowing the column */
.prose div.arithmatex { margin: 1.15em 0; }
.prose .katex { font-size: 1.12em; }
.prose .katex-display { margin: 0; padding: 0.2em 0; overflow-x: auto; overflow-y: hidden; }
.prose .katex-error { font-family: var(--font-mono); font-size: 0.85em; }
/* KaTeX's own class names collide with site utilities: "accent" (\dot, \hat, \bar…) and "tag"
   (equation numbers) would otherwise pick up the .accent / .tag colors */
.katex .accent, .katex .tag { color: inherit; }
.katex .tag:hover { text-decoration: none; }
/* Résumé entries: "### Place · Degree" followed by a `{: .cv-meta }` date line. */
.prose h3 + .cv-meta { margin-top: -0.6em; }
.prose .cv-meta { margin-bottom: 0.4em; font-family: var(--font-mono); font-size: 0.8rem; color: var(--fg-faint); }
.prose .cv-meta + p { margin-top: 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.3em; }
.prose li::marker { color: var(--fg-faint); }
.prose blockquote { padding: 0.15em 0 0.15em 1.1em; margin-inline: 0; border-left: 2px solid var(--accent); color: var(--fg-muted); }
.prose hr { margin: 2.5em 0; border: 0; border-top: 1px dashed var(--line-strong); }
.prose img, .prose video { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; }
.prose video { width: 100%; background: #000; }
.prose figure { margin: 1.8em 0; }
.prose figure > :is(img, video) { margin-inline: auto; }
.prose figcaption { margin-top: 0.7rem; font-family: var(--font-mono); font-size: 0.76rem; line-height: 1.5; color: var(--fg-faint); text-align: center; }
.prose figcaption::before { content: "fig. "; color: var(--accent); }
.prose figure.is-video figcaption::before { content: "vid. "; }
.prose figure.is-model figcaption::before { content: "mod. "; }
/* 3D model viewer (js/model-viewer.js). --model-edge colors the outline of the model's edges. */
.model-viewer { --model-edge: var(--fg-muted); position: relative; overflow: hidden; width: 100%; aspect-ratio: 4 / 3; margin-inline: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-elev); transition: border-color 0.15s; }
.model-viewer.is-active { border-color: var(--accent); }
.model-viewer:fullscreen { width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; }
.model-viewer canvas { display: block; width: 100%; height: 100%; outline: none; }
.model-tools { position: absolute; top: 0.5rem; right: 0.5rem; display: flex; gap: 0.3rem; }
.prose .model-viewer .model-tool { display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: color-mix(in srgb, var(--bg-elev) 85%, transparent); color: var(--fg-muted); text-decoration: none; cursor: pointer; transition: color 0.15s, border-color 0.15s; }
.prose .model-viewer .model-tool:hover { color: var(--accent); border-color: var(--accent); }
.model-tool svg { width: 1rem; height: 1rem; }
.model-hint { position: absolute; left: 0.75rem; bottom: 0.55rem; right: 0.75rem; margin: 0; font-family: var(--font-mono); font-size: 0.68rem; color: var(--fg-faint); pointer-events: none; }
.prose .model-viewer :is(.model-status, .model-fallback) { position: absolute; inset: 0; display: grid; place-content: center; gap: 0.6rem; margin: 0; padding: 1rem; font-family: var(--font-mono); font-size: 0.78rem; color: var(--fg-faint); text-align: center; }
.prose .model-viewer .model-fallback, .prose .model-status a { color: var(--accent); }
.prose code { padding: 0.12em 0.38em; border-radius: 4px; background: var(--chip); font-family: var(--font-mono); font-size: 0.86em; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.92rem; }
.prose th, .prose td { padding: 0.5em 0.85em; border: 1px solid var(--line); text-align: left; }
.prose th { background: var(--chip); font-weight: 600; }
.prose .footnote { margin-top: 3em; font-size: 0.88rem; color: var(--fg-muted); }

.prose .codehilite { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--code-bg); }
.prose .codehilite pre { margin: 0; padding: 1rem 1.15rem; overflow-x: auto; font-family: var(--font-mono); font-size: 0.84rem; line-height: 1.7; }
.prose .codehilite code { padding: 0; background: none; font-size: inherit; }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 0.35rem 0.5rem 0.35rem 1rem; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: 0.68rem; color: var(--fg-faint); }
.code-copy { padding: 0.15rem 0.55rem; border: 1px solid var(--line); border-radius: 5px; background: transparent; color: var(--fg-muted); font: inherit; cursor: pointer; transition: color 0.15s, border-color 0.15s; }
.code-copy:hover { color: var(--fg); border-color: var(--fg-faint); }
.code-copy[data-done] { color: var(--accent); border-color: var(--accent); }

/* ==========================================================================
   Error page / footer
   ========================================================================== */
.error-page { padding-block: 5rem 6rem; }
.error-code { margin: 0; font-family: var(--font-mono); font-size: clamp(4.5rem, 16vw, 8.5rem); font-weight: 700; line-height: 1; letter-spacing: -0.06em; color: var(--accent); }
.terminal { margin: 1.5rem 0 2rem; font-family: var(--font-mono); font-size: 0.85rem; overflow-wrap: anywhere; }
.terminal p { margin: 0.2rem 0; }
.error-page h1 { margin: 0 0 0.5rem; font-size: 1.6rem; letter-spacing: -0.02em; }

.site-footer { border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 0.74rem; color: var(--fg-faint); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 1.5rem; padding-block: 1.6rem; }
.footer-meta { display: flex; gap: 1.2rem; }
.site-footer a { color: var(--fg-muted); }
.site-footer a:hover { color: var(--accent); }

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