/* Fonts are self-hosted so the site works offline. */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url(fonts/bricolage-latin.woff2) format("woff2");
  font-weight: 500 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url(fonts/newsreader-latin.woff2) format("woff2");
  font-weight: 400 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url(fonts/newsreader-italic-latin.woff2) format("woff2");
  font-weight: 400 700; font-style: italic; font-display: swap;
}

:root {
  --bg: #f2f4f7;
  --text: #16202e;
  --muted: #566274;
  --rule: #d3d9e1;
  --line: #a5afbd;
  --code-bg: #e6eaf0;
  --panel: #e9edf2;
  --hl: #ffd84d;
  --hl-ink: #16202e;
  --good: #1e8e5a;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161f;
    --text: #e8ecf2;
    --muted: #9aa6b6;
    --rule: #2a3442;
    --line: #435166;
    --code-bg: #1b2430;
    --panel: #151d28;
    --good: #3ab57f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 19px/1.65 var(--serif);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
main { max-width: 1080px; margin: 0 auto; padding: 8px 18px 96px; outline: none; }
:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar (phone) */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  font-family: var(--display);
}
.brand { flex: 1; font-weight: 800; font-size: 1.1rem; letter-spacing: -.02em; text-decoration: none; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 2px solid var(--text); border-radius: 6px; background: none; color: var(--text); cursor: pointer;
}
.icon-btn[hidden] { display: none; }
.ring {
  --p: 0;
  position: relative; display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  background: conic-gradient(var(--hl) calc(var(--p) * 1%), var(--rule) 0);
  font: 800 .62rem var(--display);
}
.ring::before { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--bg); }
.ring span { position: relative; }

/* buttons: the same style everywhere */
.btn {
  display: block; width: 100%; margin-top: 40px; padding: 15px 18px;
  border: 2px solid var(--text); border-radius: 6px;
  font: 700 1rem var(--display); color: var(--bg); background: var(--text); cursor: pointer;
  text-decoration: none; text-align: center;
}
.btn.secondary { background: none; color: var(--text); }
.btn.auto { display: inline-block; width: auto; margin: 0; padding: 12px 20px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 40px; }
.actions .btn { flex: 1 1 220px; }

/* home and topic pages */
.hero { padding: 40px 0 8px; }
.hero h1 { margin: 0 0 12px; font: 800 clamp(2.2rem, 8vw, 3.4rem)/1.08 var(--display); letter-spacing: -.035em; }
.hero p { margin: 0; max-width: 46ch; color: var(--muted); font-size: 1.15rem; }
.hero .btn.auto { margin-top: 28px; }

.index { margin-top: 48px; border-top: 2px solid var(--text); }
.topic-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; align-items: center;
  padding: 22px 0; border-bottom: 1px solid var(--rule); text-decoration: none; color: inherit;
}
.topic-row h3 { margin: 0; font: 700 1.5rem/1.25 var(--display); letter-spacing: -.02em; }
.topic-row p { grid-column: 1; margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.45; max-width: 52ch; }
.topic-row .pips { grid-column: 2; grid-row: 1 / span 2; }
.pips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; max-width: 150px; }
.pip { width: 13px; height: 13px; border: 2px solid var(--text); border-radius: 2px; }
.pip.on { background: var(--hl); }
.topic-row:hover h3 span, .topic-row:focus-visible h3 span { background: var(--hl); color: var(--hl-ink); padding: 0 .2em; margin: 0 -.2em; }

