/* ============================================================
   Tiny Metronome — zero-dependency online metronome
   ============================================================ */

* { box-sizing: border-box; }

:root {
  --bg: #eef1f7;
  --bg-accent: #dfe5f2;
  --card: #ffffff;
  --text: #1b2233;
  --muted: #66708a;
  --line: #e3e7f0;
  --accent: #4f6ef7;
  --accent-soft: #e6ebff;
  --accent-strong: #3b55d9;
  --danger: #e0567a;
  --shadow: 0 18px 50px rgba(28, 38, 84, 0.12);
  --dot: #c6cddd;
  --dot-sub: #d4d9e6;
}

[data-theme="dark"] {
  --bg: #0e1118;
  --bg-accent: #141926;
  --card: #161c28;
  --text: #e8ecf6;
  --muted: #8b94ab;
  --line: #262e40;
  --accent: #6d8bff;
  --accent-soft: #1f2740;
  --accent-strong: #8aa2ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --dot: #39435a;
  --dot-sub: #2c344a;
}

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-accent), var(--bg));
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 28px 16px 48px;
  transition: background 0.3s ease, color 0.3s ease;
}

.card {
  width: 100%;
  max-width: 620px;
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 24px 26px 18px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}
.logo { width: 30px; height: 30px; }
.top-actions { display: flex; gap: 8px; }

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-width: 40px;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- beat dots ---------- */
.dots-wrap { min-height: 46px; margin-top: 12px; display: flex; justify-content: center; }
.dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 14px;
}
.beat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  padding: 4px 2px 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.beat-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--dot);
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.beat.accent .beat-dot {
  width: 26px;
  height: 26px;
  background: var(--accent);
}
.beat.mute .beat-dot {
  background: transparent;
  border: 2px solid var(--dot);
}
.beat.hit .beat-dot {
  animation: pop 0.22s ease;
}
.beat.accent.hit .beat-dot {
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 25%, transparent);
}
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.55); }
  100% { transform: scale(1); }
}
.subdots { position: relative; width: 38px; height: 9px; }
.subdot {
  position: absolute;
  top: 1.5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dot-sub);
  transform: translateX(-50%);
  transition: transform 0.1s ease, background 0.1s ease;
}
.subdot.hit {
  background: var(--accent);
  transform: translateX(-50%) scale(1.7);
}

/* ---------- tempo ---------- */
.tempo { text-align: center; margin-top: 6px; }
.bpm-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
.bpm-box { position: relative; display: flex; align-items: baseline; gap: 6px; }
.bpm-input {
  width: 150px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 58px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0;
  outline: none;
  border-bottom: 3px solid transparent;
  border-radius: 2px;
  transition: border-color 0.15s ease;
}
.bpm-input:focus { border-bottom-color: var(--accent); }
.bpm-unit {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1px;
}
.step-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.step-btn:hover, .step-btn:active { background: var(--accent-soft); border-color: var(--accent); }

.tempo-term {
  margin: 2px 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.4px;
  min-height: 20px;
}

/* sliders */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--card);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}
.slider::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
.slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--card);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}

/* play + tap */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  margin: 14px 0 6px;
}
.play-btn {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}
.play-btn:hover { transform: scale(1.04); }
.play-btn:active { transform: scale(0.97); }
.play-btn svg { width: 40px; height: 40px; fill: currentColor; }
.play-btn .icon-pause { display: none; }
.play-btn.playing .icon-play { display: none; }
.play-btn.playing .icon-pause { display: block; }

.tap-btn {
  height: 52px;
  min-width: 154px; /* wide enough for “点击测速 ×8” / “Tap tempo ×8” so the play button never shifts */
  padding: 0 26px;
  border-radius: 26px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
.tap-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.tap-btn.tapped { transform: scale(0.95); background: var(--accent-soft); }
.tap-count { color: var(--accent); }

/* ---------- settings ---------- */
.settings { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.setting {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 0;
}
.setting-label {
  flex: 0 0 84px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.setting-control {
  flex: 1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
}

/* time signature */
.sig-control { justify-content: flex-start; gap: 10px; }
.sig-stepper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.sig-num {
  font-size: 24px;
  font-weight: 800;
  min-width: 34px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.mini-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.mini-btn:hover { color: var(--accent); background: var(--accent-soft); }
.sig-divider {
  width: 64px;
  height: 3px;
  border-radius: 2px;
  background: var(--text);
  opacity: 0.8;
  margin: 0 2px;
}
.sig-presets { margin-left: 6px; }

/* chips */
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 18px;
  padding: 6px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.chip:hover { border-color: var(--accent); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip .sym { margin-right: 5px; }

/* rhythm pattern chips: notation icon over label, 5 per row */
.chips.patterns { display: flex; flex-wrap: wrap; gap: 8px; }
.pattern-chip {
  flex: 1 1 calc(20% - 7px);
  max-width: 122px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px 6px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
}
.pattern-chip .nota {
  display: block;
  height: 24px;
  width: auto;
  max-width: 100%;
}
.pattern-chip .nota ellipse,
.pattern-chip .nota rect,
.pattern-chip .nota circle,
.pattern-chip .nota path { fill: currentColor; }
.pattern-chip .nota ellipse.hollow { fill: none; stroke: currentColor; }
.pattern-chip .nota text { fill: currentColor; font-family: inherit; }

/* help overlay */
.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: rgba(15, 20, 35, 0.45);
  backdrop-filter: blur(3px);
}
.help-overlay[hidden] { display: none; }
.help-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  max-height: min(80vh, 640px);
  overflow-y: auto;
  padding: 20px 26px;
}
.help-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.help-head h2 { margin: 0; font-size: 18px; }
.help-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  padding: 4px 9px;
  border-radius: 8px;
  cursor: pointer;
}
.help-close:hover { color: var(--text); background: var(--accent-soft); }
.help-body h3 {
  font-size: 13.5px;
  color: var(--accent);
  margin: 14px 0 4px;
}
.help-body ul { margin: 0; padding-left: 18px; }
.help-body li {
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text);
}

/* timer readout */
.timer-readout-row .setting-label { color: var(--accent); }
.timer-left {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

/* ---------- footer ---------- */
.foot {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  text-align: center;
}
.credit { font-size: 12px; color: var(--muted); margin: 0; }
.icp { display: inline-block; margin-top: 4px; font-size: 12px; color: var(--muted); text-decoration: none; }
.icp:hover { text-decoration: underline; }
.foot-links { display: flex; justify-content: center; gap: 14px; margin-bottom: 8px; }
.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: color .15s, border-color .15s, transform .15s;
}
.icon-link svg { width: 20px; height: 20px; }
.icon-link svg.filled { fill: currentColor; }
.icon-link:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-2px); }

/* mini-app QR overlay */
.qr-card { max-width: 340px; text-align: center; }
.qr-body { padding: 10px 0 4px; }
.qr-img {
  display: block;
  margin: 0 auto;
  width: 220px;
  height: 220px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.qr-tip { margin: 12px 0 0; font-size: 13px; color: var(--muted); }

/* focus outlines */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 480px) {
  .card { padding: 18px 16px 14px; border-radius: 20px; }
  .bpm-input { font-size: 46px; width: 120px; }
  .play-btn { width: 76px; height: 76px; }
  .setting { flex-wrap: wrap; gap: 6px 10px; }
  .setting-label { flex: 0 0 100%; }
  .dots-wrap { margin-top: 8px; }
  .pattern-chip { flex: 1 1 calc(33.333% - 6px); }
}
