/* ===========================================================
   ✧ Metronome — kawaii cosmic styling
   =========================================================== */

:root {
  --bg-deep: #14082a;
  --bg-mid: #1f0e3d;
  --ink: #f6e9ff;
  --ink-dim: #c7b3e8;
  --pink: #ff7eb6;
  --pink-soft: #ffb3d1;
  --purple: #b794f4;
  --purple-soft: #d6bcfa;
  --gold: #ffd56b;
  --teal: #7be5e0;
  --accent: var(--pink);
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.14);
  --border-strong: rgba(255, 255, 255, 0.28);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at top, var(--bg-mid) 0%, var(--bg-deep) 65%);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── cosmic backdrop ─────────────────────────────────── */

.sky {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 126, 182, 0.22), transparent 38%),
    radial-gradient(circle at 82% 18%, rgba(123, 229, 224, 0.18), transparent 42%),
    radial-gradient(circle at 50% 95%, rgba(183, 148, 244, 0.2), transparent 45%);
  z-index: -2;
  pointer-events: none;
}

.stars {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 14%, #fff, transparent 50%),
    radial-gradient(1px 1px at 24% 32%, rgba(255,255,255,0.6), transparent 50%),
    radial-gradient(1.5px 1.5px at 36% 8%, #fff, transparent 50%),
    radial-gradient(1px 1px at 48% 28%, rgba(255,255,255,0.7), transparent 50%),
    radial-gradient(1px 1px at 60% 18%, rgba(255,255,255,0.5), transparent 50%),
    radial-gradient(1.5px 1.5px at 72% 40%, #fff, transparent 50%),
    radial-gradient(1px 1px at 86% 12%, rgba(255,255,255,0.6), transparent 50%),
    radial-gradient(1px 1px at 92% 36%, rgba(255,255,255,0.7), transparent 50%),
    radial-gradient(1px 1px at 8% 64%, rgba(255,255,255,0.5), transparent 50%),
    radial-gradient(1.5px 1.5px at 22% 78%, #fff, transparent 50%),
    radial-gradient(1px 1px at 38% 88%, rgba(255,255,255,0.6), transparent 50%),
    radial-gradient(1px 1px at 56% 72%, rgba(255,255,255,0.4), transparent 50%),
    radial-gradient(1px 1px at 70% 92%, rgba(255,255,255,0.7), transparent 50%),
    radial-gradient(1.5px 1.5px at 84% 82%, #fff, transparent 50%),
    radial-gradient(1px 1px at 96% 68%, rgba(255,255,255,0.5), transparent 50%);
  background-size: 600px 600px;
  background-repeat: repeat;
  opacity: 0.85;
  animation: twinkle 8s ease-in-out infinite alternate;
}

@keyframes twinkle {
  0%   { opacity: 0.65; }
  100% { opacity: 0.95; }
}

/* ─── layout ──────────────────────────────────────────── */

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 56px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.app-header {
  text-align: center;
  margin-bottom: 4px;
}

.title {
  font-size: clamp(2rem, 6vw, 2.6rem);
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.04em;
  background: linear-gradient(120deg, var(--pink), var(--purple) 50%, var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(255, 126, 182, 0.25);
}

.sparkle {
  font-size: 0.7em;
  color: var(--gold);
  margin: 0 8px;
  display: inline-block;
  animation: sparkle 3s ease-in-out infinite;
}

.sparkle:last-child { animation-delay: 1.5s; }

@keyframes sparkle {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.85; }
  50%      { transform: scale(1.25) rotate(20deg); opacity: 1; }
}

.subtitle {
  margin: 8px 0 0;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

.subtitle em {
  color: var(--pink-soft);
  font-style: normal;
  font-weight: 600;
}

/* ─── metronome visual ───────────────────────────────── */

.metronome {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: 230px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow:
    var(--shadow),
    inset 0 0 60px rgba(183, 148, 244, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
  padding: 24px;
}

.metronome::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 50%;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 213, 107, 0.12), transparent 70%);
  pointer-events: none;
}

.metronome-arm-wrap {
  position: relative;
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.pivot-dot {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow:
    0 0 12px rgba(255, 213, 107, 0.7),
    0 0 24px rgba(255, 213, 107, 0.4);
  z-index: 3;
}

.arm {
  position: absolute;
  top: 25px;
  left: 50%;
  width: 4px;
  height: 165px;
  background: linear-gradient(180deg, var(--pink-soft), var(--purple));
  transform-origin: 50% 0%;
  transform: translateX(-50%) rotate(-25deg);
  border-radius: 4px;
  box-shadow: 0 0 12px rgba(255, 126, 182, 0.55);
  transition: transform 0.05s cubic-bezier(0.5, 0, 0.5, 1);
}

.arm-weight {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 30px;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--purple-soft), var(--pink));
  box-shadow: 0 4px 12px rgba(183, 148, 244, 0.5);
}

.display {
  position: absolute;
  bottom: 18px;
  right: 22px;
  text-align: right;
  pointer-events: none;
}

.bpm-readout {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.bpm-label {
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-top: 2px;
}

.beat-readout {
  font-size: 0.85rem;
  color: var(--gold);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1em;
}

/* pulse the metronome border on each beat */
.metronome.pulse {
  border-color: var(--border-strong);
  box-shadow:
    var(--shadow),
    inset 0 0 80px rgba(255, 126, 182, 0.18),
    0 0 40px rgba(255, 126, 182, 0.25);
}

.metronome.pulse.downbeat {
  box-shadow:
    var(--shadow),
    inset 0 0 80px rgba(255, 213, 107, 0.25),
    0 0 50px rgba(255, 213, 107, 0.35);
}

/* ─── options panel ───────────────────────────────────── */

.options {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-group label {
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-dim);
  font-style: italic;
  min-height: 1.2em;
}

/* BPM controls */
.bpm-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bpm-controls input[type="range"] {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 8px;
  background: linear-gradient(90deg, var(--pink), var(--purple), var(--teal));
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}

.bpm-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid var(--bg-deep);
  cursor: pointer;
  box-shadow: 0 0 16px rgba(255, 213, 107, 0.6);
  transition: transform 0.15s ease;
}

.bpm-controls input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.bpm-controls input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid var(--bg-deep);
  cursor: pointer;
  box-shadow: 0 0 16px rgba(255, 213, 107, 0.6);
}

.btn-step {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-step:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.08);
  box-shadow: 0 0 16px rgba(255, 126, 182, 0.5);
}

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

