/* Progresiones: config chips, stage, and the self-playing sequence row. */

.prog {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-4);
  padding: var(--s-4) var(--gutter) var(--s-7);
  background: var(--bg);
}

.prog:focus {
  outline: none;
}

/* ---------- Config ---------- */

.prog-config {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
}

.prog-options,
.prog-tempo {
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
}

.prog-sep {
  width: 1px;
  height: 32px;
  background: var(--line);
}

.field {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--ink-2);
  font-size: var(--t-small);
  font-weight: 600;
}

.field select {
  min-height: 44px;
  padding: 0 38px 0 var(--s-3);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b6bac3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 10px center / 18px;
  color: var(--ink);
  font-size: var(--t-body);
  font-weight: 600;
  appearance: none;
  cursor: pointer;
}

.field select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
}

.stepper button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.stepper button:hover {
  background: var(--surface-2);
}

.stepper span {
  min-width: 92px;
  text-align: center;
  color: var(--ink-2);
  font-weight: 600;
}

.stepper b {
  color: var(--ink);
  font: 800 var(--t-body) var(--font-display);
  font-variant-numeric: tabular-nums;
}

/* ---------- Stage ---------- */

.prog-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto minmax(260px, 340px);
  gap: var(--s-6);
  align-items: center;
}

.prog-name h1 {
  font: 800 var(--t-chord) / 0.86 var(--font-display);
  font-size: clamp(6rem, 4rem + 6vw, 10rem);
  letter-spacing: -0.035em;
}

.prog-name > p:first-of-type {
  margin-top: var(--s-2);
  color: var(--ink-2);
  font: 600 var(--t-title) / 1.15 var(--font-display);
}

.pulse {
  display: flex;
  gap: var(--s-3);
  margin-top: var(--s-5);
}

.pulse i {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  transition: background-color 80ms var(--ease-out), transform 80ms var(--ease-out);
}

.pulse i.is-on {
  background: var(--accent);
  transform: scale(1.15);
}

.prog-status {
  margin-top: var(--s-3);
  color: var(--ink-2);
  font-size: var(--t-small);
  font-weight: 600;
}

.prog-visual {
  width: clamp(280px, 25vw, 360px);
}

.is-quick .cd-finger {
  animation-duration: 240ms;
  animation-delay: calc(var(--order, 0) * 50ms);
}

.prog-count {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  display: none;
  place-items: center;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font: 800 6rem / 1 var(--font-display);
  outline: 8px solid var(--bg);
  pointer-events: none;
}

.is-counting .prog-count {
  display: grid;
}

.prog-side {
  display: grid;
  gap: var(--s-4);
}

.prog-next {
  display: grid;
  justify-items: start;
  gap: 2px;
  padding: var(--s-4) var(--s-5);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.prog-next .label {
  color: var(--ink-2);
  font-weight: 600;
}

.prog-next b {
  font: 800 4.5rem / 1 var(--font-display);
  letter-spacing: -0.02em;
}

.prog-next .sub {
  color: var(--ink-2);
}

.btn--small {
  min-height: 44px;
  margin-top: var(--s-3);
  padding: 0 var(--s-4);
}

.is-finished .prog-next {
  outline: 2px solid var(--accent-edge);
}

.prog-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.prog-controls .btn {
  min-height: 50px;
  padding: 0 var(--s-4);
}

.prog-controls [data-action="toggle"] {
  min-width: 150px;
}

/* ---------- Sequence row ---------- */

.seq {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-3);
  padding-top: var(--s-4);
  border-top: 1px solid var(--line);
}

.seq-head {
  display: flex;
  align-items: baseline;
  gap: var(--s-4);
}

.seq-title {
  font: 800 var(--t-title) / 1.1 var(--font-display);
  letter-spacing: -0.01em;
}

