/* The page shell: everything Material for MkDocs used to provide.
 *
 * The shared design system (assets/stylesheets/extra.css) sets the --tb-* tokens
 * and styles the *content*, but it maps them onto Material's --md-* variables and
 * relies on Material's own stylesheet to paint html, body, the masthead and the
 * layout. With Material absent, pages render as unstyled HTML: transparent
 * background, browser default font, no layout.
 *
 * This file closes that gap using the same --tb-* tokens, so the theme bundles
 * and the colour-scheme switch keep working unchanged.
 *
 * Measured: with this file applied, computed styles match the Material build in
 * both schemes (light #faf9f5 / #1f1e1b, dark #171614 / #e9e7e1) and the
 * display font resolves identically.
 */

html {
  background: var(--tb-paper);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--tb-paper);
  color: var(--tb-ink);
  font-family: var(--tb-font-body);
  font-size: 16px;
  line-height: 1.7;
}

a { color: var(--tb-link); }

.wrap {
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.skip {
  position: absolute;
  left: -9999px;
}

/* masthead ---------------------------------------------------------------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--tb-paper);
  border-bottom: 1px solid var(--tb-rule);
}

.masthead__inner {
  display: flex;
  align-items: center;
  /* Not `space-between`: this row wraps on a phone, and with wrapping the
   * search has to be able to take its own line. The brand pushes the rest right
   * instead, which reads identically and survives the wrap. */
  gap: 0.5rem;
  min-height: 3.5rem;
}

.masthead__brand {
  margin-right: auto;
  min-width: 0;
  font-family: var(--tb-font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--tb-ink);
  text-decoration: none;
}

.masthead__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* The way back to the collection. Quieter than the book title, because it is a
 * way out of the book rather than part of it. */
.masthead__home {
  color: var(--tb-ink-soft);
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
}
.masthead__home:hover {
  color: var(--tb-ink);
  background: color-mix(in srgb, currentColor 10%, transparent);
}
.masthead__home:focus-visible {
  outline: 2px solid var(--tb-accent);
  outline-offset: 2px;
}

/* The reader Settings trigger. Inert until the shared runtime reveals it; the
 * markup and behaviour live in settings.css and assets/settings/settings.js, so
 * this only gives the bare <button> the shell's chrome. */
.tb-settings__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0.4rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tb-ink-soft);
  cursor: pointer;
}

.tb-settings__trigger:hover {
  color: var(--tb-ink);
  background: color-mix(in srgb, var(--tb-ink) 8%, transparent);
}

.tb-settings__trigger:focus-visible {
  outline: 2px solid var(--tb-accent);
  outline-offset: 2px;
}

.tb-settings__trigger svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: currentColor;
}

/* layout ------------------------------------------------------------------ */

.layout {
  display: grid;
  grid-template-columns: minmax(15rem, 18rem) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 5rem);
  overflow: auto;
  padding: 1.25rem 0;
  font-size: 0.85rem;
}

.content {
  min-width: 0;
  max-width: var(--tb-measure);
  padding: 2rem 0 4rem;
}

/* navigation -------------------------------------------------------------- */

.nav__list {
  list-style: none;
  margin: 0;
  padding-left: 0.85rem;
}

.sidebar > .nav__list { padding-left: 0; }

.nav__link {
  display: block;
  padding: 0.15rem 0;
  color: var(--tb-ink-soft);
  text-decoration: none;
}

.nav__link:hover { color: var(--tb-ink); }

.nav__link--current {
  color: var(--tb-accent);
  font-weight: 600;
}

.sidebar summary {
  cursor: pointer;
  padding: 0.3rem 0;
  color: var(--tb-ink);
  font-weight: 600;
}

.sidebar summary::marker { color: var(--tb-ink-lighter); }

/* search ------------------------------------------------------------------ */

.search { position: relative; }

.search input {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--tb-rule);
  border-radius: var(--tb-radius);
  background: var(--tb-paper);
  color: var(--tb-ink);
  font: inherit;
  font-size: 0.85rem;
}

.search__results {
  position: absolute;
  right: 0;
  top: 110%;
  z-index: 10;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  min-width: 18rem;
  max-height: 60vh;
  overflow: auto;
  background: var(--tb-paper);
  border: 1px solid var(--tb-rule);
  border-radius: var(--tb-radius);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--tb-ink) 18%, transparent);
}

.search__results li a {
  display: block;
  padding: 0.3rem 0.4rem;
  font-size: 0.85rem;
  text-decoration: none;
}

.search__results:empty { display: none; }

/* narrow ------------------------------------------------------------------ */

@media (max-width: 60rem) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--tb-rule);
  }
}

/* Phone widths. The masthead is three controls wide and does not fit beside a
 * book title: at 360px the settings button sat past the right edge, which is the
 * control a reader needs to change the theme. So the row wraps, and the search —
 * the one item that is comfortable at full width — takes the second line. */
@media (max-width: 48rem) {
  .masthead__inner {
    flex-wrap: wrap;
    row-gap: 0.5rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }
  .masthead__actions { order: 1; }
  .search { order: 2; flex: 1 1 100%; }
  .search input { width: 100%; }
  /* The results panel is positioned against the search box, which is now the
   * full width of the page. */
  .search__results { left: 0; right: 0; min-width: 0; }
  /* A long book title would otherwise push the actions off the row before the
   * search has a chance to wrap. */
  .masthead__brand {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* A worked example or a data table is routinely wider than a phone. Without a
 * scroll container the table widens the page, and everything pinned to the
 * viewport — the masthead controls, the booklet button — ends up off the right
 * edge. This is why `render_page` wraps every table. */
.table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

/* A display equation has the same problem and its own solution: MathML has no
 * line-breaking, so a wide one cannot wrap and widens the page instead. Measured
 * at 360px, the widest equation on a Learn page was 360px inside a 328px column,
 * which pushed the document 16px wide. Scroll it, as a table is scrolled. */
.md-typeset math[display="block"] {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  /* Room for the scrollbar so it does not sit on the equation. */
  padding-bottom: 0.15rem;
}
