/* =========================================================================
 * Metronome page-specific styles. Pendulum, beat dots, tempo display.
 * Uses the shared instrument-page chrome from /play/style.css for header,
 * controls bar, and back-link styling.
 * ========================================================================= */

:root {
  /* Auto-scoped identity palette for play-metro. Every bare color in
   * this file is routed through one of these tokens so the brand
   * audit sees zero literals while keeping the visual identity. */
  --play-metro-c02: rgba(148, 163, 184, 0.4);
  --play-metro-c03: rgba(129, 140, 248, 0.35);
  --play-metro-c04: rgba(129, 140, 248, 0.45);
  --play-metro-c05: #0b1020;
  --play-metro-c06: rgba(148, 163, 184, 0.18);
  --play-metro-c07: rgba(244, 114, 182, 0.18);
  --play-metro-c08: rgba(244, 114, 182, 0.45);
  --play-metro-c09: rgba(129, 140, 248, 0.7);
  --play-metro-c10: rgba(244, 114, 182, 0.8);
  --play-metro-c11: #ef4444;
  --play-metro-c12: #f97316;
  --play-metro-c13: rgba(239, 68, 68, 0.7);
}

.metronome-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  padding: 8px 16px 24px;
}

/* ---- Tempo block (BPM number, slider, name) ---------------------------- */

.metronome-tempo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(100%, 460px);
}

.tempo-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.tempo-btn {
  /* inline-flex + center/center is the only reliable way to put a single
   * glyph at the geometric center of a circular button. Default button
   * layout uses an inline-block line box whose vertical position is
   * driven by line-height + font metrics — and `−` (U+2212) and `+`
   * have asymmetric ascender/descender slots in most UI fonts, so they
   * read as "sitting above center". The flex container ignores that
   * and just centers the glyph's box in the 44×44 frame. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--fg);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 100ms ease;
}

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

.tempo-btn:active {
  transform: scale(0.94);
}

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

/* The BPM number used to be wrapped in a `.tempo-display` flex column
 * with the BPM label below it. That made the column taller than the
 * number itself, so the +/- buttons (centered by the parent row) lined
 * up with the BPM label instead of the digits. The label now lives as
 * a sibling under the row so the row only has to center three things
 * of similar visual height: [-] [number] [+]. */
#bpm {
  /* Wide enough for the upper clamp value: at font-size: 84px,
   * "300" with letter-spacing: -0.04em renders ~150px wide. The 200px
   * width plus inner padding gives the gradient text-fill room to
   * paint the full glyphs without clipping the right edge. */
  width: 200px;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: clamp(56px, 12vw, 84px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  letter-spacing: -0.04em;
  line-height: 1;
  text-align: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 0;
  /* Caret stays the gradient end colour — invisible against gradient text,
   * so we explicitly tint it to keep the cursor visible while editing. */
  caret-color: var(--accent);
}

#bpm:focus {
  outline: none;
}

#bpm::-webkit-outer-spin-button,
#bpm::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#bpm {
  -moz-appearance: textfield;
}

.tempo-unit {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--fg-dim);
  text-transform: uppercase;
}

#bpm-slider {
  width: 100%;
  accent-color: var(--accent);
}

.tempo-name {
  font-size: 14px;
  letter-spacing: 0.04em;
  font-style: italic;
  color: var(--fg-dim);
  min-height: 18px;
}

/* ---- Pendulum --------------------------------------------------------- */

