/* 配色と文字の設定。IDE（style.css）とドキュメント（docs.css）で共通 */
:root {
  /* One Dark 系の配色（ダークのみ） */
  --bg: #21252b;          /* ヘッダー・タブまわり */
  --surface: #282c34;     /* エディタ・出力 */
  --surface-2: #2c313a;   /* ボタン */
  --text: #abb2bf;
  --text-strong: #d7dae0;
  --muted: #7f848e;
  --border: #3e4451;
  --accent: #c678dd;      /* 紫 */
  --accent-text: #21252b;
  --error: #e06c75;       /* 赤 */
  --ok: #98c379;          /* 緑 */
  --syn-string: #98c379;
  --syn-meta: #e5c07b;    /* 黄 */
  --syn-number: #d19a66;  /* 橙 */
  --syn-atom: #56b6c2;    /* 水色 */
  --syn-type: #e5c07b;
  --syn-link: #61afef;    /* 青 */
  --code-font: ui-monospace, 'SF Mono', 'Menlo', 'Cascadia Code', 'Roboto Mono', monospace;
  --ui-font: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --editor-size: 15px;
  color-scheme: dark;
}

/* アクセス解析の Cookie のお知らせ（scripts/site.mjs の gtmSnippet() が、公開先でだけ出す） */
.consent-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  color: var(--text);
  font: 13px/1.5 var(--ui-font);
}
.consent-bar p { margin: 0; flex: 1; }
.consent-bar a { color: var(--syn-link); margin-left: 6px; }
/* ボタンは IDE の「▶ 実行」と同じ見た目（緑の文字） */
.consent-bar button {
  flex: none;
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ok);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
.consent-bar button:hover { background: #333842; border-color: #4b5263; }

/* 検索（⌘K）。IDE（style.css から読み込む）とドキュメント（docs.css にまとめる）で共通 */
.search-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.search-button:hover { border-color: #4b5263; color: var(--text); }
.search-kbd { font-family: var(--ui-font); font-size: 11px; padding: 1px 5px; border: 1px solid var(--border); border-radius: 4px; }
@media (max-width: 720px) {
  .search-label, .search-kbd { display: none; }
}

/* 黒ベースの半透明のモーダル。大きさは中身によらず一定 */
.search-dialog {
  width: min(620px, calc(100vw - 24px));
  height: min(460px, calc(100dvh - 120px));
  margin: max(10vh, 48px) auto auto;
  padding: 0;
  border: 1px solid rgb(255 255 255 / .09);
  border-radius: 16px;
  background: rgb(18 20 24 / .72);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  backdrop-filter: blur(22px) saturate(150%);
  color: var(--text);
  overflow: hidden;
  box-shadow: 0 24px 64px rgb(0 0 0 / .55), inset 0 1px 0 rgb(255 255 255 / .06);
}
.search-dialog[open] { display: flex; flex-direction: column; animation: search-in .14s ease-out; }
@keyframes search-in { from { opacity: 0; transform: translateY(-6px) scale(.985); } }
.search-dialog::backdrop { background: rgb(0 0 0 / .45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }

.search-box { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid rgb(255 255 255 / .07); }
.search-icon { opacity: .7; }
.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text-strong);
  font: inherit;
  font-size: 17px; /* 16px 未満だと iOS が入力時にズームする */
}
.search-box input::placeholder { color: rgb(255 255 255 / .35); }

.search-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { position: relative; padding: 9px 12px 9px 14px; border-radius: 10px; cursor: pointer; }
.search-results li[aria-selected="true"] { background: rgb(255 255 255 / .07); }
.search-results li[aria-selected="true"]::before {
  content: '';
  position: absolute;
  left: 4px; top: 10px; bottom: 10px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.search-results li.search-group { padding: 12px 14px 4px; cursor: default; color: rgb(255 255 255 / .38); font-size: 11px; letter-spacing: .04em; }
.search-title { color: var(--text-strong); font-size: 14px; line-height: 1.5; }
.search-page { color: var(--muted); }
.search-snippet { margin-top: 2px; color: rgb(255 255 255 / .45); font-size: 12px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-tag { margin-right: 6px; padding: 0 6px; border-radius: 4px; background: rgb(198 120 221 / .16); color: var(--accent); }
.search-dialog mark { background: none; color: var(--syn-meta); font-weight: 600; }

.search-hint { padding: 12px 12px 6px; color: rgb(255 255 255 / .5); font-size: 13px; }
.search-hint p { margin: 0 0 10px; }
.search-examples { display: flex; flex-wrap: wrap; gap: 6px; }
.search-examples button {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgb(255 255 255 / .1);
  background: rgb(255 255 255 / .04);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.search-examples button:hover { background: rgb(255 255 255 / .09); }
.search-empty { margin: 0; padding: 32px 12px; text-align: center; color: rgb(255 255 255 / .45); font-size: 13px; }

.search-footer {
  display: flex;
  gap: 16px;
  padding: 8px 18px;
  border-top: 1px solid rgb(255 255 255 / .07);
  color: rgb(255 255 255 / .4);
  font-size: 11px;
}
.search-footer kbd {
  display: inline-block;
  min-width: 18px;
  margin-right: 3px;
  padding: 0 4px;
  border-radius: 4px;
  border: 1px solid rgb(255 255 255 / .12);
  background: rgb(255 255 255 / .05);
  font-family: var(--ui-font);
  text-align: center;
}
/* スマホでは画面の上のほうに出して、キーボードと重ならないようにする */
@media (max-width: 560px) {
  .search-dialog { margin-top: 12px; height: min(420px, calc(100dvh - 24px)); }
  .search-footer { display: none; }
}

/* 新しい記事の印（ドキュメントのサイドバーと検索結果） */
.new-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ok) 18%, transparent);
  color: var(--ok);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 16px;
  vertical-align: 1px;
}
.new-badge[hidden] { display: none; }

/* ドキュメントのページ（scripts/build-docs.mjs が theme.css とつなげて /docs/docs.css に出す） */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: var(--ui-font);
  line-height: 1.8;
}

