/* bookgen site styles */

/* ---- Theme variables ---- */
:root {
  --bg: #ffffff; --fg: #1a1a2e; --accent: #0f3460;
  --border: #e2e8f0; --code-bg: #f7fafc; --sidebar-bg: #f8fafc;
  --link: #0f3460; --table-stripe: #f7fafc; --table-header: #0f3460;
  --active: #e94560; --shadow: rgba(0,0,0,0.08);
  --hl-keyword: #d73a49; --hl-string: #22863a; --hl-number: #005cc5;
  --hl-title: #6f42c1; --hl-builtin: #e36209;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg: #0f172a; --fg: #e2e8f0; --accent: #60a5fa;
    --border: #334155; --code-bg: #1e293b; --sidebar-bg: #1e293b;
    --link: #60a5fa; --table-stripe: #1e293b; --table-header: #1e40af;
    --active: #f472b6; --shadow: rgba(0,0,0,0.3);
    --hl-keyword: #ff7b72; --hl-string: #a5d6a7; --hl-number: #79b8ff;
    --hl-title: #d2a8ff; --hl-builtin: #ffa657;
  }
}
html[data-theme="dark"] {
  --bg: #0f172a; --fg: #e2e8f0; --accent: #60a5fa;
  --border: #334155; --code-bg: #1e293b; --sidebar-bg: #1e293b;
  --link: #60a5fa; --table-stripe: #1e293b; --table-header: #1e40af;
  --active: #f472b6; --shadow: rgba(0,0,0,0.3);
  --hl-keyword: #ff7b72; --hl-string: #a5d6a7; --hl-number: #79b8ff;
  --hl-title: #d2a8ff; --hl-builtin: #ffa657;
}

/* ---- Reset ---- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", -apple-system, sans-serif;
  background: var(--bg); color: var(--fg);
  line-height: 1.85; font-size: 16px;
}

/* ---- Top bar ---- */
.top-bar {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg); border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem; display: flex; align-items: center; gap: 1rem;
  box-shadow: 0 1px 3px var(--shadow);
}
.top-bar .parent-site { color: var(--muted, var(--fg)); font-size: 0.85rem; text-decoration: none; opacity: 0.7; }
.top-bar .parent-site:hover { opacity: 1; }
.top-bar .parent-sep { opacity: 0.3; font-size: 0.85rem; }
.top-bar .book-title { font-weight: 700; color: var(--accent); font-size: 0.95rem; text-decoration: none; }
.top-bar .chapter-info { font-size: 0.8rem; opacity: 0.6; }
.top-bar-spacer { flex: 1; }
.sidebar-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 4px; padding: 0.3rem 0.6rem; cursor: pointer; color: var(--fg); font-size: 1.1rem; }

/* ---- Layout ---- */
.layout { display: flex; max-width: 1200px; margin: 0 auto; }

/* ---- Sidebar ---- */
.sidebar {
  width: 260px; min-width: 260px; position: sticky; top: 52px; height: calc(100vh - 52px);
  overflow-y: auto; padding: 1.2rem 0.8rem; border-right: 1px solid var(--border);
  background: var(--sidebar-bg); font-size: 0.85rem;
}
.sidebar .toc-title { font-weight: 700; color: var(--accent); margin-bottom: 0.6rem; font-size: 0.9rem; }
.sidebar ul { list-style: none; }
.sidebar li { margin: 0.15rem 0; }
.sidebar .toc-h3 { padding-left: 1rem; }
.sidebar a { color: var(--fg); text-decoration: none; display: block; padding: 0.25rem 0.5rem; border-radius: 4px; transition: all 0.15s; }
.sidebar a:hover { background: var(--border); }
.sidebar a.active { color: var(--active); font-weight: 600; background: color-mix(in srgb, var(--active) 10%, transparent); }

/* ---- Content ---- */
.content { flex: 1; max-width: 800px; padding: 2rem 2.5rem; min-width: 0; }
.content.full-width { max-width: 900px; margin: 0 auto; }

