/* QuantBible Explained — Apple-HIG-inspired theme.
   Principles used: system type scale (17pt body), semantic colours (light/dark/increased contrast),
   translucent material only on the navigation layer, inset-grouped cards, 44pt touch targets,
   reduced motion + reduced transparency respected, visible keyboard focus. */
:root {
  --bg: #ffffff;
  --panel: #f5f5f7;          /* grouped / inset surface */
  --panel2: #ececf0;
  --ink: #1d1d1f;            /* 16.1:1 on white */
  --muted: #6e6e73;          /* 5.0:1 on white */
  --line: #d2d2d7;
  --brand: #0066cc;          /* 5.6:1 on white — links & primary */
  --brand-soft: #e8f1fc;
  --good: #1d7a3a;  --good-soft: #e9f6ed;
  --warn: #8a5300;  --warn-soft: #fff4e0;
  --bad: #c1272d;   --bad-soft: #fdeceb;
  --idea: #6b3fa0;  --idea-soft: #f3ecfa;
  --code-bg: #efeff2;
  --c1: #0071e3; --c2: #f56300; --c3: #248a3d; --c4: #8944ab; --grid: #d9d9de;
  --nav-bg: rgba(255, 255, 255, .72);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 18px; --radius-s: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-d: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0f; --panel: #1c1c1e; --panel2: #2c2c2e; --ink: #f5f5f7; --muted: #a1a1a6; --line: #38383a;
    --brand: #2997ff; --brand-soft: #0e2a47; --good: #30d158; --good-soft: #0f2a18;
    --warn: #ffb340; --warn-soft: #33260c; --bad: #ff6961; --bad-soft: #351a18;
    --idea: #bf8bff; --idea-soft: #261c3a; --code-bg: #2c2c2e;
    --c1: #0a84ff; --c2: #ff9f0a; --c3: #30d158; --c4: #bf5af2; --grid: #3a3a3c;
    --nav-bg: rgba(13, 13, 15, .72); --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d0f; --panel: #1c1c1e; --panel2: #2c2c2e; --ink: #f5f5f7; --muted: #a1a1a6; --line: #38383a;
  --brand: #2997ff; --brand-soft: #0e2a47; --good: #30d158; --good-soft: #0f2a18;
  --warn: #ffb340; --warn-soft: #33260c; --bad: #ff6961; --bad-soft: #351a18;
  --idea: #bf8bff; --idea-soft: #261c3a; --code-bg: #2c2c2e;
  --c1: #0a84ff; --c2: #ff9f0a; --c3: #30d158; --c4: #bf5af2; --grid: #3a3a3c;
  --nav-bg: rgba(13, 13, 15, .72); --shadow: 0 1px 2px rgba(0,0,0,.4);
}
@media (prefers-contrast: more) { :root { --muted: #4a4a4f; --line: #8e8e93; } }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.6 var(--font);
  letter-spacing: -.011em; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- navigation bar (the one translucent layer) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; min-height: 52px;
  padding: 6px max(16px, env(safe-area-inset-left)); background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--line);
}
@media (prefers-reduced-transparency: reduce) { .topbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; } }
.topbar .brand { font-weight: 600; color: var(--ink); text-decoration: none; letter-spacing: -.02em; font-size: 17px; }
.topbar .brand span { color: var(--brand); }
.topbar .spacer { flex: 1; }
.progress-pill { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.topbar button, .btn {
  font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; color: var(--brand); background: var(--panel);
  border: 0; border-radius: 980px; padding: 8px 16px; min-height: 36px; transition: background .15s, transform .1s;
}
.topbar button:hover, .btn:hover { background: var(--panel2); }
.btn:active, .topbar button:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand); filter: brightness(1.1); }
@media (pointer: coarse) { .topbar button, .btn { min-height: 44px; } }
#menuBtn { display: none; }

