:root {
  color-scheme: dark;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  --background: #0a0d12;
  --surface: #141922;
  --surface-raised: #1d2430;
  --text: #f7f9fc;
  --muted: #98a3b3;
  --line: #3b4656;
  --cyan: #20d9ff;
  --cyan-soft: #a5f3ff;
  --violet: #9d8cff;
  --red: #ff4f5e;
  --gold: #ffd166;
  --green: #37d67a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--background);
}

body {
  min-height: 100dvh;
  color: var(--text);
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  position: relative;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(18rem, 1fr) auto auto;
  gap: clamp(0.55rem, 1.4vh, 1.2rem);
  padding: calc(0.8rem + var(--safe-top)) calc(1rem + var(--safe-right))
    calc(0.8rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
}

.app-header {
  min-height: 4rem;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow,
.app-header h1,
.runtime-status,
.hotkey-hint,
.message {
  margin: 0;
}

.eyebrow {
  color: var(--cyan);
  font-size: clamp(0.72rem, 1vw, 0.95rem);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.app-header h1 {
  font-size: clamp(1.8rem, 3vw, 3.25rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
  text-transform: uppercase;
}

.runtime-status {
  margin-right: 3.5rem;
  color: var(--muted);
  font-size: clamp(0.8rem, 1vw, 1rem);
  text-align: right;
}

.counter-region {
  position: relative;
  min-height: clamp(4.8rem, 15vh, 10rem);
  display: grid;
  place-items: center;
}

.bar-counter {
  font-size: clamp(4rem, 11vw, 10rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  letter-spacing: -0.06em;
  line-height: 0.85;
  text-align: center;
}

.counter-current {
  color: var(--cyan);
  text-shadow: 0 0 1.4rem rgb(32 217 255 / 24%);
}

.counter-divider {
  color: #687486;
}

.counter-total,
.counter-message {
  color: var(--text);
}

.last-one-label {
  position: relative;
  z-index: 6;
  grid-row: 1;
  align-self: center;
  justify-self: center;
  margin: 0;
  padding: clamp(0.55rem, 1.2vh, 0.9rem) clamp(1.5rem, 3vw, 3rem);
  border: clamp(0.12rem, 0.2vw, 0.2rem) solid rgb(255 79 94 / 58%);
  border-radius: 999px;
  background: rgb(112 25 36 / 72%);
  color: #ffadb4;
  font-size: clamp(1.25rem, 2.4vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0.18em;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  text-transform: uppercase;
  transform: translateY(0.45rem);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  white-space: nowrap;
}

.last-eight .last-one-label {
  opacity: 1;
  transform: translateY(0);
}

.last-eight .bar-counter {
  animation: last-eight-pulse 900ms ease-in-out infinite alternate;
}

@keyframes last-eight-pulse {
  from {
    filter: drop-shadow(0 0 0 rgb(255 79 94 / 0%));
    transform: scale(1);
  }

  to {
    filter: drop-shadow(0 0 1.15rem rgb(255 79 94 / 52%));
    transform: scale(1.025);
  }
}

.metronome-stage {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-rows: clamp(3.25rem, 7vh, 5.75rem) minmax(0, 1fr);
  align-items: center;
}

.beat-grid,
.count-in-grid {
  display: grid;
  align-items: center;
  width: 100%;
}

.beat-grid {
  grid-row: 2;
  grid-template-columns: repeat(17, minmax(0, 1fr));
  grid-template-rows: auto auto;
  align-content: center;
  row-gap: clamp(0.55rem, 1.6vh, 1.2rem);
}

.beat {
  position: relative;
  display: grid;
  place-items: center;
  justify-self: center;
  border-style: solid;
  border-radius: 50%;
  color: var(--text);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  transition:
    background-color 70ms linear,
    border-color 70ms linear,
    box-shadow 70ms linear,
    transform 70ms linear;
  -webkit-tap-highlight-color: transparent;
}

.beat:focus-visible,
.command:focus-visible,
.stepper-button:focus-visible,
.repetition-value:has(input:focus-visible),
.loop-control:has(input:focus-visible),
input:focus-visible,
.features-menu summary:focus-visible,
.feature-toggle:has(input:focus-visible) {
  outline: 0.22rem solid white;
  outline-offset: 0.24rem;
}

.beat.main-beat {
  grid-row: 2;
  grid-column: span 2;
  width: min(10.7vw, 9rem);
  min-width: 3.2rem;
  aspect-ratio: 1;
  border-width: clamp(0.2rem, 0.35vw, 0.38rem);
  border-color: #6c7583;
  background: #282e38;
  font-size: clamp(1.75rem, 4.6vw, 4.7rem);
}

.beat.inter-beat {
  display: none;
  grid-row: 1;
  grid-column: span 2;
  width: min(5.7vw, 5.2rem);
  min-width: 2.45rem;
  aspect-ratio: 1;
  border-width: clamp(0.13rem, 0.24vw, 0.25rem);
  border-color: #65617d;
  background: #232332;
  color: #e7e3ff;
  font-size: clamp(0.8rem, 2vw, 1.85rem);
}

#beat-grid .main-beat[data-index="0"] {
  grid-column: 1 / span 2;
}

#beat-grid .main-beat[data-index="1"] {
  grid-column: 3 / span 2;
}

#beat-grid .main-beat[data-index="2"] {
  grid-column: 5 / span 2;
}

#beat-grid .main-beat[data-index="3"] {
  grid-column: 7 / span 2;
}

#beat-grid .main-beat[data-index="4"] {
  grid-column: 9 / span 2;
}

#beat-grid .main-beat[data-index="5"] {
  grid-column: 11 / span 2;
}

