/* Course website styles. No external fonts or resources; light and dark follow the system. */
:root {
  --bg: #ffffff;
  --fg: #1b2a35;
  --muted: #5a6b78;
  --accent: #176b82;
  --accent-soft: #e4f0f4;
  --line: #d9e4ea;
  --soft: #f4f8fa;
  --code-bg: #eef3f6;
  --mark: #ffe9a8;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10171c;
    --fg: #dbe5eb;
    --muted: #9db0bd;
    --accent: #6cc0d8;
    --accent-soft: #15303a;
    --line: #26353f;
    --soft: #151f26;
    --code-bg: #19252d;
    --mark: #5c4d16;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 4.5rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.85 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei",
    "Heiti TC", "Segoe UI", sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.skip { position: absolute; left: -999px; top: 0; z-index: 10; padding: .5rem 1rem; background: var(--accent); color: #fff; }
.skip:focus { left: 1rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.25rem;
  padding: .6rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--fg); font-size: 1.05rem; font-weight: 700; text-decoration: none; }
.toplinks { display: flex; flex-wrap: wrap; gap: .2rem 1rem; font-size: .95rem; }
.toplinks a { color: var(--muted); text-decoration: none; }
.toplinks a:hover { color: var(--accent); }
.toplinks .jump { display: none; }
.search { margin-left: auto; }
.search input {
  width: 13rem; max-width: 100%; padding: .35rem .75rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--soft); color: var(--fg);
  font: inherit; font-size: .9rem;
}

.layout {
  display: grid; grid-template-columns: 16.5rem minmax(0, 1fr); gap: 3rem;
  max-width: 78rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem;
}
main { grid-column: 2; grid-row: 1; min-width: 0; max-width: 46rem; }
.sidebar {
  grid-column: 1; grid-row: 1; align-self: start;
  position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow-y: auto;
  padding-right: .5rem; font-size: .9rem; line-height: 1.5;
}
.sidebar h2 { margin: 1.2rem 0 .4rem; color: var(--muted); font-size: .8rem; letter-spacing: .08em; border: 0; padding: 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0; }
.sidebar li a { display: block; padding: .28rem .6rem; border-radius: 6px; color: var(--fg); text-decoration: none; }
.sidebar li a:hover { background: var(--soft); }
.sidebar li a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

h1 { margin: .4rem 0 1rem; font-size: 1.85rem; line-height: 1.4; }
h2 { margin: 2.4rem 0 .8rem; padding-top: .5rem; border-top: 1px solid var(--line); font-size: 1.35rem; line-height: 1.45; }
h3 { margin: 1.8rem 0 .6rem; font-size: 1.1rem; }
p, ul, ol { margin: 0 0 1rem; }
li { margin: .25rem 0; }
/* Long URLs and IPv6 addresses must wrap instead of widening the page on phones. */
main p, main li, main td, main th, figcaption { overflow-wrap: anywhere; }
.lead { color: var(--muted); font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.notice { padding: .75rem 1rem; border-left: 4px solid var(--accent); border-radius: 6px; background: var(--soft); }

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: .9em; }
:not(pre) > code { padding: .08em .35em; border-radius: 4px; background: var(--code-bg); overflow-wrap: anywhere; }
pre {
  position: relative; overflow-x: auto; margin: 0 0 1.2rem; padding: .9rem 1rem;
  border-radius: 8px; background: var(--code-bg); font-size: .9rem; line-height: 1.55;
}
.copy {
  position: absolute; top: .4rem; right: .4rem; padding: .1rem .5rem;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--muted);
  font: inherit; font-size: .75rem; cursor: pointer;
}

.table-wrap { overflow-x: auto; margin: 1.2rem 0 1.4rem; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; line-height: 1.6; }
th, td { padding: .55rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { background: var(--soft); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }

figure { margin: 1.6rem 0; }
figure img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
figcaption { margin-top: .4rem; color: var(--muted); font-size: .9rem; }

.page-toc { margin: 0 0 1.6rem; padding: .8rem 1.2rem; border-radius: 8px; background: var(--soft); font-size: .93rem; }
.page-toc p { margin: 0 0 .3rem; font-weight: 600; }
.page-toc ol { margin: 0; padding-left: 1.2rem; }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.pager a { max-width: 48%; text-decoration: none; }
.pager .next { margin-left: auto; text-align: right; }

.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1.2rem 0 1.6rem; }
.button { display: inline-block; padding: .5rem 1.1rem; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; }
.button.ghost { border: 1px solid var(--accent); background: transparent; color: var(--accent); }
@media (prefers-color-scheme: dark) { .button { color: #0c1418; } .button.ghost { color: var(--accent); } }

/* Home page: one centred column without the sidebar, since it lists every page itself. */
.home .layout { grid-template-columns: minmax(0, 1fr); max-width: 54rem; }
.home main { grid-column: 1; max-width: none; }
.hero { padding: 1.2rem 0 .4rem; }
.hero h1 { margin: 0 0 .6rem; font-size: 2.1rem; text-wrap: balance; }
.hero .lead { max-width: 36rem; }
.toc { list-style: none; margin: 0 0 1rem; padding: 0; columns: 2 20rem; column-gap: 1.5rem; }
.toc li { margin: 0; break-inside: avoid; }
.toc a { display: flex; gap: .7rem; padding: .35rem .5rem; border-radius: 6px; color: var(--fg); line-height: 1.55; text-decoration: none; }
.toc a:hover { background: var(--soft); color: var(--accent); }
.toc .num { flex: none; width: 2.3rem; color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.files { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .75rem; margin: 0 0 1rem; padding: 0; list-style: none; }
.files li { margin: 0; }
.files a { display: block; height: 100%; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 8px; color: var(--fg); line-height: 1.5; text-decoration: none; }
.files a:hover { border-color: var(--accent); }
.files strong { display: block; color: var(--accent); }
.files span { color: var(--muted); font-size: .85rem; }

.search-page { display: flex; gap: .5rem; margin-bottom: 1rem; }
.search-page input { flex: 1; min-width: 0; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); color: var(--fg); font: inherit; }
.search-page button { padding: .5rem 1rem; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font: inherit; cursor: pointer; }
.results { padding-left: 1.2rem; }
.results li { margin-bottom: 1rem; }
.results p { margin: .2rem 0 0; color: var(--muted); font-size: .92rem; }
mark { border-radius: 2px; background: var(--mark); color: inherit; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  main { grid-column: 1; }
  .sidebar { grid-column: 1; grid-row: 2; position: static; max-height: none; padding-top: .5rem; border-top: 1px solid var(--line); }
  .toplinks .jump { display: inline; }
}
@media (max-width: 600px) {
  body { font-size: 15.5px; }
  .topbar { position: static; padding: .6rem 1rem; }
  .search { width: 100%; margin-left: 0; }
  .search input { width: 100%; }
  .layout { padding: 1rem 1rem 2.5rem; }
  h1 { font-size: 1.55rem; }
  .hero h1 { font-size: 1.7rem; }
}
@media print {
  .topbar, .sidebar, .pager, .copy, .skip { display: none !important; }
  .layout { display: block; padding: 0; }
  main { max-width: none; }
}
