/* ==========================================================================
   The homepage's third screen, "Hear it, then fix what's off" (home-hear.js; the score and the bubble's markup from
   scripts/home_examples.py, hear_block). The workspace's own score stage, in the workspace's own values: the paper on
   its ground, the floating video window (apps/app/shared/ui.css .video-window), the glass player pill
   (apps/app/workspace/style.css .score .player), the playing note and its line in --play, the selected note in
   --select, and the pitch readout beside the selection controls.
   The heading, the stage and the two steps fill one window: the score's width follows the window's height.
   ========================================================================== */
.hh {
  /* The workspace's values (ui.css), here under names of their own. */
  --hh-play: #c27c0e;
  --hh-select: #e8501a;
  --hh-shadow-pop: 0 12px 32px -14px rgba(15, 14, 18, 0.3), 0 0 0 1px rgba(15, 14, 18, 0.08);
  /* The frame around the score: the section's padding, the gaps, the band over the score (title and bubble) and the
     band under it (the player); what is left of the window's height is the score's. */
  --hh-pad: clamp(12px, 2svh, 22px);
  --hh-gap: clamp(10px, 1.8svh, 18px);
  --hh-h2: var(--hm-h2);
  --hh-ground: 8px;
  --hh-band: 108px;
  --hh-under: 64px;
  --hh-foot: 44px;
  --hh-wide-ratio: 0.3513; /* the wide drawing, 527 / 1500 */
  --hh-ratio: var(--hh-wide-ratio);
  --hh-top: var(--nav-h, 72px);
  --hh-fixed: calc(
    var(--hh-top) +
    2 *
    var(--hh-pad) +
    var(--hh-h2) +
    2 *
    var(--hh-gap) +
    var(--hh-foot) +
    2 *
    var(--hh-ground) +
    var(--hh-band) +
    var(--hh-under) +
    8px
  );
  padding-block: var(--hh-pad);
}
.hh-in {
  display: grid;
  gap: var(--hh-gap);
}
.hh .hm-h2 {
  height: var(--hh-h2);
  line-height: 1;
  white-space: nowrap;
}