#beat-grid .main-beat[data-index="6"] {
  grid-column: 13 / span 2;
}

#beat-grid .main-beat[data-index="7"] {
  grid-column: 15 / span 2;
}

#beat-grid .inter-beat[data-index="0"] {
  grid-column: 2 / span 2;
}

#beat-grid .inter-beat[data-index="1"] {
  grid-column: 4 / span 2;
}

#beat-grid .inter-beat[data-index="2"] {
  grid-column: 6 / span 2;
}

#beat-grid .inter-beat[data-index="3"] {
  grid-column: 8 / span 2;
}

#beat-grid .inter-beat[data-index="4"] {
  grid-column: 10 / span 2;
}

#beat-grid .inter-beat[data-index="5"] {
  grid-column: 12 / span 2;
}

#beat-grid .inter-beat[data-index="6"] {
  grid-column: 14 / span 2;
}

#beat-grid .inter-beat[data-index="7"] {
  grid-column: 16 / span 2;
}

.show-intermediates .beat.inter-beat {
  display: grid;
}

.count-in-active #beat-grid .inter-beat {
  visibility: hidden;
}

.beat.accent {
  border-color: #ff727d;
  background: #8f2631;
  box-shadow: 0 0 0 0.22rem rgb(255 79 94 / 22%);
}

.beat.inter-beat.accent {
  border-color: #ffbd59;
  background: #6e4300;
  box-shadow: 0 0 0 0.18rem rgb(255 189 89 / 22%);
}

.beat.active {
  z-index: 2;
  border-color: white;
  background: var(--cyan);
  color: #071014;
  box-shadow:
    0 0 0 0.38rem var(--cyan-soft),
    0 0 2.2rem rgb(32 217 255 / 78%);
  transform: scale(1.07);
}

.beat.inter-beat.active {
  background: var(--violet);
  box-shadow:
    0 0 0 0.28rem #cec7ff,
    0 0 1.5rem rgb(157 140 255 / 70%);
  transform: scale(1.07);
}

.beat.accent.active {
  border-color: var(--gold);
  background: var(--red);
  box-shadow:
    0 0 0 0.38rem #fff0ad,
    0 0 2.2rem rgb(255 79 94 / 82%);
}

.beat.inter-beat.accent.active {
  background: #ff9f43;
}

.count-in {
  position: absolute;
  z-index: 5;
  inset: clamp(3.25rem, 7vh, 5.75rem) 10% 0;
  display: grid;
  align-items: start;
  padding-top: 1rem;
  pointer-events: none;
}

.count-in[hidden] {
  display: none;
}

.count-in-grid {
  grid-template-columns: repeat(16, minmax(0, 1fr));
  grid-template-rows: minmax(4rem, 1fr);
  opacity: 0.96;
}

.count-beat {
  display: grid;
  place-items: center;
  justify-self: center;
  border: 0.2rem solid #49684e;
  border-radius: 50%;
  background: #17251a;
  color: #cce8d0;
  font-weight: 900;
}

