:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-strong: #eef2f1;
  --border: #d9dfdc;
  --text: #18201d;
  --muted: #63706a;
  --accent: #197a56;
  --accent-strong: #126242;
  --accent-soft: #d9efe6;
  --warning: #ce7a21;
  --info: #4776b8;
  --danger: #ba2d36;
  --shadow: 0 16px 40px rgb(20 31 28 / 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, #f6f7f8 0%, #edf1ef 100%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 18px;
}

.tempo-workspace {
  display: grid;
  gap: 16px;
}

.app-header {
  padding-top: 4px;
}

h2,
p {
  margin: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.mode-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  min-height: 44px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
}

.mode-button {
  min-width: 0;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 750;
}

.mode-button.is-selected {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 2px 8px rgb(28 39 35 / 0.12);
}

.tempo-readout {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 10px 0 0;
}

.tempo-display {
  font-size: 4.5rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.tempo-bpm {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.tool-panel {
  display: grid;
  gap: 14px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 8px;
}

.preset-button {
  display: grid;
  gap: 2px;
  place-items: center;
  min-width: 0;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #f8faf9;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.preset-bpm {
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.78;
}

.preset-button.is-selected {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.slider-field {
  display: grid;
  gap: 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timing-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.timing-stat {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.timing-stat span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.timing-stat strong {
  overflow: hidden;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.play-button {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 66px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 14px 28px rgb(18 98 66 / 0.24);
  font-size: 1.35rem;
  font-weight: 850;
}

.play-button:hover {
  background: var(--accent-strong);
}

.play-button.is-playing {
  background: var(--danger);
  box-shadow: 0 14px 28px rgb(186 45 54 / 0.18);
}

.play-glyph {
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 15px solid currentColor;
}

.stop-glyph {
  width: 17px;
  height: 17px;
  border-radius: 3px;
  background: currentColor;
}

.audio-message {
  min-height: 1.15rem;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.beat-dots {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.beat-dot {
  display: inline-block;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  position: relative;
}

.beat-dot::before {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: var(--dot-size);
  height: var(--dot-size);
  border-radius: 999px;
  background: var(--dot-color);
  opacity: 0.36;
  transform: translate(-50%, -50%);
  transition:
    width 160ms ease,
    height 160ms ease,
    opacity 160ms ease,
    box-shadow 160ms ease;
}

.beat-dot-normal {
  --dot-size: 12px;
  --dot-color: var(--muted);
}

.beat-dot-medium {
  --dot-size: 15px;
  --dot-color: var(--warning);
}

.beat-dot-strong {
  --dot-size: 18px;
  --dot-color: var(--accent);
}

.beat-dot.is-active::before {
  width: calc(var(--dot-size) + 8px);
  height: calc(var(--dot-size) + 8px);
  opacity: 1;
  box-shadow: 0 0 0 4px rgb(24 32 29 / 0.1);
}

.beat-dot.is-muted::before {
  opacity: 0.14;
}

.beat-dot.is-muted::after {
  content: "";
  position: absolute;
  top: 18px;
  left: 7px;
  width: 24px;
  height: 2px;
  border-radius: 999px;
  background: rgb(24 32 29 / 0.36);
  transform: rotate(-45deg);
}

.options-panel {
  gap: 16px;
}

.options-panel summary {
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 800;
}

.select-field {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  font-weight: 750;
}

select {
  min-width: min(100%, 210px);
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfc;
  padding: 0 36px 0 12px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgb(71 118 184 / 0.35);
  outline-offset: 3px;
}

@media (min-width: 680px) {
  .app-shell {
    display: grid;
    align-items: center;
    padding-block: 28px;
  }
}

@media (max-width: 390px) {
  .app-shell {
    padding-inline: 12px;
  }

  .tool-panel {
    padding: 14px;
  }

  .select-field {
    align-items: stretch;
    flex-direction: column;
  }

  .tempo-display {
    font-size: 3.8rem;
  }

  .timing-grid {
    gap: 10px;
  }
}
