/* ============ Tempo · Style ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-1: #020617;
  --bg-2: #0a0e2a;
  --bg-3: #131846;
  --blue:    #3b82f6;
  --blue-2:  #60a5fa;
  --blue-3:  #93c5fd;
  --electric: #0084ff;
  --indigo:  #6366f1;
  --gold:    #fbbf24;
  --green:   #22c55e;
  --red:     #f43f5e;
  --text:    #eff6ff;
  --muted:   rgba(239,246,255,.55);
  --faint:   rgba(239,246,255,.32);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}

html, body {
  background: var(--bg-1);
  color: var(--text);
  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding-top: calc(58px + var(--safe-top));
  padding-bottom: calc(28px + var(--safe-bot));
}

/* Ambient electric blue background */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  background: var(--bg-1);
}
.orb-blur {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .35;
  pointer-events: none;
  will-change: transform;
}
.orb-blur.o1 {
  width: 60vmax; height: 60vmax;
  background: radial-gradient(circle, var(--electric) 0%, transparent 60%);
  top: -20vh; left: -10vw;
  animation: drift1 22s ease-in-out infinite;
}
.orb-blur.o2 {
  width: 55vmax; height: 55vmax;
  background: radial-gradient(circle, var(--indigo) 0%, transparent 60%);
  bottom: -20vh; right: -10vw;
  animation: drift2 28s ease-in-out infinite;
  opacity: .3;
}
@keyframes drift1 { 0%,100%{transform:translate(0,0)scale(1);} 50%{transform:translate(7vw,5vh)scale(1.05);} }
@keyframes drift2 { 0%,100%{transform:translate(0,0)scale(1);} 50%{transform:translate(-5vw,-7vh)scale(.96);} }
.grid-bg {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(96,165,250,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96,165,250,.04) 1px, transparent 1px);
  background-size: 50px 50px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 80%);
}

/* Top bar */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(58px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(2,6,23,.78);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid rgba(96,165,250,.12);
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--electric), var(--blue-2));
  display: grid; place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0,132,255,.5);
}
.brand span:not(.mark) {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(96,165,250,.18);
  background: rgba(96,165,250,.06);
  color: var(--text);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 16px;
  transition: background .2s, transform .15s;
}
.icon-btn:hover { background: rgba(96,165,250,.15); }
.icon-btn:active { transform: scale(.92); }
.install-btn {
  background: linear-gradient(135deg, var(--electric), var(--blue-2));
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,132,255,.5);
}
.hidden { display: none !important; }

main { padding: 14px 18px; max-width: 480px; margin: 0 auto; }

/* ============ BPM Stage ============ */
.bpm-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 8px auto 16px;
  min-height: 320px;
  justify-content: center;
}

/* Beat dots above ball */
.beat-dots {
  display: flex;
  gap: 8px;
  height: 14px;
  margin-bottom: 14px;
}
.beat-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: rgba(96,165,250,.20);
  transition: all .15s;
}
.beat-dot.beat {
  background: var(--blue-2);
  box-shadow: 0 0 12px var(--blue-2);
  transform: scale(1.4);
}
.beat-dot.accent {
  background: var(--gold);
  box-shadow: 0 0 14px var(--gold);
  transform: scale(1.5);
}

/* Pulsing ball */
.ball-wrap {
  position: relative;
  width: 200px; height: 200px;
  display: grid;
  place-items: center;
}
.ball-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(0,132,255,.18);
  opacity: 0;
  transform: scale(1);
}
.ring.active {
  animation: ring-pulse 0.6s ease-out;
}
@keyframes ring-pulse {
  0%   { opacity: .8; transform: scale(1); border-color: rgba(0,132,255,.6); }
  100% { opacity: 0; transform: scale(1.6); border-color: rgba(0,132,255,0); }
}
.ball {
  position: relative;
  width: 130px; height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%,
    rgba(255,255,255,0.45) 0%,
    rgba(96,165,250,0.6) 30%,
    rgba(0,132,255,0.85) 65%,
    rgba(2,6,23,1) 100%);
  box-shadow:
    inset 0 -16px 30px rgba(0,0,0,.5),
    inset 0 8px 20px rgba(255,255,255,.18),
    0 30px 80px rgba(0,132,255,.4),
    0 0 0 1px rgba(96,165,250,.18);
  transition: transform .15s cubic-bezier(.34,1.56,.64,1), box-shadow .25s;
}
.ball.beat {
  transform: scale(1.12);
  box-shadow:
    inset 0 -16px 30px rgba(0,0,0,.5),
    inset 0 8px 20px rgba(255,255,255,.25),
    0 0 60px rgba(96,165,250,.7),
    0 30px 80px rgba(0,132,255,.6),
    0 0 0 2px rgba(96,165,250,.5);
}
.ball.accent {
  background: radial-gradient(circle at 30% 25%,
    rgba(255,255,255,0.55) 0%,
    rgba(251,191,36,0.7) 30%,
    rgba(245,158,11,0.85) 65%,
    rgba(80,60,2,1) 100%);
  box-shadow:
    inset 0 -16px 30px rgba(0,0,0,.5),
    inset 0 8px 20px rgba(255,255,255,.25),
    0 0 60px rgba(251,191,36,.7),
    0 30px 80px rgba(245,158,11,.6);
}