.count-beat.main-beat {
  grid-row: 1;
  grid-column: span 4;
  width: clamp(3.5rem, 7vw, 6.5rem);
  aspect-ratio: 1;
  font-size: clamp(1.5rem, 3vw, 2.8rem);
}

#count-in .main-beat[data-index="0"] {
  grid-column: 1 / span 4;
}

#count-in .main-beat[data-index="1"] {
  grid-column: 5 / span 4;
}

#count-in .main-beat[data-index="2"] {
  grid-column: 9 / span 4;
}

#count-in .main-beat[data-index="3"] {
  grid-column: 13 / span 4;
}

.count-beat.active {
  border-color: white;
  background: #7dff98;
  color: #0c2512;
  box-shadow: 0 0 1.4rem rgb(125 255 152 / 68%);
}

.bounce-visual {
  --ball-size: clamp(2.8rem, 4vw, 4.4rem);
  --ball-travel: clamp(6rem, 13vh, 10rem);
  position: absolute;
  z-index: 9;
  top: calc(4.25rem + var(--safe-top));
  right: calc(1.25rem + var(--safe-right));
  width: clamp(7rem, 10vw, 11rem);
  height: calc(var(--ball-travel) + var(--ball-size) + 0.8rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.playing.show-ball .bounce-visual {
  opacity: 1;
}

.bouncing-ball {
  position: absolute;
  top: 0;
  left: calc(50% - (var(--ball-size) / 2));
  width: var(--ball-size);
  aspect-ratio: 1;
  border: clamp(0.16rem, 0.2vw, 0.24rem) solid #d8faff;
  border-radius: 50%;
  background-color: var(--cyan);
  box-shadow:
    0 0 0 0.18rem rgb(32 217 255 / 20%),
    0 0 1.3rem rgb(32 217 255 / 52%);
  transform: translateY(var(--ball-travel));
  transform-origin: 50% 100%;
}

.bouncing-ball::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 34% 27%, rgb(255 255 255 / 88%) 0 7%, transparent 30%);
  content: "";
}

.bounce-floor {
  position: absolute;
  right: 4%;
  bottom: 0.55rem;
  left: 4%;
  height: 0.2rem;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #748295 18% 82%, transparent);
  box-shadow: 0 0 0.8rem rgb(32 217 255 / 25%);
  transform-origin: center;
}

.playing.cursor-hidden,
.playing.cursor-hidden * {
  cursor: none !important;
}

.progress-region {
  min-height: 1.25rem;
}

.loop-mode .progress-region {
  visibility: hidden;
}

progress {
  display: block;
  width: 100%;
  height: clamp(1rem, 2.4vh, 1.7rem);
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #252c36;
}

progress::-webkit-progress-bar {
  background: #252c36;
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, #00a9cf, var(--cyan));
}

progress::-moz-progress-bar {
  background: linear-gradient(90deg, #00a9cf, var(--cyan));
}

.controls {
  min-height: 12.5rem;
  display: grid;
  gap: 0.8rem;
  align-content: end;
}

.settings-row,
.command-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.55rem, 1.2vw, 1rem);
  flex-wrap: wrap;
}

.tempo-control,
.exercise-control,
.features-menu summary {
  min-height: 3.25rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--surface);
  font-weight: 750;
}

.tempo-control {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  padding: 0.35rem 0.4rem 0.35rem 0.8rem;
}

