/* Beatmatch Trainer — a CDJ-flavoured console in the site's own palette.
   Depth comes from tonal layering, never shadows; Signal Orange is reserved for
   the things that are live: the lit lock-in cells, deck B's playhead, an armed
   transport button. */

/* The gate, the console, the grid, the needle and the grade card are all built
   visible and hidden by the `hidden` attribute from JS. Layout rules below set
   `display`, and a `display` from a class beats the UA's `[hidden]` rule — the
   gate stayed on screen for the whole session until this list included it. Inline
   styles are not an option: style-src is 'self' with no 'unsafe-inline'.
   beatmatch-hidden.test.js keeps this list in step with what the JS toggles. */
.bm-gate[hidden],
.bm-assists[hidden],
.bm-console[hidden],
.bm-grid[hidden],
.bm-phase-meter[hidden],
.bm-grade[hidden] {
  display: none;
}

.bm-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-3);
  background: var(--color-surface-low);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-align: center;
}

.bm-gate-hint {
  max-width: 46ch;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.bm-console {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 0.9fr) 1fr;
  gap: var(--space-2);
  align-items: start;
}

/* --- decks ---------------------------------------------------------------- */

.bm-deck {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-surface-low);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

/* The deck's display: an inset panel on the page floor, the darkest tone on the
   page, so it reads as a lit screen against the deck body without a gradient or
   a shadow. Name and tempo by default; the pattern list unfolds inside it. */
.bm-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: var(--space-1) var(--space-2) var(--space-2);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.bm-screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.bm-browse[aria-expanded='true'] {
  border-color: var(--color-signal);
  color: var(--color-signal);
}

.bm-deck-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  color: var(--color-text-dim);
}

.bm-track-name {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  text-align: center;
}

.bm-readout {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
}

.bm-bpm {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
}

.bm-bpm-unit {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  color: var(--color-text-dim);
}

/* The jog is the signature control: a platter whose index marker rides the deck's
   real bar phase, so two matched decks show two marks turning as one. */
.bm-jog {
  width: 180px;
  height: 180px;
  border-radius: var(--radius-full);
  background: var(--color-surface-high);
  border: 2px solid var(--color-border);
  display: grid;
  place-items: center;
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
}

.bm-jog-face {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.bm-jog-marker {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
}

.bm-jog-marker::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 6px;
  width: 3px;
  height: 26px;
  margin-left: -1.5px;
  border-radius: var(--radius-sm);
  background: var(--color-signal);
}

.bm-transport,
.bm-nudge {
  display: flex;
  gap: var(--space-1);
  width: 100%;
}

.bm-btn {
  flex: 1;
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface-high);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all var(--transition);
}

.bm-btn:hover,
.bm-btn:focus-visible {
  border-color: var(--color-signal);
  color: var(--color-primary);
}

.bm-btn-play {
  background: var(--color-signal);
  border-color: var(--color-signal);
  color: var(--color-on-signal);
  font-weight: 600;
}

.bm-btn-play:hover,
.bm-btn-play:focus-visible {
  color: var(--color-on-signal);
}

.bm-btn-small {
  flex: 0 0 auto;
  padding: 4px var(--space-1);
  font-size: 0.6875rem;
}

.bm-pitch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  width: 100%;
}

.bm-pitch-label,
.bm-field-label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}

/* A vertical throw, like the fader it imitates. */
.bm-pitch-fader {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 28px;
  height: 190px;
  accent-color: var(--color-signal);
}

.bm-pitch-value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

/* --- mixer ---------------------------------------------------------------- */

.bm-mixer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface-low);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.bm-round,
.bm-lock,
.bm-crossfade {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.bm-select {
  padding: var(--space-1);
  background: var(--color-surface-high);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.bm-lock-meter {
  display: flex;
  gap: 4px;
}

.bm-lock-cell {
  flex: 1;
  height: 12px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-high);
  border: 1px solid var(--color-border);
  transition: background var(--transition);
}

.bm-lock-cell.is-lit {
  background: var(--color-signal);
  border-color: var(--color-signal);
}

.bm-status {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.bm-grade {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  background: var(--color-surface-high);
  border: 1px solid var(--color-success);
  border-radius: var(--radius-md);
}

.bm-grade-letter {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-success);
}

.bm-grade-list {
  flex: 1;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bm-grade-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.bm-grade-list li span:last-child {
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.bm-faders {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
}

.bm-fader-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.bm-channel {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 24px;
  height: 120px;
  accent-color: var(--color-signal);
}

.bm-crossfade input[type='range'],
.bm-mixer input[type='range']:not(.bm-channel) {
  accent-color: var(--color-signal);
  width: 100%;
}

/* The assist toggles sit above the decks, as their own bar rather than a cell of
   the console grid: a full-width row *inside* that grid is what wrecked the
   layout when the phase meter tried it. This is a plain block, so it cannot
   disturb the three columns below it. */
.bm-assists {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-low);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.bm-assists-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bm-assists-title {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}

.bm-assists-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.bm-assists-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* Each toggle is a chip with its own indicator lamp, the way the switch it stands
   in for would be on the hardware. Pills are the one place this design system
   allows a full radius, and chips are what these are. */
.bm-assist {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 6px var(--space-2) 6px 10px;
  background: var(--color-surface-high);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: border-color var(--transition);
}

/* Visually gone, still focusable and still reachable by every assistive
   technology — `display: none` would take it out of the tab order. */
.bm-assist input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  margin: 0;
  pointer-events: none;
}

.bm-assist-led {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  transition: background var(--transition), border-color var(--transition);
}

.bm-assist-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  transition: color var(--transition);
}

.bm-assist:hover {
  border-color: var(--color-text-dim);
}

/* The lamp lights through a sibling selector, which every browser has had for
   twenty years. The chip's own fill needs :has(), so an older engine simply gets
   a lit lamp and no fill rather than a toggle with no feedback at all. */
.bm-assist input:checked ~ .bm-assist-led {
  background: var(--color-signal);
  border-color: var(--color-signal);
}

.bm-assist input:checked ~ .bm-assist-text {
  color: var(--color-primary);
}

.bm-assist:has(input:checked) {
  border-color: var(--color-signal);
}

.bm-assist:has(input:focus-visible) {
  outline: 2px solid var(--color-signal);
  outline-offset: 2px;
}

.bm-grid {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

/* First thing in the centre column, above the round controls: it is the readout
   you watch while your hand is on the jog. Stacked and full-column-width — it
   spanned the whole console for one revision and wrecked the grid. */
.bm-phase-meter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.bm-phase-track {
  position: relative;
  width: 100%;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--color-surface-high);
  border: 1px solid var(--color-border);
}

/* Dead centre is a match; without a mark the needle has nothing to be right of. */
.bm-phase-track::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -4px;
  bottom: -4px;
  width: 1px;
  background: var(--color-border);
}