.spacer { flex: 1; }
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.logo { font-size: 16px; font-weight: 650; color: var(--text-strong); text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 2px; margin-left: 8px; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--text); font-size: 14px; text-decoration: none; white-space: nowrap; }
.nav a:hover, .nav a[aria-current] { background: var(--surface-2); color: var(--text-strong); }

/* 目次：広い画面では左に固定、狭い画面ではヘッダーの「目次」から開く */
.layout { display: grid; grid-template-columns: 256px minmax(0, 1fr); max-width: 1140px; margin: 0 auto; }
/* ヘッダーの高さ（--bar-h）と下のお知らせの高さ（--consent-h）は docs/runtime.ts が測って入れる。
   余白込みで画面に収め、サイドバーだけで一番下までスクロールできるようにする。
   html の zoom（--zoom、下の PC 向け）がかかると 100dvh も拡大されてはみ出すので、その分を割り戻す */
.toc { position: sticky; top: var(--bar-h, 54px); align-self: start; box-sizing: border-box; max-height: calc(100dvh / var(--zoom, 1) - var(--bar-h, 54px) - var(--consent-h, 0px)); overflow-y: auto; overscroll-behavior: contain; padding: 12px 14px 40px 16px; border-right: 1px solid var(--border); }
/* 区切りの見出し（はじめに・基本…）：少し大きく明るく、上に余白 */
.toc h2, .toc-drawer h2 { font-size: 12px; font-weight: 600; color: color-mix(in srgb, var(--text) 75%, transparent); margin: 22px 0 6px 2px; letter-spacing: .06em; }
.toc section:first-child h2, .toc-drawer section:first-child h2 { margin-top: 10px; }
.toc ul, .toc-drawer ul { list-style: none; padding: 0; margin: 0; }
/* ページ名：一段下げて、左に細い縦線 */
.toc section > ul, .toc-drawer section > ul { margin-left: 6px; padding-left: 4px; border-left: 1px solid var(--border); }
.toc a, .toc-drawer a { position: relative; display: block; padding: 6px 10px; border-radius: 6px; color: var(--text); font-size: 14px; line-height: 1.45; text-decoration: none; }
.toc a:hover, .toc-drawer a:hover { background: var(--surface-2); color: var(--text-strong); }
/* 今いるページ：左にアクセントの線、太字 */
.toc a[aria-current], .toc-drawer a[aria-current] { color: var(--text-strong); font-weight: 650; background: color-mix(in srgb, var(--accent) 9%, transparent); }
.toc a[aria-current]::before, .toc-drawer a[aria-current]::before {
  content: '';
  position: absolute;
  left: -6px; top: 6px; bottom: 6px;
  width: 2px;
  border-radius: 1px;
  background: var(--accent);
}
.toc-toggle { display: none; margin-left: auto; position: relative; }
.toc-toggle summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.toc-toggle[open] summary { color: var(--text-strong); border-color: #4b5263; }
.toc-toggle summary::-webkit-details-marker { display: none; }
.toc-drawer { position: absolute; right: 0; top: calc(100% + 8px); width: min(300px, calc(100vw - 32px)); max-height: 70dvh; overflow-y: auto; padding: 4px 12px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); box-shadow: 0 8px 24px rgb(0 0 0 / .35); }