/* ── The stage: the ground, the paper and the window floating over its corner ──────────────────────────────────── */
.hh-stage {
  position: relative;
}
.hh-desk {
  position: relative;
  padding: var(--hh-ground);
  border-radius: 16px;
  background: var(--lg-ground);
}
.hh-paper {
  position: relative;
  display: grid;
  grid-template-rows: var(--hh-band) auto var(--hh-under);
  justify-items: center;
  border-radius: 12px;
  background: var(--lg-paper, #fdfdfc);
  box-shadow: var(--lg-object-shadow);
  --hh-w: min(100% - 56px, (100svh - var(--hh-fixed)) / var(--hh-ratio));
}
/* The title on the score's left edge: the bubble comes out beside it, the window stands opposite. */
.hh-head {
  display: grid;
  justify-items: start;
  align-content: start;
  gap: 2px;
  box-sizing: border-box;
  width: var(--hh-w);
  margin: 0;
  padding: 16px 0 0 8px;
}
.hh-title,
.hh-by,
.hh-moment {
  margin: 0;
}
.hh-title {
  font: 600 22px / 1.15 var(--serif);
  color: var(--ink);
}
.hh-by {
  font: 400 14px / 1.3 var(--serif);
  color: var(--muted);
}
.hh-moment {
  margin-top: 6px;
  font: 500 12px / 18px var(--sans);
  color: var(--muted);
}
.hh-moment span {
  display: none;
  padding: 2px 8px;
  border-radius: 999px;
}
.hh-stage[data-draft] [data-moment="draft"] {
  display: inline-block;
  background: var(--accent-tint, rgba(232, 80, 26, 0.12));
  color: var(--accent-text, #c23b0d);
}
.hh-stage[data-corrected] [data-moment="done"] {
  display: inline-block;
  background: rgba(47, 111, 219, 0.12);
  color: var(--ai-mark, #2f6fdb);
}
.hh-score {
  position: relative;
  width: var(--hh-w);
  min-width: 0;
}
.hh-score .engraved {
  display: block;
}
.hh-score .engraved[data-layout="narrow"] {
  display: none;
}

/* The playing notes and the line, as the workspace draws them (ui.css .playing-note, .play-cursor). */
.hh-score .engraved .note {
  transition: transform 0.2s var(--ease-settle);
}
.hh-score .engraved .note[data-id="e4"],
.hh-score .engraved .note[data-id="e4-tab"],
.hh-score .engraved g.hh-draft {
  cursor: pointer;
}
.hh-score .engraved .is-selected {
  color: var(--hh-select);
  fill: var(--hh-select);
}
.hh-score .engraved .note.is-playing {
  color: var(--hh-play);
  fill: var(--hh-play);
}
.hh-line {
  position: absolute;
  top: 0;
  left: 0;
  width: 2.5px;
  height: 100px;
  border-radius: 2px;
  background: var(--hh-play);
  opacity: 0;
  pointer-events: none;
  transform-origin: 0 0;
  will-change: transform;
}
.hh-line.is-on {
  opacity: 0.9;
}

.hh-score .engraved .dir text {
  font-family: var(--sans);
  font-weight: 500;
  fill: var(--muted);
}
/* The draft's fret replaces the corrected fret only while the draft is shown. */
.hh-score .hh-draft {
  opacity: 0;
}
.hh-stage[data-draft] .hh-score .hh-draft {
  opacity: 1;
}
.hh-stage[data-draft] .hh-score .hh-fixed {
  opacity: 0;
}
.hh-stage[data-draft] .hh-score .note[data-fix-drop] {
  transform: translateY(calc(var(--hh-drop, 90) * 1px));
}

/* The floating video window (ui.css .video-window): black, 12px round, the pop shadow; it follows the player. Over
   the paper's top corner, rising past the stage's edge beside the heading, so no note it could hide is under it. */
.hh-video {
  --hh-video-h: calc(var(--hh-h2) + var(--hh-gap) + var(--hh-ground) + var(--hh-band) - 12px);
  position: absolute;
  z-index: 3;
  top: calc(-1 * (var(--hh-h2) + var(--hh-gap)));
  right: 24px;
  width: var(--hh-video-h);
  /* Keep the performer and both hands in the left 336px of the 640px source, clear of the baked-in title. */
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 12px;
  background: var(--layer-2);
  box-shadow: var(--hh-shadow-pop);
  cursor: pointer;
}
.hh-video > :is(img, video) {
  position: absolute;
  top: -12%;
  left: 0;
  width: auto;
  max-width: none;
  height: calc(100% * 480 / 336);
}
.hh-video video {
  opacity: 0;
}
.hh-stage[data-media-ready] .hh-video video {
  opacity: 1;
}
.hh-video-sound {
  --hh-sound-inset: 5px;
  position: absolute;
  right: 3px;
  bottom: 3px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: #fbfbf9;
  cursor: pointer;
}
.hh-video-sound::before {
  content: "";
  position: absolute;
  inset: var(--hh-sound-inset);
  border-radius: 50%;
  background: rgba(15, 14, 18, 0.72);
}
.hh-video-sound:hover::before {
  background: rgba(15, 14, 18, 0.9);
}
.hh-video-sound[aria-pressed="true"]::before {
  background: var(--accent);
}
.hh-stage[data-playing] .hh-video-sound::after {
  content: "";
  position: absolute;
  top: calc(var(--hh-sound-inset) + 2px);
  right: calc(var(--hh-sound-inset) + 2px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hh-play);
  box-shadow: 0 0 0 2px var(--white);
}
.hh-video-sound svg {
  position: relative;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── The player: the workspace's glass pill near the paper's foot ──────────────────────────────────────────────── */
.hh-player {
  position: absolute;
  z-index: 2;
  bottom: 12px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 12px;
  box-sizing: border-box;
  min-height: 56px;
  padding: 4px 16px 4px 6px;
  border-radius: 999px;
  background: var(--lg-glass);
  -webkit-backdrop-filter: var(--lg-blur);
  backdrop-filter: var(--lg-blur);
  box-shadow: var(--lg-glass-shadow);
  transform: translateX(-50%);
}
.hh-stage[data-playing] .hh-seek-marker::before {
  background: var(--hh-play);
  box-shadow: 0 0 0 3px rgba(194, 124, 14, 0.22);
}
.hh-play {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--layer-2);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s;
}
.hh-play:hover {
  background: var(--fill-strong);
}
.hh-play:active {
  transform: scale(0.93);
}
.hh-play:focus-visible,
.hh-seek:focus-within,
.hh-chip:focus-visible,
.hh-video-sound:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}
.hh-play svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}
.hh-play use[href="#hh-i-play"] {
  transform: translateX(1px);
}
.hh-seek {
  position: relative;
  flex: none;
  width: clamp(96px, 12vw, 160px);
  height: 44px;
  border-radius: 6px;
}
.hh-seek input {
  position: absolute;
  inset: 0;
  appearance: none;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}
.hh-seek input::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
}
.hh-seek input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
}
.hh-seek-track {
  position: absolute;
  inset-inline: 0;
  top: 50%;
  height: 4px;
  border-radius: 999px;
  background: var(--layer-2);
  transform: translateY(-50%);
  pointer-events: none;
}
.hh-seek-marker {
  position: absolute;
  inset: 0 7px;
  will-change: transform;
}
.hh-seek-marker::before {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--hh-select);
  transform: translate(-50%, -50%);
  content: "";
}
.hh-video-status {
  position: absolute;
  right: 12px;
  bottom: 12px;
  max-width: 18ch;
  margin: 0;
  font: 500 13px / 1.4 var(--sans);
  color: var(--muted);
  text-wrap: pretty;
}
.hh-time {
  flex: none;
  font: 500 12px / 1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

/* SelectionTools.tsx and ui.css give the note its orange selection and the open pitch row. */
.hh-bubble {
  position: absolute;
  z-index: 2;
  top: calc(var(--hh-band) - 8px);
  left: var(--hh-note-x, 50%);
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(344px, calc(100% - 24px));
  transform: translate(-50%, -100%);
}
.hh-stage[data-step="play"] .hh-bubble {
  visibility: hidden;
}
.hh-stage[data-draft] .hh-ask {
  animation: hh-bubble-in 0.24s var(--ease-settle) both;
}
@keyframes hh-bubble-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}
.hh-ask {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  box-sizing: border-box;
  padding: 3px 12px 3px 3px;
  border-radius: 999px;
  background: var(--layer-1);
  color: var(--ink);
}
.hh-bird {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  margin: 1px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--ring);
}
.hh-mascot {
  width: 19px;
  height: 19px;
  fill: #0f0e12;
}
.hh-mascot .hh-eye {
  fill: #fbfbf9;
}
.hh-mascot .hh-pupil {
  fill: #141414;
}
.hh-ask-text {
  display: inline-flex;
  align-items: center;
  font: 600 13px / 1 var(--sans);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.hh-ask-text [data-note] {
  display: none;
}
.hh-stage[data-draft] .hh-ask-text [data-note="draft"] {
  display: inline;
  color: var(--accent-text);
}
.hh-stage[data-corrected] .hh-ask-text [data-note="done"] {
  display: inline;
  color: var(--ai-mark, #2f6fdb);
}
.hh-chip svg.line {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.hh-chips {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hh-chips[hidden] {
  display: none;
}
.hh-chip {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--layer-2);
  color: var(--ink);
  cursor: pointer;
  transition:
    background-color 0.14s,
    color 0.14s,
    transform 0.12s;
}
.hh-chip:active,
.hh-chip.is-pressed {
  transform: scale(0.92);
  background: var(--ink);
  color: var(--paper);
}
.hh-chip svg {
  fill: currentColor;
  pointer-events: none;
}
.hh-chip svg.filled {
  width: 16px;
  height: 16px;
}
.hh-chip svg.accidental {
  width: 13px;
  height: 19px;
}
.hh-chip.hh-open {
  display: inline-flex;
  gap: 6px;
  width: auto;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--layer-2);
  color: var(--ink);
  font: 500 14px / 1 var(--sans);
}
.hh-chip:hover {
  box-shadow: inset 0 0 0 1px var(--hair-strong);
}
.hh-chip.hh-open svg.back {
  width: 14px;
  height: 14px;
}

/* ── The two steps and the credit ──────────────────────────────────────────────────────────────────────────────── */
.hh-foot {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: var(--hh-foot);
}
/* The workspace's segmented switch: a round track, the current step on paper with an inset ring. */
.hh-steps {
  display: flex;
  padding: 2px;
  border-radius: 999px;
  background: var(--layer-2);
}
.hh-steps button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px 0 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  font: 500 14px / 1 var(--sans);
  color: var(--muted);
  cursor: pointer;
  transition:
    background-color 0.15s,
    color 0.15s,
    box-shadow 0.15s;
}
.hh-steps button:hover {
  color: var(--ink);
}
.hh-steps button[aria-pressed="true"] {
  background: #fff;
  color: var(--ink);
  box-shadow:
    inset 0 0 0 1px rgba(15, 14, 18, 0.08),
    0 1px 2px rgba(15, 14, 18, 0.06);
}
.hh-steps button:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}
.hh-steps svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.hh-steps svg.accidental {
  width: 12px;
  fill: currentColor;
  stroke: none;
}
.hh-steps button[aria-pressed="true"] svg {
  color: var(--accent);
}
.hh-credit {
  position: absolute;
  right: 0;
  display: flex;
  gap: 0;
  margin: 0;
  font: 400 13px / 1.3 var(--sans);
}
.hh-credit a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: 6px;
  color: var(--muted);
  text-decoration: none;
}
.hh-credit a:hover {
  color: var(--ink);
}
.hh-credit a:focus-visible {
  outline: none;
  border-radius: 4px;
  box-shadow: var(--ring-focus);
}

