:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --ink: #162116;
  --muted: #5f6a5c;
  --line: #d7dfd1;
  --panel: #ffffff;
  --accent: #247c50;
  --accent-dark: #185737;
  --accent-soft: #dff2e7;
  --warn: #e56a28;
  --shadow: 0 22px 55px rgba(29, 55, 33, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(36, 124, 80, 0.13), transparent 30rem),
    linear-gradient(160deg, #f7faf4 0%, var(--bg) 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 10vw, 6.5rem);
  line-height: 0.92;
}

h2 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.6rem);
  line-height: 1.05;
}

.intro {
  max-width: 650px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  line-height: 1.55;
}

.hero-play-pair {
  width: min(100%, 420px);
  margin-top: 24px;
}

.pulse {
  position: relative;
  display: grid;
  place-items: center;
  width: min(34vw, 230px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px rgba(36, 124, 80, 0.12), var(--shadow);
}

.pulse span {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.16;
  transform: scale(0.85);
  transition: transform 120ms ease, opacity 120ms ease;
}

.pulse.beat span {
  opacity: 0.28;
  transform: scale(1.08);
}

.pulse strong {
  z-index: 1;
  font-size: clamp(3rem, 8vw, 5.2rem);
  line-height: 1;
}

.pulse small {
  z-index: 1;
  color: var(--muted);
  font-weight: 700;
}

.controls {
  display: grid;
  grid-template-columns: 2fr repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.curve-builder {
  margin-top: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 30px rgba(29, 55, 33, 0.08);
}

.curve-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.curve-header .eyebrow {
  margin-bottom: 8px;
}

.duration-control {
  min-width: 170px;
}

.duration-control label,
.background-toggle {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.duration-control div {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.duration-control input {
  width: 92px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  font-weight: 900;
}

.duration-control span {
  color: var(--muted);
  font-weight: 800;
}

.graph-wrap {
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
  touch-action: none;
}

#cadenceGraph {
  display: block;
  width: 100%;
  height: auto;
  min-height: 260px;
}

#gridLayer line {
  stroke: #dfe7d9;
  stroke-width: 1;
}

#gridLayer text,
.axis-labels text {
  fill: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

#curvePath {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 8;
}

#playhead {
  opacity: 0;
  stroke: var(--warn);
  stroke-width: 4;
  transition: opacity 120ms ease;
}

#playhead.visible {
  opacity: 1;
}

.cadence-point {
  cursor: grab;
}

.cadence-point circle {
  fill: #fff;
  fill-opacity: 0.58;
  stroke: var(--accent-dark);
  stroke-width: 4;
}

.cadence-point.selected circle {
  fill: var(--accent-soft);
  fill-opacity: 0.62;
  stroke: var(--warn);
}

.cadence-point.muted circle {
  fill: #f1f3ef;
  fill-opacity: 0.62;
  stroke: #8a9386;
}

.cadence-point.muted.selected circle {
  stroke: var(--warn);
}

.cadence-point text {
  fill: var(--ink);
  font-size: 15px;
  font-weight: 900;
  text-anchor: middle;
}

.cadence-point.muted text {
  fill: #596157;
}

.cadence-point .time-label {
  fill: var(--muted);
  font-size: 14px;
}

.cadence-point .sound-label {
  fill: var(--warn);
  font-size: 13px;
  text-transform: uppercase;
}

.curve-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.secondary-button.compact {
  min-width: auto;
  min-height: 46px;
  padding: 0 16px;
}

.secondary-button.muted-toggle {
  background: #f1f3ef;
  color: #596157;
}

.background-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 2px;
  text-transform: none;
  letter-spacing: 0;
}

.background-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.background-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.save-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.save-panel label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.save-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.save-row:first-of-type {
  grid-template-columns: minmax(0, 1fr) auto;
}

.save-row input {
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 30px rgba(29, 55, 33, 0.08);
}

.panel label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tempo-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 10px;
  align-items: center;
}

.step-button,
.secondary-button,
.play-button,
.pause-button,
.quick-picks button {
  border: 0;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.step-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 1.5rem;
  font-weight: 900;
}

.step-button:active,
.secondary-button:active,
.play-button:active,
.pause-button:active,
.quick-picks button:active {
  transform: translateY(1px) scale(0.99);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.tempo-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.tempo-meta output {
  color: var(--ink);
  font-weight: 900;
}

.play-zone {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  margin-top: 16px;
}

.play-pair {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
}

.play-button,
.pause-button {
  min-height: 68px;
  border-radius: 8px;
  font-size: 1.25rem;
  font-weight: 900;
}

.play-button {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

.pause-button {
  border: 0;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(29, 55, 33, 0.08);
  transition: transform 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.pause-button:disabled {
  color: #9aa495;
  cursor: not-allowed;
  opacity: 0.65;
}

.play-button.running {
  background: var(--warn);
}

.secondary-button {
  min-width: 130px;
  min-height: 68px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 10px 30px rgba(29, 55, 33, 0.08);
}

.quick-picks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.quick-picks button {
  min-height: 82px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 800;
  box-shadow: 0 10px 30px rgba(29, 55, 33, 0.08);
}

.quick-picks span {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent-dark);
  font-size: 1.45rem;
}

.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.graph-status {
  margin: 16px 0 0;
}

.status div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

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

.status-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #a8b3a2;
}

.status-dot.running {
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(36, 124, 80, 0.14);
}

#beatCounter {
  flex: 0 0 auto;
  color: var(--ink);
  font-weight: 900;
}

@media (max-width: 780px) {
  .app {
    width: min(100% - 22px, 620px);
    padding: 18px 0;
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding-top: 12px;
  }

  .pulse {
    width: min(100%, 210px);
    justify-self: center;
  }

  .controls,
  .play-zone,
  .quick-picks {
    grid-template-columns: 1fr;
  }

  .curve-header {
    flex-direction: column;
  }

  .duration-control {
    width: 100%;
  }

  #cadenceGraph {
    min-height: 230px;
  }

  .play-zone {
    gap: 10px;
  }

  .secondary-button,
  .play-button,
  .pause-button {
    width: 100%;
    min-height: 58px;
  }

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

  .save-row,
  .save-row:first-of-type {
    grid-template-columns: 1fr;
  }

  .status {
    align-items: flex-start;
    flex-direction: column;
  }
}
