@font-face {
  font-family: Roboto;
  src: url("./fonts/roboto-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Barlow Condensed";
  src: url("./fonts/barlow-condensed-digits.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
  unicode-range: U+30-39;
}

:root {
  color-scheme: dark;
  --background: #101112;
  --surface: #191c1d;
  --line: #373b3c;
  --text: #f5f4ed;
  --secondary: #a4aaac;
  --accent: #56dfef;
  --accent-background: #17373c;
  font-family: Roboto, system-ui, sans-serif;
  background: var(--background);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; }

::selection {
  background: var(--accent);
  color: var(--background);
}

button {
  color: inherit;
  font: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: default; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.metronome {
  display: grid;
  grid-template-areas: "tempo" "interval" "controls";
  grid-template-rows: minmax(146px, 1fr) auto auto;
  gap: clamp(8px, 1.8dvh, 20px);
  width: min(100%, 520px);
  height: 100vh;
  height: 100dvh;
  min-height: 360px;
  margin-inline: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px)
    max(20px, env(safe-area-inset-right, 0px))
    calc(env(safe-area-inset-bottom, 0px) + 18px)
    max(20px, env(safe-area-inset-left, 0px));
}

.accent-control {
  grid-area: interval;
  display: grid;
  grid-template-columns: minmax(82px, 1fr) minmax(0, 2.4fr);
  align-items: center;
  column-gap: 12px;
  min-width: 0;
  padding-block: 4px;
  border-block: 1px solid var(--line);
}

.wheel {
  scrollbar-width: none;
  overflow-anchor: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.wheel::-webkit-scrollbar { display: none; }

.wheel.dragging {
  scroll-snap-type: none;
  cursor: grabbing;
}

.wheel-track { display: flex; }

.wheel-item {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  scroll-snap-align: center;
}

.digit {
  display: block;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.accent-wheel {
  --step: 44px;
  width: 100%;
  height: 46px;
  overflow: auto hidden;
  scroll-snap-type: x mandatory;
  touch-action: pan-x;
  container-type: inline-size;
}

.accent-wheel .wheel-track {
  width: max-content;
  padding-inline: max(0px, calc((100cqw - var(--step)) / 2));
}

.accent-wheel .wheel-item {
  width: var(--step);
  height: 46px;
}

.accent-circle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--secondary);
  font-size: .9375rem;
  font-weight: 520;
  border-block-end: 2px solid transparent;
}

.accent-wheel .is-centered .accent-circle {
  border-color: var(--secondary);
  color: var(--text);
  font-weight: 740;
}

.accent-wheel[data-enabled="true"] .is-centered .accent-circle {
  border-color: var(--accent);
  color: var(--accent);
}

.bpm-display {
  grid-area: tempo;
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  container-type: size;
}

.bpm-display::before {
  position: absolute;
  z-index: 1;
  inset: 50% auto auto 0;
  width: clamp(16px, 8%, 36px);
  height: 2px;
  background: var(--accent);
  transform: translateY(-50%);
  pointer-events: none;
  content: "";
}

.bpm-label {
  position: absolute;
  z-index: 1;
  inset: 50% 0 auto auto;
  color: var(--accent);
  font-size: .6875rem;
  font-weight: 680;
  letter-spacing: .08em;
  transform: translateY(-50%);
  pointer-events: none;
}

.bpm-wheel {
  --step: 30cqh;
  width: 100%;
  height: 100%;
  overflow: hidden auto;
  scroll-snap-type: y mandatory;
  touch-action: pan-y;
}

.bpm-wheel .wheel-track {
  flex-direction: column;
  padding-block: calc((100cqh - var(--step)) / 2);
}

.bpm-wheel .wheel-item {
  position: relative;
  height: var(--step);
  grid-template-columns: minmax(0, 1fr);
  color: var(--secondary);
  font-family: "Barlow Condensed", Roboto, sans-serif;
  font-size: min(12rem, 42cqw, 42cqh);
  font-weight: 700;
  letter-spacing: .005em;
}

.bpm-wheel .wheel-item::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 16px;
  background:
    linear-gradient(var(--line), var(--line)) 0 17% / 5px 1px no-repeat,
    linear-gradient(var(--line), var(--line)) 0 33% / 5px 1px no-repeat,
    linear-gradient(var(--secondary), var(--secondary)) left center / 12px 1px no-repeat,
    linear-gradient(var(--line), var(--line)) 0 67% / 5px 1px no-repeat,
    linear-gradient(var(--line), var(--line)) 0 83% / 5px 1px no-repeat;
  pointer-events: none;
  content: "";
}

.bpm-wheel .digit { font-size: .54em; }

.bpm-wheel .is-centered .digit {
  color: var(--text);
  font-size: 1em;
}

.controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(72px, max-content) minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.error-message { grid-column: 1 / -1; }

.playback-button {
  --transport-size: 54px;
  position: relative;
  min-height: 44px;
  padding: calc(var(--transport-size) + 5px) 4px 0;
  color: var(--accent);
  font-size: .8125rem;
  font-weight: 680;
  line-height: 1.125rem;
}

.playback-button::before {
  position: absolute;
  inset: 0 auto auto 50%;
  width: var(--transport-size);
  height: var(--transport-size);
  transform: translateX(-50%);
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.playback-button::after {
  position: absolute;
  inset: calc(var(--transport-size) / 2) auto auto 50%;
  width: 15px;
  height: 15px;
  margin-inline-start: 3px;
  transform: translate(-50%, -50%);
  background: var(--background);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  content: "";
}

.playback-button[data-playback="playing"]::before { background: transparent; }

.playback-button[data-playback="playing"]::after {
  margin: 0;
  background: var(--accent);
  clip-path: inset(1px);
}

.playback-button:disabled { color: var(--secondary); }
.playback-button:disabled::before { border-color: var(--line); background: transparent; }
.playback-button:disabled::after { background: var(--secondary); clip-path: inset(5px round 100%); }

.sound-button {
  display: grid;
  align-content: center;
  gap: 2px;
  min-height: 54px;
  min-width: 0;
  padding: 4px 0;
  text-align: start;
}

#accent-sound { text-align: end; }

.sound-label {
  color: var(--secondary);
  font-size: .75rem;
  font-weight: 540;
  line-height: 1rem;
}

.sound-detail {
  font-size: .9375rem;
  font-weight: 670;
  line-height: 1.125rem;
  overflow-wrap: anywhere;
}

.sound-button[data-active="true"] .sound-detail { color: var(--accent); }

.error-message {
  margin: 0;
  color: #ffb4ab;
  font-size: .875rem;
}

.sound-sheet {
  position: fixed;
  inset: auto 0 0;
  width: min(100%, 480px);
  max-width: none;
  max-height: calc(100dvh - max(20px, env(safe-area-inset-top, 0px)));
  margin: 0 auto;
  padding: 12px max(12px, env(safe-area-inset-right, 0px))
    calc(8px + env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--surface);
  color: var(--text);
}

.sound-sheet[open] { display: flex; flex-direction: column; }
.sound-sheet::backdrop { background: rgb(0 0 0 / 62%); }

.sheet-heading {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-inline: 8px 0;
}

.sheet-heading h2 {
  margin: 0;
  font-size: 1.3125rem;
  font-weight: 650;
  letter-spacing: -.02em;
}

.sheet-close {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--secondary);
}

.sheet-close::before,
.sheet-close::after {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 16px;
  height: 1.5px;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(45deg);
  content: "";
}

.sheet-close::after { transform: translate(-50%, -50%) rotate(-45deg); }

.timbre-option,
.timbre-choice {
  display: flex;
  align-items: center;
  min-height: 48px;
}

.accent-switch {
  position: relative;
  display: grid;
  place-items: center;
  justify-self: start;
  min-height: 46px;
  cursor: pointer;
}

.accent-switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: inherit;
}

