:root {
  color-scheme: light;
  --bg: #e7e9f2;
  --card: #ffffff;
  --text: #1b1e2a;
  --muted: #9aa1b3;
  --line: #eceef4;
  --track: #e6e8f0;
  --accent: #f27a45;
  --green: #2ec98a;
  --chip: #f6f1ea;
  --chip-text: #c6aa90;
  --dot: #dfe3ee;
  --dot-down: #f6d4c6;
  --ring: #e0e3ec;
  --ring-icon: #c5cad6;
  --timer: #f2f4f8;
  --check: #e6e9f1;
  --hover: rgba(20, 24, 40, 0.05);
  --shadow: 0 10px 34px rgba(48, 58, 96, 0.07);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12141c;
  --card: #1c1f2a;
  --text: #f3f4f8;
  --muted: #9aa1b3;
  --line: #2c3040;
  --track: #343848;
  --chip: #2c2823;
  --chip-text: #d4b89a;
  --dot: #343848;
  --dot-down: #6a4334;
  --ring: #3a4054;
  --ring-icon: #9aa3b8;
  --timer: #262a38;
  --check: #2e3344;
  --hover: rgba(255, 255, 255, 0.06);
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}

html[data-theme="grass"] {
  color-scheme: light;
  --bg: #e4f3e6;
  --card: #f7fff8;
  --text: #1c2e20;
  --muted: #7c9a82;
  --line: #dceee0;
  --track: #d3ead6;
  --accent: #2f9e4f;
  --green: #e0893a;
  --chip: #e7f6df;
  --chip-text: #6a9a62;
  --dot: #d5ead8;
  --dot-down: #b7ddb4;
  --ring: #d5e6d8;
  --ring-icon: #9bb8a0;
  --timer: #eef6ef;
  --check: #d7eadb;
  --hover: rgba(20, 60, 30, 0.06);
  --shadow: 0 10px 34px rgba(40, 90, 50, 0.08);
}

html[data-theme="orange"] {
  color-scheme: light;
  --bg: #fff0e4;
  --card: #fffaf5;
  --text: #3a2416;
  --muted: #b08972;
  --line: #f3e2d4;
  --track: #f3ddcc;
  --accent: #f27a2a;
  --green: #2a9a72;
  --chip: #fff1e4;
  --chip-text: #d09262;
  --dot: #f3e0d0;
  --dot-down: #f6c7a4;
  --ring: #f0ddd0;
  --ring-icon: #c9aa96;
  --timer: #fff4ea;
  --check: #f3e4d6;
  --hover: rgba(120, 60, 20, 0.06);
  --shadow: 0 10px 34px rgba(140, 70, 20, 0.08);
}

html[data-theme="sea"] {
  color-scheme: light;
  --bg: #e5f3fb;
  --card: #f7fcff;
  --text: #163044;
  --muted: #7d98ab;
  --line: #d7e8f2;
  --track: #d3e6f2;
  --accent: #2b8fd0;
  --green: #2aa876;
  --chip: #e7f4fb;
  --chip-text: #6aa0c0;
  --dot: #d5e6f2;
  --dot-down: #b7d4ea;
  --ring: #d5e4ee;
  --ring-icon: #9bb4c6;
  --timer: #eef6fb;
  --check: #d7e7f2;
  --hover: rgba(20, 60, 90, 0.06);
  --shadow: 0 10px 34px rgba(30, 80, 120, 0.08);
}

html[data-theme="grape"] {
  color-scheme: light;
  --bg: #f3eafc;
  --card: #fcf9ff;
  --text: #2c2140;
  --muted: #9788ad;
  --line: #e6dcf2;
  --track: #e4d8f2;
  --accent: #8b5cf6;
  --green: #2aa876;
  --chip: #f4eaff;
  --chip-text: #a888d0;
  --dot: #e6dcf2;
  --dot-down: #d4c0ee;
  --ring: #e4d8ee;
  --ring-icon: #b4a4c8;
  --timer: #f6f0fc;
  --check: #e6dcf2;
  --hover: rgba(60, 30, 90, 0.06);
  --shadow: 0 10px 34px rgba(80, 40, 120, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px 12px 28px;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }

button {
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.app {
  width: min(430px, 100%);
}

.card {
  position: relative;
  background: var(--card);
  border-radius: 28px;
  padding: 14px 22px 8px;
  box-shadow: var(--shadow);
}

.icon-btn,
.sheet-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.icon-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
}

.icon-btn:hover,
.sheet-close:hover { color: var(--text); background: var(--hover); }

.chip-wrap { display: flex; justify-content: center; }

.chip-gap { margin-top: 2px; }

.chip {
  background: var(--chip);
  color: var(--chip-text);
  font-size: 13px;
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-radius: 8px;
}

.bpm {
  margin: 0;
  text-align: center;
  font-family: "Arial Black", "Segoe UI", sans-serif;
  font-weight: 900;
  font-size: clamp(96px, 28vw, 128px);
  letter-spacing: -0.045em;
  line-height: 0.88;
  font-variant-numeric: tabular-nums;
}

.bpm.pulse { animation: bpmPulse 140ms ease-out; }

@keyframes bpmPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.025); }
  100% { transform: scale(1); }
}

.tempo {
  text-align: center;
  color: var(--muted);
  font-size: 18px;
  font-weight: 500;
  margin: 6px 0 16px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 2px 16px;
}

.round {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--ring);
  color: var(--ring-icon);
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0 0 1px;
  flex: 0 0 auto;
}

.round.sm {
  width: 28px;
  height: 28px;
  font-size: 18px;
}