/* ---- Typography ---- */
h1 { font-size: 1.7rem; margin: 2rem 0 1rem; border-bottom: 2px solid var(--accent); padding-bottom: 0.3rem; }
h2 { font-size: 1.35rem; margin: 2rem 0 0.8rem; color: var(--accent); scroll-margin-top: 70px; }
h3 { font-size: 1.15rem; margin: 1.5rem 0 0.6rem; scroll-margin-top: 70px; }
h4 { font-size: 1.02rem; margin: 1.2rem 0 0.5rem; }
p { margin: 0.7rem 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { margin: 0.5rem 0 0.5rem 1.5rem; }
li { margin: 0.2rem 0; }
strong { color: var(--accent); }

/* ---- Code ---- */
code {
  background: var(--code-bg); padding: 0.15rem 0.4rem; border-radius: 3px;
  font-size: 0.88em; font-family: "JetBrains Mono", "Fira Code", monospace;
}
pre { background: var(--code-bg); padding: 1rem; border-radius: 8px; overflow-x: auto; margin: 1rem 0; border: 1px solid var(--border); }
pre code { background: none; padding: 0; }

/* ---- Tables ---- */
.table-wrapper { overflow-x: auto; margin: 1.2rem 0; border-radius: 8px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
th, td { padding: 0.6rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--table-header); color: #fff; font-weight: 600; position: sticky; top: 0; white-space: nowrap; }
tr:nth-child(even) { background: var(--table-stripe); }
tr:hover { background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
td:first-child { font-weight: 500; white-space: nowrap; }

/* ---- Blockquote ---- */
blockquote { border-left: 4px solid var(--accent); margin: 1rem 0; padding: 0.6rem 1.2rem; background: var(--code-bg); border-radius: 0 8px 8px 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* ---- Mermaid / KaTeX ---- */
.mermaid { margin: 1.5rem 0; text-align: center; background: var(--code-bg); padding: 1rem; border-radius: 8px; }
.katex-display { margin: 1rem 0; overflow-x: auto; }

/* ---- Navigation ---- */
.page-nav {
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 0.8rem;
  padding: 1.2rem 0; border-top: 2px solid var(--border); margin-top: 3rem;
}
.page-nav .nav-prev { justify-self: start; }
.page-nav .nav-toc { justify-self: center; }
.page-nav .nav-next { justify-self: end; }
.page-nav a {
  padding: 0.5rem 1.2rem; border-radius: 6px; font-size: 0.85rem; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.page-nav .nav-prev, .page-nav .nav-next { background: var(--accent); color: #fff; text-decoration: none; }
.page-nav .nav-prev:hover, .page-nav .nav-next:hover { opacity: 0.85; text-decoration: none; }
.page-nav .nav-toc { background: var(--code-bg); color: var(--fg); border: 1px solid var(--border); text-decoration: none; }

/* ---- Scroll to top ---- */
.scroll-top {
  display: none; position: fixed; bottom: 2rem; right: 2rem; z-index: 50;
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 1.3rem; cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow); transition: opacity 0.2s;
}
.scroll-top:hover { opacity: 0.8; }

/* ---- Rights footer ---- */
.bookgen-rights-footer {
  max-width: 900px; margin: 3rem auto 0; padding: 1.5rem;
  border-top: 1px solid var(--border); font-size: 0.85rem; color: var(--fg); opacity: 0.6;
}
.bookgen-rights-footer p { margin: 0.3rem 0; line-height: 1.6; }
.bookgen-rights-footer a { color: var(--link); }
.bookgen-rights-note { font-size: 0.8rem; opacity: 0.8; }

/* ---- Skip link ---- */
.skip-link {
  position: absolute; left: -9999px; top: auto;
  width: 1px; height: 1px; overflow: hidden;
}
.skip-link:focus {
  position: fixed; top: 0; left: 0; z-index: 200;
  width: auto; height: auto;
  padding: 0.5rem 1rem; background: var(--accent); color: #fff;
  font-size: 0.9rem; text-decoration: none; border-radius: 0 0 4px 0;
}

/* ---- Breadcrumb ---- */
.breadcrumb {
  max-width: 1200px; margin: 0 auto;
  padding: 0.3rem 1.5rem; font-size: 0.8rem;
}
.breadcrumb ol {
  list-style: none; display: flex; flex-wrap: wrap;
  margin: 0; padding: 0;
}
.breadcrumb li { display: flex; align-items: center; }
.breadcrumb li + li::before {
  content: "/"; margin: 0 0.4rem; opacity: 0.4;
}
.breadcrumb a { color: var(--link); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb [aria-current="page"] { opacity: 0.6; }

/* ---- Theme toggle ---- */
.theme-toggle {
  background: none; border: 1px solid var(--border);
  color: var(--fg); padding: 0.3rem 0.6rem; border-radius: 4px;
  cursor: pointer; font-size: 0.8rem; white-space: nowrap;
}
.theme-toggle::after { content: "🌙 Dark"; }
html[data-theme="dark"] .theme-toggle::after { content: "☀️ Light"; }
.theme-toggle:hover { background: var(--code-bg); }

/* ---- Syntax highlighting ---- */
.hljs { background: transparent; padding: 0; }
.hljs-keyword, .hljs-selector-tag { color: var(--hl-keyword); }
.hljs-string, .hljs-attr { color: var(--hl-string); }
.hljs-number, .hljs-literal { color: var(--hl-number); }
.hljs-title, .hljs-function, .hljs-class { color: var(--hl-title); }
.hljs-built_in, .hljs-type { color: var(--hl-builtin); }
.hljs-comment, .hljs-quote { opacity: 0.55; font-style: italic; }
.hljs-meta { color: var(--hl-title); }
.hljs-deletion { color: var(--hl-keyword); }
.hljs-addition { color: var(--hl-string); }

/* ---- Code copy button ---- */
pre { position: relative; }
.copy-btn {
  position: absolute; top: 0.4rem; right: 0.4rem;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--fg); padding: 0.15rem 0.5rem; border-radius: 4px;
  font-size: 0.7rem; cursor: pointer; opacity: 0;
  transition: opacity 0.15s;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--code-bg); }

/* ---- Reading progress ---- */
.reading-progress {
  position: fixed; top: 0; left: 0; height: 3px; z-index: 150;
  background: var(--accent); width: 0; pointer-events: none;
}

/* ---- Mobile ---- */
@media (max-width: 768px) {
  .sidebar { display: none; position: fixed; top: 52px; left: 0; width: 280px; height: calc(100vh - 52px); z-index: 90; box-shadow: 4px 0 12px var(--shadow); }
  .sidebar.open { display: block; }
  .sidebar-toggle { display: block; }
  .content { padding: 1.2rem 1rem; }
  h1 { font-size: 1.4rem; }
  .page-nav { grid-template-columns: 1fr; gap: 0.5rem; }
  .page-nav .nav-prev, .page-nav .nav-toc, .page-nav .nav-next { justify-self: stretch; }
  .page-nav a { max-width: 100%; }
  .theme-toggle::after { content: "🌙"; }
  html[data-theme="dark"] .theme-toggle::after { content: "☀️"; }
}

/* ---- Callout boxes ---- */
.callout {
  padding: 1rem 1.2rem; margin: 1rem 0; border-radius: 8px;
  border-left: 4px solid var(--accent); background: var(--code-bg);
  font-size: 0.9rem;
}
.callout-warning { border-left-color: #f59e0b; }
.callout-danger { border-left-color: #ef4444; }
.callout-success { border-left-color: #22c55e; }
.callout-title { font-weight: 700; margin-bottom: 0.3rem; }

/* ---- Chart container ---- */
.chart-container { position: relative; margin: 1.5rem 0; max-width: 600px; }
.chart-container canvas { width: 100% !important; }

/* ---- Key term highlight ---- */
.key-term { font-weight: 600; color: var(--accent); border-bottom: 2px solid var(--accent); }

/* ---- Timeline ---- */
.timeline { position: relative; padding-left: 2rem; margin: 1rem 0; }
.timeline::before {
  content: ""; position: absolute; left: 0.5rem; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 1rem; }
.timeline-item::before {
  content: ""; position: absolute; left: -1.7rem; top: 0.4rem;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}

/* ---- Print ---- */
@media print {
  .top-bar, .sidebar, .sidebar-toggle, .theme-toggle,
  .scroll-top, .skip-link, .breadcrumb, .page-nav,
  .copy-btn, .reading-progress { display: none !important; }
  .layout { display: block; }
  .content { max-width: 100%; padding: 0; }
  body { font-size: 12pt; line-height: 1.6; color: #000; background: #fff; }
  a { color: inherit; text-decoration: underline; }
  pre { border: 1px solid #ccc; page-break-inside: avoid; }
  table { page-break-inside: avoid; }
  h1, h2, h3 { page-break-after: avoid; }
}
