/* The quantum demos at /quantum. Loaded only on those pages.
 *
 * The same paper, ink, and spruce tokens as site.css. Spruce marks the
 * target and the active choice, never a whole panel. The Intercepts demo also
 * loads intercepts.css after this file.
 */

/* The scripts show and hide panels with the hidden attribute, and the
   display rules below would beat it. */
[hidden]:not([hidden="until-found"]) {
  display: none !important;
}

/* The title is in the spruce header band, which gives the space above it. */
.q-title {
  max-width: 18ch;
}

.q-lede {
  margin-top: 1.5rem;
  max-width: 54ch;
}

@media (max-width: 39.9375em) {
  .q-lede {
    font-size: 1rem;
    line-height: 1.65;
  }
}

.q-guide-link {
  margin-top: 0.75rem;
  color: var(--ink-700);
}

.band--head .q-guide-link {
  color: var(--on-band-muted);
}

/* A demo page is for the demo, so its intro stays short. */
.q-header .q-title {
  font-size: clamp(2.25rem, 1rem + 3.4vw, 3.25rem);
}

.q-header .q-lede {
  margin-top: 0.75rem;
  max-width: 62ch;
  font-size: 1rem;
  line-height: 1.65;
}

.q-header .q-guide-link {
  font-size: 0.9375rem;
}

/* The noscript message sits between them in the page, even with scripts on. */
.q-header + .band--white,
.q-header + noscript + .band--white {
  padding-top: 1.5rem;
}

.q-crumb + .q-title {
  margin-top: 0.75rem;
}

.q-crumb a {
  text-decoration: none;
}

.q-crumb a:hover {
  color: var(--gold);
  text-decoration: underline;
}

.q-index {
  margin-top: 1.5rem;
}

/* No date or topic column here: the title and description take the row. */
.q-index .entry {
  grid-template-columns: minmax(0, 1fr);
}

/* Title on the left, description on the right, so the row takes the full width. */
@media (min-width: 40em) {
  .q-index .entry {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    align-items: baseline;
  }

  .q-index .entry > span {
    display: contents;
  }

  .q-index .entry__excerpt {
    margin-top: 0;
  }
}

.q-mono {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-700);
}

.q-note > * + * {
  margin-top: 1rem;
}

.q-note p {
  max-width: 62ch;
  line-height: 1.75;
  color: var(--ink-800);
}

.q-note--wide p {
  max-width: 72ch;
}

/* The short guide on the demo index: one column of parts, each with a
   serif heading. */
.q-basics__title {
  margin-top: 0.75rem;
  scroll-margin-top: 4rem;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 0.5rem + 3vw, 2.5rem);
  font-weight: 400;
  line-height: 1.15;
}

.q-basics__part {
  margin-top: 2.25rem;
  max-width: 68ch;
}

.q-basics__part h3 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1.25;
}

.q-basics__part p {
  margin-top: 0.625rem;
  line-height: 1.75;
  color: var(--ink-800);
}

/* A short formula stays on one line. */
.q-math {
  white-space: nowrap;
}

.q-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2.5rem;
}

.q-band-gap {
  border-top: 0;
}

/* -------------------------------------------------------------- panels --- */
.q-demo {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.75rem;
}

.q-demo--split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}

.q-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

.q-panel__head > * + *,
.q-panel__head > [data-level] > * + * {
  margin-top: 0.75rem;
}

/* A title sits close to its eyebrow, and body text gets room below the title. */
.q-panel__head > .eyebrow + .q-panel__title {
  margin-top: 0.35rem;
}

.q-panel__head > .q-panel__title + * {
  margin-top: 1rem;
}

/* On the putting green, Start the course sits beside the title. */
.q-panel__titlerow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.q-panel__titlerow .btn {
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
}

.q-panel__titlerow .btn[hidden] {
  display: none;
}

.q-panel__title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(2rem, 1rem + 2.4vw, 2.75rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.q-panel__title--small {
  font-size: 1.5rem;
}

.q-panel__hint {
  max-width: 62ch;
  color: var(--ink-700);
}

.q-panel__hint > p + p {
  margin-top: 0.75rem;
}

/* What to do next, in its own box, apart from the explanation around it. */
.q-howto {
  max-width: 62ch;
  padding: 0.9rem 1.25rem;
  border-left: 4px solid var(--spruce);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-950);
}

.q-howto > p + p {
  margin-top: 0.5rem;
}

.q-howto__list {
  display: grid;
  gap: 0.35rem;
  padding-left: 1.25rem;
}

.q-howto__label,
.q-play__label {
  margin-bottom: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-700);
}

/* A game's moving parts, grouped in one frame: what is in play, the message,
   the buttons, and the running score. */
.q-play {
  display: grid;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  background: var(--white);
}

.q-play__label {
  margin-bottom: 0;
}

.q-play__stats {
  display: grid;
  gap: 0.35rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--ink-200);
}

/* A one-line readout that changes as you play, in a small frame. */
.q-meter {
  justify-self: start;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  background: var(--paper);
}

/* A side note with its own control, boxed so it does not run into the game. */
.q-aside {
  display: grid;
  gap: 0.6rem;
  max-width: 62ch;
  padding: 1rem 1.25rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-700);
}

/* A line that a demo rewrites as you play, set apart from the text above it. */
.q-logline {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-800);
}

.q-logline:empty {
  display: none;
}

/* An opened hint sits in its own box, apart from the instructions. */
.q-hint__box {
  max-width: 62ch;
  margin-top: 0.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--ink-200);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-950);
}

.q-hint__label {
  margin-bottom: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-700);
}

/* The box picker of the box puzzles, apart from the heading above and the table below. */
.q-boxpick {
  display: grid;
  gap: 0.75rem;
  margin: 1rem 0 1.5rem;
  padding: 1rem 0;
  border-block: 1px solid var(--ink-100);
}

