:root {
  --bg: #ffffff;
  --bg-sidebar: #f6f7f9;
  --bg-topbar: #1f2a44;
  --fg: #1d2330;
  --fg-muted: #5d6677;
  --fg-topbar: #ffffff;
  --accent: #0b63ce;
  --accent-bg: #e8f1fc;
  --border: #dde1e7;
  --note: #0b63ce;
  --tip: #1a7f4b;
  --important: #b76e00;
  --warning: #c62828;
  --topbar-h: 52px;
  --sidebar-w: 320px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181f;
    --bg-sidebar: #1a1f28;
    --bg-topbar: #0e1219;
    --fg: #e4e7ec;
    --fg-muted: #9aa3b2;
    --accent: #6aa8ff;
    --accent-bg: #1d2a3d;
    --border: #2c3340;
    --note: #6aa8ff;
    --tip: #4cc38a;
    --important: #f0a940;
    --warning: #ff6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.8;
}
a { color: var(--accent); }

/* ヘッダー */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  height: var(--topbar-h); padding: 0 16px;
  background: var(--bg-topbar); color: var(--fg-topbar);
}
.topbar a { color: var(--fg-topbar); text-decoration: none; }
.brand { font-weight: 700; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.site-name { color: #b9c3d6; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar a.site-name { color: #b9c3d6; }
.topbar a.site-name:hover { color: var(--fg-topbar); }
.original-link {
  margin-left: auto; font-size: 13px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.4); border-radius: 4px; padding: 3px 10px;
}
.original-link:hover { background: rgba(255,255,255,.1); }
.toc-toggle { display: none; background: none; border: 0; color: inherit; font-size: 20px; cursor: pointer; padding: 4px; }

/* 2 ペイン */
.layout { display: flex; }
.sidebar {
  position: sticky; top: var(--topbar-h);
  flex: 0 0 var(--sidebar-w); height: calc(100vh - var(--topbar-h));
  overflow-y: auto; padding: 12px 8px 24px;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  font-size: 13.5px; line-height: 1.5;
}
.content { flex: 1; min-width: 0; max-width: 960px; padding: 24px 40px 48px; }

/* 目次 */
.toc-filter {
  width: 100%; margin: 0 0 8px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--fg); font: inherit;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc ul ul { padding-left: 14px; display: none; }
.toc li.expanded > ul { display: block; }
.toc-row { display: flex; align-items: flex-start; }
.toc-row a {
  flex: 1; display: block; padding: 4px 6px; border-radius: 4px;
  color: var(--fg); text-decoration: none;
}
.toc-row a:hover { background: var(--accent-bg); }
.toc-row a[aria-current="page"] { background: var(--accent-bg); color: var(--accent); font-weight: 700; }
.toc-row a.untranslated { color: var(--fg-muted); }
.toc-row a.untranslated::after { content: "EN"; margin-left: 6px; font-size: 10px; padding: 0 4px; border: 1px solid var(--border); border-radius: 3px; }
.toc-twisty {
  flex: 0 0 20px; height: 28px; border: 0; background: none; cursor: pointer; color: var(--fg-muted);
}
.toc-twisty::before { content: "▸"; display: inline-block; transition: transform .15s; }
.toc li.expanded > .toc-row .toc-twisty::before { transform: rotate(90deg); }
.toc-row:not(:has(.toc-twisty)) a { margin-left: 20px; }
.toc.filtering li { display: none; }
.toc.filtering li.match, .toc.filtering li.match-parent { display: block; }
.toc.filtering li.match-parent > ul { display: block; }

/* 本文 */
.breadcrumbs { font-size: 13px; color: var(--fg-muted); min-height: 1em; }
.breadcrumbs a { color: var(--fg-muted); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs a + a::before { content: "›"; margin: 0 8px; color: var(--fg-muted); }
.notice {
  margin: 12px 0 20px; padding: 8px 12px; font-size: 12.5px; line-height: 1.6;
  color: var(--fg-muted); background: var(--bg-sidebar); border-radius: 4px;
}
.untranslated { color: var(--important); font-weight: 600; }
.topic h1, .topic h2.title, .topic h3.title, .topic h4.title, .topic h5.title, .topic h6.title { line-height: 1.4; }
/* Paligo は階層に応じて h2〜h6 を使うため、見た目は見出しの階層（section の入れ子）で決める */
.topic .titlepage .title :is(h1, h2, h3, h4, h5, h6) { font-size: inherit; margin: 0; }
.topic > section > .titlepage .title { font-size: 26px; font-weight: 700; margin: 0 0 16px; }
.topic section section > .titlepage .title { font-size: 19px; font-weight: 700; margin: 32px 0 8px; }
.topic section section section > .titlepage .title { font-size: 16px; margin: 24px 0 4px; }
/* 本文中の小見出し（Paligo の bridgehead） */
.topic .bridgehead { font-size: 17px; font-weight: 700; margin: 28px 0 8px; line-height: 1.4; }
.topic img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 4px; }
.topic .mediaobject { margin: 12px 0; }
.topic code, .topic pre { font-family: Consolas, "Courier New", monospace; font-size: 13.5px; }
.topic pre { background: var(--bg-sidebar); padding: 12px; border-radius: 4px; overflow-x: auto; }
.topic table { border-collapse: collapse; margin: 12px 0; display: block; overflow-x: auto; }
.topic th, .topic td { border: 1px solid var(--border); padding: 6px 10px; vertical-align: top; }
.topic th { background: var(--bg-sidebar); }
.topic ol.procedure > li { margin: 6px 0; }

/* 注記 */
.topic .note, .topic .tip, .topic .important, .topic .warning, .topic .caution {
  margin: 16px 0; padding: 10px 16px; border-left: 4px solid var(--note);
  background: var(--bg-sidebar); border-radius: 0 4px 4px 0;
}
.topic .tip { border-color: var(--tip); }
.topic .important, .topic .caution { border-color: var(--important); }
.topic .warning { border-color: var(--warning); }
.topic .note > h3.title, .topic .tip > h3.title, .topic .important > h3.title,
.topic .warning > h3.title, .topic .caution > h3.title { font-size: 14px; margin: 0 0 4px; }
.topic .note > h3.title { color: var(--note); }
.topic .tip > h3.title { color: var(--tip); }
.topic .important > h3.title, .topic .caution > h3.title { color: var(--important); }
.topic .warning > h3.title { color: var(--warning); }
.topic .note p:last-child, .topic .tip p:last-child, .topic .important p:last-child,
.topic .warning p:last-child, .topic .caution p:last-child { margin-bottom: 0; }

/* 前後リンク・フッター */
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 40px; }
.pager a {
  display: flex; flex-direction: column; max-width: 48%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 6px; text-decoration: none;
}
.pager a:hover { border-color: var(--accent); }
.pager a.next { margin-left: auto; text-align: right; }
.pager small { color: var(--fg-muted); }
.footer { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--fg-muted); }
.footer p { margin: 2px 0; overflow-wrap: anywhere; }

/* ポータル（サイト一覧） */
.portal-main { max-width: 880px; margin: 0 auto; padding: 32px 16px; }
.site-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.site-card {
  display: flex; flex-direction: column; gap: 4px; padding: 20px;
  border: 1px solid var(--border); border-radius: 8px; text-decoration: none; color: var(--fg);
}
.site-card:hover { border-color: var(--accent); }
.site-card-title { font-weight: 700; font-size: 17px; }
.site-card-meta { color: var(--fg-muted); font-size: 13px; }

/* スマートフォン */
@media (max-width: 860px) {
  .toc-toggle { display: block; }
  .site-name { display: none; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); z-index: 10;
    width: min(88vw, var(--sidebar-w)); transform: translateX(-100%); transition: transform .2s;
    box-shadow: 2px 0 12px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: none; }
  .content { padding: 16px 16px 40px; }
  .topic > section > .titlepage .title { font-size: 22px; }
}
