/* Mabato User Guide: one shared stylesheet, no web fonts, no scripts. */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #f3f5f8;
  --fg: #1a202c;
  --muted: #4a5568;
  --link: #1d4ed8;
  --border: #6b7280;
  --focus: #1d4ed8;
  --tip: #e6f4ea;
  --warn: #fdf2e0;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --surface: #1f2937;
    --fg: #f3f4f6;
    --muted: #cbd5e1;
    --link: #93c5fd;
    --border: #9ca3af;
    --focus: #93c5fd;
    --tip: #17301f;
    --warn: #3a2a10;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.6 var(--font);
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) minmax(0, 1fr);
  grid-template-areas: "head head" "nav main" "foot foot";
  min-height: 100vh;
  grid-template-rows: auto 1fr auto;
}

.skip {
  position: absolute;
  left: 0.5rem;
  top: -4rem;
  background: var(--surface);
  color: var(--fg);
  border: 2px solid var(--focus);
  padding: 0.5rem 0.75rem;
  z-index: 10;
}
.skip:focus { top: 0.5rem; }

.site-header {
  grid-area: head;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}
.site-header a { font-weight: 700; font-size: 1.15rem; color: var(--fg); text-decoration: none; }
.site-header a:hover { text-decoration: underline; }

.chapters {
  grid-area: nav;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.chapters ol { list-style: none; margin: 0; padding: 0; }
.chapters li { margin: 0; }
.chapters a {
  display: block;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  color: var(--link);
  text-decoration: none;
  overflow-wrap: anywhere;
}
.chapters a:hover { text-decoration: underline; }
.chapters a[aria-current="page"] { background: var(--surface); color: var(--fg); font-weight: 700; }

main {
  grid-area: main;
  min-width: 0;
  padding: 1rem 1.5rem 2rem;
}
main > * { max-width: 70ch; }
main > figure, main > .table-scroll { max-width: 100%; }
main:focus { outline: none; }

h1, h2, h3 { line-height: 1.25; overflow-wrap: anywhere; }
h1 { font-size: 2rem; margin-top: 0.5rem; }
h2 { font-size: 1.5rem; margin-top: 2rem; scroll-margin-top: 1rem; }
h3 { font-size: 1.2rem; }

a { color: var(--link); text-underline-offset: 0.15em; }
a:focus-visible, summary:focus-visible, .scroll:focus-visible, .table-scroll:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

p, ul, ol, dl { overflow-wrap: break-word; }
.muted { color: var(--muted); }

figure { margin: 1.25rem 0; }
figure img, picture, picture img, img { max-width: 100%; height: auto; }
figure img { border: 1px solid var(--border); border-radius: 6px; display: block; }
figcaption { color: var(--muted); font-size: 0.9rem; margin-top: 0.35rem; }

.table-scroll, .scroll { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; }
th { background: var(--surface); }

aside { border-left: 4px solid var(--border); border-radius: 4px; padding: 0.6rem 1rem; margin: 1.25rem 0; background: var(--surface); }
aside.tip { background: var(--tip); }
aside.warning { background: var(--warn); }
aside > :first-child { margin-top: 0; }
aside > :last-child { margin-bottom: 0; }

code, kbd, pre { font-family: var(--mono); font-size: 0.9em; }
code, kbd { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0.05em 0.35em; overflow-wrap: anywhere; }
kbd { border-bottom-width: 2px; }
pre { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem; overflow-x: auto; max-width: 100%; }
pre code { border: 0; padding: 0; background: none; }

.chapter-list { list-style: none; padding: 0; }
.chapter-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.start-box { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 1rem; margin: 1.25rem 0; }

.pager { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.75rem; margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--border); max-width: 70ch; }

.site-footer { grid-area: foot; background: var(--surface); border-top: 1px solid var(--border); padding: 0.75rem 1rem; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 48rem) {
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "head" "nav" "main" "foot";
  }
  .chapters { border-right: 0; border-bottom: 1px solid var(--border); }
  .chapters ol { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; }
  .chapters a { padding: 0.5rem; }
  main { padding: 1rem; }
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .skip, .chapters, .pager, .site-header { display: none; }
  body { display: block; background: #fff; color: #000; }
  main { padding: 0; }
  a { color: inherit; }
}