.q-gate--box.is-right::after {
  content: " ✓";
}

.q-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.q-actions .btn,
.q-stats-controls .btn {
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.q-result {
  border: 1px solid var(--ink-200);
  border-left: 4px solid var(--spruce);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 1.25rem 1.5rem;
  display: grid;
  gap: 1rem;
  justify-items: start;
}

.q-result p {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  line-height: 1.45;
}

.q-result .btn {
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
}

/* Not display: none, which takes a live region out of the accessibility tree,
   so a screen reader would miss the first text put in it. */
#circ-note:empty {
  margin: 0;
}

.q-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.q-big {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  line-height: 1.3;
  margin-right: auto;
}

/* ---------------------------------------------------------------- gates --- */
.q-gates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* A gate button reads as a key: a thicker lower edge that goes flat when it
   is pressed. */
.q-gate {
  min-width: 3.25rem;
  min-height: 3.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--ink-300);
  border-bottom-width: 3px;
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink-950);
  font-family: var(--font-mono);
  font-size: 1.0625rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.q-gate:hover:not(:disabled) {
  border-color: var(--spruce);
}

.q-gate:active:not(:disabled) {
  border-bottom-width: 1px;
  transform: translateY(2px);
}

.q-tap:active:not(:disabled),
.q-level button:active {
  transform: translateY(1px);
}

.q-gate[aria-pressed="true"],
.q-gate[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--spruce);
  border-color: var(--spruce);
  color: var(--paper);
}

.q-gate:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.q-gates--spaced {
  margin-top: 0.5rem;
}

.q-gate--erase {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
}

/* The tip over the gates on the putting green. It points down at the row
   and goes away after the first gate. */
.q-tip {
  position: relative;
  justify-self: start;
  width: fit-content;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: var(--band-deep);
  color: var(--paper);
  font-size: 0.875rem;
  line-height: 1.4;
}

.q-tip::after {
  content: "";
  position: absolute;
  top: 100%;
  /* bloch-golf.js sets --tip-arrow-x so the arrow points at the H gate. */
  left: calc(var(--tip-arrow-x, 1.1rem + 6px) - 6px);
  border: 6px solid transparent;
  border-top-color: var(--band-deep);
}

.q-tip[hidden] {
  display: none;
}

/* While the tip shows, ring the gate it suggests. */
.q-gates-wrap:has(.q-tip:not([hidden])) .q-gate--suggest {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 16%, var(--white));
}

/* The gate key under What this shows. */
.q-gatekey__title {
  margin-top: 2.5rem;
  scroll-margin-top: 1.5rem;
}

.q-gatekey {
  margin-top: 1rem;
}

/* Prose in the cells, not figures, so the sans face and top alignment. */
.q-gatekey th,
.q-cases.q-gatekey td {
  vertical-align: top;
}

.q-cases.q-gatekey td {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.55;
}

.q-gatekey td:nth-child(2) {
  width: 32%;
}

/* --------------------------------------------------------------- readout --- */
/* The readout opens with the gold lead rule. */
.q-readout {
  margin: 0;
  display: grid;
  border-top: 2px solid var(--gold);
}

.q-readout > div {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--ink-200);
}

.q-readout dt {
  align-self: center;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-500);
}

.q-readout dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.q-readout--row {
  border-top: 0;
  gap: 1rem;
}

.q-readout--row > div {
  grid-template-columns: none;
  gap: 0.25rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.q-readout--row dd {
  font-family: var(--font-serif);
  font-size: 1.75rem;
}

.q-readout__note {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--ink-600);
}

.q-nowrap {
  white-space: nowrap;
}

/* ---------------------------------------------------------- bloch golf --- */
.q-sphere {
  margin: 0;
}

.q-sphere canvas {
  display: block;
  width: 100%;
  max-width: min(30rem, 50svh);
  aspect-ratio: 1;
  margin-inline: auto;
  /* A vertical swipe scrolls the page. A sideways drag turns the sphere. */
  touch-action: pan-y;
  cursor: grab;
  border-radius: var(--radius);
}

.q-sphere canvas:active {
  cursor: grabbing;
}

.q-sphere figcaption,
.q-dial figcaption,
.q-chart figcaption {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--ink-600);
  text-align: center;
}

.q-scorecard table,
.q-cases {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.q-scorecard table {
  margin-top: 1rem;
  border-top: 2px solid var(--gold);
}

.q-scorecard th,
.q-scorecard td,
.q-cases th,
.q-cases td {
  text-align: left;
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-bottom: 1px solid var(--ink-200);
}

.q-scorecard thead th,
.q-cases thead th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-500);
}

.q-scorecard td,
.q-cases td {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.q-scorecard tbody th {
  font-weight: 400;
}

.q-scorecard .is-current th {
  color: var(--spruce);
  font-weight: 600;
}

.q-scorecard tfoot th,
.q-scorecard tfoot td {
  padding-top: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--spruce);
  border-bottom: 0;
}

/* -------------------------------------------------------------- circuit --- */
.q-circuit-wrap {
  display: grid;
  gap: 1.25rem;
}

.q-toolbox {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.q-toolbox__label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-500);
}

.q-circuit {
  display: grid;
  grid-template-columns: 4.5rem repeat(var(--cols, 4), minmax(2.75rem, 4.5rem));
  grid-template-rows: repeat(var(--rows, 2), 4rem);
  align-items: center;
  max-width: 100%;
}

.q-wire-label {
  grid-column: 1;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-700);
}

.q-slot {
  position: relative;
  height: 100%;
  display: grid;
  place-items: center;
}

/* The wire runs through every slot. */
.q-slot::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1.5px solid var(--ink-400);
}

/* The CNOT line joins the control and the target, up or down, and passes
   through any line between them. */