.control-caption {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.tempo-control .control-caption {
  grid-row: 1;
  grid-column: 1;
  align-self: center;
}

.tempo-stepper {
  grid-row: 1;
  grid-column: 2;
  display: grid;
  grid-template-columns: 2.65rem 5.4rem 2.65rem;
  overflow: hidden;
  border: 1px solid #4b586b;
  border-radius: 0.65rem;
  background: var(--surface-raised);
}

.stepper-button {
  min-height: 2.75rem;
  border: 0;
  background: #283344;
  color: var(--cyan-soft);
  font-size: 1.45rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}

.stepper-button:active {
  background: #315267;
  color: white;
}

.stepper-button:disabled {
  background: #232b38;
  color: #697588;
  cursor: not-allowed;
}

.tempo-value {
  position: relative;
  display: grid;
  place-items: center;
  border-inline: 1px solid #4b586b;
}

.tempo-value input {
  appearance: textfield;
  -moz-appearance: textfield;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.15rem 0.35rem 0.8rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 850;
  text-align: center;
}

.tempo-value input::-webkit-inner-spin-button,
.tempo-value input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.tempo-value span {
  position: absolute;
  bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.exercise-control {
  min-width: 25rem;
  display: grid;
  grid-template-columns: auto auto auto auto;
  grid-template-rows: auto;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.8rem;
}

.exercise-control > .control-caption {
  grid-row: 1;
  align-self: center;
  padding-right: 0.15rem;
}

.loop-control {
  min-height: 2.15rem;
  display: flex;
  align-items: center;
  border: 1px solid #4b586b;
  border-radius: 0.55rem;
  background: var(--surface-raised);
}

.repetitions-stepper {
  display: grid;
  grid-template-columns: 2.35rem 5.8rem 2.35rem;
  overflow: hidden;
  border: 1px solid #4b586b;
  border-radius: 0.65rem;
  background: var(--surface-raised);
}

.repetition-value {
  display: grid;
  grid-template-columns: minmax(2.15rem, auto) auto;
  place-content: center;
  align-items: center;
  gap: 0.2rem;
  border-inline: 1px solid #4b586b;
}

.repetition-value input {
  width: 2.45rem;
  min-height: 2.75rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 850;
  line-height: 1;
  text-align: center;
}

.repetition-expression {
  padding-right: 0.45rem;
  color: var(--cyan-soft);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.exercise-divider {
  align-self: center;
  color: #687486;
  font-size: 0.68rem;
  font-weight: 700;
}

.loop-control {
  gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  transition:
    border-color 120ms ease,
    background-color 120ms ease,
    color 120ms ease;
}

.loop-control input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--cyan);
}

.loop-symbol {
  color: var(--cyan-soft);
  font-size: 1.2rem;
  line-height: 0.7;
}

.loop-mode .repetitions-stepper,
.loop-mode .exercise-divider {
  opacity: 0.3;
}

.loop-mode .loop-control {
  border-color: rgb(32 217 255 / 72%);
  background: rgb(15 93 111 / 62%);
  color: white;
}

.features-menu {
  position: relative;
  z-index: 20;
}

.features-menu summary {
  min-width: 9.5rem;
  justify-content: space-between;
  padding: 0.72rem 0.9rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.features-menu summary::-webkit-details-marker {
  display: none;
}

.features-menu summary::after {
  color: var(--cyan);
  content: "+";
  font-size: 1.25rem;
  line-height: 1;
}

.features-menu[open] summary::after {
  content: "−";
}

.features-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.features-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.55rem);
  width: min(23rem, calc(100vw - 2rem));
  overflow: hidden;
  border: 1px solid #596579;
  border-radius: 0.9rem;
  background: #121821;
  box-shadow: 0 1rem 2.5rem rgb(0 0 0 / 55%);
}

.features-panel-header {
  display: none;
}

.panel-close-button {
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid #596579;
  border-radius: 50%;
  background: #242d3b;
  color: white;
  font-size: 1.55rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
}

.panel-close-button:focus-visible {
  outline: 0.2rem solid white;
  outline-offset: 0.16rem;
}

.feature-section + .feature-section {
  border-top: 1px solid #4a5668;
}