/* BPM number */
.bpm-number {
  text-align: center;
  margin-top: 18px;
}
.bpm-value {
  font-size: 72px;
  font-weight: 200;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--blue-2);
  text-shadow: 0 0 24px rgba(0,132,255,.45);
  transition: color .3s;
}
.bpm-value.tap-active {
  color: var(--gold);
  text-shadow: 0 0 24px rgba(251,191,36,.5);
}
.bpm-unit {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  letter-spacing: 4px;
  color: var(--muted);
  margin-top: -2px;
}
.sub-info {
  margin-top: 10px;
  font-size: 13px;
  color: var(--faint);
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 1px;
}

/* BPM control: slider + step buttons */
.bpm-control {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.bpm-step {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(96,165,250,.22);
  background: rgba(96,165,250,.06);
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.bpm-step:hover { background: rgba(96,165,250,.12); }
.bpm-step:active { transform: scale(.92); }
.bpm-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: linear-gradient(90deg, rgba(0,132,255,.35), rgba(96,165,250,.55));
  border-radius: 2px;
  outline: none;
}
.bpm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  background: linear-gradient(135deg, var(--electric), var(--blue-2));
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,132,255,.6);
}
.bpm-slider::-moz-range-thumb {
  width: 22px; height: 22px;
  background: linear-gradient(135deg, var(--electric), var(--blue-2));
  border-radius: 50%;
  cursor: pointer;
  border: 0;
  box-shadow: 0 4px 12px rgba(0,132,255,.6);
}