/* ---------- layout ---------- */
.layout { display: flex; max-width: 1180px; margin: 0 auto; }
.sidebar {
  width: 280px; flex: none; position: sticky; top: 52px; align-self: flex-start;
  height: calc(100vh - 52px); overflow-y: auto; padding: 14px 12px 40px 16px;
}
.sidebar h4 { margin: 20px 10px 6px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.sidebar a {
  display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; border-radius: 10px; color: var(--ink);
  text-decoration: none; font-size: 15px; line-height: 1.35;
}
.sidebar a:hover { background: var(--panel); }
.sidebar a.current { background: var(--brand); color: #fff; font-weight: 600; }
.sidebar a.current .num, .sidebar a.current .tick { color: #fff; }
.sidebar a .num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 22px; }
.sidebar a .tick { margin-left: auto; color: var(--good); opacity: 0; font-weight: 700; }
.sidebar a.done .tick { opacity: 1; }
main { flex: 1; min-width: 0; padding: 40px 32px 96px; max-width: 800px; }
@media (max-width: 900px) {
  #menuBtn { display: inline-block; }
  .sidebar { position: fixed; left: 0; top: 52px; z-index: 25; background: var(--bg); width: 300px; transform: translateX(-104%); transition: transform .25s ease; border-right: .5px solid var(--line); }
  body.nav-open .sidebar { transform: none; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
  main { padding: 24px max(16px, env(safe-area-inset-left)) 72px; }
}

/* ---------- typography ---------- */
h1 { font: 700 clamp(2.1rem, 5.5vw, 3rem)/1.08 var(--font-d); letter-spacing: -.035em; margin: .15em 0 .3em; text-wrap: balance; }
h2 { font: 700 1.65rem/1.2 var(--font-d); letter-spacing: -.025em; margin: 2.4em 0 .5em; }
h3 { font: 600 1.2rem/1.3 var(--font-d); letter-spacing: -.018em; margin: 1.7em 0 .4em; }
p { margin: .75em 0; }
.kicker { color: var(--brand); font-weight: 600; font-size: 14px; letter-spacing: .01em; }
.lede { font-size: 1.3rem; line-height: 1.4; color: var(--muted); margin-top: .3em; letter-spacing: -.018em; }
.meta { color: var(--muted); font-size: 14px; display: flex; gap: 6px 16px; flex-wrap: wrap; margin: 14px 0 28px; }
a { color: var(--brand); text-underline-offset: 3px; }
ul, ol { padding-left: 1.4em; } li { margin: .35em 0; }
code, .mono { font: .9em ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--code-bg); padding: 2px 6px; border-radius: 6px; }
hr { border: 0; border-top: .5px solid var(--line); margin: 2.4em 0; }
table { border-collapse: separate; border-spacing: 0; width: 100%; margin: 1.2em 0; font-size: 15px; display: block; overflow-x: auto; border: .5px solid var(--line); border-radius: var(--radius-s); }
th, td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: .5px solid var(--line); }
tr:last-child > td, tr:last-child > th { border-bottom: 0; }
th { background: var(--panel); font-weight: 600; }

/* ---------- math ---------- */
.eq {
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", "Times New Roman", serif; font-size: 1.25rem;
  text-align: center; margin: 1.2em 0; padding: 16px 18px; background: var(--panel); border-radius: var(--radius-s);
  overflow-x: auto; line-height: 1.9;
}
.m { font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", "Times New Roman", serif; font-style: italic; white-space: nowrap; }
.m b, .eq b { font-style: normal; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 3px; line-height: 1.25; font-size: .95em; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 5px 1px; }
.frac > span:last-child { padding: 1px 5px 0; }
sub, sup { line-height: 0; }

/* ---------- callouts: tinted, no outline ---------- */
.box { border-radius: var(--radius); padding: 16px 20px; margin: 1.5em 0; }
.box > :first-child { margin-top: 0; } .box > :last-child { margin-bottom: 0; }
.box .t { font-weight: 600; display: block; margin-bottom: 4px; font-size: 15px; }
.idea { background: var(--idea-soft); } .idea .t { color: var(--idea); }
.tip { background: var(--brand-soft); } .tip .t { color: var(--brand); }
.warn { background: var(--warn-soft); } .warn .t { color: var(--warn); }
.good { background: var(--good-soft); } .good .t { color: var(--good); }
.bad { background: var(--bad-soft); } .bad .t { color: var(--bad); }
.note { color: var(--muted); font-size: 15px; }

/* ---------- check-yourself: inset grouped list rows ---------- */
details.check { background: var(--panel); border-radius: var(--radius-s); margin: .6em 0; }
details.check summary { cursor: pointer; padding: 14px 18px; font-weight: 500; list-style: none; display: flex; gap: 10px; }
details.check summary::-webkit-details-marker { display: none; }
details.check summary::before { content: "›"; color: var(--brand); font-weight: 700; transition: transform .15s; display: inline-block; }
details.check[open] summary::before { transform: rotate(90deg); }
details.check > div { padding: 2px 18px 14px; }
.checkhead { margin-top: 2.6em; font: 700 1.3rem/1.2 var(--font-d); letter-spacing: -.02em; }
.steps { counter-reset: s; list-style: none; padding-left: 0; }
.steps > li { counter-increment: s; position: relative; padding-left: 44px; margin: 1em 0; }
.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 1px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 14px;
}

/* ---------- interactive widgets ---------- */
.widget { background: var(--panel); border-radius: var(--radius); padding: 20px 22px; margin: 1.8em 0; }
.widget > .wt { font: 600 1.1rem/1.3 var(--font-d); letter-spacing: -.015em; }
.widget > .wt::before { content: "▸ "; color: var(--brand); }
.widget .sub { color: var(--muted); font-size: 15px; margin: 2px 0 12px; }
.widget canvas { width: 100%; display: block; border-radius: var(--radius-s); background: var(--bg); }
.widget table { background: var(--bg); }
.ctrl { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; margin: 14px 0 4px; font-size: 15px; }
.ctrl label { display: flex; gap: 10px; align-items: center; }
.ctrl input[type=range] { width: 170px; accent-color: var(--brand); height: 28px; }
.ctrl input[type=number], .ctrl select, .ctrl input[type=text] {
  font: inherit; font-size: 15px; width: 92px; padding: 7px 10px; border-radius: 10px; border: .5px solid var(--line); background: var(--bg); color: var(--ink); min-height: 36px;
}
.ctrl select { width: auto; }
.ctrl .val { font-variant-numeric: tabular-nums; min-width: 42px; display: inline-block; color: var(--brand); font-weight: 600; }
.readout { margin-top: 12px; padding: 12px 16px; background: var(--bg); border-radius: var(--radius-s); font-size: 15.5px; }
.readout b { color: var(--brand); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; }

/* ---------- prev/next ---------- */
.pager { display: flex; gap: 12px; margin-top: 2.4em; flex-wrap: wrap; }
.pager a { flex: 1; min-width: 220px; text-decoration: none; color: var(--ink); background: var(--panel); border-radius: var(--radius); padding: 16px 20px; font-weight: 600; transition: background .15s; }
.pager a:hover { background: var(--panel2); }
.pager small { display: block; color: var(--brand); font-weight: 500; font-size: 13px; }
.pager .next { text-align: right; }
.donebar { margin-top: 3em; text-align: center; }

/* ---------- home ---------- */
.hero { padding: 36px 0 12px; text-align: center; }
.hero h1 { font-size: clamp(2.6rem, 8vw, 4.4rem); line-height: 1.03; }
.hero h1 em { font-style: normal; background: linear-gradient(90deg, var(--c1), var(--c4)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .lede { max-width: 640px; margin: .6em auto 0; }
.hero .cta { display: flex; gap: 12px; justify-content: center; margin: 28px 0 8px; flex-wrap: wrap; }
.hero .cta .btn { padding: 12px 24px; font-size: 17px; text-decoration: none; display: inline-block; }
.hero .bar { margin: 18px auto 6px; max-width: 360px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin: 12px 0 30px; }
.card { display: block; text-decoration: none; color: var(--ink); background: var(--panel); border-radius: var(--radius); padding: 18px 20px; position: relative; transition: transform .2s, background .2s; }
.card:hover { background: var(--panel2); transform: translateY(-2px); }
.card .n { color: var(--brand); font-weight: 600; font-size: 13px; }
.card .ti { font-weight: 600; margin: 3px 0 5px; font-size: 17px; line-height: 1.3; letter-spacing: -.015em; }
.card .ds { color: var(--muted); font-size: 14.5px; line-height: 1.45; }
.card .tick { position: absolute; right: 14px; top: 12px; color: var(--good); opacity: 0; font-weight: 700; }
.card.done .tick { opacity: 1; }
.bar { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width .4s; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
