:root {
  --bg: #ffffff;
  --bg-soft: #f7f8f9;
  --fg: #1c1f23;
  --fg-mut: #5b636c;
  --line: #e3e6e9;
  --line-strong: #cdd2d7;
  --accent: #0f6b4f;
  --accent-soft: #e8f4ef;
  --warn: #a35c00;
  --warn-soft: #fdf4e5;
  --bad: #b3261e;
  --bad-soft: #fdeceb;
  --code-bg: #1e2227;
  --code-fg: #e6e9ec;
  --max: 1180px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.85 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
        "Noto Sans JP", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration: none; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(150%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.site-header .inner {
  max-width: var(--max); margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 20px;
}
.brand { font-weight: 700; font-size: 15px; color: var(--fg); text-decoration: none; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.site-header nav { margin-left: auto; display: flex; gap: 18px; flex-wrap: wrap; }
.site-header nav a {
  font-size: 13.5px; color: var(--fg-mut); text-decoration: none; padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.site-header nav a:hover { color: var(--fg); }
.site-header nav a.current { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }

.menu-toggle { display: none; }

/* ---------- layout ---------- */
.layout { max-width: var(--max); margin: 0 auto; padding: 0 24px; display: flex; gap: 44px; }
.toc {
  width: 232px; flex: none; position: sticky; top: 72px; align-self: flex-start;
  max-height: calc(100vh - 96px); overflow-y: auto; padding: 32px 0 40px;
  font-size: 13.5px;
}
.toc p { margin: 0 0 10px; font-weight: 700; font-size: 12px; letter-spacing: .06em; color: var(--fg-mut); }
.toc a {
  display: block; padding: 5px 12px; color: var(--fg-mut); text-decoration: none;
  border-left: 2px solid var(--line); line-height: 1.5;
}
.toc a:hover { color: var(--fg); background: var(--bg-soft); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

main { flex: 1; min-width: 0; padding: 36px 0 96px; }

/* ---------- typography ---------- */
h1 { font-size: 30px; line-height: 1.4; margin: 0 0 12px; letter-spacing: -.01em; }
h2 {
  font-size: 22px; margin: 56px 0 16px; padding-top: 20px;
  border-top: 1px solid var(--line); letter-spacing: -.01em;
}
h2:first-of-type { border-top: 0; padding-top: 0; }
h3 { font-size: 17px; margin: 32px 0 10px; }
h4 { font-size: 15px; margin: 24px 0 8px; color: var(--fg-mut); }
p { margin: 0 0 16px; }
ul, ol { margin: 0 0 16px; padding-left: 24px; }
li { margin: 6px 0; }
strong { font-weight: 700; }
.lead { font-size: 17.5px; color: var(--fg-mut); line-height: 1.8; margin-bottom: 28px; }
.eyebrow {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .1em;
  color: var(--accent); background: var(--accent-soft);
  padding: 4px 10px; border-radius: 4px; margin-bottom: 14px;
}

/* ---------- code ---------- */
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .88em; background: var(--bg-soft); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 4px;
}
.code {
  position: relative; margin: 0 0 20px;
  background: var(--code-bg); border-radius: 8px; overflow: hidden;
}
.code .label {
  font-size: 11.5px; letter-spacing: .06em; color: #9aa3ad;
  padding: 8px 14px; border-bottom: 1px solid #2c3238; font-weight: 600;
}
.code pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  color: var(--code-fg); font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13.5px; line-height: 1.75;
}
.code pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; }
.copy {
  position: absolute; top: 6px; right: 8px;
  background: #333a41; color: #d8dde2; border: 1px solid #454d55;
  border-radius: 5px; font-size: 11.5px; padding: 4px 10px; cursor: pointer;
  font-family: inherit;
}
.copy:hover { background: #414951; }
.copy.done { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- callouts ---------- */
.box {
  border: 1px solid var(--line); border-left: 3px solid var(--line-strong);
  background: var(--bg-soft); border-radius: 0 8px 8px 0;
  padding: 16px 18px; margin: 0 0 20px;
}
.box > :last-child { margin-bottom: 0; }
.box .box-title {
  font-weight: 700; font-size: 13px; letter-spacing: .04em;
  margin: 0 0 8px; display: flex; align-items: center; gap: 7px;
}
.box.expect { border-left-color: var(--accent); background: var(--accent-soft); }
.box.expect .box-title { color: var(--accent); }
.box.trap { border-left-color: var(--warn); background: var(--warn-soft); }
.box.trap .box-title { color: var(--warn); }
.box.fail { border-left-color: var(--bad); background: var(--bad-soft); }
.box.fail .box-title { color: var(--bad); }
.box.term { border-left-color: var(--line-strong); }
.box.term .box-title { color: var(--fg-mut); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 0 20px; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; vertical-align: top; }
th { background: var(--bg-soft); font-weight: 700; font-size: 13px; white-space: nowrap; }
td code { white-space: nowrap; }

/* ---------- step blocks ---------- */
.step {
  border: 1px solid var(--line); border-radius: 10px; padding: 24px 26px; margin: 0 0 28px;
}
.step > h3:first-child { margin-top: 0; }
.step-meta {
  display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--fg-mut);
  border-bottom: 1px dashed var(--line); padding-bottom: 12px; margin-bottom: 18px;
}
.step-meta b { color: var(--fg); font-weight: 600; }

.num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
  margin-right: 10px; flex: none;
}

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin: 0 0 24px; }
.card {
  border: 1px solid var(--line); border-radius: 10px; padding: 20px;
  text-decoration: none; color: inherit; display: block; background: #fff;
}
.card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0; font-size: 13.5px; color: var(--fg-mut); line-height: 1.7; }
.card .tag { font-size: 11.5px; color: var(--accent); font-weight: 700; letter-spacing: .06em; }