.seq-round {
  color: var(--ink-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.seq-tiles {
  display: flex;
  gap: var(--s-3);
  padding: 4px;
  margin: -4px;
  overflow-x: auto;
}

.seq-tile {
  position: relative;
  display: grid;
  align-content: start;
  gap: 2px;
  flex: none;
  width: 156px;
  min-height: 104px;
  padding: var(--s-3) var(--s-4);
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  transition:
    width var(--dur) var(--ease-out),
    opacity var(--dur) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.seq-name {
  font: 800 1.75rem / 1 var(--font-display);
  letter-spacing: -0.01em;
}

.seq-sub {
  color: var(--ink-2);
  font-size: var(--t-small);
  font-weight: 600;
  white-space: nowrap;
}

.seq-beats {
  display: flex;
  gap: 8px;
  margin-top: var(--s-2);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.seq-beats i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
}

.seq-beats i.is-on {
  background: var(--ink);
}

.seq-meter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
}

.seq-meter span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition-property: transform;
  transition-timing-function: linear;
}

/* Signature: the card that sounds opens and fills beat by beat. */
.seq-tile.is-current {
  width: 300px;
  border-color: var(--accent-edge);
  background: var(--surface-2);
}

.seq-tile.is-current .seq-beats {
  opacity: 1;
}

.seq-tile.is-done {
  opacity: 0.55;
}

/* ---------- Full screen class view ---------- */

.prog.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 20;
  align-content: center;
  padding: var(--s-6) clamp(24px, 4vw, 64px);
  overflow: auto;
}

.prog.is-fullscreen .prog-config,
.prog.is-fullscreen .seq,
.prog.is-fullscreen [data-action="restart"],
.prog.is-fullscreen [data-action="mute"],
.prog.is-fullscreen [data-action="chord-sound"],
.prog.is-fullscreen .prog-status {
  display: none;
}

.prog.is-fullscreen .prog-stage {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 0.8fr);
  gap: clamp(24px, 4vw, 72px);
}

.prog.is-fullscreen .prog-name h1 {
  font-size: clamp(9rem, 16vw, 18rem);
}

.prog.is-fullscreen .prog-name > p:first-of-type {
  font-size: clamp(1.75rem, 2.4vw, 2.75rem);
}

.prog.is-fullscreen .pulse i {
  width: clamp(28px, 2.6vw, 44px);
  height: clamp(28px, 2.6vw, 44px);
}

.prog.is-fullscreen .prog-visual {
  width: clamp(320px, 32vw, 560px);
}

.prog.is-fullscreen .prog-next b {
  font-size: clamp(5rem, 9vw, 9rem);
}

/* ---------- Responsive ---------- */

@media (max-width: 1240px) {
  .prog-stage {
    grid-template-columns: minmax(200px, 1fr) auto minmax(240px, 300px);
    gap: var(--s-5);
  }

  .prog-next b {
    font-size: 3.5rem;
  }
}

@media (max-width: 900px) {
  .prog-stage,
  .prog.is-fullscreen .prog-stage {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s-4);
  }

  .prog-visual {
    order: 0;
    width: min(100%, 320px);
    justify-self: center;
  }

  .prog-options,
  .prog-tempo,
  .prog-config > .filters {
    flex-basis: 100%;
  }

  .prog-name {
    display: grid;
    justify-items: start;
  }

  .prog-sep {
    display: none;
  }

  .prog-config > .filters,
  .prog-options .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    width: calc(100% + var(--gutter) * 2);
    margin: 0 calc(var(--gutter) * -1);
    padding: 2px var(--gutter);
    scrollbar-width: none;
  }

  .seq-tile {
    width: 120px;
  }

  .seq-tile.is-current {
    width: 220px;
  }
}


.is-finished .prog-next b {
  font-size: 2.5rem;
  line-height: 1.05;
}

/* Phone: controls live in a bar fixed to the bottom, always reachable while playing. */
@media (max-width: 520px) {
  .prog {
    padding-bottom: 120px;
  }

  .prog-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: 1fr repeat(4, 52px);
    gap: var(--s-2);
    padding: var(--s-3) var(--gutter) calc(var(--s-3) + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(10px);
  }

  .prog-controls .btn {
    min-height: 52px;
    padding: 0;
  }

  .prog-controls [data-action="toggle"] {
    min-width: 0;
    padding: 0 var(--s-4);
  }

  .prog-controls .btn:not([data-action="toggle"]) span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .prog.is-fullscreen .prog-controls {
    grid-template-columns: 1fr 52px;
  }
}


