/* === Metronome, reference pitch and tuner === */

main { max-width: 560px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* the site has no global focus ring; these controls are small and there are a
   lot of them, so a keyboard user needs one that is impossible to lose */
main :focus-visible {
  outline: 3px solid var(--pick-border);
  outline-offset: 2px;
}

/* --- Tabs --- */
.met-tabs {
  display: flex;
  gap: 0.25rem;
  margin: 0 0 1.3rem;
  padding: 0.25rem;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.met-tab {
  flex: 1;
  padding: 0.5rem 0.4rem;
  border-radius: 999px;
  border: 2px solid transparent;
  background: transparent;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--muted);
}
.met-tab:hover { transform: none; border-color: transparent; color: var(--primary-dark); }
.met-tab.picked {
  background: var(--pick-bg);
  border-color: var(--pick-border);
  color: var(--primary-dark);
}
.tab-dot {
  display: inline-block;
  width: 7px; height: 7px;
  margin-left: 0.35rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  animation: tab-pulse 1.5s ease-in-out infinite;
}
.tab-dot[hidden] { display: none; }
@keyframes tab-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.met-panel[hidden] { display: none; }

/* --- BPM display --- */
.met-display { text-align: center; margin: 0.5rem 0 1rem; }
.met-bpm {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: 4.5rem;
  line-height: 1;
  color: var(--ink);
}
/* the number itself is a button: activating it swaps in a text field, so an
   exact tempo is one thing you type rather than twenty-five things you tap */
.met-bpm-num,
.met-bpm-input {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: 1;
  color: inherit;
  padding: 0 0.1rem;
  border: none;
  border-bottom: 3px dashed transparent;
  border-radius: 8px;
  background: none;
}
.met-bpm-num:hover {
  transform: none;
  border-bottom-color: var(--border);
  color: var(--primary-dark);
}
.met-bpm-input {
  width: 3.4ch;
  text-align: center;
  border-bottom-color: var(--pick-border);
  -moz-appearance: textfield;
  appearance: textfield;
}
.met-bpm-input::-webkit-outer-spin-button,
.met-bpm-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.met-bpm-unit { font-size: 1.1rem; font-weight: 700; color: var(--muted); }
.met-tempo-name {
  margin-top: 0.3rem;
  font-style: italic;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 1.05rem;
}
.met-counter {
  margin-top: 0.15rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* --- Beat dots --- */
.met-dots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  min-height: 26px;
  margin-bottom: 0.4rem;
}
.met-dot {
  width: 22px;
  height: 22px;
  padding: 0;
  flex: none;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--border);
  transition: background 0.08s ease, border-color 0.08s ease, opacity 0.15s ease;
}
.met-dot:hover { transform: none; border-color: var(--primary); }
.met-dot.lvl2 { border-color: var(--primary); border-width: 3px; }   /* loud */
/* a silent beat shrinks to a bare dot: at this size a dashed ring reads as a
   cog, and the point is that there is less of it, not that it is decorated */
.met-dot.lvl0 { position: relative; border-color: transparent; background: transparent; }
.met-dot.lvl0::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.4;
  transition: opacity 0.08s ease;
}
.met-dot.on { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 8px var(--accent); }
.met-dot.lvl2.on { background: var(--primary); border-color: var(--primary); box-shadow: 0 0 11px var(--primary); }
.met-dot.lvl0.on { background: transparent; border-color: transparent; box-shadow: none; }
.met-dot.lvl0.on::after { opacity: 0.95; }
.met-dot.lvl0:hover { border-color: var(--primary); }   /* the .lvl0 rule above outranks the shared :hover */
.met-dot.pop { animation: met-pop 0.18s ease; }
@keyframes met-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.55); }
  100% { transform: scale(1); }
}
/* a bar the speed trainer is deliberately keeping quiet */
.met-dots.quiet .met-dot { opacity: 0.4; }
.met-dots.quiet .met-dot.on { opacity: 0.8; }
.met-dots-hint { text-align: center; margin: 0 0 1.2rem; }

