* {
  box-sizing: border-box;
}

:root {
  --app-radius: 24px;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #ffffff;
  color: #f0f0f0;
  font-family: system-ui, sans-serif;
}

button {
  font-family: inherit;
  text-box: trim-both cap alphabetic;
}

.title {
  margin: 16px 0;
  font-size: 1rem;
  font-weight: normal;
  color: #1e1e1e;
}

.app {
  --label-gap: 4px;
  --button-gap: 12px;
  --group-gap: 16px;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--group-gap);
  width: calc(100% - 32px);
  max-width: 560px;
  padding: 24px;
  margin: 0 16px 16px;
  border-radius: var(--app-radius);
  background: #1e1e1e;
  user-select: none;
  -webkit-user-select: none;
}

.beat {
  width: 80px;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 16px;
  background: #333;
  font-size: 2rem;
}

.beat.accent {
  background: #d4a017;
}

.beat.normal {
  background: #336fb5;
}

.bpm-panel {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-areas:
    "head   head   head   head   head   head"
    "minus  minus  minus  plus   plus   plus"
    "slow   slow   start  start  fast   fast"
    "slider slider slider slider slider slider";
  column-gap: var(--button-gap);
  row-gap: var(--button-gap);
  align-items: center;
}

.bpm-head    { grid-area: head; }
.bpm-minus   { grid-area: minus; }
.bpm-plus    { grid-area: plus; }
.nudge-slow  { grid-area: slow; }
.start-stop  { grid-area: start; }
.nudge-fast  { grid-area: fast; }
.bpm-slider  { grid-area: slider; }

.bpm-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--label-gap);
}

.bpm {
  font-size: 2rem;
  font-weight: bold;
  line-height: 1;
  white-space: nowrap;
}

.bpm-number {
  display: inline-block;
  min-width: 3ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bpm.nudging .bpm-number {
  color: #336fb5;
}

.unit {
  font-size: 1rem;
  font-weight: 300;
}

.tempo-name {
  font-size: 1rem;
  line-height: 1.2;
  font-style: italic;
  color: #b0b0b0;
}

.bpm-group {
  display: flex;
  gap: var(--button-gap);
}

.bpm-button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: #3a3a3a;
  color: #f0f0f0;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.bpm-button:active {
  background: #555;
}

.nudge-button,
.start-stop {
  text-transform: uppercase;
  min-width: 0;
  min-height: 56px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.nudge-button {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: #3a3a3a;
  color: #f0f0f0;
  font-size: 1rem;
  touch-action: none;
  -webkit-touch-callout: none;
}

.nudge-button.pressed {
  background: #336fb5;
  box-shadow: 0 0 0 2px #f0f0f0;
}

.nudge-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(32px * 38 / 28);
  height: 32px;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.22);
  z-index: -1;
}

.start-stop {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: #2a8050;
  color: #fff;
  font-size: 1rem;
  touch-action: manipulation;
}

.start-stop.playing {
  background: #b22222;
}

.start-stop::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.22);
  clip-path: polygon(15% 0, 100% 50%, 15% 100%);
  z-index: -1;
}

.start-stop.playing::before {
  width: 32px;
  height: 32px;
  clip-path: none;
}

.bpm-slider,
.beats-slider,
.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  --fill: 0%;
}

.bpm-slider {
  margin-top: calc(var(--group-gap) - var(--button-gap));
}

.bpm-slider::-webkit-slider-runnable-track,
.beats-slider::-webkit-slider-runnable-track,
.volume-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, #d4a017 var(--fill), #808080 var(--fill));
}

.bpm-slider::-webkit-slider-thumb,
.beats-slider::-webkit-slider-thumb,
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border: none;
  border-radius: 50%;
  background: #d4a017;
}

.bpm-slider::-moz-range-track,
.beats-slider::-moz-range-track,
.volume-slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: #808080;
}

.bpm-slider::-moz-range-progress,
.beats-slider::-moz-range-progress,
.volume-slider::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: #d4a017;
}

.bpm-slider::-moz-range-thumb,
.beats-slider::-moz-range-thumb,
.volume-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: #d4a017;
}

.settings {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--button-gap);
}

.settings-row,
.practice,
.audio-controls {
  display: flex;
  align-items: center;
}

.settings-row {
  gap: var(--group-gap);
}

.practice {
  gap: 8px;
}

.audio-controls {
  gap: 12px;
}

.practice-label {
  font-size: 0.75rem;
  font-weight: 300;
  text-box: trim-both cap alphabetic;
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 52px;
  height: 30px;
  margin: 0;
  border-radius: 15px;
  background: #3a3a3a;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s;
}

.switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f0f0f0;
  transition: transform 0.15s;
}

.switch:checked {
  background: #d4a017;
}

.switch:checked::before {
  transform: translateX(22px);
}

.reset-button {
  height: 28px;
  padding: 0 12px;
  border: 1px solid #b0b0b0;
  border-radius: 8px;
  background: transparent;
  color: #b0b0b0;
  font-size: 0.75rem;
  cursor: pointer;
  touch-action: manipulation;
}

.reset-button:active {
  background: #3a3a3a;
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #f0f0f0;
  cursor: pointer;
}

.icon-button:active {
  background: #3a3a3a;
}

.icon-button svg {
  width: 24px;
  height: 24px;
}

.icon-muted,
.volume-button.muted .icon-sound {
  display: none;
}

.volume-button.muted .icon-muted {
  display: block;
}

.popover-layer {
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  touch-action: none;
}

.popover-dim {
  position: absolute;
  border-radius: var(--app-radius);
  background: rgba(0, 0, 0, 0.7);
}

.popover-window {
  position: absolute;
  transform: translate(-50%, calc(-100% - 8px));
  border-radius: 12px;
  background: #3a3a3a;
}

.volume-window {
  width: 48px;
  height: 144px;
}

.sound-window {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sound-option {
  min-width: 120px;
  min-height: 40px;
  padding: 0 16px;
  border: none;
  background: transparent;
  color: #f0f0f0;
  font-size: 1rem;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}

@media (hover: hover) {
  .sound-option:hover {
    background: #555;
  }
}

.sound-option:active {
  background: #1e1e1e;
}

.sound-option[aria-pressed="true"] {
  background: #d4a017;
  color: #1e1e1e;
}

.volume-slider {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 120px;
  transform: translate(-50%, -50%) rotate(-90deg);
  touch-action: none;
}

.volume-slider::-webkit-slider-runnable-track {
  background: linear-gradient(to right, #d4a017 var(--fill), #b0b0b0 var(--fill));
}

.volume-slider::-moz-range-track {
  background: #b0b0b0;
}

.beats-control {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.beats-label {
  font-size: 1rem;
  font-weight: bold;
}

.beat-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.beat-hint {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 300;
  color: #b0b0b0;
}

.beat-grid {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.beat-cell {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: #3a3a3a;
  color: #f0f0f0;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.beat-cell.accent {
  background: #d4a017;
  color: #1e1e1e;
}

.beat-cell.playing {
  box-shadow: 0 0 0 2px #f0f0f0;
}

.beat-cell.playing:not(.accent) {
  background: #336fb5;
}

@media (max-width: 360px) {
  .app {
    --button-gap: 8px;
    padding: 16px;
  }
}

@media (min-width: 768px) {
  .bpm-panel {
    grid-template-columns: repeat(3, 1fr);
    grid-template-areas:
      "minus  head   plus"
      "slow   start  fast"
      "slider slider slider";
  }

  .settings {
    flex-direction: row;
    gap: var(--group-gap);
  }
}
