/* Crab Beats music maker (docs/music/index.html). Built from the tokens in
 * ../assets/conshy.css; only the music maker's own pieces live here. The
 * chord colors are this page's own: six soft colors a child can tell apart,
 * each carrying ink text in light and dark mode. */

.mu {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1fr);
}
/* Conshy Crab takes a third of the width beside the instrument on wide
 * screens, and a third of the screen's height above it on phones, where
 * he stays in view while the controls scroll under him. */
@media (min-width: 1024px) {
  .mu { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
  .mu > .mu-stage { order: 2; position: sticky; top: var(--space-3); height: min(38rem, calc(100vh - 2 * var(--space-3))); }
  .mu-deck { order: 1; }
}

/* ---------- The stage ---------- */

.mu-stage {
  --glow: #942bff;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: radial-gradient(120% 80% at 50% 110%, #4a3358 0%, var(--aubergine) 55%, #1d1424 100%);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mu-lights {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(55% 45% at 50% 62%, color-mix(in srgb, var(--glow) 55%, transparent) 0%, transparent 70%),
    radial-gradient(30% 60% at 12% 0%, color-mix(in srgb, var(--glow) 30%, transparent) 0%, transparent 70%),
    radial-gradient(30% 60% at 88% 0%, color-mix(in srgb, var(--glow) 30%, transparent) 0%, transparent 70%);
  transition: background 400ms ease;
  opacity: 0.55;
}
.mu-stage[data-playing] .mu-lights { opacity: 1; }
@media (max-width: 1023px) {
  .mu-stage { position: sticky; top: 0; z-index: 5; height: 34vh; min-height: 13rem; margin-inline: -16px; border-radius: 0; }
}
@media (min-width: 640px) and (max-width: 1023px) {
  .mu-stage { margin-inline: -24px; }
}
/* The floor: a lighter oval for him to stand on. */
.mu-stage::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 4%;
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04) 70%, transparent);
}

.mu-now {
  position: absolute;
  top: var(--space-3);
  left: 0;
  right: 0;
  z-index: 3;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(18px, 2.4vw, 26px);
  line-height: 1.2;
  color: var(--paper);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.mu-dancer {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 6%;
  width: min(92%, 52vh);
  aspect-ratio: 640 / 560;
  transform: translateX(-50%);
}
@media (max-width: 1023px) {
  .mu-dancer { width: auto; height: 78%; bottom: 4%; }
}
.mu-pose { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
/* crab3d.js draws into .mu-three; once it has, the picture and the flat
 * floor give way to the 3D dance floor. */
.mu-three { position: absolute; inset: 0; z-index: 1; }
.mu-canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.mu-stage[data-3d] .mu-dancer, .mu-stage[data-3d]::after { display: none; }
.mu-stage[data-3d] .mu-lights { opacity: 0.35; }
@media (prefers-reduced-motion: reduce) {
  .mu-lights { transition: none; }
}

/* ---------- The instrument ---------- */

.mu-deck {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
@media (max-width: 639px) {
  .mu-deck { padding: var(--space-3); gap: var(--space-3); }
}
.mu-block { display: grid; gap: var(--space-2); min-width: 0; }
.mu-label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  font-family: var(--font-display);
  font-size: 13px;
  line-height: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-heading);
}
.mu-hint { font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text-muted); }

.mu-transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
}
.mu-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 9.5rem;
  min-height: 64px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}
