/* ── tokens ─────────────────────────────────────────────── */
:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --ink: #1c1f24;
  --sub: #6b7280;
  --faint: #6c7583;
  --line: #e7e9ed;
  --track: #e4e6ea;
  --accent: #ff7a45;
  --accent-deep: #ea5f28;
  --accent-soft: rgba(255, 122, 69, 0.13);
  /* 亮橙上必须用深褐字：白字只有 2.6:1，深褐 6.8:1 */
  --on-accent: #2a1206;
  --chip-bg: #fdece5;
  --chip-ink: #9c4522;
  --shadow: 0 18px 44px rgba(24, 28, 36, 0.09);
  --radius: 22px;
}

html[data-theme="dark"] {
  --bg: #101216;
  --card: #191c22;
  --ink: #f2f4f7;
  --sub: #99a1ae;
  --faint: #8a93a1;
  --line: #262a32;
  --track: #2a2f38;
  --accent: #ff8a5c;
  --accent-deep: #ff7040;
  --accent-soft: rgba(255, 138, 92, 0.17);
  --on-accent: #2a1206;
  --chip-bg: #2e2119;
  --chip-ink: #ffab86;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
}

/* 共享外壳的 token 直接指回本页变量，明暗切换自动跟随 */
:root {
  --site-bg: var(--bg);
  --site-card: var(--card);
  --site-ink: var(--ink);
  --site-sub: var(--sub);
  --site-line: var(--line);
  --site-accent: var(--accent);
  --site-on-accent: var(--on-accent);
}

.site-bar { width: 100%; padding-top: max(10px, env(safe-area-inset-top)); }
.site-foot { width: 100%; margin-top: var(--site-sp-6); }
/* 全屏练习模式下站点导航让位 */
.app.is-full .site-bar,
.app.is-full .site-foot { display: none; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}

body { padding: 0 0 max(28px, env(safe-area-inset-bottom)); }

.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;
}

.app {
  width: min(100% - 28px, 560px);
  margin: 0 auto;
}

/* ── top bar ────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 2px 14px;
}

.brand {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .18em;
  color: var(--sub);
}

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--card);
  color: var(--sub);
  cursor: pointer;
  transition: transform .12s ease, border-color .2s ease, color .2s ease;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn:active { transform: scale(.94); }

.icon-sun, .icon-full { width: 18px; height: 18px; display: block; }
.icon-sun {
  border-radius: 50%;
  border: 2px solid currentColor;
  position: relative;
  overflow: hidden;
}
.icon-sun::after {
  content: "";
  position: absolute;
  top: -2px; bottom: -2px; left: -2px;
  width: 50%;
  background: currentColor;
}
.icon-full {
  position: relative;
}
.icon-full::before,
.icon-full::after {
  content: "";
  position: absolute;
  width: 7px; height: 7px;
  border: 2px solid currentColor;
}
.icon-full::before { top: 0; left: 0; border-right: none; border-bottom: none; }
.icon-full::after { bottom: 0; right: 0; border-left: none; border-top: none; }

/* ── card ───────────────────────────────────────────────── */
.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 20px 24px;
  overflow: hidden;
}

.edge-glow {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 44px -8px var(--accent);
  will-change: opacity;
}

.chip-label {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-ink);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
}

/* ── stage ──────────────────────────────────────────────── */
.stage {
  position: relative;
  width: min(80vw, 320px);
  aspect-ratio: 1;
  margin: 6px auto 4px;
  display: grid;
  place-items: center;
}

.rings { position: absolute; inset: 0; }

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent);
  opacity: 0;
  transform: scale(.62);
  will-change: transform, opacity;
}
.ring-sub { border-width: 2px; border-color: var(--faint); }

.core {
  position: absolute;
  width: 63%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent-soft);
  opacity: 0;
  will-change: transform, opacity;
}

.timer-arc {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  pointer-events: none;
}
/* 轨道常驻，给脉冲环一个静止参照；只有定时器开着时才画进度弧 */
.arc-track { fill: none; stroke: var(--track); stroke-width: 3; }
.arc-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 590.6;
  stroke-dashoffset: 0;
  opacity: 0;
  transition: opacity .3s ease;
}
.timer-arc.on .arc-fill { opacity: 1; }

.readout {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.bpm {
  font-size: clamp(76px, 23vw, 148px);
  font-weight: 800;
  line-height: .92;
  letter-spacing: -.045em;
  font-variant-numeric: tabular-nums;
  transition: color .2s ease;
}

/* 点大数字就地改成输入框 */
button.bpm {
  display: block;
  padding: 0 4px;
  border: 0;
  border-radius: 14px;
  background: none;
  color: inherit;
  font-family: inherit;
  cursor: text;
}
button.bpm:hover { color: var(--accent); }

.bpm-input {
  display: block;
  width: 3.4ch;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: inherit;
  text-align: center;
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}
.bpm-input:focus,
.bpm-input:focus-visible { outline: none; }

/* button.bpm 显式设了 display，会盖掉 UA 的 [hidden]，得强制回来 */
[hidden] { display: none !important; }

.term {
  font-size: clamp(13px, 3.6vw, 16px);
  color: var(--faint);
  letter-spacing: .04em;
  min-height: 1.2em;
}

.timer-left {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--sub);
  letter-spacing: .06em;
}
.timer-left.urgent { color: var(--accent); }