main { min-width: 0; padding: 24px max(16px, env(safe-area-inset-right)) 64px max(24px, env(safe-area-inset-left)); }
article { max-width: 760px; }
article h1 { font-size: 28px; line-height: 1.4; color: var(--text-strong); margin: 8px 0 16px; }
/* 固定のヘッダーに隠れないように、見出しへ飛んだときの止まる位置を下げる */
article :is(h2, h3) { scroll-margin-top: 72px; }
/* 検索から飛んできた節のハイライト（節全体を 1 枚で覆って、少しずつ消える） */
article { position: relative; }
.jump-overlay {
  position: absolute;
  left: -14px;
  right: -14px;
  border-radius: 10px;
  border-left: 3px solid var(--syn-meta);
  background: color-mix(in srgb, var(--syn-meta) 8%, transparent);
  pointer-events: none;
  animation: jump-fade 2.6s ease-out forwards;
}
.jump-heading { color: var(--syn-meta); transition: color .6s; }
/* 節の中の検索語 */
mark.jump-mark {
  background: color-mix(in srgb, var(--syn-meta) 32%, transparent);
  color: inherit;
  border-radius: 3px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--syn-meta) 32%, transparent);
  transition: background .9s, box-shadow .9s;
}
mark.jump-mark.flash { animation: jump-pulse .9s ease-out 2; }
mark.jump-mark.fading { background: transparent; box-shadow: 0 0 0 2px transparent; }
@keyframes jump-pulse { 50% { background: color-mix(in srgb, var(--syn-meta) 60%, transparent); } }
@keyframes jump-fade { 0%, 55% { opacity: 1; } 100% { opacity: 0; } }
article h2 { font-size: 20px; color: var(--text-strong); margin: 36px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
article h3 { font-size: 16px; color: var(--text-strong); margin: 24px 0 6px; }
article p, article li { font-size: 15px; }
article a { color: var(--syn-link); }
/* コードの形のリンクも、周りのリンクと同じ色と下線にする */
article a > code { color: inherit !important; text-decoration: inherit; }
article code { font-family: var(--code-font); font-size: .92em; }
article :not(pre) > code { padding: 1px 5px; border-radius: 4px; background: var(--surface-2); color: var(--text-strong); }
article table { border-collapse: collapse; font-size: 14px; margin: 12px 0; display: block; overflow-x: auto; }
article th, article td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
article th { background: var(--bg); color: var(--text-strong); }
article td code, article th, article td a { white-space: nowrap; } /* 表の中のコードは折り返さず、表ごと横にスクロールする */
article blockquote { margin: 16px 0; padding: 8px 14px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 8px 8px 0; }
article blockquote p { margin: 4px 0; }

/* コード例 */
figure { margin: 14px 0; }
.code { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); }
.code-bar { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 12px; border-bottom: 1px solid var(--border); font-size: 12px; }
.code-label { color: var(--muted); }
.code-label.error { color: var(--error); }
.code-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.code-actions button {
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.code-actions .run-example { color: var(--ok); font-weight: 600; }
.code-actions .copy-code { display: inline-flex; align-items: center; justify-content: center; padding: 3px 7px; color: var(--muted); }
.code-actions .copy-code:hover { color: var(--text-strong); }
.code-actions .copy-code.done { color: var(--ok); }
/* コンパイルエラーの場所（IDE と同じ赤い波線） */
.diag-mark { text-decoration: underline wavy var(--error); text-decoration-skip-ink: none; text-underline-offset: 3px; border-radius: 3px; }
.diag-mark.flash { animation: diag-flash 1.2s ease-out; }
@keyframes diag-flash { 0%, 40% { background: color-mix(in srgb, var(--error) 30%, transparent); } }
.diag-line { cursor: pointer; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--error) 50%, transparent); }
.diag-line:hover { text-decoration-color: var(--error); }
.code-actions button:hover { border-color: #4b5263; }
.code-actions button:disabled { opacity: .5; cursor: default; }
.code-actions [hidden] { display: none; }
.code.editing { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.io-block.changed { border-style: solid; border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.code pre, .io-block pre, pre.plain { margin: 0; padding: 12px 14px; overflow-x: auto; font-family: var(--code-font); font-size: 14px; line-height: 1.6; white-space: pre; }
.code-error { border-color: color-mix(in srgb, var(--error) 45%, var(--border)); }
.io-block { border: 1px dashed var(--border); border-radius: 10px; }
/* パッチの差分（リンクのような見出しを押すと開く） */
.patch-toggle { margin: 10px 0; }
.patch-toggle summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; color: var(--syn-link); }
.patch-toggle summary::-webkit-details-marker { display: none; }
.patch-toggle summary::before { content: '▸'; font-size: 11px; transition: transform .15s; }
.patch-toggle[open] summary::before { transform: rotate(90deg); }
.patch-toggle summary code { color: inherit !important; text-decoration: underline; text-underline-offset: 3px; }
.patch-toggle summary:hover code { text-decoration-thickness: 2px; }
.patch-toggle figure { margin-top: 8px; }
.code-diff pre { font-size: 13px; }
.diff-add { color: var(--ok); }
.diff-del { color: var(--error); }
.diff-hunk { color: var(--syn-atom); }
.io-block figcaption { padding: 4px 12px 0; font-size: 11px; color: var(--muted); }
.io-block pre { padding-top: 4px; color: var(--text-strong); }
.io-block.error pre { color: var(--error); }
/* 公式コンパイラでの実行結果（固定の表示） */
.io-block.official { border-style: solid; border-color: color-mix(in srgb, var(--muted) 35%, var(--border)); background: color-mix(in srgb, var(--bg) 60%, transparent); }
.io-block.official pre { color: var(--muted); }
pre.plain { background: var(--bg); border-radius: 10px; }

/* ハイライト（@lezer/highlight の classHighlighter のクラス。色は IDE と同じ） */
.tok-keyword { color: var(--accent); font-weight: 600; }
.tok-string { color: var(--syn-string); }
.tok-meta { color: var(--syn-meta); font-weight: 600; }
.tok-comment { color: var(--muted); font-style: italic; }
.tok-number { color: var(--syn-number); }
.tok-atom { color: var(--syn-atom); }
.tok-typeName { color: var(--syn-type); }
.tok-variableName { color: var(--error); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 760px; margin-top: 48px; }
.pager a { display: flex; flex-direction: column; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; color: var(--text-strong); text-decoration: none; font-size: 14px; }
.pager a span { font-size: 11px; color: var(--muted); }
.pager .next { text-align: right; }
.pager a:hover { border-color: #4b5263; background: var(--bg); }

@media (max-width: 860px) {
  .layout { display: block; }
  .toc { display: none; }
  .toc-toggle { display: block; }
  main { padding-left: max(16px, env(safe-area-inset-left)); }
}
@media (max-width: 480px) {
  .logo-text { display: none; }
  .nav { margin-left: 0; }
  .nav a { padding: 6px 8px; font-size: 13px; }
  article h1 { font-size: 24px; }
}

/* 開いているページの h2 の一覧 */
.toc-sub { margin: 2px 0 8px 12px !important; padding-left: 6px !important; border-left: 1px solid var(--border); }
.toc .toc-sub a, .toc-drawer .toc-sub a { padding: 4px 8px; font-size: 12.5px; line-height: 1.5; color: var(--muted); font-weight: 400; background: none; }
.toc .toc-sub a::before, .toc-drawer .toc-sub a::before { content: none; }
.toc .toc-sub a:hover, .toc-drawer .toc-sub a:hover { color: var(--text-strong); }
.toc .toc-sub a.active, .toc-drawer .toc-sub a.active { color: var(--syn-meta); }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* IDE の使い方・既知のバグは Emojicode の説明とは別もの：一番下に区切って、↗ をつける */
.toc-separate { margin-top: 24px; padding-top: 8px; border-top: 1px dashed var(--border); }
.toc-separate a { color: var(--muted); }
.toc-separate .ext { margin-left: 4px; font-size: 11px; opacity: .8; }

/* PC（広い画面）では全体を 1.15 倍にする */
@media (min-width: 1100px) {
  :root { --zoom: 1.15; }
  html { zoom: var(--zoom); }
}

/* 言語メニュー（ヘッダー）：🌐 と今の言語。開くと言語の一覧 */
.lang-menu { position: relative; }
.lang-menu summary { list-style: none; display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 6px; color: var(--text); font-size: 13px; cursor: pointer; white-space: nowrap; }
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-menu summary:hover, .lang-menu[open] summary { background: var(--surface-2); color: var(--text-strong); }
.lang-menu ul { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 140px; margin: 0; padding: 4px; list-style: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / .35); }
.lang-menu a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 14px; }
.lang-menu a:hover { background: var(--surface); color: var(--text-strong); }
.lang-menu a[aria-current] { color: var(--ok); font-weight: 650; }
@media (max-width: 480px) {
  .lang-label { display: none; }
}

/* ページの言語と希望の言語が違うときの案内（ヘッダーの下） */
.lang-banner { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: color-mix(in srgb, var(--syn-link) 12%, var(--bg)); border-bottom: 1px solid var(--border); font-size: 14px; }
.lang-banner span { flex: 1; }
.lang-banner a { color: var(--syn-link); font-weight: 600; white-space: nowrap; }
.lang-banner button { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 6px; }

/* ページの下：GitHub で編集・問題を報告 */
.page-footer { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 28px 0 48px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13px; }
.page-footer a { color: var(--muted); text-decoration: none; }
.page-footer a:hover { color: var(--syn-link); text-decoration: underline; }

/* ファイルの中身をコピーするボタン（```copyfile） */
.copy-file button { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-strong); font: inherit; font-size: 14px; cursor: pointer; }
.copy-file button:hover { border-color: #4b5263; background: #333842; }