.list { margin-top: 36px; max-width: 720px; border-top: 2px solid var(--text); }
.lesson-row {
  display: flex; align-items: center; gap: 16px; padding: 16px 0;
  border-bottom: 1px solid var(--rule); text-decoration: none; color: inherit;
}
.lesson-row .num {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px;
  border: 2px solid var(--text); border-radius: 4px; font: 800 .9rem var(--display);
}
.lesson-row.done .num { background: var(--good); border-color: var(--good); color: #fff; }
.lesson-row .t { flex: 1; font: 650 1.1rem/1.3 var(--display); }
.lesson-row .m { display: block; margin-top: 2px; color: var(--muted); font: 400 .9rem var(--serif); }
.lesson-row:hover .t span, .lesson-row:focus-visible .t span { background: var(--hl); color: var(--hl-ink); padding: 0 .2em; margin: 0 -.2em; }

.empty { padding: 36px 0; color: var(--muted); border-top: 2px solid var(--text); }
.footer-note { margin-top: 56px; color: var(--muted); font-size: .9rem; }

/* lesson reading */
.lesson-main { max-width: 720px; }
.crumb { margin: 24px 0 0; color: var(--muted); font: 500 .9rem var(--display); }
.crumb a { text-decoration-color: var(--hl); text-decoration-thickness: .14em; text-underline-offset: .2em; }
article h1 { margin: 10px 0 22px; font: 800 clamp(2rem, 7vw, 3rem)/1.1 var(--display); letter-spacing: -.035em; }
article h2 { margin: 42px 0 10px; font: 700 1.55rem/1.2 var(--display); letter-spacing: -.02em; }
article h3 { margin: 28px 0 6px; font: 700 1.15rem/1.3 var(--display); }
article p, article li { max-width: 62ch; }
article ul, article ol { padding-left: 1.3em; }
article li { margin: 6px 0; }
article a { text-decoration: underline; text-decoration-color: var(--hl); text-decoration-thickness: .16em; text-underline-offset: .2em; }
article code { background: var(--code-bg); padding: .1em .35em; border-radius: 4px; font: .85em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
article pre { background: var(--code-bg); border-radius: 6px; padding: 14px 16px; overflow-x: auto; }
article pre code { background: none; padding: 0; }
article blockquote { margin: 28px 0; padding: 2px 0 2px 20px; border-left: 4px solid var(--text); max-width: 52ch; }
article blockquote p { margin: 0; font-size: 1.3rem; line-height: 1.5; font-style: italic; }

details.check { margin: 20px 0; max-width: 62ch; }
details.check summary { cursor: pointer; list-style: none; font: 650 1.1rem/1.5 var(--display); }
details.check summary::-webkit-details-marker { display: none; }
details.check summary span { background: var(--hl); color: var(--hl-ink); -webkit-box-decoration-break: clone; box-decoration-break: clone; padding: .06em .25em; }
details.check summary::after { content: "Tap to answer"; display: block; margin-top: 6px; color: var(--muted); font: 500 .85rem var(--display); }
details.check[open] summary::after { content: none; }
details.check .answer { margin-top: 12px; padding-left: 16px; border-left: 4px solid var(--text); }

/* sidebar tree: desktop only */
.shell { display: block; }
#tree { display: none; }

@media (min-width: 760px) {
  body { font-size: 20px; }
  main { padding-top: 16px; }
  .hero { padding-top: 56px; }
}

/* desktop-only pieces are hidden by default (phone) */
.docbar, .overview, #rail { display: none; }

@media (min-width: 1040px) {
  body { font-size: 17px; }
  .topbar, .crumb, .index, .hero.phone-only { display: none; }

  .shell {
    display: grid; grid-template-columns: 260px minmax(0, 1fr); max-width: 1560px; min-height: 100vh;
    margin: 0 auto; border-left: 1px solid var(--rule); border-right: 1px solid var(--rule);
  }
  main { max-width: none; margin: 0; padding: 0 48px 96px; min-width: 0; }

  .docbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    position: sticky; top: 0; z-index: 5; margin: 0 -48px 28px; padding: 13px 48px;
    background: var(--bg); border-bottom: 1px solid var(--rule); color: var(--muted); font: 500 .85rem var(--display);
  }
  .docbar b { color: var(--text); font-weight: 700; }

  /* smaller, denser type */
  .hero { padding: 0 0 8px; }
  .hero h1 { font-size: 2rem; margin-bottom: 6px; }
  .hero p { font-size: 1rem; }
  .list { margin-top: 24px; }
  .lesson-main { max-width: 740px; }
  article h1 { margin: 6px 0 16px; font-size: 2.1rem; }
  article h2 { margin: 32px 0 8px; font-size: 1.3rem; scroll-margin-top: 72px; }
  article h3 { margin: 22px 0 6px; font-size: 1.05rem; }
  article p, article li { max-width: 70ch; }
  article blockquote p { font-size: 1.15rem; }
  details.check summary { font-size: 1rem; }
  .btn { margin-top: 28px; padding: 8px 14px; border-width: 1.5px; font-size: .9rem; }
  .btn.auto { padding: 8px 14px; }
  .actions { gap: 8px; margin-top: 32px; }
  .actions .btn { flex: 0 0 auto; }
  .footer-note { margin-top: 32px; }

  /* home overview */
  .overview { display: block; }
  .continue {
    display: flex; align-items: center; justify-content: space-between; gap: 20px;
    padding: 16px 20px; border: 1px solid var(--rule); border-radius: 6px; background: var(--panel); font-family: var(--display);
  }
  .continue small { display: block; color: var(--muted); font: 500 .8rem var(--display); }
  .continue strong { font: 700 1.2rem var(--display); letter-spacing: -.01em; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 16px 0 28px; border: 1px solid var(--rule); border-radius: 6px; }
  .stat { padding: 14px 20px; }
  .stat + .stat { border-left: 1px solid var(--rule); }
  .stat b { display: block; font: 800 1.6rem/1.15 var(--display); letter-spacing: -.02em; }
  .stat span { color: var(--muted); font: 500 .8rem var(--display); }
  table.topics { width: 100%; border-collapse: collapse; font-family: var(--display); font-size: .92rem; }
  .topics th { padding: 8px 12px; border-bottom: 2px solid var(--text); color: var(--muted); font: 600 .78rem var(--display); text-align: left; }
  .topics td { padding: 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
  .topics tr.row { cursor: pointer; }
  .topics td:first-child a { text-decoration: none; }
  .topics td:first-child strong { font-weight: 700; }
  .topics td:first-child small { display: block; margin-top: 2px; color: var(--muted); font: 400 .85rem var(--serif); }
  .topics tr.row:hover td:first-child strong { background: var(--hl); color: var(--hl-ink); padding: 0 .2em; margin: 0 -.2em; }
  .meter { min-width: 120px; height: 8px; overflow: hidden; border-radius: 2px; background: var(--rule); }
  .meter i { display: block; height: 100%; background: var(--hl); }

  /* sidebar tree */
  #tree {
    display: block; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 22px 14px 40px 18px; border-right: 1px solid var(--rule); background: var(--panel); font-family: var(--display);
  }
  .tree-head { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; }
  .tree-list, .tree-list ul { margin: 0; padding: 0; list-style: none; }
  .node {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px;
    border: 0; border-radius: 4px; background: none; color: var(--text);
    font: 500 .9rem/1.35 var(--display); text-align: left; text-decoration: none; cursor: pointer;
  }
  .node:hover span:not(.ico):not(.count):not(.caret):not(.sr) {
    text-decoration: underline; text-decoration-color: var(--hl); text-decoration-thickness: .16em; text-underline-offset: .2em;
  }
  .node.topic { font-weight: 700; font-size: .95rem; }
  .node.current { background: var(--hl); color: var(--hl-ink); font-weight: 700; }
  .node.current:hover span { text-decoration: none; }
  .caret {
    flex: none; width: 0; height: 0;
    border-left: 6px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  }
  .branch.open > .topic .caret { transform: rotate(90deg); }
  .count { margin-left: auto; color: var(--muted); font-size: .8rem; font-weight: 500; }
  .ico { flex: none; width: 1em; color: var(--good); font-weight: 800; }
  .node.current .ico { color: var(--hl-ink); }
  .tree-list ul { margin-left: 16px; }
  .tree-list ul > li { position: relative; padding-left: 18px; }
  .tree-list ul > li::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; border-left: 2px solid var(--line); }
  .tree-list ul > li:last-child::before { bottom: 50%; }
  .tree-list ul > li::after { content: ""; position: absolute; left: 0; top: 50%; width: 14px; border-top: 2px solid var(--line); }
}

