/*
  The music maker page. Everything here references the shared tokens
  (assets/css/tokens.css), so the page follows the site theme, pinned
  or from the system, with no second palette to keep in sync.
*/

/* The controls sit in labelled groups, so the flow reads top to
   bottom: play, pick a song, take it away. Group labels take the
   muted small voice the facts list uses for its keys. */
.music-transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--step) / 2);
  margin-block: var(--step) calc(var(--step) / 2);
}

.music-group {
  display: flex;
  align-items: baseline;
  gap: calc(var(--step) / 2);
  margin-block-end: calc(var(--step) / 2);
}

.music-group__label {
  flex: none;
  width: 5.5rem;
  color: var(--muted-color);
  font-size: var(--text-small);
}

.music-group--stack {
  flex-direction: column;
  align-items: stretch;
  gap: calc(var(--step) / 4);
}

.music-group--stack .music-group__label {
  width: auto;
}

/* The song picker: a list, not a field of buttons. One row per
   song, grouped by game, the whole row a button. Thirteen rows
   would push the player far down a phone page, so the list
   keeps a capped height and scrolls inside its own frame; the
   current row is scrolled into view whenever the song changes.
   The current song wears the same accent fill as the page's
   other pressed buttons. */
.songlist {
  flex: 1 1 auto;
  min-width: 0;
  max-height: calc(var(--step) * 11);
  overflow-y: auto;
  border: 1px solid var(--page-rule);
  background: var(--page-subtle);
}

.songlist__group {
  margin: 0;
  padding: calc(var(--step) / 2) var(--step-half) calc(var(--step) / 4);
  color: var(--muted-color);
  font-size: var(--text-caption);
}

.songrow {
  display: block;
  width: 100%;
  padding: calc(var(--step) / 4) var(--step-half);
  background: none;
  border: none;
  border-top: 1px solid var(--page-rule);
  color: inherit;
  font: inherit;
  font-size: var(--text-small);
  text-align: left;
  cursor: pointer;
}

.songrow__title {
  display: block;
}

.songrow__meta {
  display: block;
  color: var(--muted-color);
  font-size: var(--text-caption);
}

.songrow:hover .songrow__title {
  color: var(--accent-color);
}

.songrow:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: -2px;
}

.songrow[aria-current="true"] {
  background: var(--accent-color);
  color: var(--inverted-color);
}

.songrow[aria-current="true"] .songrow__meta {
  color: var(--inverted-color);
}

.songrow[aria-current="true"]:hover .songrow__title {
  color: var(--inverted-color);
}

/* The selected song's facts, split out of the song text: name,
   game, system and year from the text's first line, and the
   key and time its second line leads with, when it leads with
   them. Nothing else from the header prose is shown here. */
.songfacts p {
  margin: 0;
  font-size: var(--text-small);
}

.songfacts__name {
  font-weight: 700;
}

.songfacts__meta,
.songfacts__key {
  color: var(--muted-color);
}

.music-tempo {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--step) / 2);
  margin-inline-start: auto;
}

.music-tempo__label {
  color: var(--muted-color);
  font-size: var(--text-small);
}

/* Fixed width, so the buttons either side never shift as the
   number changes. */
.music-tempo__value {
  min-width: 7ch;
  text-align: center;
  font-size: var(--text-small);
}

.music-btn {
  font: inherit;
  font-size: var(--text-small);
  line-height: var(--step);
  padding: 0 calc(var(--step) / 2);
  background: var(--page-subtle);
  color: var(--page-color);
  border: 1px solid var(--page-rule);
  cursor: pointer;
  /* Rapid taps on the tempo buttons are a rhythm, not a zoom:
     manipulation keeps the taps and drops the double-tap zoom. */
  touch-action: manipulation;
}

.music-btn:hover,
.music-btn:focus-visible {
  background: var(--accent-color);
  color: var(--inverted-color);
  border-color: var(--accent-color);
}

.music-btn[aria-pressed="true"] {
  background: var(--accent-color);
  color: var(--inverted-color);
  border-color: var(--accent-color);
}

/* Play is the one primary action: wider, bold, and bordered in the
   accent before it is ever pressed. */
