:root {
  --content-max-width: 780px;
  --book-bg: #f7f8fb;
  --panel-bg: #ffffff;
  --panel-border: #d8e1ea;
  --book-sidebar-bg: #f2f6fa;
  --sidebar-border: #d7e0ea;
  --text-strong: #101820;
  --text-base: #1f2937;
  --text-muted: #5b6977;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: #d8eefb;
  --accent-underline: rgba(3, 105, 161, 0.28);
  --accent-outline: rgba(2, 132, 199, 0.42);
  --accent-hover-bg: rgba(2, 132, 199, 0.08);
  --accent-active-bg: rgba(2, 132, 199, 0.12);
  --accent-code-bg: rgba(2, 132, 199, 0.07);
  --accent-code-border: rgba(2, 132, 199, 0.12);
  --code-bg: #f3f6fa;
  --code-border: #e2e8f0;
  --blockquote-bg: #f6fbff;
  --table-border: #d8e1ea;
  --table-header-bg: #eef6fb;
  --table-row-alt: #fbfdff;
  --surface-alt: #f8fbfe;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

/*
 * 暗色テーマ（coal / navy / ayu）では、独自パレットを使わず
 * mdBook 標準のテーマ変数に追従させる。これにより明色固定で
 * 表示が壊れるのを避ける。標準変数が無い場合に備えてフォールバックを置く。
 */
.coal,
.navy,
.ayu {
  --book-bg: var(--bg);
  --panel-bg: var(--bg);
  --panel-border: var(--table-border-color, rgba(255, 255, 255, 0.12));
  --book-sidebar-bg: var(--sidebar-bg);
  --sidebar-border: var(--table-border-color, rgba(255, 255, 255, 0.12));
  --text-strong: var(--fg);
  --text-base: var(--fg);
  --text-muted: var(--sidebar-non-existant, rgba(255, 255, 255, 0.55));
  --accent: var(--links);
  --accent-strong: var(--links);
  --accent-soft: rgba(255, 255, 255, 0.08);
  --accent-underline: rgba(255, 255, 255, 0.28);
  --accent-outline: rgba(255, 255, 255, 0.42);
  --accent-hover-bg: rgba(255, 255, 255, 0.08);
  --accent-active-bg: rgba(255, 255, 255, 0.12);
  --accent-code-bg: rgba(255, 255, 255, 0.08);
  --accent-code-border: rgba(255, 255, 255, 0.16);
  --code-bg: rgba(255, 255, 255, 0.1);
  --code-border: var(--table-border-color, rgba(255, 255, 255, 0.16));
  --blockquote-bg: var(--quote-bg, rgba(255, 255, 255, 0.04));
  --table-border: var(--table-border-color, rgba(255, 255, 255, 0.12));
  --table-header-bg: rgba(255, 255, 255, 0.08);
  --table-row-alt: rgba(255, 255, 255, 0.03);
  --surface-alt: rgba(255, 255, 255, 0.04);
  --shadow: none;
}

html {
  background: var(--book-bg);
  color: var(--text-base);
}

body {
  background: var(--book-bg);
  color: var(--text-base);
}

a {
  color: var(--accent-strong);
  text-decoration-color: var(--accent-underline);
  text-underline-offset: 0.16em;
}

a:hover {
  color: var(--accent);
}

a:focus-visible,
button:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent-outline);
  outline-offset: 3px;
}

#sidebar {
  background: var(--book-sidebar-bg);
  border-inline-end: 1px solid var(--sidebar-border);
}

.sidebar-scrollbox {
  padding: 0.95rem 0.85rem 1.5rem;
}

.sidebar .menu-title {
  color: var(--text-strong);
  padding: 0.9rem 0.75rem 1rem;
  margin: 0 0 0.75rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar a {
  color: var(--text-base);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  margin: 0.08rem 0;
}

.sidebar a:hover {
  background: var(--accent-hover-bg);
  color: var(--accent-strong);
}

.sidebar .active {
  background: var(--accent-active-bg);
  color: var(--accent-strong) !important;
  font-weight: 700;
}

.sidebar .chapter {
  margin: 0.25rem 0 0.45rem;
}

.sidebar .chapter > .chapter-item {
  margin: 0.18rem 0;
}

.sidebar .chapter > .chapter-item > a {
  font-weight: 600;
}

.sidebar .chapter-item .chapter-item {
  margin-left: 0.4rem;
}

.sidebar-resize-handle {
  opacity: 0.55;
}

.sidebar-resize-indicator {
  background: var(--sidebar-border);
}

.page-wrapper {
  background: var(--book-bg);
}

.page {
  background: transparent;
}

.content {
  color: var(--text-base);
}

.content strong {
  color: var(--text-strong);
}

.content blockquote {
  border-inline-start: 4px solid var(--accent);
  background: var(--blockquote-bg);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.content table th,
.content table td {
  padding: 0.72em 0.9em;
  border-color: var(--table-border);
  vertical-align: top;
  line-height: 1.65;
}

.content table td {
  word-break: normal;
  overflow-wrap: anywhere;
}

.content table thead th {
  background: var(--table-header-bg);
  color: var(--text-strong);
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  word-break: keep-all;
  border-bottom-width: 2px;
}

.content .table-wrapper {
  margin: 1.3em 0 1.7em;
  overflow-x: auto;
}

.content table {
  width: max-content;
  min-width: 100%;
  max-width: none;
  margin: 0;
  font-size: 0.95em;
  border: 1px solid var(--table-border);
  border-radius: 12px;
  background: var(--panel-bg);
}

.content table tbody tr:nth-child(even) {
  background: var(--table-row-alt);
}

.content :not(pre) > code {
  background: var(--accent-code-bg);
  border: 1px solid var(--accent-code-border);
}

.content pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/*
 * runnable な Rust ブロックは <pre><pre class="playground"> と入れ子になる。
 * パネル装飾は外側の pre だけに効かせ、内側はリセットして二重枠を防ぐ。
 */
.content pre pre {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  margin: 0;
  padding: 0;
}

.content img {
  border-radius: 14px;
}

.content details {
  margin: 1.2em 0 1.5em;
  padding: 0.9em 1em;
  border: 1px solid var(--table-border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.content summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text-strong);
}

.content details > :not(summary) {
  margin-top: 0.8em;
}

.content figure {
  margin: 1.5em 0 2em;
}

.content figure img {
  display: block;
  max-width: 100%;
}

.content figcaption {
  margin-top: 0.65em;
  font-size: 0.92em;
  line-height: 1.7;
  color: var(--text-muted);
}

.nav-wrapper,
.nav-wide-wrapper {
  margin-top: 2.2rem;
}

.nav-chapters {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.nav-chapters:hover {
  background: var(--accent-hover-bg);
}

.nav-wrapper .nav-chapters,
.nav-wide-wrapper .nav-chapters {
  color: var(--text-strong);
}
