/* The metronome (/metronome/). The page hero, card and option buttons come from page.css, the ebony case and its
   buttons from piano.css. */

/* Base (phones) */

.met-mode {
  margin-bottom: 18px;
}

/* The case: the tempo large, with − and + either side (Basic), the beat lights, and Start */
.met-case {
  margin-bottom: 22px;
  padding: 20px 16px 14px;
}

.met-tempo {
  display: grid;
  grid-template-columns: auto auto auto;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
}

.met-step {
  width: 52px;
  height: 52px;
  border: 1px solid rgba(250, 250, 249, 0.2);
  border-radius: 50%;
  background: transparent;
  color: var(--ebony-text);
  font: inherit;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.1s var(--ease);
}

.met-step:active {
  transform: scale(0.94);
}

.met-step:focus-visible {
  outline-color: var(--ebony-text);
}

/* tempo changes: the tempo is set in the list of sections, so the case only shows it */
.met-case.is-plan .met-step {
  visibility: hidden;
}

.met-bpm {
  display: grid;
  justify-items: center;
}

.met-bpm input {
  width: 3.4ch;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ebony-text);
  font-family: var(--font-display);
  font-size: clamp(3.6rem, 17vw, 5.2rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.04em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.met-bpm input::-webkit-inner-spin-button,
.met-bpm input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.met-bpm input:focus-visible {
  outline: 2px solid var(--ebony-text);
  outline-offset: 2px;
}

.met-bpm input:read-only {
  cursor: default;
}

/* the count-in: the big number counts down the beats to go, in brass, over "Count-in" */
.met-case.is-counting .met-bpm input,
.met-case.is-counting .met-bpm span {
  color: var(--brass);
}

.met-bpm span {
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ebony-muted);
}

.met-detail {
  min-height: 1.5em;
  margin: 10px 0 18px;
  font-size: 0.92rem;
  text-align: center;
  color: var(--ebony-muted);
}

/* one light for each beat, a button to tap that changes its accent. Strong is ringed in felt red, medium in brass,
   soft is a plain light, silent an empty ring; the stronger, the larger. The beat playing lights up in its accent's
   colour (brass for all in the count-in). In 6/8, 9/8 and 12/8 a gap comes before each group of three. */
.met-beats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  margin-bottom: 4px;
}

.met-beat {
  display: grid;
  place-items: center;
  width: 30px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.met-beat::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(250, 250, 249, 0.16);
  transition: background-color 0.05s linear, transform 0.05s linear;
}

.met-beat.lvl-3::before {
  width: 18px;
  height: 18px;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.met-beat.lvl-2::before {
  width: 16px;
  height: 16px;
  box-shadow: inset 0 0 0 2px var(--brass);
}

.met-beat.lvl-0::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px rgba(250, 250, 249, 0.3);
}

.met-beat.is-on::before {
  background: var(--ebony-text);
  transform: scale(1.15);
}

.met-beat.lvl-3.is-on::before {
  background: var(--accent);
}

.met-beat.lvl-2.is-on::before {
  background: var(--brass);
}

.met-beat.lvl-0.is-on::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--ebony-text);
}

.met-beats.is-counting .met-beat.is-on::before {
  background: var(--brass);
}

.met-beat:focus-visible {
  outline: 2px solid var(--ebony-text);
  outline-offset: -2px;
}

.met-beat.is-group {
  margin-left: 8px;
}

.met-beats.is-compact .met-beat {
  width: 24px;
}

/* 12/8 on a phone: two rows of six */
@media (max-width: 559px) {
  .met-beats.is-twelve {
    display: grid;
    grid-template-columns: repeat(6, auto);
    justify-content: center;
  }

  .met-beats.is-twelve .met-beat:nth-child(6n + 1) {
    margin-left: 0;
  }
}

/* the narrowest phones: nine beats (9/8) still fit on one line */
@media (max-width: 380px) {
  .met-beats.is-compact {
    gap: 0;
  }

  .met-beats.is-compact .met-beat {
    width: 21px;
  }

  .met-beats.is-compact .met-beat.is-group {
    margin-left: 5px;
  }
}