.mu-play .icon { width: 26px; height: 26px; margin-right: 10px; }
.mu-play .on-play, .mu-play[aria-pressed="true"] .on-stop { display: none; }
.mu-play[aria-pressed="true"] .on-play { display: inline-flex; align-items: center; }
.mu-play .on-stop { display: inline-flex; align-items: center; }
.mu-play:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.mu-tempo { display: grid; gap: 4px; flex: 1 1 11rem; min-width: 10rem; }
.mu-tempo-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
}
.mu-tempo input { width: 100%; flex: 1; min-width: 0; height: 32px; accent-color: var(--violet); }
.mu-tools { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* Song boxes: four to a row, so the eight bars read as two lines. */
.mu-song { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.mu-slot, .mu-chord {
  --c: var(--surface-sunken);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 64px;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  background: var(--c);
  color: var(--ink);
  font-family: var(--font-display);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.mu-slot[data-empty], .mu-chord[data-empty] {
  background: transparent;
  border: 2px dashed var(--border-strong);
  color: var(--text-muted);
}
.mu-name { font-size: 24px; font-weight: 800; line-height: 1; }
.mu-rest { font-size: 16px; font-weight: 700; }
.mu-mood { width: 20px; height: 20px; flex: none; opacity: 0.75; }
.mu-num {
  position: absolute;
  top: 4px;
  left: 7px;
  font-size: 11px;
  font-weight: 800;
  opacity: 0.55;
}
.mu-slot[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--violet); }
.mu-slot[data-now] { transform: translateY(-3px) scale(1.04); box-shadow: 0 6px 0 -2px color-mix(in srgb, var(--c) 70%, var(--ink)); }
.mu-slot[data-now][aria-pressed="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--violet); }
.mu-slot:focus-visible, .mu-chord:focus-visible, .mu-step:focus-visible, .mu-seg button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.mu-chords { display: grid; grid-template-columns: repeat(auto-fill, minmax(5.25rem, 1fr)); gap: var(--space-2); }
.mu-chord:active, .mu-slot:active { transform: scale(0.96); }

.mu-seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
}
.mu-seg button {
  min-height: 48px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.mu-seg button[aria-checked="true"] { background: var(--surface); color: var(--text-heading); box-shadow: var(--shadow-card), inset 0 0 0 2px var(--violet); }

/* Small toggles and pattern buttons. A pressed toggle turns violet. */
.mu-tog {
  min-height: 34px;
  padding: 0 var(--space-3);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  touch-action: manipulation;
}
.mu-tog[aria-pressed="true"] { background: var(--violet); border-color: var(--violet); color: var(--on-violet); }
.mu-tog:active { transform: scale(0.96); }
.mu-label .mu-push { margin-left: auto; }

.mu-row3 { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
.mu-seg-wrap { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); }

.mu-bpm {
  margin-left: auto;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}
.mu-bpm [data-bpm] { color: var(--text-heading); }

/* ---------- Drums ---------- */

.mu-drums { gap: var(--space-3); }
.mu-drum-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.mu-drum-bar .mu-seg { flex: 0 1 18rem; }
.mu-patterns { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.mu-patterns .mu-hint { font-family: var(--font-display); font-size: 13px; margin-right: 2px; }

.mu-live { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.mu-big {
  min-height: 52px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--aubergine);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 100ms ease;
}
.mu-big:active { transform: scale(0.97); }
.mu-drop { background: linear-gradient(90deg, var(--violet), var(--pink)); color: #fff; }
/* Armed: waiting for the next bar to start. */
.mu-big[data-armed] { animation: mu-armed 0.5s ease-in-out infinite alternate; }
@keyframes mu-armed { to { box-shadow: 0 0 0 4px var(--cyan); } }

.mu-mix summary { cursor: pointer; list-style: none; padding: 4px 0; }
.mu-mix summary::-webkit-details-marker { display: none; }
.mu-mix summary::before { content: "▸"; margin-right: 2px; transition: transform 120ms ease; }
.mu-mix[open] summary::before { transform: rotate(90deg); }
.mu-mixer { display: grid; gap: 2px; margin-top: var(--space-2); }
.mu-ch {
  display: grid;
  grid-template-columns: 5.25rem minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-2);
  padding: 3px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
}
.mu-ch:nth-child(3n) { border-bottom-color: var(--border-strong); }
.mu-ch-name { font-family: var(--font-display); font-size: 14px; font-weight: 800; color: var(--text-heading); }
.mu-ch input { width: 100%; height: 28px; accent-color: var(--row); }
.mu-ch .mu-tog { min-height: 30px; font-size: 13px; padding: 0 var(--space-2); }

/* ---------- Sound pad ---------- */

.mu-pad { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: var(--space-2); }
.mu-sfx {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 72px;
  padding: 8px 4px 6px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-heading);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 90ms ease, background 90ms ease;
}
.mu-sfx-icon { font-size: 28px; line-height: 1; }
.mu-key {
  position: absolute;
  top: 4px;
  right: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.mu-sfx:active, .mu-sfx[data-hit] { transform: scale(0.94); background: color-mix(in srgb, var(--cyan) 45%, var(--surface-sunken)); }
@media (hover: none) { .mu-key { display: none; } }
@media (max-width: 479px) {
  .mu-pad { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .mu-sfx { min-height: 62px; font-size: 12px; }
  .mu-sfx-icon { font-size: 24px; }
  .mu-ch { grid-template-columns: 4rem minmax(0, 1fr) auto auto; }
}

.mu-tog:focus-visible, .mu-big:focus-visible, .mu-sfx:focus-visible, .mu-beat-label:focus-visible, .mu-mix summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Drum grid: a name, then eight steps. Each row takes its drum's color
 * (--row, set by music.js). The off-beat steps sit on a slightly darker
 * cell, so the counting "1 and 2 and" shows. */
.mu-beat { display: grid; gap: 5px; }
.mu-beat-row {
  --row: var(--violet);
  --on-row: var(--on-violet);
  display: grid;
  grid-template-columns: 5.25rem repeat(8, minmax(0, 1fr));
  gap: 5px;
  align-items: center;
}
.mu-beat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-heading);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.1;
  text-align: left;
  cursor: pointer;
}
.mu-beat-label::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--row); }
.mu-beat-row[data-muted] .mu-beat-label { color: var(--text-muted); text-decoration: line-through; }
.mu-beat-row[data-muted] .mu-step { opacity: 0.4; }
.mu-step {
  position: relative;
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--surface-sunken);
  cursor: pointer;
  touch-action: manipulation;
}
.mu-step:nth-of-type(even) { background: color-mix(in srgb, var(--surface-sunken) 90%, var(--text)); }
.mu-step::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 38%;
  aspect-ratio: 1;
  max-width: 26px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  transition: transform 100ms ease;
}
.mu-step[aria-pressed="true"]::after { background: var(--row); border-color: var(--row); width: 56%; max-width: 34px; }
.mu-step[data-now] { box-shadow: inset 0 0 0 3px var(--row); }
.mu-step[data-now][aria-pressed="true"]::after { transform: scale(1.2); }
@media (max-width: 479px) {
  .mu-beat-row { grid-template-columns: 3.75rem repeat(8, minmax(0, 1fr)); gap: 3px; }
  .mu-beat-label { font-size: 12px; padding: 0 2px; }
  .mu-beat-label::before { display: none; }
  .mu-step { height: 38px; }
  .mu-name { font-size: 20px; }
  .mu-mood { width: 16px; height: 16px; }
  .mu-slot, .mu-chord { min-height: 56px; }
}

.mu-help { display: grid; gap: var(--space-2); padding-left: 1.1rem; list-style: disc; }

/* On phones the stage sits over the top third of the screen, so a control
 * scrolled into view by the keyboard lands below him. */
@media (max-width: 1023px) {
  .mu-deck :is(button, input, summary) { scroll-margin-top: calc(max(34vh, 13rem) + var(--space-2)); }
}