.round:hover { color: var(--text); border-color: var(--muted); }

.round.is-dim { opacity: 0.35; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 28px;
  background: transparent;
  margin: 0;
  cursor: pointer;
}

input[type="range"]:focus { outline: none; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--track);
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -10px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(242, 122, 69, 0.4);
  cursor: pointer;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--track);
  border: none;
  border-radius: 999px;
}

input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(242, 122, 69, 0.4);
  cursor: pointer;
}

.dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  min-height: 28px;
  margin: 14px 0 20px;
  flex-wrap: wrap;
}

.dots.compact { gap: 7px; }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--dot);
  transform: scale(1);
  transition: transform 80ms ease, background-color 80ms ease;
}

.dots.compact .dot { width: 10px; height: 10px; }

.dot.down { background: var(--dot-down); }

.dot.active {
  background: var(--accent);
  transform: scale(1.38);
}

.actions {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.btn {
  flex: 1;
  height: 52px;
  border-radius: 14px;
  color: #fff;
  font-size: 17px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 0.01em;
}

.btn svg { display: block; flex: 0 0 auto; }

.btn-start {
  background: var(--accent);
  box-shadow: 0 8px 16px rgba(242, 122, 69, 0.28);
}

.btn-tap {
  background: var(--green);
  box-shadow: 0 8px 16px rgba(46, 201, 138, 0.24);
}

.btn:hover { filter: brightness(1.03); }
.btn:active { transform: translateY(1px); }

.btn-start .ico-stop { display: none; }
.btn-start.is-playing .ico-play { display: none; }
.btn-start.is-playing .ico-stop { display: block; }

.btn-tap.tapped { transform: scale(0.97); }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  border-top: 1px solid var(--line);
  font-size: 16px;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

label.setting { justify-content: flex-start; }

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}

#beatCount {
  min-width: 1.5em;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.box-wrap {
  position: relative;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.box-wrap input {
  position: absolute;
  inset: 0;
  z-index: 1;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.box {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--check);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.box::after {
  content: "";
  width: 5px;
  height: 9px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg) translate(-1px, -1px);
  opacity: 0;
}

.box-wrap input:checked + .box { background: var(--accent); }
.box-wrap input:checked + .box::after { opacity: 1; }
.box-wrap input:focus-visible + .box {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.timer-pick { position: relative; }

.timer-pill {
  width: 92px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--timer);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.timer-pill:disabled { opacity: 1; cursor: default; }

.timer-caret { display: block; flex: 0 0 auto; }

.timer-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  color: var(--text);
}

.timer-pill.armed { color: var(--text); font-weight: 650; }

.timer-pill.running,
.timer-pill.running:disabled {
  color: var(--accent);
  -webkit-text-fill-color: var(--accent);
  opacity: 1;
  font-weight: 700;
}

.timer-pill.running .timer-caret { display: none; }

.timer-menu {
  position: absolute;
  right: calc(100% + 8px);
  top: 0;
  z-index: 6;
  width: 112px;
  max-height: 196px;
  padding: 6px;
  overflow: auto;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow), 0 0 0 1px var(--line);
}

.timer-menu[hidden] { display: none; }

.timer-option {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
}

.timer-option[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
}

@media (hover: hover) {
  .timer-option:hover { background: var(--hover); }
  .timer-option[aria-selected="true"]:hover { background: var(--accent); }
}

.sub-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  min-height: 48px;
  border-top: 1px solid var(--line);
  font-size: 16px;
}

#subName {
  color: var(--muted);
  font-size: 13px;
}

.sub-list {
  border-bottom: 1px solid var(--line);
  padding: 4px 0 12px;
}

.sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sub-row + .sub-row {
  justify-content: center;
  gap: 8px;
  margin-top: 2px;
}

.sub-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: var(--text);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.sub-btn svg {
  width: 42px;
  height: 30px;
  display: block;
}

.sub-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

@media (hover: hover) {
  .sub-btn:hover { background: var(--hover); }
  .sub-btn[aria-pressed="true"]:hover { background: var(--accent); }
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
}

.sheet[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 20, 28, 0.42);
}

.sheet-card {
  position: relative;
  width: min(430px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--card);
  color: var(--text);
  border-radius: 24px;
  padding: 14px 16px 18px;
  box-shadow: var(--shadow);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.sheet-label {
  margin: 16px 2px 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.theme-choice {
  height: 68px;
  border-radius: 14px;
  background: var(--timer);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 650;
}

.theme-choice[aria-selected="true"] {
  outline: 2px solid var(--accent);
  background: var(--card);
}

.swatch {
  width: 34px;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  border: 1px solid var(--line);
}

.swatch i { flex: 1; }

.voice-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.voice-choice {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  background: var(--timer);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  text-align: left;
}

.voice-choice b { font-size: 15px; font-weight: 650; }

.voice-choice small {
  color: var(--muted);
  font-size: 12px;
}

.voice-choice[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
}

.voice-choice[aria-selected="true"] small { color: rgba(255, 255, 255, 0.86); }

.sub-btn:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.sheet-close:focus-visible,
.theme-choice:focus-visible,
.voice-choice:focus-visible,
.round:focus-visible,
.timer-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

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

@media (max-width: 380px) {
  .card { padding: 12px 14px 6px; border-radius: 24px; }
  .sub-btn { width: 42px; height: 42px; }
  .sub-btn svg { width: 36px; height: 26px; }
  .btn { font-size: 16px; height: 48px; }
  .actions { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .bpm.pulse { animation: none; }
  .dot { transition: none; }
}