/* ── Phones: the narrow drawing (two lines), the window in the paper's top corner beside the title, the bubble's
   circles at the paper's foot in the player's place (a phone's workspace docks the bubble above its player) ─────── */
@media (max-width: 759.98px) {
  .hm-part.hh {
    --hh-pad: 12px;
    --hh-gap: 12px;
    --hh-ground: 6px;
    --hh-band: 92px;
    --hh-under: 112px;
    --hh-ratio: 1.2575; /* the narrow drawing, 1006 / 800 */
    --hh-fixed: calc(
      var(--hh-top) +
      2 *
      var(--hh-pad) +
      var(--hh-h2) +
      2 *
      var(--hh-gap) +
      var(--hh-foot) +
      44px +
      2 *
      var(--hh-ground) +
      var(--hh-band) +
      var(--hh-under) +
      22px
    );
    padding-bottom: var(--hh-pad);
  }
  .hh-paper {
    --hh-w: min(100% - 20px, (100svh - var(--hh-fixed)) / var(--hh-ratio));
    --hh-player-room: 68px;
    grid-template-rows:
      var(--hh-band) auto minmax(calc(var(--hh-under) - var(--hh-player-room)), auto)
      var(--hh-player-room);
  }
  .hh-head {
    padding: 8px 0 0 8px;
  }
  .hh-title {
    font-size: 19px;
  }
  .hh-by {
    font-size: 13px;
  }
  .hh-score .engraved[data-layout="wide"] {
    display: none;
  }
  .hh-score .engraved[data-layout="narrow"] {
    display: block;
  }
  .hh-video {
    width: 80px;
    top: calc(var(--hh-ground) + 8px);
    right: calc(var(--hh-ground) + 8px);
  }
  .hh-video-sound {
    --hh-sound-inset: 8px;
    right: 0;
    bottom: 0;
  }
  .hh-video-sound:focus-visible {
    box-shadow: none;
  }
  .hh-video-sound:focus-visible::before {
    box-shadow: var(--ring-focus);
  }
  .hh-video-sound svg {
    width: 14px;
    height: 14px;
  }
  .hh-player {
    bottom: 10px;
  }
  .hh-seek {
    width: 96px;
  }
  .hh-bubble {
    position: static;
    grid-row: 3;
    align-self: start;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
    margin-top: var(--space-1);
    padding-inline: 8px;
    transform: none;
  }
  .hh-ask {
    gap: var(--space-1);
    padding-inline-end: var(--space-2);
  }
  .hh-chip.hh-open {
    padding-inline: var(--space-2);
  }
  .hh-video-status {
    right: 8px;
    bottom: auto;
    top: 8px;
    z-index: 4;
    color: var(--paper);
    background: var(--ink);
    padding: 6px;
    border-radius: 6px;
  }
  .hh-foot {
    flex-direction: column;
    gap: 0;
  }
  .hh-credit {
    position: static;
    min-height: 44px;
    align-items: center;
  }
}