/* right rail: lesson outline and questions, on wide screens */
@media (min-width: 1180px) {
  .shell.with-rail { grid-template-columns: 260px minmax(0, 1fr) 250px; }
  .with-rail #rail {
    display: block; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 24px 18px 40px; border-left: 1px solid var(--rule); background: var(--panel); font-family: var(--display);
  }
  #rail h4 { margin: 0 0 8px; color: var(--muted); font: 700 .8rem var(--display); }
  #rail .outline { margin: 0 0 24px; padding: 0; list-style: none; border-left: 2px solid var(--rule); }
  #rail .outline button {
    display: block; width: 100%; margin-left: -2px; padding: 5px 0 5px 12px; border: 0; border-left: 2px solid transparent;
    background: none; color: var(--muted); font: 500 .88rem/1.35 var(--display); text-align: left; cursor: pointer;
  }
  #rail .outline button:hover { color: var(--text); }
  #rail .outline button.active { border-left-color: var(--text); color: var(--text); font-weight: 700; }
  #rail .qs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 24px; }
  #rail .dot {
    display: grid; place-items: center; width: 26px; height: 26px; padding: 0;
    border: 2px solid var(--text); border-radius: 50%; background: none; color: var(--text); font: 700 .72rem var(--display); cursor: pointer;
  }
  #rail .dot.on { background: var(--hl); border-color: var(--hl); color: var(--hl-ink); }
  #rail .prog { margin: 0; color: var(--muted); font: 500 .85rem/1.4 var(--display); }
}

article figure { margin: 24px 0; max-width: 62ch; }
article figure img { display: block; width: 100%; height: auto; border-radius: 6px; }
article figcaption { margin-top: 8px; font: .9rem/1.4 var(--display); color: var(--muted); }
