:root {
  --bg: #ffffff;
  --bg-soft: #f5f7fa;
  --text: #1c2430;
  --muted: #5d6878;
  --line: #e2e7ee;
  --accent: #0b63b6;
  --accent-soft: #e8f1fb;
  --note: #fff8e6;
  --note-line: #f0c75e;
  --radius: 10px;
  --sidebar: 280px;
  --icon-filter: none;
  --logo-filter: none;
  color-scheme: light;
}
/* Dark: follows the OS, unless the page sets data-theme (e.g. a host's theme toggle) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --bg-soft: #1a2029;
    --text: #e4e9f0;
    --muted: #9aa6b6;
    --line: #2a323e;
    --accent: #6cb2f5;
    --accent-soft: #172a3f;
    --note: #2a2414;
    --note-line: #8a6d1f;
    --icon-filter: invert(1);  /* black glyph icons stay visible */
    --logo-filter: invert(1) hue-rotate(180deg) brightness(1.15);  /* slate logo → light, same hue */
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c;
  --bg-soft: #1a2029;
  --text: #e4e9f0;
  --muted: #9aa6b6;
  --line: #2a323e;
  --accent: #6cb2f5;
  --accent-soft: #172a3f;
  --note: #2a2414;
  --note-line: #8a6d1f;
  --icon-filter: invert(1);  /* black glyph icons stay visible */
  --logo-filter: invert(1) hue-rotate(180deg) brightness(1.15);  /* slate logo → light, same hue */
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }

/* Top bar */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  color: var(--text); font-weight: 650; text-decoration: none; letter-spacing: -0.01em;
}
.brand .logo {
  height: 22px; width: auto; flex: none;
  border: 0; border-radius: 0; filter: var(--logo-filter);
}
.brand span { padding-left: 12px; border-left: 1px solid var(--line); }
.platform {
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 2px 10px; border-radius: 999px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  max-width: 1200px; margin: 0 auto;
}
main { padding: 40px 48px 64px; min-width: 0; }
article { max-width: 72ch; }

/* Sidebar */
.sidebar {
  position: sticky; top: 57px; align-self: start;
  max-height: calc(100vh - 57px); overflow-y: auto;
  padding: 28px 12px 40px 24px;
  border-right: 1px solid var(--line);
  font-size: 15px;
}
.sidebar summary {
  list-style: none; cursor: default;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 8px;
}
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar a.home-link {
  display: inline-block; margin: 0 0 18px; padding: 4px 10px 4px 8px;
  color: var(--muted); font-size: 14px; font-weight: 550;
}
.sidebar a.home-link::before { content: "← "; }
.sidebar a.home-link:hover { color: var(--accent); }
.sidebar ol { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: block; padding: 5px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none; line-height: 1.4;
}
.sidebar a:hover { background: var(--bg-soft); }
.sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Content */
h1 { font-size: 2.1rem; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 24px; }
h2 { font-size: 1.45rem; line-height: 1.3; margin: 40px 0 12px; }
h3 { font-size: 1.15rem; line-height: 1.35; margin: 32px 0 8px; }
h2, h3 { scroll-margin-top: 80px; }
p, ul, ol { margin: 0 0 16px; }
li { margin-bottom: 6px; }
li > ul, li > ol { margin-top: 6px; }
article ol > li::marker { color: var(--muted); font-weight: 600; }
strong { font-weight: 650; }
code {
  font: 0.88em/1.4 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  background: var(--bg-soft); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px;
  overflow-wrap: anywhere;
}
img {
  max-width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
}
img.icon { height: 1.3em; width: auto; vertical-align: -0.3em; border: 0; border-radius: 0; filter: var(--icon-filter); }
p.note {
  background: var(--note); border-left: 4px solid var(--note-line);
  padding: 12px 16px; border-radius: 0 var(--radius) var(--radius) 0;
}
/* Tables: ruled rows, left-aligned headers, scroll sideways when too wide */
article table {
  display: block; max-width: 100%; overflow-x: auto;
  border-collapse: collapse; margin: 0 0 20px; font-size: 0.94em; line-height: 1.45;
}
article th, article td { padding: 8px 14px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
article th { text-align: left; font-weight: 650; border-bottom-width: 2px; }
article th:last-child, article td:last-child { padding-right: 0; }
article tr:last-child td { border-bottom: 0; }
.brand .kind { font-style: normal; }

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

/* Previous / next */
.pager {
  max-width: 72ch; margin-top: 56px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.pager a {
  display: block; padding: 14px 18px;
  border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--text); font-weight: 600; line-height: 1.4;
}
.pager a:hover { border-color: var(--accent); }
.pager span { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 2px; }
.pager .next { grid-column: 2; text-align: right; }
.edit { display: inline-block; margin-top: 24px; font-size: 14px; color: var(--muted); }

/* Site footer: steganos.com, legal notice, privacy */
footer.site {
  max-width: 72ch; margin-top: 48px; padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 6px 22px;
  font-size: 14px; color: var(--muted);
}
footer.site a { color: var(--muted); text-decoration: none; }
footer.site a:hover { color: var(--accent); text-decoration: underline; }
.home footer.site { max-width: none; }

/* Language switch */
.langs { display: flex; gap: 4px; margin-left: auto; font-size: 14px; }
.langs a {
  padding: 4px 10px; border-radius: 6px;
  color: var(--muted); text-decoration: none; font-weight: 550;
}
.langs a:hover { color: var(--text); background: var(--bg-soft); }
.langs a[aria-current] { color: var(--accent); background: var(--accent-soft); }
.langs .short { display: none; }

/* Home */
.home { max-width: 720px; margin: 0 auto; padding: 56px 24px; }
.books { list-style: none; padding: 0; display: grid; gap: 12px; }
.books li {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius);
}
.books strong { display: block; }
.books span { color: var(--muted); font-size: 15px; }
.books .langs { margin-left: 0; }
.books .langs a { border: 1px solid var(--line); color: var(--accent); }

/* Narrow screens: the chapter list folds above the content */
@media (max-width: 860px) {
  .top { padding: 12px 16px; }
  .brand { font-size: 15px; gap: 10px; }
  .brand .logo { height: 17px; }
  .brand span { padding-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand .kind { display: none; }
  .top .platform { display: none; }
  .top .langs .long { display: none; }
  .top .langs .short { display: inline; }
  .layout { display: block; }
  .sidebar {
    position: static; max-height: none; overflow: visible;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 12px 16px;
  }
  .sidebar a.home-link { margin: 0 0 4px -10px; }
  .sidebar summary { cursor: pointer; margin: 0; padding: 6px 0; }
  .sidebar summary::after { content: " ▾"; }
  .sidebar details[open] summary { margin-bottom: 8px; }
  main { padding: 28px 16px 48px; }
  h1 { font-size: 1.7rem; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
}