.feature-section h3 {
  margin: 0;
  padding: 0.65rem 0.85rem 0.15rem;
  color: var(--cyan-soft);
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.feature-toggle {
  min-height: 3.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  user-select: none;
}

.feature-section .feature-toggle + .feature-toggle,
.feature-family + .feature-toggle,
.feature-toggle + .feature-family {
  border-top: 1px solid rgb(59 70 86 / 72%);
}

.feature-toggle.unavailable {
  cursor: not-allowed;
  opacity: 0.45;
}

.feature-family {
  position: relative;
}

.feature-child {
  position: relative;
  min-height: 3.35rem;
  margin-left: 1rem;
  padding-left: 1.35rem;
  background: rgb(29 36 48 / 58%);
}

.feature-child::before {
  position: absolute;
  top: 0.25rem;
  bottom: 0.25rem;
  left: 0.45rem;
  width: 0.16rem;
  border-radius: 999px;
  background: var(--violet);
  content: "";
  opacity: 0.65;
}

.feature-toggle > span {
  min-width: 0;
  display: grid;
  gap: 0.12rem;
}

.feature-toggle strong {
  font-size: 0.95rem;
}

.feature-toggle small {
  color: var(--muted);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.feature-toggle input {
  width: 1.45rem;
  height: 1.45rem;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--cyan);
}

.command {
  min-width: 8.5rem;
  min-height: 3.35rem;
  padding: 0.72rem 1.1rem;
  border: 0;
  border-radius: 0.75rem;
  color: white;
  font-weight: 850;
  cursor: pointer;
}

.command:active {
  transform: translateY(0.1rem);
}

.command.start {
  background: #167542;
}

.command.stop {
  background: #a82d38;
}

.command.reset {
  background: #2455ba;
}

.command.tap {
  background: #673bb5;
}

.command.fullscreen {
  background: #414b5c;
}

.hotkey-hint,
.message {
  min-height: 1.25rem;
  text-align: center;
}

.hotkey-hint {
  color: var(--muted);
  font-size: clamp(0.72rem, 1vw, 0.9rem);
}

.message {
  color: #ff9ca5;
  font-weight: 750;
}

.message:empty {
  display: none;
}

.playing .chrome {
  visibility: hidden;
  pointer-events: none;
}

.playing .beat {
  cursor: default;
}

.focus-actions {
  position: fixed;
  z-index: 10;
  right: calc(1rem + var(--safe-right));
  bottom: calc(1rem + var(--safe-bottom));
  display: none;
  align-items: center;
  gap: 0.55rem;
}

.playing .focus-actions {
  display: flex;
}

.focus-command {
  min-width: 5.5rem;
  min-height: 3.25rem;
  border: 0.15rem solid rgb(255 255 255 / 55%);
  border-radius: 999px;
  color: white;
  font-weight: 850;
  box-shadow: 0 0.4rem 1.4rem rgb(0 0 0 / 42%);
  cursor: pointer;
  touch-action: manipulation;
}

.focus-intermediates {
  background: rgb(65 75 92 / 92%);
}

.show-intermediates .focus-intermediates {
  border-color: var(--cyan-soft);
  background: rgb(0 121 150 / 94%);
}

.focus-ball {
  background: rgb(65 75 92 / 92%);
}

.show-ball .focus-ball {
  border-color: var(--cyan-soft);
  background: rgb(0 121 150 / 94%);
}

.focus-final {
  display: none;
  background: rgb(143 38 49 / 94%);
}

.playing.loop-mode .focus-final {
  display: block;
}

.focus-final:disabled {
  border-color: #ffadb4;
  background: rgb(143 38 49 / 72%);
  cursor: default;
}

.focus-stop {
  background: rgb(168 45 56 / 88%);
}

.focus-command:focus-visible,
.shortcut-help-button:focus-visible {
  outline: 0.22rem solid white;
  outline-offset: 0.22rem;
}

.shortcut-help {
  position: fixed;
  z-index: 100;
  top: calc(0.8rem + var(--safe-top));
  right: calc(0.8rem + var(--safe-right));
  transition: opacity 100ms ease;
}

.features-open .shortcut-help,
.app-shell:has(.features-menu[open]) .shortcut-help {
  opacity: 0;
  pointer-events: none;
}

.shortcut-help-button {
  position: relative;
  z-index: 2;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid #566174;
  border-radius: 50%;
  background: rgb(29 36 48 / 94%);
  color: var(--cyan-soft);
  font-size: 1.25rem;
  font-weight: 900;
  box-shadow: 0 0.35rem 1rem rgb(0 0 0 / 30%);
  cursor: pointer;
  transition: opacity 100ms ease;
}

.shortcut-help.open > .shortcut-help-button {
  opacity: 0;
  pointer-events: none;
}

.shortcut-help-panel {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  width: min(40rem, calc(100vw - 1.6rem));
  max-height: calc(100dvh - 1.6rem - var(--safe-top));
  overflow: auto;
  padding: 1rem;
  border: 1px solid #465164;
  border-radius: 1rem;
  background: #141922;
  box-shadow: 0 1rem 3rem rgb(0 0 0 / 55%);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.35rem);
  transition:
    opacity 130ms ease,
    transform 130ms ease;
}