.q-slot--link-up::after,
.q-slot--link-down::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  border-left: 2px solid var(--ink-950);
}

.q-slot--link-up:not(.q-slot--link-down)::after {
  bottom: 50%;
}

.q-slot--link-down:not(.q-slot--link-up)::after {
  top: 50%;
}

/* A line that the CNOT passes over shows the CNOT line through its box. */
.q-slot--through button {
  background: transparent;
}

.q-slot button {
  position: relative;
  z-index: 1;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px dashed var(--ink-500);
  border-radius: var(--radius);
  background: var(--white);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink-950);
  cursor: pointer;
}

.q-slot button:hover:not(:disabled) {
  border-color: var(--spruce);
}

.q-slot button.is-filled {
  border-style: solid;
  border-color: var(--ink-950);
}

.q-slot--control button.is-filled,
.q-slot--target button.is-filled {
  border-color: transparent;
  background: transparent;
  font-size: 1.5rem;
}

.q-slot--control button.is-filled {
  font-size: 1.25rem;
}

.q-slot button:disabled {
  cursor: default;
}

/* The box fills its whole step, drawn as one dark block across the lines. */
.q-slot--box::after {
  content: "";
  position: absolute;
  left: calc(50% - 1.375rem);
  width: 2.75rem;
  top: 0;
  bottom: 0;
  background: var(--ink-950);
}

.q-slot--box-first::after {
  top: calc(50% - 1.375rem);
}

.q-slot--box-last::after {
  bottom: calc(50% - 1.375rem);
}

.q-slot--box button.is-filled {
  border-color: var(--ink-950);
  background: var(--ink-950);
  color: var(--paper);
  font-style: italic;
}

.q-gate--box {
  font-family: var(--font-mono);
}

/* Drag and drop. A gate you can drag does not scroll the page on touch. */
.q-gates .q-gate:not(.q-gate--erase),
.q-slot button.is-filled {
  touch-action: none;
}

.q-slot button.is-dragging,
.q-gate.is-dragging {
  opacity: 0.4;
}

.q-slot button.is-drop {
  border-style: solid;
  border-color: var(--spruce);
  box-shadow: 0 0 0 3px var(--spruce);
}

.q-drag-ghost {
  position: fixed;
  z-index: 100;
  display: grid;
  place-items: center;
  min-width: 2.75rem;
  height: 2.75rem;
  padding: 0 0.5rem;
  border: 1px solid var(--ink-950);
  border-radius: var(--radius);
  background: var(--white);
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink-950);
  pointer-events: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.q-amps__head {
  margin-bottom: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.q-legend {
  display: flex;
  gap: 1.25rem;
  font-size: 0.8125rem;
  color: var(--ink-600);
}

.q-legend span::before {
  content: "";
  display: inline-block;
  width: 1.25rem;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.q-legend__you::before {
  border-top: 2.5px solid var(--ink-950);
}

.q-legend__target::before {
  border-top: 2px dashed var(--spruce);
}

.q-amptable {
  width: 100%;
  margin-top: 0.75rem;
  border-collapse: collapse;
}

.q-amptable th,
.q-amptable td {
  text-align: left;
  padding: 0.4rem 0.75rem 0.4rem 0;
  border-bottom: 1px solid var(--ink-200);
  vertical-align: middle;
}

.q-amptable thead th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-500);
}

.q-amptable tbody th {
  font-weight: 500;
}

.q-amptable td:nth-child(4) {
  width: 40%;
}

/* The counts column is one more than a 320px screen has room for. */
@media (max-width: 22.5em) {
  .q-amptable th,
  .q-amptable td {
    padding-right: 0.3rem;
  }

  .q-amptable .q-phasor {
    width: 1.75rem;
    height: 1.75rem;
  }

  .q-amptable td:nth-child(4) {
    min-width: 3.5rem;
  }
}

.q-phasor {
  display: block;
  width: 2.5rem;
  height: 2.5rem;
}

.q-amp-target {
  display: block;
  font-size: 0.75rem;
  color: var(--spruce);
}

.q-bar {
  position: relative;
  display: block;
  height: 0.75rem;
  background: var(--ink-50);
  border-radius: var(--radius-sm);
}

.q-bar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ink-950);
  border-radius: var(--radius-sm);
}

.q-bar__target {
  position: absolute;
  top: -0.25rem;
  bottom: -0.25rem;
  width: 0;
  border-left: 2px solid var(--spruce);
  transform: translateX(-1px);
}

.q-bar__value {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
}

/* ----------------------------------------------------------------- chsh --- */
.q-rules__list {
  margin-top: 1rem;
  padding-left: 1.375rem;
  max-width: 68ch;
  display: grid;
  gap: 0.5rem;
  color: var(--ink-800);
}

.q-rules .q-panel__hint {
  margin-top: 1.25rem;
}

var {
  font-family: var(--font-serif);
  font-style: italic;
}

.q-players {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.q-player {
  margin: 0;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: grid;
  gap: 0.75rem;
}

.q-player legend {
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-500);
}

.q-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.q-seg {
  display: inline-flex;
  border: 1px solid var(--ink-300);
  border-radius: var(--radius);
  overflow: hidden;
}

.q-seg button {
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  background: var(--white);
  font-family: var(--font-mono);
  font-size: 1rem;
  cursor: pointer;
}

.q-seg button + button {
  border-left: 1px solid var(--ink-300);
}

.q-seg button[aria-pressed="true"] {
  background: var(--spruce);
  color: var(--paper);
}

/* The ring sits inside the button, so on a spruce button it must be paper. */
.q-seg button[aria-pressed="true"]:focus-visible {
  outline-color: var(--paper);
}

.q-seg button:focus-visible {
  outline-offset: -3px;
}

