.rhythm-main {
  width: min(100% - 2rem, var(--max-width));
  margin: 0 auto;
}

.rhythm-hero {
  min-height: 70svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 0.42fr);
  gap: clamp(2rem, 7vw, 6rem);
  align-items: end;
  padding: clamp(5rem, 12vw, 9rem) 0 clamp(3rem, 7vw, 5rem);
  border-bottom: 1px solid var(--line);
}

.rhythm-hero h1 {
  max-width: 9ch;
  margin-bottom: 1rem;
  font-size: clamp(4rem, 10vw, 8rem);
  line-height: 0.86;
}

.rhythm-hero > div > p:not(.eyebrow) {
  max-width: 43rem;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.3rem);
}

.rhythm-hero-note {
  padding: clamp(1.2rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-top: 0.35rem solid var(--accent-strong);
  background: var(--panel);
}

.rhythm-hero-note strong {
  display: block;
  margin: 0.7rem 0;
  color: var(--text);
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.05;
}

.rhythm-hero-note p,
.rhythm-privacy p {
  margin: 0;
  color: var(--muted);
}

.rhythm-privacy {
  margin: 2rem 0;
}

.rhythm-shell {
  margin: clamp(3rem, 8vw, 6rem) 0;
  padding: clamp(1rem, 4vw, 2.2rem);
  border: 1px solid var(--line);
  background: linear-gradient(150deg, rgba(15, 34, 41, 0.92), rgba(4, 12, 16, 0.97));
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, 0.28);
}

.rhythm-shell-header,
.rhythm-grid-section > header,
.rhythm-input > div:first-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
}

.rhythm-shell-header h2,
.rhythm-grid-section h3,
.rhythm-input h3 {
  margin-bottom: 0.35rem;
}

.rhythm-shell-header p {
  max-width: 50rem;
  margin: 0;
  color: var(--muted);
}

.rhythm-setup {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 2rem;
}

.rhythm-field,
.rhythm-stage-field,
.rhythm-layer-controls {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.rhythm-field {
  display: grid;
  align-content: start;
  gap: 0.55rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
}

.rhythm-field > span,
.rhythm-field > legend,
.rhythm-stage-field > legend,
.rhythm-layer-controls > legend,
.rhythm-device > span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.rhythm-field select,
.rhythm-field input[type="number"],
.rhythm-device select {
  width: 100%;
  min-width: 0;
  min-height: var(--tap-target);
  padding: 0.68rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: #071117;
  color: var(--text);
  font: inherit;
}

.rhythm-segmented,
.rhythm-input-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.rhythm-segmented label,
.rhythm-input-options label,
.rhythm-stage-grid label {
  position: relative;
}

.rhythm-segmented input,
.rhythm-input-options input,
.rhythm-stage-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.rhythm-segmented span,
.rhythm-input-options span,
.rhythm-stage-grid label > span {
  min-height: var(--tap-target);
  display: grid;
  place-items: center;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
}

.rhythm-segmented input:checked + span,
.rhythm-input-options input:checked + span,
.rhythm-stage-grid input:checked + span {
  border-color: var(--accent-strong);
  background: rgba(73, 188, 194, 0.13);
  color: var(--text);
  box-shadow: inset 0 -0.2rem 0 var(--accent-strong);
}

.rhythm-segmented input:focus-visible + span,
.rhythm-input-options input:focus-visible + span,
.rhythm-stage-grid input:focus-visible + span,
.rhythm-field :focus-visible,
.rhythm-layer-controls :focus-visible,
.rhythm-grid-scroll:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.rhythm-tempo-inputs {
  display: grid;
  grid-template-columns: minmax(4rem, 1fr) 4.4rem auto;
  gap: 0.45rem;
  align-items: center;
}

.rhythm-tempo-inputs small {
  color: var(--muted);
  font-weight: 800;
}

.rhythm-stage-field {
  margin-top: 1rem;
}

.rhythm-stage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.55rem;
}

.rhythm-stage-grid label > span {
  min-height: 5rem;
  align-content: center;
}

.rhythm-stage-grid b,
.rhythm-stage-grid small {
  display: block;
}

.rhythm-stage-grid small {
  margin-top: 0.2rem;
  color: var(--muted);
}

