/* Site styles. Diagrams bring their own styles (scoped under .diagram). */

/* Anuphan (SIL Open Font License, fonts/OFL.txt): a loopless Thai face for the Thai pages,
   self-hosted so the site needs no third-party request. Variable weight 100–700. */
@font-face {
  font-family: "Anuphan";
  src: url("fonts/anuphan-thai.woff2") format("woff2");
  font-weight: 100 700;
  font-display: swap;
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Anuphan";
  src: url("fonts/anuphan-latin.woff2") format("woff2");
  font-weight: 100 700;
  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;
}

:root {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface-2: #eef1f4;
  --border: #d1d9e0;
  --border-strong: #b7c0c9;
  --text: #1f2328;
  --muted: #59636e;
  --faint: #6a737d;
  --accent: #0969da;
  --accent-soft: rgba(9, 105, 218, 0.1);
  --green: #1a7f37;
  --green-soft: rgba(26, 127, 55, 0.1);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.05), 0 8px 24px rgba(31, 35, 40, 0.06);
  --wrap: 1180px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", "Noto Sans Thai", "Leelawadee UI", Thonburi, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1c232c;
    --border: #3d444d;
    --border-strong: #545d68;
    --text: #e6edf3;
    --muted: #9198a1;
    --faint: #7d8590;
    --accent: #4493f8;
    --accent-soft: rgba(68, 147, 248, 0.16);
    --green: #3fb950;
    --green-soft: rgba(63, 185, 80, 0.16);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 24px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
code { font-family: var(--mono); font-size: 0.875em; background: var(--surface-2); padding: 0.15em 0.4em; border-radius: 6px; }
.wrap { max-width: var(--wrap); margin: 0 auto; padding-inline: 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- top bar ---------------------------------------------------------- */
.topbar { border-bottom: 1px solid var(--border); background: var(--bg); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; padding-block: 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; flex: none; }
.topbar nav { display: flex; gap: 18px; font-size: 14px; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--text); }
.topbar nav .lang-switch { color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; margin-block: -2px; }
.topbar nav .lang-switch:hover { border-color: var(--accent); text-decoration: none; }
/* Thai pages use Anuphan for Thai and Latin alike, so mixed lines look even; code stays monospace.
   Thai stacks tone marks above and vowels below the line: give the text a little more room. */
html:lang(th) { --font: "Anuphan", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif; }
html:lang(th) body { line-height: 1.75; }
.lang-switch:lang(th) { font-family: "Anuphan", var(--font); }
.lang-note { font-size: 14px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin: 0 0 20px; max-width: 46em; }

/* ---- index: hero -------------------------------------------------------- */
.hero { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 48px; align-items: center; padding-block: 56px 40px; }
.hero h1 { font-size: clamp(34px, 4.4vw, 52px); line-height: 1.08; letter-spacing: -0.03em; margin: 0 0 18px; }
.hero h1 span { color: var(--accent); }
.lede { font-size: 18px; color: var(--muted); margin: 0 0 22px; max-width: 34em; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 26px; padding: 0; list-style: none; }
.stats li { font-size: 13px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; }
.stats strong { color: var(--text); }
.motion-toggle { font: inherit; font-size: 13px; color: var(--muted); background: none; border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.motion-toggle:hover { color: var(--text); border-color: var(--accent); }
.motion-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.featured { margin: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg); box-shadow: var(--shadow); }
.featured img { display: block; width: 100%; height: auto; }
.featured figcaption { font-size: 13px; color: var(--muted); padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface); }
.search { position: relative; max-width: 420px; }
.search input { width: 100%; font: inherit; font-size: 15px; color: var(--text); background: var(--bg); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 14px 10px 40px; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { position: absolute; left: 13px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--faint); }

/* ---- index: catalog layout with a sticky category menu on the left ---- */
.catalog { display: grid; grid-template-columns: 236px minmax(0, 1fr); gap: 44px; align-items: start; }
.side-toc { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; padding-bottom: 16px; }
.side-toc-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 44px 0 10px 15px; }
.side-toc ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.side-toc a { display: flex; align-items: center; gap: 10px; padding: 7px 10px 7px 12px; border-left: 3px solid transparent; border-radius: 0 8px 8px 0; color: var(--muted); font-size: 14px; line-height: 1.3; }
.side-toc a:hover { text-decoration: none; color: var(--text); background: var(--surface); }
.side-toc a.active { color: var(--text); font-weight: 600; background: var(--accent-soft); border-left-color: var(--accent); }
.side-toc a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.side-toc .icon { flex: none; width: 1.3em; text-align: center; }
.side-toc .name { flex: 1; }
.side-toc .n { flex: none; font-size: 12px; font-weight: 400; color: var(--faint); font-variant-numeric: tabular-nums; }
.side-toc-toggle { display: none; }
.sections { min-width: 0; }

/* ---- index: categories -------------------------------------------------- */
.category { padding-block: 40px 8px; }
.category > header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 18px; }
.category h2 { font-size: 26px; letter-spacing: -0.02em; margin: 0; }
.category h2 .icon { margin-right: 6px; }
.category > header p { margin: 0; color: var(--muted); flex: 1 1 320px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); background: var(--bg); transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s; }
.card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.card .thumb { aspect-ratio: 960 / 400; background: var(--bg); border-bottom: 1px solid var(--border); }
.card .thumb img { display: block; width: 100%; height: 100%; }
.card .body { padding: 12px 16px 16px; }
.card h3 { font-size: 16px; margin: 0 0 4px; letter-spacing: -0.01em; }
.card p { font-size: 14px; line-height: 1.5; color: var(--muted); margin: 0; }
.planned { margin-top: 18px; }
.planned h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 0 0 8px; }
.planned ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 2px 24px; margin: 0; padding: 0; list-style: none; }
.planned li { font-size: 14px; line-height: 1.45; padding: 7px 0 7px 14px; border-left: 2px dashed var(--border); }
.planned li strong { font-weight: 600; }
.planned li span { color: var(--muted); }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
[hidden] { display: none !important; }