.q-cases .is-win td:last-child {
  color: var(--spruce);
  font-weight: 500;
}

.q-cases .is-loss td:last-child {
  color: var(--ink-500);
  text-decoration: line-through;
}

/* Each player's input or line stays in one group on a phone. */
.q-cases--triple td {
  white-space: nowrap;
}

.q-dial {
  margin: 0;
}

.q-dial svg {
  display: block;
  width: 100%;
  max-width: 18rem;
  margin-inline: auto;
}

.q-sliders {
  display: grid;
  gap: 1rem;
  justify-items: start;
}

.q-sliders .btn {
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
}

.q-slider {
  width: 100%;
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr) 4rem;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9375rem;
}

.q-slider input {
  width: 100%;
  min-height: 2.75rem;
  accent-color: var(--spruce);
}

.q-slider output {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  text-align: right;
}

.q-chart {
  margin: 0;
}

.q-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

/* -------------------------------------------------------- bomb tester --- */
.q-sphere .q-zeno-hidden {
  width: calc(0.72 * min(100%, 15rem, 32svh));
  margin-inline: auto;
}

.q-mz,
#zeno-chart {
  max-width: 40rem;
  margin-inline: auto;
}

/* Clear of the pinned sphere and the Explain bar when a run ends. */
.q-zeno .q-result {
  scroll-margin-block: calc(min(15rem, 32svh) + 5rem) calc(var(--q-level-height, 0px) + 1rem);
}

/* The diagram scales with its width, so its labels need a larger size here. */
@media (max-width: 39.9375em) {
  .q-mz__text,
  .q-mz__boxlabel {
    font-size: 24px;
  }
}

.q-mz__beam path {
  fill: none;
  stroke: var(--ink-300);
  stroke-width: 2;
}

.q-mz__split line,
.q-mz__mirror line {
  stroke: var(--ink-950);
  stroke-width: 3;
}

.q-mz__split line {
  stroke-dasharray: 5 4;
}

.q-mz__beam .q-mz__back {
  stroke-dasharray: 6 5;
}

.q-mz__box,
.q-mz__det {
  fill: var(--white);
  stroke: var(--ink-950);
  stroke-width: 2;
  transform-box: fill-box;
  transform-origin: center;
}

.q-mz__text,
.q-mz__boxlabel {
  font-family: var(--font-mono);
  font-size: 18px;
  fill: var(--ink-700);
}

.q-mz__boxlabel {
  fill: var(--ink-950);
  font-size: 20px;
}

.q-mz.is-bright .q-mz__det--bright,
.q-mz.is-dark .q-mz__det--dark {
  fill: var(--spruce);
  stroke: var(--spruce);
}

.q-mz.is-boom .q-mz__box {
  fill: var(--ink-950);
}

.q-mz.is-boom .q-mz__boxlabel {
  fill: var(--paper);
}

.q-sphere--fixed canvas,
.q-sphere--fixed canvas:active {
  cursor: default;
}

.q-zeno,
.q-zeno-loop,
.q-zeno-chart {
  margin-top: 2rem;
}

.q-zeno .q-panel__hint {
  min-height: 4.5em;
}

/* The parts of one long demo page. */
.q-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
}

.q-toc a {
  display: inline-block;
  padding: 0.5rem 0;
}

.q-anchor {
  scroll-margin-top: 1.5rem;
}

/* The parts of a long demo, one at a time. parts.js adds is-enhanced. Without
   it, the links are a plain list and every part shows on one page. With it,
   the links are a row of tabs on the bottom edge of the band, each with its
   number in a small circle. */
.q-parts {
  padding-top: 0.75rem;
  padding-bottom: 0;
  border-bottom: 1px solid var(--ink-200);
}

/* Without the script, the part links read as plain links. */
.q-toc:not(.is-enhanced) a {
  color: var(--spruce);
  font-weight: 600;
}

.q-toc:not(.is-enhanced) {
  padding-bottom: 1rem;
}

.q-toc.is-enhanced {
  scroll-margin-top: 1rem;
  flex-wrap: nowrap;
  gap: 0 0.25rem;
  /* One row of tabs. When they do not fit, the row scrolls sideways. */
  overflow-x: auto;
  scrollbar-width: thin;
  font-size: 0.9375rem;
}

.q-toc.is-enhanced a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  flex: none;
  padding: 0.85rem 0.9rem 0.8rem;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  color: var(--ink-700);
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
}

.q-toc.is-enhanced .q-parts__num {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--ink-400);
  border-radius: 50%;
  background: var(--white);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-950);
}

/* The colon is for screen readers and plain links; the circle replaces it on screen. */
.q-toc.is-enhanced .q-parts__sep {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.q-toc.is-enhanced a:hover {
  border-bottom-color: var(--ink-300);
  color: var(--ink-950);
}

.q-toc.is-enhanced a:focus-visible {
  outline: 2px solid var(--spruce);
  outline-offset: -2px;
}

.q-toc.is-enhanced a[aria-current="true"],
.q-toc.is-enhanced a[aria-current="true"]:hover {
  border-bottom-color: var(--spruce);
  color: var(--ink-950);
}

.q-toc.is-enhanced a[aria-current="true"] .q-parts__num {
  border-color: var(--spruce);
  background: var(--spruce);
  color: var(--paper);
}

.q-parts__status {
  margin-top: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-600);
}

.q-parts__status:focus {
  outline: none;
}

.q-parts__status:focus-visible {
  outline: 2px solid var(--spruce);
  outline-offset: 2px;
}

/* Where the buttons show their names, this line repeats them. It stays for
   screen readers, and it still takes the focus after a switch. */
@media (min-width: 48em) {
  /* The first number lines up with the text below. */
  .q-toc.is-enhanced {
    margin-inline: -1rem;
  }

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

/* A part after the first opens on its own, so it needs its top edge back. */
.q-part > .q-band-gap:first-child {
  border-top: 1px solid var(--ink-200);
}

.q-pager__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
}