.rhythm-input {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.rhythm-input[hidden],
.rhythm-results[hidden],
.rhythm-tap-pad[hidden],
[hidden] {
  display: none !important;
}

.rhythm-input-options {
  max-width: 34rem;
}

.rhythm-microphone-setup {
  display: grid;
  gap: 0.8rem;
}

.rhythm-headphone,
.rhythm-device,
.rhythm-click-volume {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  color: var(--muted);
}

.rhythm-device {
  align-items: stretch;
  flex-direction: column;
  max-width: 28rem;
}

.rhythm-input-actions,
.rhythm-transport-actions,
.rhythm-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.rhythm-calibration {
  display: grid;
  gap: 0.45rem;
  max-width: 42rem;
}

.rhythm-calibration > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.rhythm-calibration p {
  margin: 0;
  color: var(--muted);
}

.rhythm-meter,
.rhythm-progress {
  height: 0.55rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.rhythm-meter i,
.rhythm-progress i {
  width: 0;
  height: 100%;
  display: block;
  background: var(--accent-strong);
  transition: width 120ms linear;
}

.rhythm-grid-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.rhythm-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.rhythm-legend b {
  color: var(--accent);
}

.rhythm-grid-scroll {
  overflow-x: auto;
  margin-top: 1rem;
  padding-bottom: 0.55rem;
}

.rhythm-count-grid {
  min-width: max-content;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(7.2rem, 1fr);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  overflow: hidden;
}

.rhythm-step {
  min-height: 8rem;
  display: grid;
  grid-template-rows: auto 1fr auto;
  place-items: center;
  padding: 0.65rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  text-align: center;
}

.rhythm-step:last-child {
  border-right: 0;
}

.rhythm-step.is-beat {
  box-shadow: inset 0.18rem 0 0 rgba(127, 230, 234, 0.35);
}

.rhythm-step.is-current {
  background: rgba(127, 230, 234, 0.18);
  color: var(--text);
  box-shadow: inset 0 -0.25rem 0 var(--accent);
}

.rhythm-transport {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
}

.rhythm-session-position {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.rhythm-session-position span {
  padding: 0.65rem;
  border: 1px solid var(--line);
  text-align: center;
}

.rhythm-session-position small,
.rhythm-session-position strong {
  display: block;
}

.rhythm-session-position small {
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rhythm-status {
  min-height: 1.5rem;
  margin: 0;
  color: var(--muted);
}

.rhythm-layer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: center;
  margin-top: 1rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
}

.rhythm-layer-controls > label:not(.rhythm-click-volume) {
  min-height: var(--tap-target);
  display: flex;
  gap: 0.4rem;
  align-items: center;
  color: var(--muted);
}

.rhythm-click-volume {
  margin-left: auto;
}

.rhythm-click-volume output {
  min-width: 3ch;
}

.rhythm-tap-pad {
  width: 100%;
  min-height: 9rem;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.3rem;
  margin-top: 1rem;
  border: 2px solid var(--accent-strong);
  border-radius: 0.8rem;
  background: rgba(73, 188, 194, 0.09);
  color: var(--text);
  font: 900 clamp(1.4rem, 4vw, 2.4rem)/1 var(--font-sans, sans-serif);
  cursor: pointer;
  touch-action: manipulation;
}

.rhythm-tap-pad small {
  color: var(--muted);
  font-size: 0.8rem;
}

.rhythm-tap-pad.is-hit {
  background: rgba(127, 230, 234, 0.27);
  transform: scale(0.99);
}

.rhythm-results {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1.2rem;
  margin-top: 1.5rem;
  padding: clamp(1rem, 4vw, 2rem);
  border: 1px solid var(--accent-strong);
  background: rgba(73, 188, 194, 0.07);
}

.rhythm-results:focus {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.rhythm-result-score {
  min-width: 9rem;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 1rem;
  border: 1px solid var(--line);
  text-align: center;
}

.rhythm-result-score span,
.rhythm-result-score small {
  color: var(--muted);
  text-transform: uppercase;
}

.rhythm-result-score strong {
  color: var(--accent);
  font-size: 4rem;
  line-height: 1;
}

.rhythm-metrics {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0;
}

.rhythm-metrics div {
  padding: 0.7rem;
  border: 1px solid var(--line);
}

.rhythm-metrics dt {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rhythm-metrics dd {
  margin: 0.25rem 0 0;
  color: var(--text);
  font-weight: 800;
}

.rhythm-result-footnote,
.rhythm-result-actions {
  grid-column: 1 / -1;
}

.rhythm-result-footnote {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.rhythm-notes {
  padding: clamp(3rem, 8vw, 6rem) 0;
  border-top: 1px solid var(--line);
}

@media (max-width: 920px) {
  .rhythm-setup {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rhythm-tempo-field {
    grid-column: 1 / -1;
  }

  .rhythm-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .rhythm-hero {
    min-height: auto;
    padding-top: 3rem;
  }
}

@media (max-width: 700px) {
  .rhythm-hero {
    min-height: auto;
    grid-template-columns: 1fr;
    padding-top: 3rem;
  }

  .rhythm-setup,
  .rhythm-stage-grid,
  .rhythm-results {
    grid-template-columns: 1fr;
  }

  .rhythm-tempo-field,
  .rhythm-result-score,
  .rhythm-metrics,
  .rhythm-result-footnote,
  .rhythm-result-actions {
    grid-column: 1;
  }

  .rhythm-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rhythm-click-volume {
    width: 100%;
    margin-left: 0;
  }

  .rhythm-transport-actions .button,
  .rhythm-result-actions .button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rhythm-meter i,
  .rhythm-progress i,
  .rhythm-tap-pad {
    transition: none;
  }

  .rhythm-tap-pad.is-hit {
    transform: none;
  }
}
