/* Superposition Lab (/labs/superposition/): the instrument screen, the scene tabs and the control panels.
   Every colour, face and step comes from site.css tokens; the screen itself is always forest. */
@layer pages {
  .sl { padding-bottom: var(--s9); }
  .sl .hub-head { margin-bottom: var(--s5); }
  .sl .hub-head .meta a { display: inline-block; min-width: 44px; }
  /* Phones: three equal tabs on one row, two lines each, so the row never wraps unevenly. */
  .sl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-bottom: var(--s5); }
  .sl-tabs { flex: 1 1 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
  #sl-play:not([data-set]) { visibility: hidden; }
  .sl-tab.sl-btn { white-space: normal; text-align: center; padding: 6px 10px; min-height: 52px; border-radius: 26px; }

  /* Pills in the chart control's shape; the quiet form is an outline. */
  .sl-btn {
    display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px;
    border-radius: 999px; background: var(--btn-bg); color: var(--btn-fg);
    font-size: 14px; font-weight: 600; line-height: 1.2; white-space: nowrap;
    box-shadow: 0 1px 2px var(--btn-shade), 0 8px 20px -10px var(--btn-shade);
    transition: var(--tr-btn);
    -webkit-tap-highlight-color: transparent;
  }
  .sl-btn:active { transform: scale(.98); }
  .sl-btn.is-quiet, .sl-btn[aria-pressed="false"], .sl-btn[aria-selected="false"] {
    background: transparent; color: var(--fg); box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 38%, transparent);
  }
  /* Hover only where a pointer can hover, so a tapped pill does not keep the hover colour on a phone. */
  @media (hover: hover) {
    .sl-btn:not([aria-disabled="true"]):hover { background: var(--btn-hover); transform: translateY(-1px); }
    .sl-btn.is-quiet:not([aria-disabled="true"]):hover, .sl-btn[aria-pressed="false"]:hover, .sl-btn[aria-selected="false"]:hover { background: var(--wash); }
  }
  .sl-btn[aria-disabled="true"] { opacity: .45; cursor: default; transform: none; }
  /* The detector is a switch: a track and a knob ahead of its name. */
  .sl-switch { gap: 10px; padding-left: 12px; white-space: normal; }
  .sl-switch::before {
    content: ""; flex: none; width: 36px; height: 20px; border-radius: 999px;
    background: radial-gradient(circle at 10px 50%, var(--paper) 7px, transparent 7.5px) color-mix(in srgb, currentColor 38%, transparent);
    transition: var(--tr-btn);
  }
  .sl-switch[aria-checked="true"]::before { background: radial-gradient(circle at 26px 50%, var(--paper) 7px, transparent 7.5px) var(--accent); }

  /* Below 1024 the screen is a direct grid child, so it can stay in view while the controls scroll under it. */
  .sl-lab { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); align-items: start; }
  .sl-left { display: contents; }
  .sl-stage {
    width: 100%; background: var(--forest); border-radius: 4px; overflow: hidden;
    aspect-ratio: var(--sl-ar, 2.357); max-height: 44svh; box-shadow: 0 0 0 var(--s2) var(--paper);
    position: sticky; top: var(--s2); z-index: 5;
  }
  .sl-stage[data-scene="slits"] { --sl-ar: 2.357; }
  .sl-stage[data-scene="worlds"] { --sl-ar: 1.15; }
  .sl-stage[data-scene="halo"] { --sl-ar: 1; }
  /* The canvas keeps its scene's shape inside the screen, so a short screen (a phone on its side) letterboxes it
     and the screen itself still covers the column. The dark-matter view is square. */
  .sl-stage { container-type: size; }
  .sl-stage canvas { position: absolute; inset: 0; margin: auto; display: block; width: min(100cqw, calc(100cqh * var(--sl-ar, 2.357))); height: min(100cqh, calc(100cqw / var(--sl-ar, 2.357))); }
  /* Touch keeps vertical page scroll; a sideways drag throws. */
  .sl-stage[data-scene="halo"] canvas { width: min(100cqw, 100cqh); height: min(100cqw, 100cqh); touch-action: pan-y; cursor: crosshair; }
  .sl-state, .sl-status {
    position: absolute; left: var(--s2); margin: 0; padding: 4px 10px; border-radius: 999px; pointer-events: none;
    background: color-mix(in srgb, var(--forest) 82%, transparent); color: var(--ivory);
    font-family: var(--mono); font-size: var(--small); line-height: 1.2;
  }
  .sl-state { top: var(--s2); letter-spacing: .06em; text-transform: uppercase; }
  .sl-state[hidden] { display: none; }
  .sl-status { bottom: var(--s2); max-width: calc(100% - 2 * var(--s2)); opacity: 0; transition: opacity var(--t2) var(--ease); }
  .sl-status.is-on { opacity: 1; }
  .sl-panels { margin-top: var(--s3); }
  .sl-stage noscript { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s4); color: var(--ivory); font-size: var(--small); text-align: center; }
  /* Phones: the button, then the caption at full width. From 640 they sit side by side. */
  .sl-transport { display: grid; justify-items: start; gap: var(--s3); }
  .sl-caption { color: var(--fg-2); font-size: 16px; line-height: var(--small-lh); min-width: 0; max-width: 60ch; }

  .sl-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
  .sl-head { display: grid; justify-items: start; gap: var(--s3); }
  .sl-head h2 { font-family: var(--display); font-size: var(--d2s); line-height: 1.02; letter-spacing: -.02em; }
  .sl-chip {
    font-family: var(--mono); font-size: var(--small); letter-spacing: .06em; text-transform: uppercase; line-height: 1.2;
    color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: 4px 10px;
  }
  .sl-panel > p { max-width: 36em; }
  .sl-panel > .sl-aside, .sl-note { color: var(--fg-2); font-size: 16px; line-height: var(--small-lh); }
  /* Each part of a scene's panel rises in when its tab is chosen. */
  .sl-panel:not([hidden]) > * { animation: sl-in var(--t3) var(--ease) backwards; }
  .sl-panel > :nth-child(2) { animation-delay: 60ms; }
  .sl-panel > :nth-child(3) { animation-delay: 120ms; }
  .sl-panel > :nth-child(n+4) { animation-delay: 180ms; }
  @keyframes sl-in { from { opacity: 0; translate: 0 12px; } }
  .sl-controls { background: var(--field); border-radius: 4px; padding: var(--s4); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
  .sl-row { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); align-items: center; }
  .sl-field { display: grid; gap: 0; }
  .sl-field label { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); font-size: 16px; font-weight: 500; }
  .sl-field output, .sl-read dd { font-family: var(--mono); font-size: var(--small); }
  .sl-field output { color: var(--fg-2); }
  .sl-field input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); }
  /* The readouts sit on a paper inset: a tone step, no rule. */
  .sl-read { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2) var(--s4); font-size: 16px; line-height: 1.4; background: var(--paper); border-radius: 4px; padding: var(--s3) var(--s4); }
  .sl-read dt { color: var(--fg-2); }
  .sl-read dd { text-align: end; align-self: center; }
  .sl-foot { color: var(--fg-2); font-size: 16px; line-height: var(--small-lh); margin-top: var(--s8); max-width: 60ch; }

  @media (min-width: 640px) {
    .sl-bar { margin-bottom: var(--s6); }
    .sl-tabs { flex: 0 1 auto; display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); }
    #sl-play { margin-inline-start: auto; }
    .sl-tab.sl-btn { white-space: nowrap; padding: 0 20px; min-height: 44px; border-radius: 999px; }
    .sl-stage[data-scene="worlds"] { --sl-ar: 1.7; }
    .sl-controls { padding: 20px; }
    .sl-transport { display: flex; gap: var(--s4); align-items: flex-start; }
  }
  @media (min-width: 1024px) {
    .sl-lab { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: var(--s7); }
    .sl-left { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); position: sticky; top: var(--s5); }
    .sl-stage { position: relative; top: auto; max-height: none; box-shadow: none; }
    .sl-stage[data-scene="halo"] { --sl-ar: 1.25; }
    .sl-panels { margin-top: 0; }
  }
  @media (prefers-reduced-motion: reduce) {
    .sl-btn, .sl-switch::before, .sl-status { transition: none; }
    .sl-panel:not([hidden]) > * { animation: none; }
    .sl-btn:hover, .sl-btn:active { transform: none; }
  }
  /* High contrast: the chosen tab, the pressed reading and the switch when on use the system highlight. */
  @media (forced-colors: active) {
    .sl-btn { border: 1px solid ButtonText; }
    .sl-btn[aria-selected="true"], .sl-btn[aria-pressed="true"], .sl-switch[aria-checked="true"] { background: Highlight; color: HighlightText; forced-color-adjust: none; }
    .sl-switch::before { forced-color-adjust: none; background: radial-gradient(circle at 10px 50%, Canvas 7px, transparent 7.5px) ButtonText; }
    .sl-switch[aria-checked="true"]::before { background: radial-gradient(circle at 26px 50%, Highlight 7px, transparent 7.5px) HighlightText; }
    .sl-btn[aria-disabled="true"] { color: GrayText; border-color: GrayText; }
  }
}