.bm-phase-needle {
  position: absolute;
  top: -3px;
  left: 50%;
  width: 3px;
  height: 14px;
  margin-left: -1.5px;
  border-radius: var(--radius-sm);
  background: var(--color-signal);
}

.bm-phase-value {
  min-width: 7ch;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

/* --- the pattern list, inside the screen ---------------------------------- */

/* .hidden is set through el[`bmTrackList${deck}`], which beatmatch-hidden.test.js
   cannot see; the rule is here by hand for the same reason the others are. */
.bm-track-list[hidden] {
  display: none;
}

.bm-track-list {
  list-style: none;
  width: 100%;
  margin: var(--space-1) 0 0;
  padding: var(--space-1) 0 0;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bm-track-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  width: 100%;
  padding: 6px var(--space-1);
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-muted);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
}

.bm-track-row:hover,
.bm-track-row:focus-visible {
  background: var(--color-surface-low);
  color: var(--color-text);
  outline: none;
}

.bm-track-row:focus-visible {
  border-left-color: var(--color-primary);
}

.bm-track-row.is-loaded {
  border-left-color: var(--color-signal);
  color: var(--color-text);
}

.bm-track-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 500;
}

.bm-track-bpm {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-dim);
}

@media (max-width: 768px) {
  .bm-console {
    grid-template-columns: 1fr;
  }

  .bm-jog {
    width: 140px;
    height: 140px;
  }

  .bm-jog-face {
    width: 100px;
    height: 100px;
  }

  .bm-pitch-fader {
    height: 150px;
  }
}

/* The countdown digit, under the round button. Sized so it reads from across a
   desk — the point of the count is that you are looking at the decks, not here. */
.bm-countdown {
  font-family: var(--font-mono);
  font-size: 2.75rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  color: var(--color-signal);
  min-height: 2.75rem;
  padding-top: var(--space-1);
}

/* The UA's [hidden] is the weakest rule there is; without this the digit keeps
   its slot in the column between rounds. */
.bm-countdown[hidden] {
  display: none;
}

/* The beep toggle is not an assist — it hides nothing and gives nothing away —
   so it sits apart from the three that are. */
.bm-assist-beep {
  margin-left: auto;
}

/* The rules of the drill, above the rig and only once there is a rig to explain.
   Read once, then never again — hence a <details> the player can fold away, and
   a quiet card rather than a banner. */
.bm-howto {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-low);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

/* The UA's [hidden] is the weakest rule there is, and <details> carries its own
   display, so without this the card is on screen with the attribute set. */
#bmHowto[hidden] {
  display: none;
}

.bm-howto-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  cursor: pointer;
  list-style: none;
}

.bm-howto-title::-webkit-details-marker {
  display: none;
}

/* Own marker, so it points the right way in both states without a script. */
.bm-howto-title::before {
  content: '▸';
  display: inline-block;
  margin-right: var(--space-1);
  color: var(--color-signal);
}

.bm-howto[open] .bm-howto-title::before {
  content: '▾';
}

.bm-howto-title:hover,
.bm-howto[open] .bm-howto-title {
  color: var(--color-text-muted);
}

.bm-howto-title:focus-visible {
  outline: 2px solid var(--color-signal);
  outline-offset: 2px;
}

.bm-howto-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-2) var(--space-3);
  margin: var(--space-2) 0 0;
  padding-left: var(--space-3);
  color: var(--color-text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.bm-howto-steps li::marker {
  font-family: var(--font-mono);
  color: var(--color-signal);
}

@media (max-width: 768px) {
  .bm-howto-steps {
    grid-template-columns: 1fr;
  }
}