.switch-track {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 60px;
  height: 28px;
  padding-inline: 7px;
  border: 1px solid var(--secondary);
  border-radius: 14px;
  color: var(--secondary);
  font-size: .6875rem;
  font-weight: 700;
  pointer-events: none;
}

.switch-track::before {
  position: absolute;
  inset: 5px auto auto 5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--secondary);
  content: "";
}

.accent-switch input:checked + .switch-track {
  justify-content: flex-start;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--background);
}

.accent-switch input:checked + .switch-track::before {
  transform: translateX(32px);
  background: var(--background);
}

.switch-on,
.accent-switch input:checked + .switch-track .switch-off { display: none; }

.accent-switch input:checked + .switch-track .switch-on { display: inline; }

.accent-switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

#timbre-options {
  min-height: 0;
  margin-block-start: 6px;
  padding: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--secondary) var(--surface);
  border-top: 1px solid var(--line);
}

.timbre-option {
  justify-content: space-between;
  gap: 8px;
  padding-inline: 6px;
  border-bottom: 1px solid var(--line);
}

.timbre-option:has(input:checked) { color: var(--accent); }

.timbre-choice {
  flex: 1;
  gap: 12px;
  cursor: pointer;
}

.timbre-choice input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.preview-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--accent);
}

.preview-button::before {
  width: 11px;
  height: 12px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  content: "";
}

.preview-button:disabled { color: #7d8b8e; }

@media (hover: hover) {
  .playback-button:enabled:hover { filter: brightness(1.12); }
  .sound-button:hover .sound-detail { text-decoration: underline; }
  .sheet-close:hover,
  .preview-button:enabled:hover { background: #243237; }
}

.playback-button:enabled:active { filter: brightness(.9); }
.sound-button:active .sound-detail { color: var(--accent); }
.sheet-close:active,
.preview-button:enabled:active { background: var(--accent-background); }

@media (min-width: 700px) and (min-height: 560px) {
  .sound-sheet {
    inset: 0;
    max-height: calc(100dvh - 64px);
    margin: auto;
    border-bottom: 1px solid var(--line);
  }
}

@media (min-width: 720px) {
  .metronome {
    grid-template-areas:
      "tempo interval"
      "tempo controls";
    grid-template-columns: minmax(0, 1fr) minmax(250px, .58fr);
    grid-template-rows: 1fr 1fr;
    column-gap: clamp(32px, 6vw, 96px);
    width: min(100%, 1040px);
  }

  .accent-control { align-self: end; }
  .controls { align-self: start; padding-top: 16px; }
}

@media (max-height: 510px) {
  .metronome { row-gap: 8px; }
  .bpm-wheel .wheel-item { font-size: min(12rem, 42cqw, 35cqh); }
  .playback-button { --transport-size: 46px; }
}
