/* ==========================================================
   The document reader
   ----------------------------------------------------------
   Word and HTML guides land here as converted HTML, so both get one reading
   experience: a measured column, and a contents panel that tracks where you
   are. A PDF gets the browser's own viewer instead.
   ========================================================== */

.doc-main { background: var(--bg); }

.doc-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}
.doc-bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.doc-bar-title strong {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-bar-title span { font-size: 11.5px; color: var(--text-3); }

/* ---------- contents beside the text ---------- */

.doc-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 40px;
  align-items: start;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 28px 96px;
}
.doc-layout.no-toc { grid-template-columns: minmax(0, 1fr); max-width: 760px; }

.doc-toc {
  position: sticky;
  /* Clears the sticky bar above it. */
  top: calc(var(--topbar-h) + 20px);
  max-height: calc(100dvh - var(--topbar-h) - 60px);
  overflow-y: auto;
  padding-right: 8px;
}
.doc-toc-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}
.doc-toc ul { list-style: none; margin: 0; padding: 0; }
.doc-toc li { margin: 0; }
.doc-toc a {
  display: block;
  padding: 5px 10px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-2);
  text-decoration: none;
  border-left: 2px solid var(--line);
  transition: color .12s var(--ease), border-color .12s var(--ease), background .12s var(--ease);
}
.doc-toc a:hover { color: var(--text); background: var(--surface-2); }
/* Set by the IntersectionObserver in main.js as you scroll. */
.doc-toc a.on {
  color: var(--brand-text);
  border-left-color: var(--brand);
  font-weight: 600;
}
.doc-toc .lvl-1 a { padding-left: 22px; font-size: 12px; }
.doc-toc .lvl-2 a { padding-left: 34px; font-size: 11.5px; }

/* ---------- the document itself ---------- */

.doc-body {
  min-width: 0;
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--text);
  max-width: 72ch;
}
.doc-body > :first-child { margin-top: 0; }

/* Room for the sticky bar when a heading is jumped to. */
.doc-body h1, .doc-body h2, .doc-body h3,
.doc-body h4, .doc-body h5, .doc-body h6 {
  scroll-margin-top: calc(var(--topbar-h) + 24px);
  line-height: 1.3;
  font-weight: 650;
}
.doc-body h1 { font-size: 26px; margin: 40px 0 14px; letter-spacing: -.01em; }
.doc-body h2 { font-size: 20px; margin: 34px 0 12px; }
.doc-body h3 { font-size: 16.5px; margin: 26px 0 10px; }
.doc-body h4, .doc-body h5, .doc-body h6 { font-size: 15px; margin: 22px 0 8px; }
/* A rule under the top two levels is what makes a long guide scannable. */
.doc-body h1, .doc-body h2 { padding-bottom: 8px; border-bottom: 1px solid var(--line); }

.doc-body p { margin: 0 0 16px; }
.doc-body ul, .doc-body ol { margin: 0 0 16px; padding-left: 26px; }
.doc-body li { margin-bottom: 6px; }
.doc-body li > ul, .doc-body li > ol { margin: 6px 0 0; }

.doc-body a { color: var(--brand-text); text-decoration: underline; text-underline-offset: 2px; }
.doc-body strong { font-weight: 650; }
.doc-body img { max-width: 100%; height: auto; border-radius: var(--r-md); margin: 8px 0; }

.doc-body blockquote {
  margin: 0 0 16px;
  padding: 2px 0 2px 18px;
  border-left: 3px solid var(--brand);
  color: var(--text-2);
}
.doc-body pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 16px;
  font-size: 13px;
}
.doc-body code {
  font-family: var(--font-mono);
  font-size: .9em;
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: var(--r-sm);
}
.doc-body pre code { background: none; padding: 0; }

/* A wide table must scroll inside itself rather than widen the page. */
.doc-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 18px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.doc-body th, .doc-body td {
  border: 1px solid var(--line);
  padding: 8px 11px;
  text-align: left;
  vertical-align: top;
}
.doc-body th { background: var(--surface-2); font-weight: 650; }
.doc-body tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }

.doc-body hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.doc-loading { color: var(--text-3); font-size: 13px; padding: 40px 0; }

/* ---------- PDFs ---------- */

.doc-pdf { flex: 1; min-height: 0; display: flex; }
.doc-pdf iframe { flex: 1; width: 100%; border: 0; background: var(--surface-3); }

/* ---------- a document tile on a course page ---------- */

.doc-kind {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}

@media (max-width: 900px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 22px 18px 72px; }
  /* Above the text rather than beside it, and no longer sticky — a pinned
     panel on a phone eats the screen the document needs. */
  .doc-toc {
    position: static;
    max-height: none;
    margin-bottom: 24px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
  }
}

/* ---------- Exact / Reader ---------- */

.doc-views {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  flex-shrink: 0;
}
.doc-view {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.doc-view:hover { color: var(--text); }
.doc-view.on { background: var(--surface); color: var(--brand-text); box-shadow: var(--shadow-sm); }

/* An HTML guide brings its own background, so the frame must not sit on the
   portal's — a white page inside a dark theme should still look like the page. */
.doc-pdf iframe[sandbox] { background: #fff; }

@media (max-width: 700px) {
  .doc-bar { gap: 8px; padding: 0 14px; }
  .doc-bar-title span { display: none; }
  .doc-view { padding: 5px 8px; }
}