.bpm-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.chip {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink-dim);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  background: var(--panel-strong);
  color: var(--ink);
  border-color: var(--border-strong);
}

.chip.active {
  background: linear-gradient(120deg, var(--pink), var(--purple));
  color: white;
  border-color: transparent;
  box-shadow: 0 0 16px rgba(255, 126, 182, 0.4);
}

/* segmented control */
.seg {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 4px;
  border: 1px solid var(--border);
  isolation: isolate;
}

.seg-three {
  grid-template-columns: repeat(4, 1fr);
}

.seg input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg label {
  position: relative;
  z-index: 2;
  padding: 10px 8px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  cursor: pointer;
  border-radius: 9px;
  transition: color 0.18s ease;
  text-transform: none;
  user-select: none;
}

.seg label:hover {
  color: var(--ink);
}

.seg input[type="radio"]:checked + label {
  color: white;
}

.seg .seg-indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: calc(25% - 4px);
  background: linear-gradient(120deg, var(--pink), var(--purple));
  border-radius: 9px;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
  box-shadow: 0 4px 14px rgba(255, 126, 182, 0.35);
}

/* ─── start button ────────────────────────────────────── */

.start-btn {
  width: 100%;
  max-width: 460px;
  padding: 18px;
  border-radius: 999px;
  border: none;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(120deg, var(--pink), var(--purple));
  color: white;
  box-shadow:
    0 8px 28px rgba(255, 126, 182, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: all 0.2s ease;
  font-family: inherit;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 12px 36px rgba(255, 126, 182, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.start-btn:active {
  transform: translateY(0);
}

.start-btn.running {
  background: linear-gradient(120deg, var(--gold), #ffa552);
  box-shadow:
    0 8px 28px rgba(255, 213, 107, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.start-icon {
  font-size: 1.3rem;
}

/* ─── footer ──────────────────────────────────────────── */

.app-footer {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--ink-dim);
  opacity: 0.7;
}

.app-footer p {
  margin: 0;
}

/* ─── responsive ──────────────────────────────────────── */

@media (max-width: 540px) {
  .app { padding: 36px 18px 28px; gap: 22px; }
  .metronome { height: 200px; padding: 18px; }
  .arm { height: 145px; }
  .bpm-readout { font-size: 2rem; }
  .seg label { font-size: 0.78rem; padding: 8px 4px; }
  .title { font-size: 1.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  .stars,
  .sparkle {
    animation: none;
  }
  .arm {
    transition: transform 0.01s linear;
  }
}