/* Navigation shared by all five pages: one bar, links only, current page marked.
   Uses each page's own colour variables so it fits the light and dark pages alike. */
.sitenav {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 10px max(28px, calc((100vw - 1440px) / 2));
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.sitenav::-webkit-scrollbar { display: none; }
.sitenav a {
  flex: 0 0 auto; padding: 9px 16px; border-radius: 10px;
  font: 750 13.5px/1 system-ui, sans-serif; text-decoration: none;
  color: var(--muted); white-space: nowrap;
}
.sitenav a:hover { background: color-mix(in srgb, var(--teal, #08767a) 12%, transparent); color: var(--ink); }
.sitenav a.is-here { background: var(--teal, #08767a); color: #fff; }

.page-toc {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin: 18px auto 24px; padding: 14px 18px; max-width: 1180px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
}
.page-toc-label { font: 800 10px/1 system-ui, sans-serif; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.page-toc-links { display: flex; gap: 6px; flex-wrap: wrap; }
.page-toc-links a {
  padding: 6px 11px; border-radius: 9px;
  background: color-mix(in srgb, var(--teal, #08767a) 10%, transparent);
  font: 700 12.5px/1.3 system-ui, sans-serif; text-decoration: none; color: var(--ink);
}
.page-toc-links a:hover { background: color-mix(in srgb, var(--teal, #08767a) 22%, transparent); }
:target { scroll-margin-top: 64px; }
html { scroll-behavior: smooth; }
.obj-guide { font-weight: 700; }
@media (max-width: 720px) {
  .sitenav { padding: 8px 12px; }
  .sitenav a { padding: 8px 13px; font-size: 13px; }
  .page-toc { margin: 12px; padding: 12px; }
  .page-toc-links a { font-size: 12px; padding: 6px 9px; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* ── Standalone (Home Screen) mode ──────────────────────────────────────
   With no browser chrome, the Dynamic Island and the home indicator sit on
   top of the page, so the insets have to be paid explicitly. max() keeps a
   sane gutter on devices that report zero. */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.topbar, .exam-topbar {
  padding-top: max(18px, calc(env(safe-area-inset-top) + 10px));
}
.sitenav { top: env(safe-area-inset-top); }
main, .exam-main {
  padding-bottom: max(42px, calc(env(safe-area-inset-bottom) + 28px));
}
/* The grade row and the exam status bar are the two things a thumb reaches for. */
.grade-row { margin-bottom: env(safe-area-inset-bottom); }
.exam-status { bottom: env(safe-area-inset-bottom); }

/* Home-screen prompt, shown only in iOS Safari and only before install. */
.a2hs {
  position: fixed; left: 12px; right: 12px;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 14px));
  z-index: 60; display: none; gap: 12px; align-items: center;
  padding: 14px 16px; border-radius: 16px;
  background: #062c3e; color: #fff;
  box-shadow: 0 18px 50px rgba(3, 24, 34, .45);
  font: 500 14px/1.4 system-ui, sans-serif;
}
.a2hs.is-visible { display: flex; }
.a2hs p { margin: 0; flex: 1; }
.a2hs b { font-weight: 800; }
.a2hs button {
  flex: 0 0 auto; border: 0; border-radius: 10px; cursor: pointer;
  padding: 9px 13px; font: 700 13px/1 system-ui, sans-serif;
  background: rgba(255,255,255,.16); color: #fff;
}
.offline-note {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 14px));
  z-index: 60; display: none; padding: 9px 16px; border-radius: 999px;
  background: #3d2b12; color: #ffe2b0; font: 700 12.5px/1 system-ui, sans-serif;
}
.offline-note.is-visible { display: block; }

/* "Carry on where you left off" affordances. */
.resume-toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 16px));
  z-index: 55; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 16px; border-radius: 999px;
  background: #062c3e; color: #fff; box-shadow: 0 14px 40px rgba(3,24,34,.4);
  font: 600 13px/1 system-ui, sans-serif;
}
.resume-toast button {
  border: 0; border-radius: 999px; cursor: pointer; padding: 7px 12px;
  background: rgba(255,255,255,.18); color: #fff; font: 700 12.5px/1 system-ui, sans-serif;
}
.continue-chip {
  display: flex; align-items: center; gap: 9px; margin: -8px 0 18px;
  padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); text-decoration: none; color: var(--ink);
  font: 750 14px/1 system-ui, sans-serif;
}
.continue-chip span {
  font: 800 10px/1 system-ui, sans-serif; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
}
.continue-chip::after { content: "→"; margin-left: auto; opacity: .55; }
.continue-chip:hover { border-color: var(--teal, #0a6e75); }

.resumed-note {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 14px; padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--teal, #0a6e75) 10%, transparent);
  font: 600 13px/1.4 system-ui, sans-serif; color: var(--ink);
}
.resumed-note button {
  border: 0; border-radius: 9px; cursor: pointer; padding: 7px 11px;
  background: var(--teal, #0a6e75); color: #fff; font: 700 12.5px/1 system-ui, sans-serif;
}

/* Keyboard-aware modal bounds apply to every study page. */
dialog:modal { bottom: var(--keyboard-inset, 0px); max-height: calc(var(--visible-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 32px); overscroll-behavior: contain; }

/* Persistent way back when reading was opened from a specific trainer visit. */
body.has-trainer-return { padding-bottom: calc(116px + env(safe-area-inset-bottom, 0px)); }
.trainer-return {
  position: fixed; z-index: 80; bottom: 0; left: 0; right: 0;
  display: grid; justify-items: center; gap: 6px;
  padding: 10px max(16px, env(safe-area-inset-left, 0px)) calc(12px + env(safe-area-inset-bottom, 0px));
  background: #f4faf9; color: #123544; border-top: 1px solid #b9d5d2;
  box-shadow: 0 -4px 18px #062c3e18; font: 600 13px/1.4 system-ui, sans-serif;
}
.trainer-return span { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.trainer-return a {
  display: flex; justify-content: center; align-items: center; min-height: 50px;
  width: min(100%, 560px); padding: 12px; box-sizing: border-box;
  border-radius: 12px; background: #006c67; color: white;
  text-decoration: none; font-size: 16px;
}
.trainer-return a:focus-visible { outline: 3px solid #df8b32; outline-offset: 3px; }