/* ── tempo slider ───────────────────────────────────────── */
.tempo-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 10px 2px 22px;
}

.step-btn {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--sub);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform .1s ease, border-color .2s ease, color .2s ease;
}
.step-btn:hover { border-color: var(--accent); color: var(--accent); }
.step-btn:active { transform: scale(.9); }
.step-btn.small { width: 38px; height: 38px; font-size: 19px; }

/* 轨道只有 6px 高，但可拖区域给到 32px —— 孩子在平板上单手拖得动 */
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 32px;
  background: transparent;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--track);
}
.slider::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--track);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  cursor: grab;
}
.slider::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  cursor: grab;
}
.slider:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── beat dots ──────────────────────────────────────────── */
.beats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.beat-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 2.4vw, 14px);
  min-height: 44px;
}

.dot {
  width: clamp(22px, 6.4vw, 34px);
  height: clamp(22px, 6.4vw, 34px);
  border-radius: 50%;
  background: var(--track);
  will-change: transform, background-color;
  transition: background-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.dot.lit { background: var(--accent); transform: scale(1.28); }
.dot.lit.accent {
  transform: scale(1.5);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
/* 第一拍在静止时就要认得出来，不能只靠响的那一下 */
.dot.accent-mark { background: transparent; box-shadow: inset 0 0 0 3px var(--accent); }
.dot.accent-mark.lit { background: var(--accent); }

/* ── controls ───────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 22px 0 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 14px 26px;
  border-radius: 14px;
  border: 1.5px solid transparent;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform .1s ease, background-color .2s ease, border-color .2s ease;
}
.btn:active { transform: scale(.96); }
.btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  min-width: 142px;
  justify-content: center;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.ghost.flash { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.btn-icon { display: block; }
.btn-icon.play {
  width: 0; height: 0;
  border-left: 14px solid currentColor;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}
.btn-icon.stop { width: 14px; height: 14px; background: currentColor; border-radius: 3px; }
.btn-icon.tap {
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-radius: 50%;
  position: relative;
}
.btn-icon.tap::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: currentColor;
}

/* ── settings panel ─────────────────────────────────────── */
.panel { margin-top: 24px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 2px;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: none; }

.row-name {
  font-size: 15px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.row-hint {
  font-style: normal;
  font-size: 12px;
  color: var(--faint);
}

.stepper { display: flex; align-items: center; gap: 12px; }
.stepper-value {
  min-width: 26px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 视觉上还是 28px 的开关，但上下补白把点击区撑到 44px */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 8px 0;
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 48px; height: 28px;
  border-radius: 999px;
  background: var(--track);
  transition: background-color .2s ease;
  position: relative;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
  transition: transform .2s cubic-bezier(.3, .9, .4, 1.2);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }

.timer-body { padding: 2px 2px 14px; }

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; }
.preset {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--sub);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .2s ease, color .2s ease, background-color .2s ease;
}
.preset:hover { border-color: var(--accent); color: var(--accent); }
.preset.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.timer-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--faint);
}
.timer-meta b { color: var(--sub); font-variant-numeric: tabular-nums; }

/* ── subdivision ────────────────────────────────────────── */
.subdiv {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}

.subdiv-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  width: 100%;
}

.sub-btn {
  aspect-ratio: 1 / .92;
  border: 1.5px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 5px;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}
.sub-btn:hover { border-color: var(--line); }
.sub-btn svg { width: 100%; height: auto; max-height: 42px; }
.sub-btn.on { background: var(--accent); color: var(--on-accent); }

/* 键盘焦点：所有可交互元素都要看得见 */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 8px;
}
.switch input:focus-visible + .switch-track { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ── hints + toast ──────────────────────────────────────── */
.hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--faint);
}
.hints kbd {
  font-family: inherit;
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  margin-right: 3px;
  color: var(--sub);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: var(--card);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .24s ease, transform .24s ease;
  pointer-events: none;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── fullscreen practice mode ───────────────────────────── */
.app.is-full {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.app.is-full .topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding-inline: 16px;
  z-index: 5;
}
.app.is-full .card {
  box-shadow: none;
  background: transparent;
  border-radius: 0;
  padding: 0 18px;
}
.app.is-full .stage { width: min(70vmin, 440px); }
.app.is-full .bpm { font-size: clamp(96px, 24vmin, 200px); }
.app.is-full .panel,
.app.is-full .subdiv,
.app.is-full .hints { display: none; }
.app.is-full .tempo-row { max-width: 460px; margin-inline: auto; }
.app.is-full .dot {
  width: clamp(26px, 5.4vmin, 46px);
  height: clamp(26px, 5.4vmin, 46px);
}

/* ── responsive ─────────────────────────────────────────── */
@media (max-width: 400px) {
  .subdiv-grid { grid-template-columns: repeat(4, 1fr); }
  .controls { flex-direction: column; }
  .btn { justify-content: center; }
}

@media (min-width: 561px) {
  .card { padding: 32px 30px 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .dot { transition-duration: .05s; }
  .dot.lit,
  .dot.lit.accent { transform: none; }
}