.shortcut-help:focus-within .shortcut-help-panel,
.shortcut-help.open .shortcut-help-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.shortcut-help-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.shortcut-help-panel h2 {
  margin: 0;
  color: var(--cyan-soft);
  font-size: 1.15rem;
}

@media (hover: hover) and (pointer: fine) {
  .shortcut-help:hover > .shortcut-help-button {
    opacity: 0;
    pointer-events: none;
  }

  .shortcut-help:hover .shortcut-help-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
}

.shortcut-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.shortcut-group {
  padding: 0.7rem;
  border: 1px solid #374252;
  border-radius: 0.7rem;
  background: #10151d;
}

.shortcut-group h3 {
  margin: 0 0 0.55rem;
  color: var(--cyan-soft);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.shortcut-group dl {
  display: grid;
  gap: 0.5rem;
  margin: 0;
}

.shortcut-group dl div {
  display: grid;
  grid-template-columns: minmax(5.8rem, 0.8fr) 1.25fr;
  align-items: start;
  gap: 0.55rem;
}

.shortcut-group dt {
  color: white;
  font-weight: 800;
}

.shortcut-group dd {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.82rem, 1vw, 0.92rem);
  line-height: 1.3;
}

.shortcut-group kbd {
  display: inline-block;
  min-width: 1.55rem;
  padding: 0.12rem 0.34rem;
  border: 1px solid #58667a;
  border-bottom-width: 0.16rem;
  border-radius: 0.32rem;
  background: #252d3a;
  color: white;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .shortcut-groups {
    grid-template-columns: 1fr;
  }
}

noscript {
  position: fixed;
  inset: 1rem;
  z-index: 20;
  padding: 1rem;
  border-radius: 0.75rem;
  background: #7f1d1d;
  color: white;
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-rows: auto auto minmax(14rem, 1fr) auto auto;
    padding-inline: calc(0.55rem + var(--safe-right)) calc(0.55rem + var(--safe-left));
  }

  .counter-region {
    min-height: 4.2rem;
  }

  .bar-counter {
    font-size: clamp(3.5rem, 18vw, 6.5rem);
  }

  .metronome-stage {
    grid-template-rows: clamp(3.5rem, 8vh, 4.75rem) minmax(0, 1fr);
  }

  .last-one-label {
    max-width: calc(100vw - 2rem - var(--safe-left) - var(--safe-right));
    padding: 0.7rem clamp(1rem, 6vw, 1.75rem);
    font-size: clamp(1.1rem, 6vw, 1.65rem);
    letter-spacing: 0.14em;
    text-align: center;
  }

  .beat-grid {
    row-gap: clamp(0.4rem, 1.2vh, 0.75rem);
  }

  .count-in {
    inset: clamp(3.5rem, 8vh, 4.75rem) 5% 0;
  }

  .beat.main-beat {
    width: 11vw;
    min-width: 2.75rem;
    font-size: clamp(1.35rem, 5.8vw, 2.8rem);
  }

  .beat.inter-beat {
    width: 6.3vw;
    min-width: 2.5rem;
    font-size: clamp(0.62rem, 2.4vw, 1rem);
  }

  .controls {
    min-height: 18.5rem;
  }

  .settings-row,
  .command-row {
    gap: 0.48rem;
  }

  .tempo-control,
  .exercise-control,
  .features-menu summary,
  .command {
    min-height: 3rem;
  }

  .exercise-control {
    width: 100%;
    min-width: 0;
    grid-template-columns: auto auto auto;
    grid-template-rows: auto auto;
    justify-content: center;
    column-gap: 0.35rem;
  }

  .exercise-control > .control-caption {
    grid-row: 1;
    grid-column: 1 / -1;
    justify-self: start;
  }

  .repetitions-stepper {
    grid-row: 2;
    grid-column: 1;
    justify-self: start;
  }

  .exercise-divider {
    grid-row: 2;
    grid-column: 2;
  }

  .loop-control {
    grid-row: 2;
    grid-column: 3;
  }

  .command {
    min-width: min(8.2rem, 30vw);
    flex: 1 1 7.5rem;
  }

  .focus-actions {
    max-width: calc(100vw - 2rem - var(--safe-left) - var(--safe-right));
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .features-panel {
    position: fixed;
    inset: calc(0.6rem + var(--safe-top)) calc(0.6rem + var(--safe-right)) auto
      calc(0.6rem + var(--safe-left));
    width: auto;
    max-height: calc(100dvh - 1.2rem - var(--safe-top) - var(--safe-bottom));
    overflow-x: hidden;
    overflow-y: auto;
  }

  .features-panel-header {
    position: sticky;
    z-index: 2;
    top: 0;
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0.65rem 0.5rem 0.85rem;
    border-bottom: 1px solid #4a5668;
    background: #121821;
    color: var(--cyan-soft);
  }

  .features-panel-header strong {
    font-size: 0.78rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .feature-toggle {
    gap: 0.7rem;
  }

  .shortcut-help {
    top: calc(0.55rem + var(--safe-top));
    right: calc(0.55rem + var(--safe-right));
  }

  .shortcut-help-panel {
    position: fixed;
    inset: calc(0.55rem + var(--safe-top)) calc(0.55rem + var(--safe-right)) auto
      calc(0.55rem + var(--safe-left));
    width: auto;
    max-height: calc(100dvh - 1.1rem - var(--safe-top) - var(--safe-bottom));
  }
}

.expanded-view {
  position: fixed;
  z-index: 90;
  inset: 0;
  width: 100%;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--background);
}