/* ---- pattern page ------------------------------------------------------- */
.page-head { padding-block: 28px 20px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.page-head h1 { font-size: clamp(30px, 4vw, 44px); line-height: 1.1; letter-spacing: -0.03em; margin: 0 0 12px; }
.page-head .lede { margin: 0; }
.aka { font-size: 14px; color: var(--faint); margin: 10px 0 0; }

.player { border: 1px solid var(--border); border-radius: calc(var(--radius) + 4px); background: var(--surface); padding: 12px; box-shadow: var(--shadow); }
.stage { position: relative; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); overflow: hidden; cursor: pointer; }
.stage svg { display: block; width: 100%; height: auto; }
.controls { display: flex; align-items: center; gap: 8px; padding: 12px 4px 10px; flex-wrap: wrap; }
.controls button { font: inherit; font-size: 13px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; height: 34px; min-width: 34px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; }
.controls button:hover { border-color: var(--accent); }
.controls button:focus-visible, .steps button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.controls svg { width: 14px; height: 14px; }
.controls .status { margin-left: auto; font-size: 13px; color: var(--muted); }
.controls .status b { color: var(--text); font-weight: 600; }
.icon-pause, .player.paused .icon-play { display: inline; }
.icon-play, .player.paused .icon-pause { display: none; }
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.steps li { display: flex; }
.steps button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 10px; width: 100%; cursor: pointer; border-radius: 10px; padding: 13px 12px 11px; background: var(--bg); border: 1px solid var(--border); position: relative; overflow: hidden; }
.steps button:hover { border-color: var(--border-strong); }
.steps button::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--border); }
.steps button::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--accent); transform-origin: left; transform: scaleX(var(--p, 0)); }
.steps .n { flex: none; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.steps .t { font-weight: 600; font-size: 14px; line-height: 1.3; color: var(--muted); }
.steps li.active button { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.steps li.active .n { background: var(--accent); color: var(--bg); }
.steps li.active .t { color: var(--text); }
/* all four details share one grid cell, so the panel keeps the height of the longest one */
.details { display: grid; margin-top: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; }
.detail { grid-area: 1 / 1; margin: 0; font-size: 15px; line-height: 1.6; max-width: 72em; visibility: hidden; }
.detail.on { visibility: visible; }
.detail strong:first-child { font-weight: 700; }

.content { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 48px; padding-block: 36px 24px; }
.prose { max-width: 740px; }
.prose h2 { font-size: 22px; letter-spacing: -0.015em; margin: 34px 0 10px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 17px; margin: 26px 0 8px; }
.prose p, .prose li { color: var(--text); }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin: 4px 0; }
.prose li::marker { color: var(--faint); }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 16px 0; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface); }
.prose pre { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin: 16px 0; overflow-x: auto; line-height: 1.5; }
.prose pre code { background: none; padding: 0; border-radius: 0; font-size: 13.5px; }
aside.side { display: flex; flex-direction: column; gap: 28px; }
aside.side h2 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 0 0 10px; }
aside.side ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
aside.side li { font-size: 14px; line-height: 1.45; }
aside.side li .tag { font-size: 11px; color: var(--faint); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; margin-left: 6px; white-space: nowrap; }
aside.side li.planned-item { color: var(--muted); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding-block: 16px 48px; border-top: 1px solid var(--border); margin-top: 24px; }
.pager a { display: block; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; color: var(--text); }
.pager a:hover { text-decoration: none; border-color: var(--accent); }
.pager small { display: block; font-size: 12px; color: var(--faint); margin-bottom: 2px; }
.pager .next { text-align: right; grid-column: 2; }

.foot { border-top: 1px solid var(--border); color: var(--faint); font-size: 13px; padding-block: 28px 40px; margin-top: 32px; }
.foot p { margin: 0; }

@media (max-width: 900px) {
  html { scroll-padding-top: 76px; }
  .hero { grid-template-columns: 1fr; gap: 28px; padding-block: 32px 24px; }
  /* the category menu folds into a sticky dropdown above the sections */
  .catalog { grid-template-columns: 1fr; gap: 0; }
  .side-toc { top: 0; z-index: 10; max-height: none; overflow: visible; margin-inline: -24px; padding: 8px 24px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
  .side-toc-title { display: none; }
  .side-toc-toggle { display: flex; align-items: center; gap: 8px; width: 100%; font: inherit; font-size: 14px; font-weight: 600; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 9px 14px; cursor: pointer; }
  .side-toc-toggle .current { flex: 1; text-align: left; font-weight: 400; color: var(--muted); }
  .side-toc-toggle .current:not(:empty)::before { content: "· "; }
  .side-toc ul { display: none; position: absolute; left: 24px; right: 24px; top: calc(100% - 2px); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 6px; box-shadow: 0 8px 24px rgba(1, 4, 9, 0.18); max-height: 70vh; overflow-y: auto; }
  .side-toc.open ul { display: flex; }
  .side-toc a { border-left: 0; border-radius: 8px; }
  .content { grid-template-columns: 1fr; gap: 24px; }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .wrap { padding-inline: 16px; }
  .side-toc { margin-inline: -16px; padding-inline: 16px; }
  .side-toc ul { left: 16px; right: 16px; }
  .brand { font-size: 15px; line-height: 1.25; }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .details { padding: 12px 14px; }
  .controls .status { width: 100%; margin-left: 0; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .card:hover { transition: none; transform: none; }
}
