/* Play — chirp as an instrument: a faceplate of ivory keys, role-tinted pads and a pixel
   kit, with the patch's own dials above. Square working surfaces like the studio; the lit
   key (the accent under a finger) and the level LED are the motif. Every colour comes from the
   theme. */

:root,
[data-theme="ember"],
[data-theme="ice"] {
  --key-white: var(--text);
  --key-white-down: var(--accent);
  --key-black: #0a0908;
  --key-black-down: var(--accent);
  --key-label: var(--dim);
  --pad-face: var(--raise);
}

[data-theme="paper"] {
  --key-white: #fbf8f1;
  --key-black: var(--text);
  --key-label: var(--dim);
  --pad-face: var(--panel);
}

/* ── mode: Play takes the work area; the deck stays (play along) ───── */

body[data-mode="play"] > .work {
  display: none;
}

body[data-mode="play"] > .play {
  grid-row: 2;
}

body[data-mode="play"] > .console {
  grid-row: 3;
}

/* On phones and touch screens the keys get the console's room too, and the deck keeps
   only its transport and tools. */
@media (max-width: 900px), (pointer: coarse) {
  body[data-mode="play"] {
    grid-template-rows: auto minmax(0, 1fr) 0;
  }
  body[data-mode="play"] > .console {
    display: none;
  }
}

@media (max-width: 900px) {
  body[data-mode="play"] .deck .source,
  body[data-mode="play"] .deck .tempo,
  body[data-mode="play"] .deck .clock,
  body[data-mode="play"] .deck .meter {
    display: none;
  }
}

#to-play[aria-pressed="true"] {
  color: var(--accent);
}

.play {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  min-height: 0;
  background: var(--ground);
  border-bottom: 1px solid var(--line);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.play[hidden] {
  display: none;
}

/* ── rail ─────────────────────────────────────────────── */

.play-rail {
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.play-rail button,
.play-patch select {
  height: 30px;
  font: inherit;
  color: var(--text);
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 0 10px;
  cursor: pointer;
}

@media (pointer: coarse) {
  .play-rail button,
  .play-patch select {
    height: 38px;
    min-width: 38px;
  }
}

.play-rail button:focus-visible,
.play-patch select:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.play-patch {
  flex: 1 1 140px;
  min-width: 0;
  max-width: 260px;
}

.play-patch select {
  width: 100%;
  font-weight: 700;
}

.play-meter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.play-views {
  display: inline-flex;
}

.play-views button {
  border-radius: 0;
  margin-left: -1px;
  color: var(--dim);
}

.play-views button:first-child {
  border-radius: var(--r) 0 0 var(--r);
}

.play-views button:last-child {
  border-radius: 0 var(--r) var(--r) 0;
}

.play-views button[aria-selected="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.play-views button[hidden] {
  display: none;
}

.play-oct {
  display: inline-flex;
  align-items: center;
}

.play-oct button {
  width: 34px;
  padding: 0;
  font-weight: 700;
}

.play-oct output {
  min-width: 3.2ch;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.play-oct[hidden] {
  display: none;
}

.play-tog[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--sel);
}

.play-midi .lamp {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--faint);
  vertical-align: 1px;
}

.play-midi.on .lamp {
  background: var(--ok);
}

.play-midi.err .lamp {
  background: var(--error);
}

.play-midi.pulse .lamp {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.play-voices {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: right;
}

.play-led {
  width: 44px;
  height: 6px;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--ok) 0 70%, var(--warn) 70% 90%, var(--error) 90%);
  clip-path: inset(0 calc(100% - var(--lvl, 0%)) 0 0);
  outline: 1px solid var(--line);
  outline-offset: 1px;
}

/* ── knobs ────────────────────────────────────────────── */

.play-perform {
  grid-row: 2;
  display: flex;
  gap: 14px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.play-perform[hidden],
.play-panel[hidden] {
  display: none;
}

.fader {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) 5ch;
  align-items: center;
  gap: 8px;
  flex: 1 1 220px;
  max-width: 420px;
}

.fader b {
  color: var(--accent);
  font-weight: 700;
}

.fader output {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.fader input {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

.play-panel {
  grid-row: 3;
  display: flex;
  gap: 1px;
  overflow-x: auto;
  background: var(--line);
  border-bottom: 1px solid var(--line);
  max-height: 46vh;
}

.mod {
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--panel);
  min-width: max-content;
}

.mod > h4 {
  margin: 0;
  padding: 5px 10px 2px;
  font: 700 10px/1.4 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
}

.mod > div {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, auto);
  gap: 4px 6px;
  padding: 2px 10px 8px;
  align-items: start;
}

.ctl {
  display: grid;
  justify-items: center;
  gap: 1px;
  width: 54px;
  touch-action: none;
}