/* The checked one-system score can use nearly the full paper on a short phone. */
@media (max-width: 759.98px) and (max-height: 640px) {
  .hm-part.hh {
    --hh-pad: 8px;
    --hh-gap: 8px;
    --hh-band: 82px;
    --hh-under: 98px;
    --hh-ratio: var(--hh-wide-ratio);
  }
  .hh-score .engraved[data-layout="wide"] {
    display: block;
  }
  .hh-score .engraved[data-layout="narrow"] {
    display: none;
  }
  .hh-video {
    top: calc(var(--hh-ground) + 4px);
    width: 72px;
  }
  .hh-player {
    bottom: 4px;
    min-height: 48px;
    padding-block: 2px;
  }
}

/* Reduced motion: the end frame, at once (home-hear.js plays nothing by itself). */
@media (prefers-reduced-motion: reduce) {
  .hh-score .engraved .note,
  .hh-chip {
    transition: none;
  }
  .hh-stage[data-draft] .hh-ask {
    animation: none;
  }
}

@media (forced-colors: active) {
  .hh :is(button, input, a):focus-visible,
  .hh-seek:focus-within {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
  .hh .hh-video-sound:focus-visible {
    outline-offset: -4px;
  }
  .hh-seek-track,
  .hh-seek-marker::before {
    forced-color-adjust: none;
    background: GrayText;
  }
  .hh-seek-marker::before {
    background: Highlight;
  }
}
