[data-study-lab]:empty { display: none; }

[data-study-lab] {
  container-type: inline-size;
  color: var(--ink, #282d27);
  margin: 2rem 0 1rem;
  padding: 1.25rem 0 0;
  border-top: 1px solid #bdb4a5;
}

[data-study-lab] h3 {
  margin: 0;
  font: normal clamp(1.35rem, 4vw, 1.8rem)/1.2 Georgia, serif;
}

.study-lab-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  align-items: end;
  gap: .55rem 1rem;
}

.study-lab-controls label {
  display: grid;
  gap: .3rem;
  min-width: 0;
  font-size: .91rem;
  line-height: 1.3;
}

.study-lab-controls .study-lab-toggle {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: .55rem;
  min-height: 2.75rem;
  cursor: pointer;
}

.study-lab-controls:has(.study-lab-toggle):not(:has(select, input[type="range"])) {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 7.2rem), 1fr));
}

.study-lab-controls select {
  box-sizing: border-box;
  max-width: 100%;
  min-height: 2.75rem;
  padding: .45rem .3rem;
  font: inherit;
  font-size: max(1rem, 1em);
  color: #282d27;
  background: #fffdf6;
  border: 1px solid #736b60;
  border-radius: 3px;
}

.study-lab-controls input {
  accent-color: #9c4029;
}

.study-lab-controls input[type="checkbox"] {
  width: 1.3rem;
  height: 1.3rem;
  margin: 0;
}

.study-lab-controls .study-lab-slider {
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: .5rem;
}

.study-lab-controls input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 2.75rem;
  margin: 0;
  cursor: ew-resize;
}

.study-lab-value {
  color: #6e2b1d;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.study-lab-controls :is(input, select):focus-visible {
  outline: 2px solid #315f70;
  outline-offset: 3px;
}

 .study-lab-diagram { min-width: 0; }
.study-lab-diagram > svg { display: block; width: 100%; height: auto; }

.study-lab-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.study-lab-zoom { flex: 0 0 auto; }
.study-lab-controls { margin-top: 1.25rem; }
.study-lab-zoom button, .study-lab-viewer button {
  min-height: 2.75rem;
  padding: .45rem .75rem;
  border: 1px solid #8b7c6b;
  border-radius: 3px;
  background: var(--white, #fffdf6);
  color: #6e2b1d;
  font: inherit;
  cursor: pointer;
}
.study-lab-zoom button:focus-visible, .study-lab-viewer :focus-visible {
  outline: 2px solid #315f70;
  outline-offset: 3px;
}
.study-lab-result {
  color: #282d27;
  margin: 1rem 0 0;
  padding: .75rem 0 0;
  border-top: 1px solid #c9c0b0;
  font-size: .95rem;
  line-height: 1.45;
}
.study-lab-viewer {
  box-sizing: border-box;
  width: min(96vw, 1200px);
  max-width: none;
  max-height: 94dvh;
  padding: clamp(.6rem, 2vw, 1.25rem);
  border: 1px solid #8b7c6b;
  background: var(--paper, #f5efe3);
  color: #282d27;
  overflow: auto;
}
.study-lab-viewer::backdrop { background: rgba(27, 26, 23, .7); }
.study-lab-viewer-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .75rem;
  font: .9rem/1.35 system-ui, sans-serif;
}
.study-lab-viewer-tools span { flex: 1 1 13rem; }
.study-lab-viewport {
  max-height: calc(94dvh - 10rem);
  min-height: 3rem;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
  background: var(--white, #fffdf6);
}
.study-lab-viewport.is-enlarged .study-lab-diagram {
  width: 100%;
  zoom: 2;
}
@media print {
  [data-study-lab] .study-lab-controls, .study-lab-zoom, .study-lab-viewer { display: none; }
}

/* Give the exercise its own spread while keeping the article column narrow. */
@media screen and (min-width: 52rem) {
  .study-experiment:has([data-study-lab]:not(:empty)) {
    position: relative;
    left: 50%;
    width: min(60rem, calc(100vw - 4rem));
    transform: translateX(-50%);
  }
}

/* WebKit's native menulist caps its painted height; keep the native picker and give it a full touch target. */
.study-lab-controls select {
  appearance: none;
  -webkit-appearance: none;
  padding-inline: .6rem 2.2rem;
  background-image: linear-gradient(45deg, transparent 50%, #263d32 50%), linear-gradient(135deg, #263d32 50%, transparent 50%);
  background-position: calc(100% - 1rem) 50%, calc(100% - .7rem) 50%;
  background-size: .3rem .3rem;
  background-repeat: no-repeat;
}
.study-lab-player { display: flex; flex-wrap: wrap; align-items: end; gap: .5rem 1rem; margin: 0 0 1rem; }
.study-lab-player button, .study-lab-player select { min-height: 2.75rem; font: inherit; }
.study-lab-player button { padding: .5rem .8rem; border: 1px solid #8b7c6b; border-radius: 3px; color: #6e2b1d; background: #fffdf6; cursor: pointer; }
.study-lab-player label { display: grid; gap: .3rem; font-size: .91rem; }
.study-lab-player select { appearance: none; -webkit-appearance: none; padding: .45rem 2.2rem .45rem .6rem; border: 1px solid #736b60; border-radius: 3px; color: #282d27; background-color: #fffdf6; background-image: linear-gradient(45deg, transparent 50%, #263d32 50%), linear-gradient(135deg, #263d32 50%, transparent 50%); background-position: calc(100% - 1rem) 50%, calc(100% - .7rem) 50%; background-size: .3rem .3rem; background-repeat: no-repeat; }
.study-lab-player :is(button, select):focus-visible { outline: 2px solid #315f70; outline-offset: 3px; }
.lab-sound-notice, .lab-sound-indicator { font-size: .85rem; color: #4e6155; }
@media print { .study-lab-player { display: none; } }