@media (orientation: landscape) and (max-height: 700px) {
  .app-shell {
    grid-template-rows: 2.2rem 3.5rem minmax(7rem, 1fr) 0.8rem auto;
    gap: 0.25rem;
    padding-top: calc(0.35rem + var(--safe-top));
    padding-bottom: calc(0.35rem + var(--safe-bottom));
  }

  .app-header {
    min-height: 2.2rem;
  }

  .eyebrow,
  .runtime-status,
  .hotkey-hint {
    display: none;
  }

  .counter-region {
    min-height: 3.25rem;
  }

  .bar-counter {
    font-size: clamp(3rem, 12vh, 5.2rem);
  }

  .beat-grid {
    grid-template-rows: auto auto;
    row-gap: 0.45rem;
  }

  .beat.main-beat {
    width: min(9vw, 11vh);
    min-width: 2.8rem;
    font-size: clamp(1.3rem, 5.5vh, 2.6rem);
  }

  .beat.inter-beat {
    width: min(5vw, 6.5vh);
    min-width: 2.25rem;
    font-size: clamp(0.62rem, 2.6vh, 1rem);
  }

  .count-in {
    padding-top: 0;
  }

  .bounce-visual {
    --ball-size: 2.8rem;
    --ball-travel: 5rem;
    top: calc(3.25rem + var(--safe-top));
  }

  .controls {
    min-height: 5.5rem;
    gap: 0.4rem;
  }

  .settings-row,
  .command-row {
    flex-wrap: nowrap;
    gap: 0.4rem;
  }

  .tempo-control,
  .exercise-control,
  .features-menu summary,
  .command {
    min-height: 2.65rem;
    font-size: 0.82rem;
  }

  .tempo-control {
    gap: 0.35rem;
    padding: 0.2rem 0.25rem 0.2rem 0.5rem;
  }

  .tempo-stepper {
    grid-template-columns: 2.15rem 4rem 2.15rem;
  }

  .repetitions-stepper {
    grid-template-columns: 1.9rem 4.8rem 1.9rem;
  }

  .stepper-button,
  .tempo-value input,
  .repetition-value input {
    min-height: 2.25rem;
    font-size: 0.9rem;
  }

  .exercise-control {
    min-width: 16rem;
    gap: 0.3rem;
    padding: 0.2rem 0.35rem 0.2rem 0.5rem;
  }

  .exercise-control > .control-caption {
    grid-row: 1;
  }

  .features-menu summary {
    min-width: 7rem;
    padding: 0.45rem 0.6rem;
  }

  .command {
    min-width: 0;
    flex: 1 1 0;
    padding-block: 0.5rem;
  }

  .playing.app-shell {
    grid-template-rows: 2.2rem 3.5rem minmax(7rem, 1fr) 0.8rem 5.5rem;
  }

  .focus-actions {
    right: calc(0.55rem + var(--safe-right));
    bottom: calc(0.45rem + var(--safe-bottom));
    gap: 0.35rem;
  }

  .focus-command {
    min-width: 4.8rem;
    min-height: 2.75rem;
    font-size: 0.82rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .beat {
    transition: none;
  }

  .last-eight .bar-counter {
    animation: none;
  }
}
