:root {
  --bg: #f4f3f0;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --text: #23241f;
  --text-muted: #6b6b63;
  --border: #e6e4de;
  --accent: #b5502f;
  --accent-soft: #fbe9e2;
  --accent-contrast: #ffffff;
  --code-bg: #f1efe9;
  --shadow: 0 1px 2px rgba(30, 25, 15, 0.04), 0 8px 24px rgba(30, 25, 15, 0.06);
  --radius: 14px;
  --sidebar-w: 250px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1f2023;
    --surface-2: #232427;
    --text: #eceae4;
    --text-muted: #9a988f;
    --border: #313236;
    --accent: #e08a63;
    --accent-soft: #3a2a22;
    --accent-contrast: #1a1204;
    --code-bg: #26272a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* 安全策: 長いURL・表など、内側の要素がはみ出してもページ全体が横スクロールしないようにする
   (実際にモバイルで表がはみ出し、サイドバー・トップバーごと画面外にずれる不具合が発生した) */
html, body { overflow-x: hidden; max-width: 100%; }

body {
  margin: 0;
  font-family: "M PLUS 1 Variable", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  font-optical-sizing: auto;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

.icon {
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
  stroke-width: 2;
  vertical-align: -0.2em;
}

/* ---------- トップバー(モバイルのみ表示) ---------- */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.menu-btn:active { background: var(--accent-soft); }
.topbar-title {
  font-weight: 700;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 35;
}
.scrim.visible { display: block; }

/* ---------- レイアウト ---------- */
.layout {
  display: flex;
  align-items: flex-start;
  max-width: 1180px;
  margin: 0 auto;
}

.sidebar {
  flex: 0 0 var(--sidebar-w);
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.02rem;
  padding: 6px 10px 20px;
  color: var(--text);
}
.brand-icon { color: var(--accent); width: 1.4em; height: 1.4em; }

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.nav-link.active .icon { color: var(--accent); }

.sidebar-footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.sidebar-footer a:hover { background: var(--surface-2); color: var(--text); }

/* ---------- コンテンツ ---------- */
.content {
  flex: 1;
  min-width: 0;
  margin: 22px 22px 80px 0;
  padding: 40px 48px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.content > h1:first-child { margin-top: 0; }
.content h1 { font-size: 1.55rem; letter-spacing: -0.01em; }
.content h2 {
  font-size: 1.2rem;
  margin-top: 2.4em;
  padding-top: 1.1em;
  border-top: 1px solid var(--border);
}
.content h3 { font-size: 1.02rem; color: var(--text-muted); }
.content p, .content li { font-size: 0.98rem; }

.content a {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  overflow-wrap: anywhere; /* 長いURLでもリンク単体で折り返し、ページ幅を広げないようにする */
}

/* 表は横に長くなりがち(URL列など)なので、表だけが独立してスクロールするようにし、
   ページ全体が横スクロールしてサイドバー・トップバーごとずれる事態を防ぐ */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.2em 0;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.content table {
  border-collapse: collapse;
  width: 100%;
  min-width: max-content;
  margin: 0;
  font-size: 0.9rem;
}
.content th, .content td {
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
}
.content tr:last-child td { border-bottom: none; }
.content th { background: var(--surface-2); font-weight: 700; }

.content code {
  background: var(--code-bg);
  padding: 0.15em 0.45em;
  border-radius: 5px;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}

.content pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--code-bg);
  padding: 12px 14px;
  border-radius: 10px;
}
.content pre code { padding: 0; background: none; }

.content blockquote {
  margin: 1.2em 0;
  padding: 0.7em 1.1em;
  border-radius: 0 10px 10px 0;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.content hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

/* Markdownのチェックリスト（GFM task list） */
.content ul li:has(input[type="checkbox"]) {
  list-style: none;
  margin-left: -1.5em;
  padding: 5px 8px;
  border-radius: 8px;
}
.content ul li:has(input[type="checkbox"]):hover { background: var(--surface-2); }
.content input[type="checkbox"] {
  margin-right: 0.55em;
  width: 1.15em;
  height: 1.15em;
  accent-color: var(--accent);
  vertical-align: middle;
}
/* チェック済み項目の文字を薄くする/取り消し線を引く表現は採用しない。
   このサイトの02・03のような短い買い物リストなら「完了した項目を目立たなくする」目的で
   有効だが、00-hazard-check.mdのような1項目が長文の確認事項(重要な調査結果そのもの)を含む
   場合、内容自体が誤りであるかのように見えてしまう不具合が実際に発生した。
   チェック済みかどうかは、チェックボックス自体の色(accent-color、上記)だけで示す。 */

.file-list { list-style: none; padding: 0; }
.file-list li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
}
.file-list li a:hover { background: var(--surface-2); }

/* ---------- モバイル ---------- */
@media (max-width: 860px) {
  .topbar { display: flex; }

  .layout { display: block; max-width: none; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    width: min(80vw, 300px);
    background: var(--surface);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 40;
  }
  .sidebar.open { transform: translateX(0); }

  .content {
    margin: 14px 14px 60px;
    padding: 22px 18px;
  }
}