.ctl > span {
  font-size: 10px;
  line-height: 13px;
  color: var(--dim);
  max-width: 54px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctl > output {
  font-size: 11px;
  line-height: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.ctl.modulated > output::after {
  content: "~";
  color: var(--pending);
  margin-left: 1px;
}

.dial {
  width: 40px;
  height: 40px;
  cursor: ns-resize;
  border-radius: 50%;
}

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

.dial .track {
  fill: none;
  stroke: var(--faint);
  stroke-width: 4;
}

.dial .arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
}

.dial .cap {
  fill: var(--raise);
  stroke: var(--line);
}

.dial .tick {
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
}

.ctl.changed .arc {
  stroke: var(--accent);
}

.stepper {
  display: grid;
  grid-template-columns: 18px auto 18px;
  align-items: center;
  height: 40px;
}

.stepper button {
  width: 18px;
  height: 40px;
  padding: 0;
  color: var(--dim);
  background: transparent;
  border: 0;
  font: inherit;
  cursor: pointer;
}

.stepper button:hover {
  color: var(--accent);
}

.stepper b {
  font-weight: 700;
  font-size: 11px;
  color: var(--text);
  text-align: center;
  min-width: 4ch;
}

.switch-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--raise);
  color: var(--text);
  font: 16px/1 var(--mono);
  cursor: pointer;
}

.switch-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.switch {
  width: 40px;
  height: 22px;
  margin: 9px 0;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--raise);
  position: relative;
  cursor: pointer;
  padding: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--dim);
  transition: left 0.08s;
}

.switch[aria-checked="true"] {
  background: var(--sel);
  border-color: var(--accent);
}

.switch[aria-checked="true"]::after {
  left: 20px;
  background: var(--accent);
}

/* ── surface ──────────────────────────────────────────── */

.play-surface {
  grid-row: 4;
  position: relative;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  padding: 8px;
}

.keys {
  display: grid;
  gap: 8px;
  height: 100%;
}

.manual {
  position: relative;
  display: flex;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--key-black);
}

.key-w,
.key-b {
  touch-action: none;
}

.key-w {
  flex: 1 1 0;
  margin-right: 1px;
  background: var(--key-white);
  border-radius: 0 0 3px 3px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  color: var(--key-label);
  font-size: 11px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.12);
}

.key-w:last-child {
  margin-right: 0;
}

.key-w.down {
  background: var(--key-white-down);
  color: var(--accent-ink);
  box-shadow:
    inset 0 -2px 0 rgba(0, 0, 0, 0.18),
    0 0 18px var(--accent);
}

.key-b {
  position: absolute;
  top: 0;
  height: 60%;
  background: var(--key-black);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 3px 3px;
  box-shadow: inset 0 -5px 0 rgba(255, 255, 255, 0.06);
  z-index: 1;
}

.key-b.down {
  background: var(--key-black-down);
  box-shadow: 0 0 14px var(--accent);
}

.key-w b {
  font-weight: 700;
  color: var(--key-label);
}

.key-w.down b {
  color: var(--accent-ink);
}

/* Pads: a grid sampler, tinted by drum family. */
.pads {
  display: grid;
  gap: 8px;
  height: 100%;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}

.pad {
  --tint: var(--t3);
  position: relative;
  border-radius: 6px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--tint) 22%, transparent), transparent 70%),
    var(--pad-face);
  border: 1px solid color-mix(in srgb, var(--tint) 45%, var(--line));
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 2px;
  touch-action: none;
  overflow: hidden;
}

.pad b {
  font: 800 clamp(16px, 4.5vmin, 30px) / 1 var(--mono);
  color: var(--tint);
}

.pad span {
  font-size: 11px;
  color: var(--dim);
}

.pad i {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 0;
  background: var(--tint);
}

.pad.down {
  background: color-mix(in srgb, var(--tint) 55%, var(--pad-face));
  border-color: var(--tint);
  box-shadow: 0 0 22px color-mix(in srgb, var(--tint) 70%, transparent);
}

.pad.down b,
.pad.down span {
  color: var(--ground);
}

.pad[data-fam="kick"] {
  --tint: var(--t0);
}
.pad[data-fam="snare"] {
  --tint: var(--t1);
}
.pad[data-fam="hat"] {
  --tint: var(--t7);
}
.pad[data-fam="tom"] {
  --tint: var(--t2);
}
.pad[data-fam="cymbal"] {
  --tint: var(--t3);
}
.pad[data-fam="perc"] {
  --tint: var(--t4);
}

/* The pixel kit: a 16-bit stage, scaled up crisp. */
.pixkit {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.play-msg {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: var(--r);
  background: var(--raise);
  border: 1px solid var(--line);
  color: var(--text);
  z-index: 3;
  max-width: 90%;
}

.play-msg.err {
  border-color: var(--error);
  color: var(--error);
}

.play-msg[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .switch::after {
    transition: none;
  }
}