.q-pager .btn {
  line-height: 1.3;
}

.q-pager .textlink {
  display: inline-block;
  padding-block: 0.75rem;
}

/* The next link stays on the right when the first part has no previous link. */
.q-pager__next {
  margin-left: auto;
}

/* On a mid-size screen, every label does not fit in one row, so only the
   current part shows its name. The others keep their numbers, and screen
   readers still get each label. */
@media (min-width: 48em) and (max-width: 64em) {
  .q-toc.is-enhanced a:not([aria-current="true"]) .q-parts__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}

/* Five labels do not fit a phone. The numbers stay, and the line below the
   buttons names the part. Screen readers still get each label. */
@media (max-width: 47.9375em) {
  .q-toc.is-enhanced .q-parts__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .q-toc.is-enhanced a {
    flex: 1 1 0;
    justify-content: center;
    padding-inline: 0.25rem;
  }

  .q-parts__status {
    margin-bottom: 0.75rem;
  }
}

/* On a phone, the qubit table is taller than the screen, so its Send button
   stays over the Explain bar until the table ends. */
@media (max-width: 47.9375em) {
  .q-bb-send {
    position: sticky;
    bottom: var(--q-level-height, 0px);
    z-index: 1;
    margin-inline: calc(-1 * var(--gutter));
    padding: 0.5rem var(--gutter);
    border-top: 1px solid var(--ink-200);
    background: var(--white);
  }

  /* Keep a focused qubit clear of the Send button and the Explain bar. */
  .q-bb .q-tap {
    scroll-margin-bottom: calc(var(--q-level-height, 0px) + 6rem);
  }
}

/* The reader picks the box and the steps first, so the buttons stay under
   them on a phone, and do not move up as they do in golf. */
.q-zeno > .q-sphere + .q-panel > .q-actions,
.q-zeno > .q-sphere + .q-panel > .q-result {
  order: 0;
}

/* -------------------------------------------------------- teleportation --- */
.q-tp {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-content: center;
  gap: 1rem;
}

@media (min-width: 40em) {
  .q-tp {
    grid-template-columns: repeat(3, minmax(0, 13rem));
  }
}

.q-tp__side {
  justify-self: center;
  width: 100%;
  max-width: 13rem;
  margin: 0;
  min-width: 0;
}

.q-tp__side figcaption {
  margin-bottom: 0.4rem;
  font-size: 0.8125rem;
  text-align: center;
  color: var(--ink-600);
}

.q-tp__side canvas,
.q-tp__hidden {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

/* On a phone, the two spheres to compare share a row. */
@media (max-width: 39.9375em) {
  .q-tp.is-compare .q-tp__side:first-child {
    display: none;
  }
}

/* The size of a drawn sphere, which is 72% of its canvas. */
.q-tp__hidden {
  width: 72%;
  margin: 14%;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink-200);
  border-radius: 50%;
  background: var(--paper);
  font-family: var(--font-serif);
  font-size: 2.5rem;
  color: var(--ink-500);
}

.q-tp__bits {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.q-tp__bit {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--ink-700);
}

.q-tp__bit strong {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--ink-950);
}

.q-readout--row dd.q-tp__seen {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
}

/* ----------------------------------------------------- error correction --- */
.q-ec {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr) minmax(0, 0.8fr)) minmax(0, 1fr);
  align-items: center;
  gap: 0.35rem;
  max-width: 34rem;
}

.q-ec__qubit {
  display: grid;
  justify-items: center;
  gap: 0.4rem;
  min-width: 0;
  font-size: 0.75rem;
  color: var(--ink-600);
}

.q-ec__qubit strong {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 1px solid var(--ink-950);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--ink-950);
}

.q-ec__qubit .q-gate {
  min-width: 0;
  padding: 0 0.6rem;
}

.q-ec__lamp {
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  padding: 0.4rem 0.1rem;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--ink-600);
}

.q-ec__lamp b {
  font-weight: 600;
}

.q-ec__lamp.is-on {
  border-color: var(--spruce);
  background: var(--spruce);
  color: var(--paper);
}

.q-ec-labout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.q-ec-labout .q-ec__lamp {
  min-width: 4.5rem;
}

.q-ec-labmatch strong {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
}

.q-ec-strike th[scope="row"] {
  font-weight: 500;
  white-space: nowrap;
}

.q-result p.q-result__small {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink-700);
}

.q-cases__caption {
  margin-bottom: 0.5rem;
  text-align: left;
  font-size: 0.875rem;
  color: var(--ink-700);
}

.q-cases .is-loss-row td {
  font-weight: 600;
  color: var(--ink-950);
  background: var(--ink-50);
}

.q-legend__three::before {
  border-top: 2px solid var(--spruce);
}

.q-legend__plain::before {
  border-top: 2px dashed var(--ink-500);
}

.q-legend__perfect::before {
  border-top: 2px dotted var(--ink-500);
}

.q-chart figcaption .q-legend {
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1.25rem;
  margin-bottom: 0.4rem;
}

.q-legend__d7::before {
  border-top: 2.5px solid var(--spruce);
}

.q-legend__d5::before {
  border-top: 2px dashed var(--ink-500);
}

.q-legend__d3::before {
  border-top: 2px dotted var(--ink-400);
}

/* A distance 3 surface code: data at the odd cells, checks at the even ones. */
.q-sc {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 3rem));
  grid-template-rows: repeat(7, minmax(0, 3rem));
  justify-content: center;
  gap: 0;
}

.q-sc__wires {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  width: 100%;
  height: 100%;
}