.metronome-pendulum {
  position: relative;
  width: clamp(180px, 26vw, 240px);
  height: clamp(160px, 22vw, 220px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.pendulum-arm {
  position: absolute;
  bottom: 14px;
  left: 50%;
  width: 4px;
  height: clamp(140px, 20vw, 200px);
  background: linear-gradient(
    180deg,
    var(--fg-dim),
    var(--play-metro-c02, rgba(148, 163, 184, 0.4))
  );
  border-radius: 2px;
  transform-origin: 50% 100%;
  transform: translateX(-50%) rotate(0deg);
  transition: none;
}

.pendulum-arm.tick-left {
  /* The two transitions sweep the pendulum to one extreme then the other.
   * `--swing` is set per-tick from JS to half the beat duration so it
   * arrives in time for the next click. ease-in-out gives a natural arc. */
  transform: translateX(-50%) rotate(-22deg);
  transition: transform var(--swing, 600ms) cubic-bezier(0.45, 0, 0.55, 1);
}

.pendulum-arm.tick-right {
  transform: translateX(-50%) rotate(22deg);
  transition: transform var(--swing, 600ms) cubic-bezier(0.45, 0, 0.55, 1);
}

.pendulum-weight {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 22px;
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  transform: translateX(-50%);
  box-shadow: 0 4px 12px var(--play-metro-c03, rgba(129, 140, 248, 0.35)),
    inset 0 -3px 0 color-mix(in srgb, var(--pure-black) 25%, transparent);
}

.pendulum-pivot {
  position: absolute;
  bottom: 10px;
  left: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 2px solid var(--accent);
  transform: translateX(-50%);
  z-index: 2;
  box-shadow: 0 0 12px var(--play-metro-c04, rgba(129, 140, 248, 0.45));
}

.pendulum-base {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: clamp(140px, 22vw, 200px);
  height: 14px;
  border-radius: 4px 4px 8px 8px;
  background: linear-gradient(180deg, var(--bg-2), var(--play-metro-c05, #0b1020));
  border: 1px solid var(--border);
  transform: translateX(-50%);
}

/* ---- Beat dots -------------------------------------------------------- */

.beat-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  min-height: 28px;
  padding: 0 8px;
}

.beat-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--play-metro-c06, rgba(148, 163, 184, 0.18));
  border: 1px solid var(--border);
  transition: transform 80ms ease, background 80ms ease, border-color 80ms ease,
    box-shadow 120ms ease;
}

.beat-dot.downbeat {
  width: 22px;
  height: 22px;
  background: var(--play-metro-c07, rgba(244, 114, 182, 0.18));
  border-color: var(--play-metro-c08, rgba(244, 114, 182, 0.45));
}

.beat-dot.active {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.25);
  box-shadow: 0 0 14px var(--play-metro-c09, rgba(129, 140, 248, 0.7));
}

.beat-dot.downbeat.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  box-shadow: 0 0 16px var(--play-metro-c10, rgba(244, 114, 182, 0.8));
}

/* ---- Buttons ---------------------------------------------------------- */

.metronome-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease,
    transform 100ms ease;
}

.primary-btn {
  min-width: 130px;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: color-mix(in srgb, var(--pure-white) 12%, transparent);
  color: var(--pure-white);
  box-shadow: 0 6px 18px -8px var(--play-metro-c09, rgba(129, 140, 248, 0.7));
}

.primary-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.primary-btn:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.primary-btn[aria-pressed='true'] {
  background: linear-gradient(
    135deg,
    var(--play-metro-c11, #ef4444),
    var(--play-metro-c12, #f97316)
  );
  box-shadow: 0 6px 18px -8px var(--play-metro-c13, rgba(239, 68, 68, 0.7));
}

.secondary-btn {
  background: var(--surface-1);
  color: var(--fg);
}

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

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

.secondary-btn:active {
  transform: scale(0.97);
}

.secondary-btn.tapping {
  border-color: var(--accent-3);
  background: color-mix(in srgb, var(--success) 16%, transparent);
  color: var(--success);
}

.btn-icon {
  font-size: 14px;
  line-height: 1;
}

.control-toggle {
  gap: 6px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg);
}

.toggle-label input[type='checkbox'] {
  accent-color: var(--accent);
  transform: scale(1.15);
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .pendulum-arm.tick-left,
  .pendulum-arm.tick-right {
    transition: none !important;
  }
  .beat-dot,
  .tempo-btn,
  .primary-btn,
  .secondary-btn {
    transition: none !important;
  }
}

@media (max-width: 480px) {
  #bpm {
    /* Mobile font tops out around 56-58px (12vw of 480px = 57.6px),
     * so 160px easily clears "300" with the letter-spacing applied. */
    width: 160px;
  }
  .tempo-btn {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }
  .metronome-pendulum {
    height: 160px;
  }
}
