/* Reading controls stay outside article typography and below the site header.
   JavaScript only changes preferences; Material retains its mobile drawers. */
.reading-controls[hidden],
.reading-controls__button[hidden] {
  display: none !important;
}

.reading-controls {
  position: sticky;
  top: var(--reading-header-height, var(--aihpc-sticky-offset));
  z-index: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  margin: 0 0.8rem 0.7rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--aihpc-hairline);
  border-radius: 0.6rem;
  background: var(--md-default-bg-color);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--md-default-fg-color) 5%, transparent);
  color: var(--md-default-fg-color);
}

.reading-controls__label {
  flex: 1 0 auto;
  padding-inline: 0.25rem;
  color: var(--md-default-fg-color--light);
  font-size: 0.64rem;
  font-weight: 600;
  line-height: 1.5;
}

.reading-controls__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.reading-controls__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: 2.2rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 0.35rem;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.reading-controls__button svg {
  flex: 0 0 auto;
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reading-controls__button:hover {
  border-color: var(--aihpc-hairline);
  background: var(--md-default-fg-color--lightest);
}

.reading-controls__button[aria-pressed="true"],
.reading-controls__button[aria-expanded="false"] {
  border-color: color-mix(in srgb, var(--md-accent-fg-color) 30%, transparent);
  background: color-mix(in srgb, var(--md-accent-fg-color) 10%, var(--md-default-bg-color));
  color: var(--md-accent-fg-color);
}

.reading-controls__button:focus-visible {
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: 2px;
}

/* Collapsed: only the toggle remains, as a small pill that floats beside the
   lesson title and scrolls away with the page instead of following the reader. */
.reading-controls__toggle svg {
  transition: transform 120ms ease;
}

.reading-controls[data-reading-collapsed="true"] {
  position: static;
  float: right;
  gap: 0;
  margin: 0 0.8rem 0.4rem 0.6rem;
  padding: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.reading-controls[data-reading-collapsed="true"] > :not(.reading-controls__toggle, .reading-controls__status) {
  display: none;
}

.reading-controls[data-reading-collapsed="true"] .reading-controls__toggle svg {
  transform: rotate(180deg);
}

.reading-controls__status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.reading-controls__status:not(:empty) {
  position: static;
  flex-basis: 100%;
  width: auto;
  height: auto;
  padding: 0.15rem 0.25rem;
  overflow: visible;
  clip-path: none;
  color: var(--md-default-fg-color--light);
  font-size: 0.68rem;
  line-height: 1.5;
  white-space: normal;
}

.reading-controls [data-reading-action="navigation"],
.reading-controls [data-reading-action="contents"],
.reading-controls [data-reading-action="wide"] {
  display: none;
}

@media screen and (min-width: 60em) {
  .reading-controls [data-reading-action="contents"],
  .reading-controls [data-reading-action="wide"] {
    display: inline-flex;
  }

  html[data-reading-toc="hidden"] .md-sidebar--secondary {
    display: none;
  }
}

/* The desktop navigation is wider than Material's drawer. Keep the drawer's
   width aligned with its native off-screen offset until desktop navigation. */
@media screen and (max-width: 76.234375em) {
  .md-sidebar--primary {
    width: 12.1rem;
  }
}

@media screen and (min-width: 76.25em) {
  .reading-controls {
    margin-inline: 1.2rem;
  }

  .reading-controls [data-reading-action="navigation"] {
    display: inline-flex;
  }

  html[data-reading-nav="hidden"] .md-sidebar--primary {
    display: none;
  }
}

.reading-controls[data-reading-has-toc="false"] [data-reading-action="contents"],
.reading-controls[data-reading-has-navigation="false"] [data-reading-action="navigation"] {
  display: none;
}

@media screen and (max-width: 59.984375em) {
  .reading-controls[data-reading-fullscreen-available="false"] {
    display: none;
  }
}

@media screen {
  html[data-reading-ready="true"] .md-content__inner :is(h1, h2, h3, h4, h5, h6, [id]) {
    scroll-margin-top: calc(var(--reading-header-height, var(--aihpc-sticky-offset)) + var(--reading-toolbar-height, 0px) + 0.8rem);
  }

  html[data-reading-wide="true"] .md-main__inner {
    width: 100%;
    max-width: none;
    padding-inline: clamp(0rem, 1vw, 1.2rem);
  }

  /* A real fullscreen session uses the same document so links, diagrams,
     theme colors and reading position continue to work normally. */
  html[data-reading-focus="true"] .md-header,
  html[data-reading-focus="true"] .md-tabs,
  html[data-reading-focus="true"] .md-sidebar,
  html[data-reading-focus="true"] .md-footer,
  html[data-reading-focus="true"] .md-overlay,
  html[data-reading-focus="true"] .md-top,
  html[data-reading-focus="true"] [data-md-component="announce"],
  html[data-reading-focus="true"] [data-md-component="outdated"] {
    display: none !important;
  }

  html[data-reading-focus="true"] .md-container {
    min-height: 100vh;
    min-height: 100dvh;
  }

  html[data-reading-focus="true"] .md-main__inner {
    width: 100%;
    max-width: none;
    margin-top: 0;
    padding-inline: clamp(0rem, 1vw, 1.2rem);
  }

  html[data-reading-focus="true"] .md-content {
    width: 100%;
    max-width: none;
  }

  html[data-reading-focus="true"] .reading-controls {
    top: 0;
    margin-top: 0.5rem;
  }

  html[data-reading-focus="true"] .md-content__inner :is(h1, h2, h3, h4, h5, h6, [id]) {
    scroll-margin-top: calc(var(--reading-toolbar-height, 0px) + 0.8rem);
  }

  html[data-reading-focus="true"] .reading-controls [data-reading-action="navigation"],
  html[data-reading-focus="true"] .reading-controls [data-reading-action="contents"],
  html[data-reading-focus="true"] .reading-controls [data-reading-action="wide"] {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reading-controls__button,
  .reading-controls__toggle svg {
    transition: none;
  }
}

@media print {
  .reading-controls {
    display: none !important;
  }
}