.q-sc__wire {
  stroke: var(--ink-300);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

.q-sc__wire--phase {
  stroke: var(--ink-500);
  stroke-dasharray: 3 3;
}

.q-sc__data,
.q-sc__check {
  position: relative;
}

.q-sc__data {
  width: 100%;
  height: 100%;
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: 2px solid var(--ink-950);
  border-radius: 50%;
  background: var(--white);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-950);
  cursor: pointer;
}

.q-sc__data[aria-pressed="true"] {
  background: var(--ink-950);
  color: var(--paper);
}

.q-sc__check {
  display: grid;
  place-items: center;
  width: 80%;
  height: 80%;
  margin: auto;
  border: 1px solid var(--ink-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-500);
}

.q-sc__check.is-on {
  border-color: var(--spruce);
  background: var(--spruce);
  color: var(--paper);
  font-weight: 600;
}

/* ------------------------------------------------------------- bb84 --- */
.q-scroll {
  overflow-x: auto;
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
}

.q-bb {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  min-width: 100%;
}

.q-bb th,
.q-bb td {
  padding: 0.45rem 0.2rem;
  text-align: center;
  border-bottom: 1px solid var(--ink-100);
  white-space: nowrap;
}

.q-bb tr:last-child th,
.q-bb tr:last-child td {
  border-bottom: 0;
}

.q-bb th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--white);
  text-align: left;
  padding-left: 0.85rem;
  padding-right: 0.85rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-700);
  border-right: 1px solid var(--ink-200);
}

.q-bb__head td {
  color: var(--ink-500);
  font-size: 0.75rem;
}

.q-bb__eve th,
.q-bb__eve td {
  background: var(--paper);
}

/* The narrowest columns have no room for a word at 12px. */
@media (max-width: 22.5em) {
  .q-bb th {
    font-size: 0.6875rem !important;
    overflow-wrap: normal;
  }
}

@media (max-width: 56.1875em) {
  .q-bb {
    table-layout: fixed;
    width: 100%;
    font-size: 0.75rem;
  }

  .q-bb th,
  .q-bb td {
    padding: 0.35rem 0.1rem;
  }

  .q-bb th {
    position: static;
    padding: 0.35rem 0.1rem;
    border-right: 0;
    text-align: center;
    font-size: 0.75rem;
    line-height: 1.2;
    white-space: normal;
  }

  .q-bb .q-bb__evecell {
    background: var(--paper);
  }

  /* The last column holds Check and Error once the round ends. */

  .q-bb tr > :last-child {
    width: 18%;
    font-size: 0.75rem;
  }

  .q-bb .q-tap {
    min-width: 0;
    width: 100%;
    padding-inline: 0;
    font-size: 0.75rem;
  }

  .q-bb .q-tap.is-on {
    font-size: 0.9375rem;
  }
}

.q-tap {
  min-width: 2.25rem;
  min-height: 2.75rem;
  border: 1px solid var(--ink-300);
  border-radius: var(--radius);
  background: var(--white);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-600);
  cursor: pointer;
}

.q-tap.is-on {
  background: var(--ink-950);
  border-color: var(--ink-950);
  color: var(--paper);
  font-size: 1rem;
}

.q-bb .is-sure {
  color: var(--ink-950);
  font-weight: 500;
}

.q-bb .is-guess {
  color: var(--ink-500);
  text-decoration: line-through;
}

.q-bb .is-kept {
  color: var(--ink-950);
}

.q-bb .is-key {
  color: var(--spruce);
  font-weight: 500;
}

.q-bb .is-error {
  color: var(--paper);
  background: var(--ink-950);
}

.q-stats-controls {
  display: grid;
  gap: 1rem;
  justify-items: start;
}

.q-stats-controls .q-slider {
  grid-template-columns: 12rem minmax(0, 1fr) 4rem;
  max-width: 40rem;
}

.q-check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.75rem;
  font-size: 0.9375rem;
  cursor: pointer;
}

.q-check input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--spruce);
}

.q-select {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9375rem;
}

.q-select select {
  max-width: 100%;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border: 1px solid var(--ink-500);
  border-radius: var(--radius);
  background: var(--white);
  font: inherit;
}

/* --------------------------------------------------------------- footer --- */
.q-more__list {
  margin-top: 1rem;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
}

.q-more__list a {
  display: inline-block;
  padding: 0.6rem 0;
}

/* ----------------------------------------------------------- responsive --- */
@media (max-width: 39.9375em) {
  .q-slider,
  .q-stats-controls .q-slider {
    grid-template-columns: minmax(0, 1fr) 4rem;
  }

  .q-slider {
    row-gap: 0;
  }

  .q-slider > span {
    grid-column: 1 / -1;
  }

  .q-readout > div {
    grid-template-columns: 7rem minmax(0, 1fr);
  }

  .q-amptable td:nth-child(4) {
    width: auto;
    min-width: 5rem;
  }
}

/* After the rule above, which would otherwise win on the narrowest screens. */
@media (max-width: 22.5em) {
  .q-amptable td:nth-child(4) {
    min-width: 3.5rem;
  }
}

/* Where the sphere sits above the controls, keep it on screen while the
   reader presses gates. A grid item can only stick inside its own row, so
   the demo stacks as plain blocks here. */
