:root {
  --bg: #ffffff;
  --surface: #f6f7f8;
  --surface-strong: #eceef0;
  --text: #1d2125;
  --muted: #5d656e;
  --border: #dde1e5;
  --accent: #1f7a4d;
  --accent-soft: #e6f3ec;
  --warn-bg: #fff6e5;
  --warn-border: #e8c27a;
  --code-bg: #f0f2f4;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 8px 24px rgb(0 0 0 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1d2024;
    --surface-strong: #25292e;
    --text: #e8eaed;
    --muted: #9aa2ab;
    --border: #2f343a;
    --accent: #5cc18c;
    --accent-soft: #1b2b22;
    --warn-bg: #2d2616;
    --warn-border: #7a6226;
    --code-bg: #23272c;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--accent); text-underline-offset: 3px; }
code, kbd {
  font: 0.88em "SF Mono", Menlo, Consolas, monospace;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
kbd { border: 1px solid var(--border); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 650; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.topbar nav { margin-left: auto; display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--text); }

.language-switcher { margin-left: 18px; padding-left: 18px; border-left: 1px solid var(--border); gap: 12px; font-size: 13px; }
.language-switcher a[aria-current="true"] { color: var(--text); font-weight: 650; }

:lang(th) h1, :lang(th) h2, :lang(th) h3, :lang(th) h4 { line-height: 1.45; }

.layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 48px; max-width: 1180px; margin: 0 auto; padding: 32px 24px 96px; }
.toc { position: sticky; top: 80px; align-self: start; max-height: calc(100vh - 100px); overflow-y: auto; font-size: 14px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 2px 0; }
.toc a { display: block; padding: 3px 10px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--text); border-left-color: var(--border); }
.toc .group { margin: 18px 0 6px; padding-left: 12px; font-size: 12px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text); }
.toc .group:first-child { margin-top: 0; }

main { min-width: 0; max-width: 820px; }
.hero { padding: 16px 0 24px; }
.hero h1 { font-size: clamp(30px, 4vw, 42px); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 12px; }
.hero p.lead { font-size: 19px; color: var(--muted); margin: 0 0 20px; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; }
.button { display: inline-block; padding: 9px 18px; border-radius: 8px; border: 1px solid var(--border); color: var(--text); text-decoration: none; font-weight: 550; font-size: 15px; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }

section.part { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 48px; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; margin: 24px 0 0; }
h2 { font-size: 28px; letter-spacing: -0.015em; margin: 4px 0 12px; }
h3 { font-size: 20px; margin: 40px 0 8px; }
h4 { font-size: 16px; margin: 24px 0 4px; }
p, ul, ol { margin: 0 0 14px; }
li { margin: 4px 0; }

ol.steps { counter-reset: step; list-style: none; padding: 0; }
ol.steps > li { counter-increment: step; position: relative; padding-left: 40px; margin: 12px 0; }
ol.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 1px;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 700;
}

figure { margin: 20px 0 28px; }
figure a { display: block; }
figure img { display: block; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--shadow); background: #1f1f1f; }
figure.narrow img { max-width: 380px; }
figcaption { margin-top: 10px; font-size: 14px; color: var(--muted); }
.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; align-items: start; }
.pair figure { margin: 0; }

.note { padding: 12px 16px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); margin: 16px 0; font-size: 15px; }
.note.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.note strong:first-child { display: block; margin-bottom: 2px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 16px 0 8px; }
.card { padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card p { margin: 0; font-size: 15px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14.5px; margin: 12px 0 20px; display: block; overflow-x: auto; }
th, td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-weight: 650; background: var(--surface); }
td code { white-space: nowrap; }

footer { max-width: 1180px; margin: 0 auto; padding: 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 20px 16px 64px; gap: 0; }
  .toc { display: none; }
  .topbar { padding: 10px 16px; }
  .topbar nav { gap: 12px; font-size: 13px; }
}
@media (max-width: 560px) {
  html { scroll-padding-top: 112px; }
  .topbar { align-items: stretch; flex-wrap: wrap; }
  .topbar nav {
    width: 100%; margin-left: 0; padding-bottom: 2px;
    flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }
  .topbar nav a { flex: 0 0 auto; white-space: nowrap; }
  .language-switcher { margin-left: 0; padding-left: 0; border-left: none; }
}