/* --- Tempo slider row --- */
.met-tempo-row { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 1.1rem; }
.met-step {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--btn);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  touch-action: manipulation;      /* holding to repeat must not pan the page */
}
.met-step:hover { border-color: var(--primary); color: var(--primary-dark); }
.met-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
}
.met-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.met-slider::-moz-range-thumb {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* --- Buttons --- */
.met-buttons { display: flex; gap: 0.7rem; margin-bottom: 1.6rem; }
.met-play { flex: 1; margin-top: 0; }
.met-play.playing { background: var(--accent); border-color: var(--accent); }
.met-play.playing:hover { background: #5fb3c8; border-color: #5fb3c8; }
.met-tap {
  flex-shrink: 0;
  background: var(--btn);
  font-weight: 700;
  padding: 0.85rem 1.4rem;
}
.met-tap:hover { border-color: var(--primary); color: var(--primary-dark); }
.met-tap.flash { background: var(--pick-bg); border-color: var(--pick-border); }

/* --- Settings --- */
.met-settings {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}
.met-set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0;
}
.met-set-row + .met-set-row { border-top: 1px solid var(--border); }
/* seven instrument chips will not sit politely beside a label on a phone */
.met-set-row.stack { flex-direction: column; align-items: stretch; gap: 0.55rem; }
.met-set-row.stack .tuner-insts { justify-content: flex-start; }
.met-set-label { font-weight: 700; color: var(--ink); }
.met-stepper { display: flex; align-items: center; gap: 0.8rem; }
.met-stepper button {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--btn);
  font-size: 1.2rem; font-weight: 700; line-height: 1;
  color: var(--ink);
  padding: 0;
  touch-action: manipulation;
}
.met-stepper button:hover { border-color: var(--primary); color: var(--primary-dark); }
.met-stepper span { min-width: 1.9rem; text-align: center; font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.met-subs { display: flex; gap: 0.4rem; }
.met-sub {
  min-width: 44px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--btn);
  font-size: 1.2rem;
  color: var(--ink);
  padding: 0 0.4rem;
}
.met-sub:hover { border-color: var(--primary); }
.met-sub.picked { background: var(--pick-bg); border-color: var(--pick-border); color: var(--primary-dark); }
.met-trip { font-size: 0.7rem; letter-spacing: -1px; }
.met-vol { max-width: 180px; }

.met-sounds { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.met-sound-btn {
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--btn);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink);
}
.met-sound-btn:hover { border-color: var(--primary); }
.met-sound-btn.picked { background: var(--pick-bg); border-color: var(--pick-border); color: var(--primary-dark); }

.met-toggle {
  min-width: 64px;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}
.met-toggle.on { background: var(--pick-bg); border-color: var(--pick-border); color: var(--primary-dark); }

/* --- Practice tools --- */
.met-practice { margin-top: 1.1rem; padding: 0.2rem 1.25rem 0.7rem; }
.met-practice > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0.8rem 0;
}
.met-practice > summary::-webkit-details-marker { display: none; }
.met-practice > summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  font-size: 0.9rem;
  transition: transform 0.15s ease;
}
.met-practice[open] > summary::after { transform: rotate(180deg); }
.met-practice .met-set-row { border-top: 1px solid var(--border); }
.met-practice > div.met-set-row:first-of-type { border-top: none; }
.met-set-row.indent { padding-left: 1rem; }
.met-set-row.indent .met-set-label { font-weight: 600; color: var(--muted); }
.met-timer-wrap { display: flex; align-items: center; gap: 0.7rem; }
.met-timer-wrap b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.met-mini { padding: 0.35rem 0.85rem; font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.met-mini:hover { border-color: var(--primary); color: var(--primary-dark); }

/* --- Saved tempos --- */
.preset-card { margin-top: 1.1rem; }
.preset-add { display: flex; gap: 0.5rem; margin-bottom: 0.7rem; }
.preset-add input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--btn);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
}
.preset-list { display: flex; flex-direction: column; gap: 0.45rem; }
.preset { display: flex; gap: 0.4rem; }
.preset-go {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  text-align: left;
  padding: 0.5rem 0.9rem;
  border-radius: 12px;
  background: var(--btn);
}
.preset-go b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-go small { margin-left: auto; flex: none; color: var(--muted); font-weight: 700; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.preset-go:hover { border-color: var(--primary); }
.preset-x {
  width: 38px;
  flex: none;
  padding: 0;
  border-radius: 12px;
  background: var(--btn);
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
}
.preset-x:hover { border-color: var(--primary); color: var(--primary-dark); }
.preset-empty { margin: 0; }
.preset-empty[hidden] { display: none; }

/* --- Reference pitch --- */
.pitch-card { margin-top: 0; }
.pitch-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
.pitch-title { margin: 0; font-family: "Fredoka", "Nunito", sans-serif; font-weight: 600; font-size: 1.2rem; color: var(--ink); }
.pitch-display { font-weight: 700; color: var(--muted); }
.pitch-display b { font-size: 1.3rem; color: var(--primary-dark); margin-right: 0.35rem; }
.pitch-notes {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.pitch-note-btn {
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--btn);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  padding: 0 0.2rem;
}
.pitch-note-btn.sharp { background: #f3eef6; color: var(--muted); font-size: 0.72rem; padding: 0 0.15rem; }
.pitch-note-btn:hover { border-color: var(--primary); }
.pitch-note-btn.picked { background: var(--pick-bg); border-color: var(--pick-border); color: var(--primary-dark); }
.pitch-tones { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.pitch-tone-btn {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--btn);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink);
}
.pitch-tone-btn:hover { border-color: var(--primary); }
.pitch-tone-btn.picked { background: var(--pick-bg); border-color: var(--pick-border); color: var(--primary-dark); }
.pitch-play { margin-top: 0.9rem; }
.pitch-play.playing { background: var(--accent); border-color: var(--accent); }
.pitch-play.playing:hover { background: #5fb3c8; border-color: #5fb3c8; }
.met-hint { color: var(--muted); font-weight: 400; font-size: 0.8rem; }

/* --- Live tuner --- */
.tuner-card { margin-top: 0; }
.tuner { text-align: center; padding: 0.3rem 0 0.2rem; }
.tuner-note {
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: 3.4rem;
  line-height: 1;
  color: var(--muted);
  transition: color 0.15s ease;
}
.tuner.intune .tuner-note { color: var(--primary); }
.tuner-cents {
  margin: 0.25rem 0 1rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--muted);
  min-height: 1.2em;
}
.tuner.flat .tuner-cents,
.tuner.sharp .tuner-cents { color: #c2792e; }
.tuner.intune .tuner-cents { color: var(--primary-dark); }
.tuner-meter { max-width: 360px; margin: 0 auto; }
.tuner-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.tuner-track {
  position: relative;
  height: 18px;
  border-radius: 999px;
  background: var(--border);
}
.tuner-center {
  position: absolute;
  left: 50%; top: -3px; bottom: -3px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: var(--primary);
  opacity: 0.55;
}
.tuner-needle {
  position: absolute;
  top: 50%; left: 50%;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  transition: left 0.09s linear, background 0.15s ease;
}
.tuner.intune .tuner-needle { background: var(--primary); }
.tuner-listen { margin-top: 1rem; }
.tuner-listen.on { background: var(--accent); border-color: var(--accent); }
.tuner-listen.on:hover { background: #5fb3c8; border-color: #5fb3c8; }
.tuner-hint { text-align: center; margin-top: 0.6rem; }

/* the meter that answers "is it me being quiet, or is the mic dead?" */
.tuner-input { display: flex; align-items: center; gap: 0.6rem; margin: 1rem 0 0.2rem; }
.tuner-level {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.tuner-level-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--muted);
  transition: width 0.08s linear, background 0.2s ease;
}
.tuner-level-fill.live { background: var(--accent); }

.tuner-insts { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.tuner-inst {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--btn);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ink);
}
.tuner-inst:hover { border-color: var(--primary); }
.tuner-inst.picked { background: var(--pick-bg); border-color: var(--pick-border); color: var(--primary-dark); }

.tuner-strings {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  padding: 0.8rem 0 0.2rem;
  border-top: 1px solid var(--border);
}
.tuner-strings[hidden] { display: none; }
.tuner-string {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 58px;
  padding: 0.35rem 0.5rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--btn);
  color: var(--ink);
  line-height: 1.15;
}
.tuner-string b { font-size: 0.95rem; font-weight: 700; }
.tuner-string small { font-size: 0.68rem; font-weight: 700; color: var(--muted); }
.tuner-string:hover { border-color: var(--primary); }
.tuner-string.picked { background: var(--pick-bg); border-color: var(--pick-border); color: var(--primary-dark); }
.tuner-string.picked small { color: var(--primary-dark); }