/* Quickset row */
.bpm-quickset {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}
.quickset {
  padding: 8px 2px;
  background: rgba(96,165,250,.04);
  border: 1px solid rgba(96,165,250,.12);
  border-radius: 10px;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.quickset .lab {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: .5px;
  color: var(--faint);
}
.quickset:hover { background: rgba(96,165,250,.10); color: var(--text); }
.quickset.active {
  background: rgba(0,132,255,.16);
  border-color: rgba(0,132,255,.5);
  color: var(--blue-2);
  box-shadow: 0 4px 10px -4px rgba(0,132,255,.5);
}

/* Subdivision row */
.sub-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.sub-chip {
  padding: 9px 4px;
  background: rgba(96,165,250,.04);
  border: 1px solid rgba(96,165,250,.12);
  border-radius: 10px;
  color: var(--muted);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.sub-chip span {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .5px;
}
.sub-chip:hover { background: rgba(96,165,250,.10); color: var(--text); }
.sub-chip.active {
  background: rgba(0,132,255,.16);
  border-color: rgba(0,132,255,.5);
  color: var(--blue-2);
}

/* Time signature row */
.sig-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.sig-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--faint);
  text-transform: uppercase;
  margin-inline-end: 6px;
}
.sig-chip {
  padding: 6px 12px;
  background: rgba(96,165,250,.04);
  border: 1px solid rgba(96,165,250,.12);
  border-radius: 999px;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.sig-chip:hover { background: rgba(96,165,250,.10); color: var(--text); }
.sig-chip.active {
  background: rgba(0,132,255,.16);
  border-color: rgba(0,132,255,.5);
  color: var(--blue-2);
}

/* Action buttons */
.actions {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.btn-primary {
  padding: 18px;
  background: linear-gradient(135deg, var(--electric), var(--blue-2));
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 14px 30px -8px rgba(0,132,255,.55);
  transition: transform .15s;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary.playing {
  background: linear-gradient(135deg, #6b7280, #9ca3af);
  box-shadow: 0 14px 30px -8px rgba(107,114,128,.4);
}
.btn-tap {
  padding: 18px;
  background: rgba(251,191,36,.10);
  border: 1px solid rgba(251,191,36,.4);
  color: var(--gold);
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all .15s;
}
.btn-tap:active { transform: scale(.95); background: rgba(251,191,36,.20); }

/* Tap status */
.tap-status {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: rgba(251,191,36,.06);
  border: 1px solid rgba(251,191,36,.20);
  border-radius: 999px;
  font-size: 12px;
  color: var(--gold);
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 1px;
}
.tap-status .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
  animation: tap-pulse 1.2s ease-in-out infinite;
}
@keyframes tap-pulse { 50% { opacity: .35; } }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(2,6,23,.78);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: grid;
  place-items: end center;
  animation: modal-in .25s ease;
}
@keyframes modal-in { from{opacity:0;} to{opacity:1;} }
.modal-card {
  background: rgba(10,14,42,.95);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(96,165,250,.20);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 24px 22px calc(28px + var(--safe-bot));
  width: 100%;
  max-width: 480px;
  animation: sheet-up .35s cubic-bezier(.2,.9,.3,1.05);
}
@keyframes sheet-up { from{transform:translateY(100%);} to{transform:translateY(0);} }
.modal-card .handle { width: 38px; height: 4px; background: rgba(96,165,250,.30); border-radius: 2px; margin: -8px auto 16px; }
.modal-card h3 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.modal-card p { color: var(--muted); font-size: 13px; margin-bottom: 18px; line-height: 1.7; }
.modal-card p strong { color: var(--blue-2); }
.modal-card p code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  background: rgba(96,165,250,.10);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--blue-3);
}
.mark-big {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--electric), var(--blue-2));
  margin: 0 auto 14px;
  display: grid; place-items: center;
  color: #fff;
  font-size: 30px;
  box-shadow: 0 10px 30px rgba(0,132,255,.55);
}
.modal-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid rgba(96,165,250,.18);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  margin-bottom: 14px;
}
.modal-input:focus { outline: 2px solid var(--electric); outline-offset: 2px; }
.modal-summary {
  background: rgba(96,165,250,.06);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  text-align: center;
}
.modal-summary .stat-mini {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  color: var(--blue-2);
  font-weight: 700;
}
.modal-summary .stat-mini .k {
  display: block;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--faint);
  margin-top: 4px;
  font-weight: 500;
}
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-mini {
  padding: 12px;
  background: rgba(96,165,250,.06);
  border: 1px solid rgba(96,165,250,.18);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .2s;
}
.btn-mini:hover { background: rgba(96,165,250,.12); }
.btn-secondary {
  padding: 12px;
  background: rgba(96,165,250,.06);
  border: 1px solid rgba(96,165,250,.18);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: 12px;
  cursor: pointer;
}
.btn-secondary:hover { background: rgba(96,165,250,.12); }

/* Presets list */
.presets-list { max-height: 50vh; overflow-y: auto; }
.preset-item {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: rgba(96,165,250,.05);
  border: 1px solid rgba(96,165,250,.12);
  border-radius: 12px;
  margin-bottom: 8px;
}
.preset-item .bpm-circle {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: rgba(0,132,255,.18);
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 18px;
  color: var(--blue-2);
  font-variant-numeric: tabular-nums;
}
.preset-item .info .name { font-weight: 600; font-size: 14px; }
.preset-item .info .meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.preset-actions { display: flex; flex-direction: column; gap: 4px; }
.preset-actions button {
  background: transparent;
  border: 1px solid rgba(96,165,250,.18);
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.preset-actions button.load { color: var(--blue-2); border-color: rgba(0,132,255,.4); }
.preset-actions button.del:hover { color: var(--red); border-color: rgba(244,63,94,.4); background: rgba(244,63,94,.08); }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .ico { font-size: 40px; margin-bottom: 12px; opacity: .5; }

/* Toast */
.toast {
  position: fixed;
  top: calc(70px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,14,42,.96);
  border: 1px solid rgba(96,165,250,.30);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
  backdrop-filter: blur(10px);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from{opacity:0; transform:translate(-50%, -16px);} to{opacity:1; transform:translate(-50%, 0);} }
.toast.success { color: var(--green); border-color: rgba(34,197,94,.5); }
.toast.error { color: var(--red); border-color: rgba(244,63,94,.5); }