/* ---------- Review fixes ---------- */

/* Stage: a fixed name column (no layout shift between C and C#m), diagram beside it, the rest to the side. */
.prog-stage {
  grid-template-columns: var(--name-w, 340px) auto minmax(300px, 1fr);
}

.prog-visual {
  width: clamp(320px, 28vw, 420px);
}

.prog-next {
  grid-template-columns: auto auto;
  justify-content: start;
  align-items: center;
  column-gap: var(--s-7);
}

.prog-next-text {
  display: grid;
  justify-items: start;
  gap: 2px;
}

.prog-next-shape .chord-diagram--tile {
  display: block;
  width: clamp(72px, 7vw, 104px);
  height: auto;
}

.prog-name h1 {
  font-size: clamp(6rem, 3rem + 8vw, 11rem);
}

.prog-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.prog-controls [data-action="toggle"] {
  min-width: 0;
  grid-column: 1 / -1;
}

/* Full screen: the current chord is the biggest thing in the room; the next one steps back. */
.prog.is-fullscreen .prog-stage {
  grid-template-columns: minmax(0, 1.2fr) auto minmax(0, 0.7fr);
  align-items: center;
  min-height: calc(100dvh - 96px);
}

.prog.is-fullscreen .prog-name h1 {
  font-size: clamp(11rem, 23vw, 26rem);
  line-height: 0.82;
}

.prog.is-fullscreen .prog-visual {
  width: clamp(280px, 24vw, 420px);
}

.prog.is-fullscreen .prog-next b {
  color: var(--ink-2);
  font-size: clamp(3rem, 6vw, 7rem);
}

.prog.is-fullscreen .prog-controls {
  grid-template-columns: 1fr;
}

@media (max-width: 1240px) {
  .prog-stage {
    grid-template-columns: var(--name-w, 250px) auto minmax(260px, 1fr);
  }

  .prog-name h1 {
    font-size: clamp(5.5rem, 2rem + 8vw, 8rem);
  }
}

@media (max-width: 900px) {
  .prog-stage {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Phone: current and next side by side, the config folds away while playing so the whole diagram stays above the bar. */
@media (max-width: 520px) {
  .prog-stage,
  .prog.is-fullscreen .prog-stage {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--s-3);
    min-height: 0;
  }

  .prog-name {
    grid-column: 1;
    grid-row: 1;
  }

  .prog-name h1,
  .prog.is-fullscreen .prog-name h1 {
    font-size: 5.5rem;
  }

  .prog-name > p:first-of-type {
    font-size: 1.25rem;
  }

  .pulse {
    margin-top: var(--s-3);
  }

  .prog-side {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
  }

  .prog-next {
    padding: var(--s-3) var(--s-4);
  }

  .prog-next b,
  .prog.is-fullscreen .prog-next b {
    font-size: 2.5rem;
  }

  .prog-visual,
  .prog.is-fullscreen .prog-visual {
    grid-column: 1 / -1;
    grid-row: 2;
    width: min(100%, 290px);
  }

  .is-playing .prog-config,
  .is-paused .prog-config {
    display: none;
  }

  .prog-controls {
    grid-template-columns: 1fr repeat(4, 52px);
  }

  .prog.is-fullscreen .prog-controls {
    grid-template-columns: 1fr 52px;
  }
}

@media (max-width: 520px) {
  .prog-next-shape {
    display: none;
  }
}

.prog.is-fullscreen .prog-next-shape .chord-diagram--tile {
  width: clamp(80px, 7vw, 120px);
}

/* Phone bar: the play button shares its row with the icon buttons. */
@media (max-width: 520px) {
  .prog-controls [data-action="toggle"] {
    grid-column: auto;
  }
}