@media (max-width: 56.1875em) {
  .q-demo:has(> .q-sphere) {
    display: block;
  }

  .q-demo > .q-sphere + .q-panel {
    margin-top: 1.5rem;
  }

  /* Put the gates, their actions, and the hole result just below the
     sphere, so a reader can press a gate and see the turn without a
     scroll. */

  .q-sphere + .q-panel > .q-gates-wrap {
    order: -3;
  }

  .q-sphere + .q-panel > .q-actions {
    order: -2;
  }

  .q-sphere + .q-panel > .q-result {
    order: -1;
  }

  .q-sphere {
    position: sticky;
    top: 0;
    z-index: 2;
    margin-inline: calc(-1 * var(--gutter));
    padding: 0.5rem var(--gutter);
    border-bottom: 1px solid var(--ink-200);
    background: var(--white);
  }

  .q-sphere canvas {
    max-width: min(15rem, 32svh);
  }

  .q-sphere figcaption {
    margin-top: 0.25rem;
  }

  /* The CHSH dial does the same while the reader moves the angle
     sliders under it. */

  .q-chsh {
    display: block;
  }

  .q-chsh > .q-dial {
    position: sticky;
    top: 0;
    z-index: 2;
    margin-inline: calc(-1 * var(--gutter));
    margin-bottom: 1.5rem;
    padding: 0.5rem var(--gutter);
    border-bottom: 1px solid var(--ink-200);
    background: var(--white);
  }

  .q-chsh > .q-dial svg {
    max-width: min(12rem, 28svh);
  }

  .q-chsh > .q-dial figcaption {
    margin-top: 0.25rem;
  }

  /* Keep a focused control clear of the sticky sphere or dial above it. */

  .q-sphere + .q-panel :is(a,
  button,
  input,
  select,
  summary,
  [tabindex="0"]) {
    scroll-margin-top: calc(min(15rem, 32svh) + 6rem);
  }

  .q-chsh > .q-dial ~ * :is(a,
  button,
  input,
  select,
  summary,
  [tabindex="0"]) {
    scroll-margin-top: calc(min(12rem, 28svh) + 5rem);
  }

  /* Bloch sphere golf: only the sphere stays on screen. Its caption scrolls
     away, which leaves more room for the hole. The hole's name and hint come
     first, so the reader sees the goal before the gates. */

  .q-sphere:has(> .q-sphere__stage) {
    position: static;
    display: contents;
  }

  .q-sphere__stage {
    position: sticky;
    top: 0;
    z-index: 2;
    margin-inline: calc(-1 * var(--gutter));
    padding: 0.5rem var(--gutter);
    border-bottom: 1px solid var(--ink-200);
    background: var(--white);
  }

  .q-sphere__stage canvas {
    max-width: min(15rem, 30svh);
  }

  .q-sphere:has(> .q-sphere__stage) figcaption {
    margin-top: 0.75rem;
  }

  .q-sphere:has(> .q-sphere__stage) + .q-panel {
    gap: 1rem;
  }

  .q-sphere:has(> .q-sphere__stage) + .q-panel > .q-panel__head {
    order: -5;
    scroll-margin-top: calc(min(15rem, 30svh) + 2rem);
  }

  .q-sphere:has(> .q-sphere__stage) + .q-panel > .q-panel__hint {
    order: -4;
  }

  .q-sphere:has(> .q-sphere__stage) + .q-panel :is(a,
  button,
  input,
  select,
  summary,
  [tabindex="0"]) {
    scroll-margin-top: calc(min(15rem, 30svh) + 2rem);
  }
}

/* A phone on its side has no height to spare above the controls, so the sphere
   sits beside them. */
@media (min-width: 30.0625em) and (max-width: 56.1875em) and (max-height: 30em) and (orientation: landscape) {
  .q-demo:has(> .q-sphere > .q-sphere__stage) {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: 1.5rem;
    align-items: start;
  }

  .q-sphere:has(> .q-sphere__stage) {
    position: sticky;
    top: 0.5rem;
    display: block;
    margin-inline: 0;
    padding: 0;
    border-bottom: 0;
  }

  .q-sphere__stage {
    position: static;
    margin-inline: 0;
    padding: 0;
    border-bottom: 0;
  }

  .q-sphere__stage canvas {
    max-width: min(15rem, 50svh);
  }

  .q-demo > .q-sphere:has(> .q-sphere__stage) + .q-panel {
    margin-top: 0;
  }

  .q-sphere:has(> .q-sphere__stage) + .q-panel > .q-panel__head,
  .q-sphere:has(> .q-sphere__stage) + .q-panel :is(a,
  button,
  input,
  select,
  summary,
  [tabindex="0"]) {
    scroll-margin-top: 1rem;
  }
}

@media (max-width: 39.9375em) {
  .q-panel__titlerow .q-panel__title {
    font-size: 1.75rem;
  }

  .q-panel__titlerow .btn {
    padding: 0.75rem 1rem;
  }

  .q-gates-wrap .q-gates {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* One row, so the actions take less of the room under the sphere. */
  .q-sphere:has(> .q-sphere__stage) + .q-panel > .q-actions {
    flex-wrap: nowrap;
    gap: 0.5rem;
  }

  .q-sphere:has(> .q-sphere__stage) + .q-panel > .q-actions .btn {
    flex: 1 1 0;
    padding-inline: 0.25rem;
    white-space: nowrap;
  }
}

@media (min-width: 40em) {
  .q-players {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .q-readout--row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 56.25em) {
  .q-demo--split {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 3rem;
  }

  /* Beside the controls, the sphere sits on its own darker paper panel. */
  .q-sphere__stage {
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--wash);
  }

  .q-players--three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .q-two {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 4rem;
  }
}

/* A touch screen has no arrow keys to tell the reader about. */
@media (hover: none) and (pointer: coarse) {
  .q-keys {
    display: none;
  }
}

/* ------------------------------------------------- explanation level --- */

/* Each explanation is on the page twice. Simple shows until the reader
   picks the technical one. */
html:not([data-q-level="technical"]) [data-level="technical"],
html[data-q-level="technical"] [data-level="simple"] {
  display: none !important;
}

/* A full-width strip on the bottom edge, so it reads as part of the window
   and not as a box over the content. The body keeps the same height free
   under the footer. */
.q-level {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: var(--q-level-height);
  padding: 0 var(--gutter);
  border-top: 1px solid var(--gold);
  background: var(--band-deep);
}

.q-level :focus-visible {
  outline-color: var(--paper);
}

/* The scroll padding keeps a focused control clear of the strip. */
html:has(.q-level) {
  --q-level-height: 3.25rem;
  scroll-padding-bottom: calc(var(--q-level-height) + 1rem);
}

body:has(.q-level:not([hidden])) {
  padding-bottom: var(--q-level-height);
}

/* The strip stays on one line on a 320px screen. */
@media (max-width: 23em) {
  .q-level {
    padding: 0 1rem;
  }
}

/* Paper has no switch, no part buttons, and no hidden parts. A fixed strip would
   also print on every sheet. */
@media print {
  .q-level,
  .q-parts,
  .q-pager {
    display: none;
  }

  body:has(.q-level:not([hidden])) {
    padding-bottom: 0;
  }

  .q-part[hidden] {
    display: block !important;
    content-visibility: visible !important;
  }
}

.q-level__label {
  margin-right: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--on-band-muted);
}