.music-btn--play {
  font-weight: 700;
  padding-inline: var(--step);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.music-btn--play:hover,
.music-btn--play:focus-visible,
.music-btn--play[aria-pressed="true"] {
  background: var(--accent-color);
  color: var(--inverted-color);
}

.music-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.music-status {
  min-height: var(--step);
  margin-block: 0 calc(var(--step) / 2);
  color: var(--muted-color);
  font-size: var(--text-small);
}

.music-status.is-error {
  color: light-dark(#b3261e, #f2b8b5);
}

/* The same line, repeated above the song text: a problem with the
   text is reported where the text is, not only up by the grid. It
   keeps its step of height while empty so the text never jumps. */
.music-status--text {
  margin-block: 0 calc(var(--step) / 2);
}

/* The grid panel: the same page-rule frame the portrait and the
   meadow use. The grid itself can outgrow the text column on narrow
   screens, so the panel scrolls sideways rather than squeezing. */
.music-panel {
  border: 1px solid var(--page-rule);
  background: var(--page-subtle);
  padding: var(--step-half);
  overflow-x: auto;
}

/* The grid column hugs the widest strip, which makes it
   the song's full width rather than one panel width. The
   strips were already that wide and overflowed to exactly
   this extent, so the panel scrolls exactly as far as it
   did; what changes is the channel headers' containing
   block, which is now the whole song, the range their
   sticky pin needs (see .gchan). */
.music-panel > [data-grid] {
  width: max-content;
}

.gchan {
  display: flex;
  align-items: baseline;
  gap: calc(var(--step) / 2);
  margin-block-start: var(--step-half);
  font-size: var(--text-small);
  /* The header hugs its text and sticks at the panel's
     content inset, the same pin as the pitch labels below
     it, so the channel and its instruments stay readable
     at the left edge for the whole scroll, however far the
     playhead's follow has travelled. Nothing passes under
     it (the header has its own row), so it needs no
     background of its own. Its range is the grid column,
     which is the song's full width: see the [data-grid]
     rule under .music-panel. */
  position: sticky;
  left: var(--step-half);
  width: fit-content;
  /* Rendering containment for the scroll: a channel section
     far from the viewport is skipped whole, its contents
     unpainted, until it nears the screen. A page of eight
     grids over a thousand-plus steps otherwise repaints all
     of it under every scroll, which is what smeared and
     blanked this page on a phone. The intrinsic size is the
     section's settled height, one line at the page line
     height; once a section has rendered, the browser
     remembers its true size, so the settled layout is
     unchanged. */
  content-visibility: auto;
  contain-intrinsic-size: auto 24px;
}

.gchan:first-child {
  margin-block-start: 0;
}

.gchan__name {
  font-weight: 700;
}

.gchan__inst {
  color: var(--muted-color);
}

.gchan__mute {
  font: inherit;
  font-size: var(--text-caption);
  margin-inline-start: auto;
  padding: 0 0.4em;
  background: none;
  border: none;
  color: var(--muted-color);
  /* Controls are never underlined either (Ben's rule, 2026-11-22). */
  text-decoration: none;
  cursor: pointer;
}

.gchan__mute:hover,
.gchan__mute:focus-visible {
  background: var(--accent-color);
  color: var(--inverted-color);
  text-decoration: none;
}

.gchan__mute[aria-pressed="true"] {
  color: light-dark(#b3261e, #f2b8b5);
}

.gstrip {
  --cell: 14px;
  --pitch: 15px;
  --group: 64px;
  position: relative;
}

/* The note layer: its background draws the grid the cells
   used to draw, step lines on the step pitch with the wider
   beat gap every four steps, lane lines on the lane pitch,
   all of it tiled gradients, so an empty step costs no
   element at all. The layer starts after the label column
   and runs the song's full width; the blocks inside it are
   the only per-note elements, and only the visible window's
   worth of them exist. */
.glayer {
  position: absolute;
  left: calc(3.4rem + 1px);
  top: 0;
  bottom: 0;
  border-bottom: 1px solid var(--page-rule);
  background-image:
    linear-gradient(to right,
      var(--page-rule) 0, var(--page-rule) 1px,
      transparent 1px, transparent var(--pitch),
      var(--page-rule) var(--pitch), var(--page-rule) calc(var(--pitch) + 1px),
      transparent calc(var(--pitch) + 1px), transparent calc(var(--pitch) * 2),
      var(--page-rule) calc(var(--pitch) * 2), var(--page-rule) calc(var(--pitch) * 2 + 1px),
      transparent calc(var(--pitch) * 2 + 1px), transparent calc(var(--pitch) * 3),
      var(--page-rule) calc(var(--pitch) * 3), var(--page-rule) calc(var(--pitch) * 3 + 1px),
      transparent calc(var(--pitch) * 3 + 1px), transparent var(--group)),
    repeating-linear-gradient(to bottom,
      var(--page-rule) 0, var(--page-rule) 1px,
      transparent 1px, transparent 25px);
  background-size: var(--group) 100%, 100% 25px;
  background-repeat: repeat-x, repeat-y;
}

/* The pitch labels: one per lane, in flow down the strip,
   each a lane pitch tall (25px of box, the text centred in
   the 24px under a 1px top pad, which is exactly where the
   old absolutely placed box put it: centre at lane*25 + 13,
   the blocks' own centre). Sticky at the panel's content
   inset, so the rail stays pinned at the left edge while
   the note layer scrolls and follows the playhead under it:
   pinned means pinned, the labels never slide or drift,
   they are simply always at the edge. The background is
   the panel's own, so blocks pass hidden beneath the rail
   rather than showing through it, and a tap on the rail
   lands outside .glayer, which the grid's click handler
   already ignores, so the notes under the rail cannot be
   edited by accident. No top is set: nothing sticks
   vertically. */
.glabel {
  position: sticky;
  left: var(--step-half);
  z-index: 1;
  width: 3.4rem;
  height: 25px;
  padding-block-start: 1px;
  background: var(--page-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-inline-end: 0.5rem;
  color: var(--muted-color);
  font-size: var(--text-caption);
}

/* One block per note: the head step wears the full accent,
   as the note's first cell did, and the sustain runs behind
   it at the sustain cells' opacity, as a gradient, so a
   long note reads the way its cells did. */
.gblock {
  position: absolute;
  height: var(--cell);
  padding: 0;
  background: linear-gradient(to right,
    var(--accent-color) 0, var(--accent-color) var(--cell),
    color-mix(in srgb, var(--accent-color) 42%, transparent) var(--cell));
  border: 1px solid var(--accent-color);
  cursor: pointer;
}

.gblock:hover {
  outline: 1px solid var(--accent-color);
  outline-offset: -1px;
}

/* A filled outline, not just a border tint, so a keyboard
   user can always see which block they are standing on. */
.gblock:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: -1px;
}

/* Experiment (live note feedback): a note that has been
   edited in but is not in the current render yet wears
   amber. It clears only when the re-render actually swaps
   in. A note deleted from the text but still sounding in
   the current render shows as a dashed ghost until the
   same swap. */
:root {
  --pending-color: light-dark(#b97e0e, #e0a83c);
}

.gblock.c-pending {
  background: var(--pending-color);
  border-color: var(--pending-color);
}

/* Read-only mode (MAKER_EDITING_ENABLED = false in music.js):
   note blocks are display only, so no pointer or hover cue. */
.maker--readonly .gblock {
  cursor: default;
}

.maker--readonly .gblock:hover {
  outline: none;
}

.gblock.c-ghost {
  background: color-mix(in srgb, var(--muted-color) 38%, transparent);
  border-color: var(--muted-color);
  border-style: dashed;
}

/* The playhead: one line per strip over the note layer,
   moved by transform, where the per-step cell outline
   used to run down the stack. */
.gplay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: var(--accent-pulse-color);
  pointer-events: none;
}


.music-hint {
  margin-block-start: var(--step);
  color: var(--muted-color);
  font-size: var(--text-small);
}

.music-text {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: var(--text-small);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-x: hidden;
  /* Never a scrollable window: the script fits the box to its
     full height, so every line is on the page, wrapped. */
  overflow-y: hidden;
  background: var(--page-subtle);
  color: var(--page-color);
  border: 1px solid var(--page-rule);
  padding: var(--step-half);
}

/* Code on this page soft-wraps like everywhere else on the site:
   it never scrolls sideways. It also sits a step clear of the
   paragraphs around it, like every other block on the page, and
   wears the same framed panel as the code on the Mochi page. */
.code {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  margin-block: var(--step);
  border: 1px solid var(--page-rule);
  background: var(--page-subtle);
  padding: var(--step-half);
}

.music-text:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: -1px;
}

/* Touch targets, on the same terms the rest of the site uses:
   controls grow to two whole steps tall on coarse pointers, and
   the grid cells grow as far as a scrolling panel allows. */
@media (max-width: 34rem), (pointer: coarse) {
  .music-btn {
    min-height: calc(var(--step) * 2);
    padding-inline: calc(var(--step) / 2);
  }

  .music-btn--play {
    padding-inline: var(--step);
  }

  .music-group {
    flex-direction: column;
    gap: calc(var(--step) / 4);
  }

  .music-group__label {
    width: auto;
  }

  .gchan__mute {
    min-height: calc(var(--step) * 2);
    padding-inline: calc(var(--step) / 2);
  }

  .gstrip {
    --cell: 22px;
    --pitch: 23px;
    --group: 96px;
  }

}

/* ---------- the maker at desktop width: full width, unboxed ---------- */

/* Ben's call, 2026-11-22: on a desktop the maker takes the full
   width of the screen, and it lives outside any box: an unbounded
   focus area, not a framed widget. So at desktop widths the
   working surface (the transport row, the song picker, and the
   grid panel) leaves the 36rem column and spans the body's whole
   content width, and the panel's frame (border and panel
   background) comes off with the column constraint. The panel
   element itself stays: it is the grid's scroll container, the
   structure the sticky pins and the view math measure against.
   Only the visual box goes.
   The prose stays in the column: the intro line, the status
   lines, the hint, the details and notes groups, and the whole
   how-it-works section are untouched, as are the other pages.

   The breakout width is the viewport minus the body's own
   gutters. 100vw includes the classic scrollbar's width, so the
   box overshoots the body content width by that much, centred:
   half a scrollbar into each gutter, where the gutter absorbs
   it and nothing reaches the viewport edge, so no page-level
   horizontal scrollbar can appear. The maker's visible content
   sits inside the panel's own padding, well clear of the
   overshoot.

   The panel's padding and the sticky pins keep their shipped
   values. The pins' rendered inset from the panel's edge is the
   padding plus their left value (measured: 1px border + 12px +
   12px = 25px in the column layout), so changing either would
   move the label rail off the spot the design settled on. What
   changes here is only the frame and the width.

   The threshold is 48rem: below it the column plus gutters
   nearly fill the screen anyway and the breakout would buy
   almost nothing; above it the gain is real. On phone widths
   nothing in here applies and the page is exactly as it was. */
@media (min-width: 48rem) {
  .music-transport,
  .music-group--songs,
  .music-panel {
    width: calc(100vw - 2 * var(--page-gutter));
    margin-left: calc(50% - 50vw + var(--page-gutter));
  }

  /* The box comes off: no border, no panel background. The
     padding and the scroll containment are unchanged. */
  .music-panel {
    border: none;
    background: transparent;
  }

  /* The labels occlude the notes passing beneath them with the
     panel's background; unboxed, that is the page's own
     background. */
  .glabel {
    background: var(--page-background);
  }

  /* The section's accent frame hugs the column-width section
     box; the wide surface passes through where its sides would
     fall, so on this page at this width the frame stands down.
     The maker section is the wide one; how-it-works keeps its
     frame, and below the threshold nothing changes. */
  .maker.section {
    outline: none;
  }
}

/* The how-it-works explainer runs at the size the rest of this
   page's own text uses (small), not the larger body size: its
   paragraphs and code blocks sit beside 14px working text, and
   read big at 16px. */
.music-how p,
.music-how .code {
  font-size: var(--text-small);
}