@media (hover: hover) {
  .met-beat:hover::before {
    background-color: rgba(250, 250, 249, 0.3);
  }

  .met-beat.lvl-0:hover::before {
    background-color: transparent;
    box-shadow: inset 0 0 0 1.5px rgba(250, 250, 249, 0.55);
  }
}

/* the time signature and the subdivision, under the case */
.met-options {
  display: grid;
  gap: 16px;
}

/* the time signatures, written as in music: one number over the other */
.met-time {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

/* on a phone, two rows: the ones counted in crotchets and minims, then the ones in quavers; one row on wider screens */
.met-times {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 4px;
  align-self: start;
}

.seg.met-times button {
  display: grid;
  place-content: center;
  width: 42px;
  height: 56px;
  padding: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.met-time > .seg {
  align-self: start;
}

.met-metre {
  display: grid;
  gap: 16px;
}

.met-metre[hidden] {
  display: none;
}

.met-time-hint {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.met-time-hint:empty {
  display: none;
}

/* a number with − and + beside it */
.stepper {
  display: inline-flex;
  align-items: center;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.stepper button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 0.2s var(--ease);
}

.stepper input {
  width: 3.4ch;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper input:focus-visible {
  border-radius: 6px;
  outline: 2px solid var(--accent);
}

/* Tempo changes: the sections, one row each, the one playing picked out */
.met-plan {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.met-plan[hidden] {
  display: none;
}

.met-plan h2 {
  margin: 0 0 4px;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.met-plan-intro {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.met-sections {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* a section: its number, its tempo and the remove button; then the bars and time signature, under it all on a
   phone, under the tempo on a wider screen */
.met-section {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background-color 0.2s var(--ease);
}

.met-section.is-current {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
  box-shadow: 0 0 0 1px var(--accent);
}

.met-section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-alt);
  font-size: 0.84rem;
  font-weight: 700;
}

.met-section.is-current .met-section-num {
  background: var(--accent);
  color: #fff;
}

.met-section-num {
  grid-row: 1;
  grid-column: 1;
  align-self: start;
  margin-top: 7px; /* level with the 42px menus and steppers */
}

.met-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.met-field-tempo {
  grid-row: 1;
  grid-column: 2;
}

.met-field-bars {
  grid-column: 1 / -1;
}

.met-unit {
  font-size: 0.88rem;
  color: var(--muted);
}

/* a section's time signature */
.met-select {
  -webkit-appearance: none;
  appearance: none;
  height: 42px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2375706a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

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

.met-remove {
  grid-row: 1;
  grid-column: 3;
  align-self: start;
  margin-top: 3px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}

.met-remove[hidden] {
  display: none;
}

.met-plan-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin: 12px 0 20px;
}

.met-add {
  min-height: 42px;
  padding: 0 16px;
  font-size: 0.88rem;
}

.met-add:disabled {
  opacity: 0.45;
  cursor: default;
}

.met-total {
  font-size: 0.86rem;
  color: var(--muted);
}

@media (hover: hover) {
  .met-step:hover {
    background: rgba(250, 250, 249, 0.08);
    border-color: rgba(250, 250, 249, 0.34);
  }

  .stepper button:hover {
    background: var(--bg-alt);
  }

  .met-remove:hover {
    background: var(--bg-alt);
    color: var(--text);
  }
}

@media (min-width: 560px) {
  .met-field-bars {
    grid-column: 2;
  }
}

/* Tablet */
@media (min-width: 768px) {
  .met-case {
    padding: 24px 22px 18px;
  }

  .met-tempo {
    gap: 28px;
  }

  .met-step {
    width: 60px;
    height: 60px;
  }

  .met-times {
    grid-template-columns: repeat(9, auto);
  }

  .seg.met-times button {
    width: 52px;
  }

}

/* Desktop */
@media (min-width: 1024px) {
  .met-tool {
    max-width: 720px;
  }
}