/* ---------- pager ---------- */
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--line); }
.pager a {
  text-decoration: none; color: inherit; border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 18px; flex: 1; max-width: 48%;
}
.pager a:hover { border-color: var(--accent); }
.pager .dir { display: block; font-size: 11.5px; color: var(--fg-mut); letter-spacing: .06em; margin-bottom: 3px; }
.pager .ttl { font-weight: 600; font-size: 14.5px; }
.pager .next { text-align: right; margin-left: auto; }

footer {
  border-top: 1px solid var(--line); margin-top: 40px;
  padding: 28px 24px 48px; color: var(--fg-mut); font-size: 13px;
}
footer .inner { max-width: var(--max); margin: 0 auto; }

.kbd {
  display: inline-block; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; font-size: 12.5px; background: #fff;
  font-family: inherit;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { display: block; padding: 0 18px; }
  .toc {
    width: auto; position: static; max-height: none; padding: 20px 0 0;
    border-bottom: 1px solid var(--line);
  }
  .toc .toc-list { display: none; }
  .toc.open .toc-list { display: block; }
  .menu-toggle {
    display: block; width: 100%; text-align: left; background: var(--bg-soft);
    border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
    font: inherit; font-size: 14px; cursor: pointer; margin-bottom: 14px;
  }
  main { padding: 24px 0 72px; }
  h1 { font-size: 25px; }
  h2 { font-size: 20px; }
  .site-header .inner { padding: 10px 18px; gap: 12px; }
  .site-header nav { gap: 12px; width: 100%; margin-left: 0; }
  .step { padding: 18px; }
  .pager { display: block; }
  .pager a { max-width: none; display: block; margin-bottom: 10px; }
  .pager .next { text-align: left; }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16191c;
    --bg-soft: #1e2227;
    --fg: #e6e9ec;
    --fg-mut: #9aa3ad;
    --line: #2b3036;
    --line-strong: #3d444b;
    --accent: #5ec9a0;
    --accent-soft: #16302a;
    --warn: #e0a458;
    --warn-soft: #2e2617;
    --bad: #ef8a83;
    --bad-soft: #33201f;
    --code-bg: #0f1215;
  }
  :root:not([data-theme="light"]) .site-header { background: rgba(22,25,28,.92); }
  :root:not([data-theme="light"]) .card,
  :root:not([data-theme="light"]) .kbd { background: var(--bg-soft); }
}

/* ---------- 環境切り替え ---------- */
.env-switch {
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-soft); padding: 14px 16px; margin: 0 0 28px;
}
.env-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.env-label { font-size: 13px; font-weight: 700; color: var(--fg-mut); letter-spacing: .04em; }
.env-seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; }
.env-seg button {
  font: inherit; font-size: 13.5px; padding: 6px 16px; cursor: pointer;
  background: var(--bg); color: var(--fg-mut); border: 0; border-right: 1px solid var(--line-strong);
}
.env-seg button:last-child { border-right: 0; }
.env-seg button.on { background: var(--accent); color: #fff; font-weight: 700; }
#env-host {
  font: inherit; font-size: 13.5px; padding: 6px 10px; min-width: 220px;
  border: 1px solid var(--line-strong); border-radius: 7px;
  background: var(--bg); color: var(--fg);
}
.env-badge {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--line-strong); color: var(--fg-mut); background: var(--bg);
}
.env-badge.is-server { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.env-note { margin: 10px 0 0; font-size: 12.5px; color: var(--fg-mut); }

@media (max-width: 900px) {
  #env-host { min-width: 0; flex: 1 1 100%; }
}

/* 環境別の表示切り替え。JSが <html> に env-local / env-server を付ける。
   JS が動く前は「ローカル」を既定として表示する（サーバー用ブロックだけ隠す）。 */
[data-env-only="server"] { display: none; }
html.env-server [data-env-only="server"] { display: revert; }
html.env-server [data-env-only="local"] { display: none; }