kbd {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
}

@media (max-width: 460px) {
  .met-bpm { font-size: 3.5rem; }
  .met-set-row { flex-wrap: wrap; }
  .met-tab { font-size: 0.88rem; padding: 0.5rem 0.2rem; }
}

/* ---- visual heartbeat: BPM display pulses in time, dots glow while playing ---- */
.met-bpm { transform-origin: center; }
.met-display.beat .met-bpm { animation: met-beat 0.30s ease-out; }
.met-display.accent-beat .met-bpm { animation: met-beat-accent 0.34s ease-out; }
@keyframes met-beat {
  0% { transform: scale(1); }
  28% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes met-beat-accent {
  0% { transform: scale(1); }
  28% { transform: scale(1.13); }
  100% { transform: scale(1); }
}
/* in silent mode the pulse is the whole metronome, so it swings harder */
.met-display.silent.beat .met-bpm { animation: met-beat-accent 0.32s ease-out; }
.met-display.silent.accent-beat .met-bpm { animation: met-beat-silent 0.38s ease-out; }
@keyframes met-beat-silent {
  0% { transform: scale(1); }
  28% { transform: scale(1.24); }
  100% { transform: scale(1); }
}
.met-display.live .met-tempo-name { color: var(--primary-dark); }

/* dark mode: the accidental keys are the one surface that was hard-coded light */
html.dark .pitch-note-btn.sharp { background: var(--pick-bg); color: var(--muted); }
html.dark .tuner.flat .tuner-cents,
html.dark .tuner.sharp .tuner-cents { color: #e8b168; }

@media (prefers-reduced-motion: reduce) {
  .met-dot { transition: none; }
  .met-dot.pop { animation: none; }
  .met-display.beat .met-bpm,
  .met-display.accent-beat .met-bpm,
  .met-display.silent.beat .met-bpm,
  .met-display.silent.accent-beat .met-bpm { animation: none; }
  .tab-dot { animation: none; }
  .tuner-needle { transition: background 0.15s ease; }   /* keep the colour cue, drop the slide */
}