.q-level button {
  min-height: 2.5rem;
  padding: 0 0.9rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--paper);
  cursor: pointer;
}

.q-level button:hover {
  background: rgb(242 239 228 / 0.12);
}

.q-level button[aria-pressed="true"],
.q-level button[aria-pressed="true"]:hover {
  background: var(--paper);
  color: var(--band-deep);
}

/* ------------------------------------------------------- puzzle picker --- */
.q-pickrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.q-select--small select {
  min-height: 2.75rem;
  font-size: 0.875rem;
}

/* On a phone, the picker comes after the title, so its name does not repeat
   the title straight above or below it. */
@media (max-width: 39.9375em) {
  .q-panel__head:has(> .q-pickrow) {
    display: flex;
    flex-direction: column;
  }

  .q-panel__head > .q-pickrow {
    display: contents;
  }

  .q-pickrow > .q-select {
    order: 1;
    margin-top: 0.75rem;
  }

  .q-panel__head:has(> .q-pickrow) > .q-hint {
    order: 2;
  }
}

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

.q-rules__lead {
  margin-top: 1rem;
  max-width: 68ch;
  color: var(--ink-800);
}

.q-note [data-level] > * + * {
  margin-top: 1rem;
}

/* -------------------------------------------------------- notation key --- */
.q-notation summary {
  padding-block: 0.6rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--spruce);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.q-notation > div {
  margin-top: 0.75rem;
  max-width: 62ch;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink-700);
}

.q-notation p + p {
  margin-top: 0.6rem;
}

/* ------------------------------------------------------- putting green --- */
.q-practice {
  display: grid;
  gap: 1.25rem;
  justify-items: start;
}

.q-log {
  width: 100%;
}

.q-log__empty {
  margin-top: 0.75rem;
  font-size: 0.9375rem;
  color: var(--ink-600);
}

.q-log__list {
  margin-top: 0.75rem;
  list-style: none;
  display: grid;
  gap: 0.75rem;
}

.q-log__list > li {
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink-800);
}

/* The newest step carries the accent. */
.q-log__list > li:first-child {
  border-left: 4px solid var(--spruce);
}

.q-log__list > li > * + * {
  margin-top: 0.4rem;
}

.q-log__head {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-950);
}

.q-linkbutton {
  padding: 0.6rem 0;
  min-height: 2.75rem;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--spruce);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ------------------------------------------------------------ large text --- */

/* Under 20em wide, or 30em high, means a zoomed page or a very small screen. A
   pinned part would then fill the screen, so nothing is pinned. */
@media (max-width: 19.9375em), (max-height: 30em) {
  .q-level,
  .q-sphere,
  .q-sphere__stage,
  .q-bb-send,
  .q-chsh > .q-dial {
    position: static;
  }

  html:has(.q-level) {
    --q-level-height: 0px;
    scroll-padding-bottom: 0;
  }

  body:has(.q-level:not([hidden])) {
    padding-bottom: 0;
  }

  .q-level {
    min-height: 3.25rem;
  }
}

/* ------------------------------------------------------- forced colors --- */

/* Forced colors take away backgrounds and shadows, and those show the selected
   state here. System colors stay, so the state uses them. */
@media (forced-colors: active) {
  .q-gate[aria-pressed="true"],
  .q-gate[aria-pressed="true"]:hover:not(:disabled),
  .q-seg button[aria-pressed="true"],
  .q-level button[aria-pressed="true"],
  .q-toc.is-enhanced a[aria-current="true"] .q-parts__num,
  .q-sc__data[aria-pressed="true"],
  .q-tap.is-on,
  .q-ec__lamp.is-on,
  .q-sc__check.is-on {
    /* Or the browser puts a Canvas plate behind the text, as dark as the text. */
    forced-color-adjust: none;
    background: Highlight;
    border-color: Highlight;
    color: HighlightText;
  }

  .q-bb .is-error {
    outline: 2px solid CanvasText;
    outline-offset: -2px;
  }

  .q-gates-wrap:has(.q-tip:not([hidden])) .q-gate--suggest {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }

  .q-bar {
    border: 1px solid CanvasText;
  }

  .q-bar__fill {
    background: CanvasText;
  }

  .q-tip {
    border: 1px solid CanvasText;
  }

  .q-tip::after {
    display: none;
  }

  /* A diagram draws in ink and spruce, and its parts are not system colors. It
     keeps its own colors on a light ground, with its labels. */

  .q-chart svg,
  .q-chart svg text,
  .q-mz,
  .q-mz text,
  .q-dial svg,
  .q-dial svg text,
  .q-phasor {
    forced-color-adjust: none;
  }

  .q-chart svg,
  .q-mz,
  .q-dial svg,
  .q-phasor {
    background: var(--white);
  }

  .q-sc__wire {
    stroke: CanvasText;
  }
}
