/* Shared styles for all pages. Light and dark mode follow the system setting. */

:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #59636e;
  --border: #e3e5e8;
  --accent: #2f6fdb;
  --accent-soft: #eaf1fd;
  --callout-bg: #f4f7fb;
  --code-bg: #f3f4f6;
  --top-bar-height: 52px;
  --toc-width: 290px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --border: #2a2f39;
    --accent: #79a8ff;
    --accent-soft: #1c2840;
    --callout-bg: #161c27;
    --code-bg: #0d1117;
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--top-bar-height) + 12px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

/* ---------- Top bar ---------- */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--top-bar-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.home-link { text-decoration: none; font-weight: 600; white-space: nowrap; }
.top-title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-toggle {
  margin-left: auto;
  display: none;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

/* ---------- Layout: contents on the left, sheet on the right ---------- */

.layout { display: flex; }

.toc {
  position: sticky;
  top: var(--top-bar-height);
  flex: 0 0 var(--toc-width);
  height: calc(100vh - var(--top-bar-height));
  overflow-y: auto;
  padding: 16px 8px 40px 16px;
  border-right: 1px solid var(--border);
  font-size: 14px;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: block;
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--muted);
  text-decoration: none;
}
.toc a:hover { color: var(--text); background: var(--accent-soft); }
.toc a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.toc code { font-size: 12px; background: none; padding: 0; }
.toc-level-1 { margin-top: 14px; font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: 0.04em; }
.toc-level-3 { padding-left: 14px; font-size: 13px; }

.content {
  flex: 1;
  min-width: 0;
  max-width: 920px;
  padding: 24px 32px 120px;
}

/* ---------- Sheet content ---------- */

h1, h2, h3, h4 { line-height: 1.3; }
h1 { font-size: 30px; margin-top: 48px; }
.content > h1:first-child { margin-top: 8px; }
h2 { font-size: 24px; margin-top: 44px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
h3 { font-size: 19px; margin-top: 32px; }
h4 { font-size: 16px; margin-top: 24px; }
h1 a.anchor, h2 a.anchor, h3 a.anchor, h4 a.anchor { color: inherit; text-decoration: none; }

hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }

/* "> **Word**: explanation" blocks become callout cards. */
blockquote {
  margin: 16px 0;
  padding: 10px 16px;
  background: var(--callout-bg);
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
}
blockquote p { margin: 6px 0; }

code {
  font: 0.88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
}
pre {
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
pre code { background: none; padding: 0; font-size: 13.5px; }
pre code.hljs { background: none; padding: 0; }

pre.mermaid {
  background: var(--surface);
  text-align: center;
  font-family: inherit;
}

.table-wrap { overflow-x: auto; margin: 16px 0; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
th { background: var(--accent-soft); }
tr:nth-child(even) td { background: color-mix(in srgb, var(--surface) 60%, var(--bg)); }

li { margin: 3px 0; }
input[type="checkbox"] { margin-right: 6px; }

/* ---------- Back to top button ---------- */

.back-to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; }

/* ---------- Home page ---------- */

.index { max-width: 860px; margin: 0 auto; padding: 48px 16px; }
.index h1 { margin: 0 0 4px; }
.muted { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 28px; }
.card {
  display: block;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h2 { margin: 0 0 8px; font-size: 20px; border: 0; padding: 0; }
.card p { margin: 0; color: var(--muted); font-size: 15px; }

/* ---------- Phone: contents become a drop-down panel ---------- */

@media (max-width: 860px) {
  .toc-toggle { display: block; }
  .toc {
    display: none;
    position: fixed;
    top: var(--top-bar-height);
    left: 0;
    right: 0;
    z-index: 9;
    height: auto;
    max-height: 70vh;
    background: var(--surface);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
  }
  .toc.open { display: block; }
  .content { padding: 16px 16px 100px; }
  h1 { font-size: 26px; }
  h2 { font-size: 21px; }
}

@media print {
  .top-bar, .toc, .back-to-top { display: none; }
  .content { max-width: none; padding: 0; }
}
