*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  color-scheme: dark;
  --bg: #101114;
  --surface: #191b20;
  --surface-raised: #20232a;
  --border: #30343d;
  --text: #f3f4f6;
  --text-dim: #a0a5b0;
  --accent: #ffad42;
  --accent-strong: #ffc46d;
  --accent-ink: #1b1409;
  --beat-off: #30343d;
  --beat-on: #72dda0;
  --beat-down: #ffad42;
  --danger: #ff6969;
  --shadow: 0 16px 44px rgb(0 0 0 / 16%);
  --radius: 22px;
  --radius-small: 14px;
  --touch: 52px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-raised: #f5f6f8;
  --border: #e0e4ea;
  --text: #20242b;
  --text-dim: #68717e;
  --accent: #b85f00;
  --accent-strong: #965000;
  --accent-ink: #ffffff;
  --beat-off: #e1e5eb;
  --beat-on: #28a562;
  --beat-down: #d57516;
  --danger: #cc3333;
  --shadow: 0 14px 36px rgb(34 46 65 / 7%);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-raised: #f5f6f8;
    --border: #e0e4ea;
    --text: #20242b;
    --text-dim: #68717e;
    --accent: #b85f00;
    --accent-strong: #965000;
    --accent-ink: #ffffff;
    --beat-off: #e1e5eb;
    --beat-on: #28a562;
    --beat-down: #d57516;
    --danger: #cc3333;
    --shadow: 0 14px 36px rgb(34 46 65 / 7%);
  }
}

html,
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  line-height: 1.5;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-definitions {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

button {
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible,
.panel:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 {
  margin-top: 5px;
  font-size: 1.1rem;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.eyebrow + h2 {
  margin-top: 6px;
}

h1,
h2,
h3,
p,
label,
button {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  line-height: 1.3;
}

.eyebrow {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.14em;
  line-height: 1.45;
}

.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 15px;
  background: var(--accent);
  color: var(--accent-ink);
}

.brand-mark svg {
  width: 27px;
  height: 27px;
}

.brand-copy {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.brand-copy strong {
  font-size: 1.02rem;
  line-height: 1.25;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}

.brand-copy span {
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.4;
}

.language-control,
.theme-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.35;
}

.language-control select,
.theme-control select {
  min-height: 48px;
  max-width: 120px;
  padding: 0 26px 0 9px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a0a5b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 8px center;
  background-repeat: no-repeat;
}

.theme-control .icon {
  width: 16px;
  height: 16px;
}

@media (max-width: 460px) {
  .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
  }

  .brand {
    grid-column: 1 / -1;
    gap: 7px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 11px;
  }

  .brand-copy strong {
    font-size: 0.8rem;
  }

  .brand-copy span {
    display: none;
  }

  .language-control,
  .theme-control {
    gap: 0;
  }

  .language-control > span,
  .theme-control > span,
  .theme-control > .icon {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .language-control select,
  .theme-control select {
    width: 160px;
    max-width: 160px;
    padding: 0 20px 0 5px;
    font-size: 16px;
  }

  .theme-control select {
    width: 96px;
    max-width: 96px;
  }
}

@media (max-width: 360px) {
  .app-header {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 5px;
  }

  .brand-copy strong {
    font-size: 0.72rem;
  }

  .theme-control select {
    width: 88px;
    max-width: 88px;
  }
}

.app {
  display: grid;
  grid-template-areas:
    "header"
    "beats"
    "tempo"
    "tabs"
    "modepanel"
    "panel"
    "readout";
  gap: 16px;
  width: min(100%, 680px);
  min-width: 0;
  margin: 0 auto;
  padding: 20px 16px 36px;
  min-height: 100dvh;
  align-content: start;
}

.beats { grid-area: beats; }
.tempo { grid-area: tempo; }
.mode-tabs { grid-area: tabs; }
.mode-panel { grid-area: modepanel; }
.panel { grid-area: panel; }
.readout { grid-area: readout; }

.app > * {
  min-width: 0;
  max-width: 100%;
}

.beats {
  display: flex;
  min-height: 176px;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding: 22px;
}

.beat-display {
  display: grid;
  min-width: 0;
  min-height: 76px;
  align-content: center;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-raised);
}

.beat-activity {
  display: grid;
  gap: 8px;
}

.console-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 8px;
}

.console-actions .btn-play,
.console-actions .btn-tap {
  min-width: 0;
  min-height: 54px;
  border-radius: 14px;
  font-size: 0.92rem;
}

.console-actions .status-line {
  grid-column: 1 / -1;
  overflow-wrap: anywhere;
}

.sticky-playback {
  position: fixed;
  z-index: 10;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  display: grid;
  width: min(100% - 24px, 648px);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.sticky-playback .btn-play,
.sticky-playback .btn-tap {
  min-height: 48px;
  border-radius: 12px;
  font-size: 0.92rem;
}

body.has-sticky-playback .app {
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

.beat-row {
  display: grid;
  counter-reset: beat;
  grid-template-columns: repeat(var(--beat-count, 4), minmax(0, 1fr));
  min-height: 60px;
  width: 100%;
  align-items: center;
  justify-items: center;
}

.beat-dot {
  display: grid;
  width: min(100%, clamp(36px, 10vw, 52px));
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--beat-off);
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  transition: background-color 80ms ease, color 80ms ease, transform 80ms ease, box-shadow 80ms ease;
}

.beat-dot::after {
  content: counter(beat);
  counter-increment: beat;
}

.beat-dot.downbeat {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.beat-dot.active {
  transform: scale(1.18);
  background: var(--beat-on);
  color: #102018;
  animation: beat-pulse 180ms ease-out;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--beat-on) 22%, transparent),
    0 0 26px color-mix(in srgb, var(--beat-on) 65%, transparent);
}

.beat-dot.downbeat.active {
  background: var(--beat-down);
  color: var(--accent-ink);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--beat-down) 25%, transparent),
    0 0 30px color-mix(in srgb, var(--beat-down) 70%, transparent);
}

@keyframes beat-pulse {
  from { transform: scale(0.88); }
  to { transform: scale(1.18); }
}

.meter-badge {
  display: grid;
  min-width: 54px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--text-dim);
  font-size: 0.86rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.phrase-label {
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: center;
}

.mode-panel {
  display: grid;
  min-width: 0;
  gap: 12px;
  padding: 18px 20px;
  overflow-wrap: anywhere;
}

.mode-panel > * {
  min-width: 0;
}

.mode-panel h2 {
  font-size: 1rem;
  line-height: 1.35;
}

.mode-panel h2 + p {
  margin-top: 3px;
}

.mode-panel > p:last-child,
.mode-description {
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.65;
}

@media (min-width: 760px) {
  .sticky-playback {
    display: none !important;
  }

  body.has-sticky-playback .app {
    padding-bottom: 48px;
  }

  .app {
    width: min(100%, 1040px);
    grid-template-columns: minmax(0, 1.08fr) minmax(330px, 0.92fr);
    grid-template-areas:
      "header header"
      "beats tempo"
      "tabs tabs"
      "modepanel modepanel"
      "panel panel"
      "readout readout";
    gap: 20px;
    padding: 30px 28px 48px;
    align-content: center;
  }

  .beats {
    min-height: 220px;
    padding: 26px;
  }

}

@media (min-width: 1100px) {
  .app {
    width: min(100%, 1180px);
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.82fr);
    grid-template-areas:
      "header header"
      "beats tempo"
      "tabs tabs"
      "modepanel modepanel"
      "panel panel"
      "readout readout";
    align-content: start;
  }

  .beats,
  .tempo {
    min-height: 290px;
  }

}

@media (max-width: 380px) {
  .app {
    gap: 12px;
    padding: 14px 12px 28px;
  }

  .beats {
    min-height: 156px;
    padding: 16px;
  }

  .beats {
    gap: 18px;
  }

  .beat-display {
    padding: 10px;
  }
}

.tempo {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
}

.tempo-range {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

.bpm-display {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  min-height: clamp(116px, 24vw, 176px);
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 0;
}

.bpm-display.tempo-changed {
  animation: tempo-change-pulse 240ms ease-out;
}

@keyframes tempo-change-pulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.025); }
  100% { transform: scale(1); }
}

.bpm-value {
  display: block;
  width: 100%;
  min-width: 0;
  font-size: clamp(3.25rem, 13vw, 8rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.065em;
  text-align: center;
}

.bpm-unit {
  display: block;
  flex: 0 0 auto;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1.2;
}

@media (prefers-reduced-motion: reduce) {
  .bpm-display.tempo-changed {
    animation-duration: 1ms;
  }
}

.tempo-context {
  max-width: 28rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

.stepper-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.tempo,
.bpm-display,
.stepper-row {
  min-width: 0;
}

.btn-step {
  min-height: var(--touch);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-raised);
  font-size: 1.02rem;
  font-weight: 750;
  line-height: 1.2;
  transition: transform 80ms ease, background-color 80ms ease;
}

.btn-step:active {
  transform: scale(0.96);
  background: var(--border);
}

.slider {
  appearance: none;
  width: 100%;
  height: 44px;
  margin: 0;
  border-radius: 999px;
  background: transparent;
  outline: none;
  touch-action: pan-x;
}

.slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill, 30%), var(--border) var(--fill, 30%));
}

.slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill, 30%), var(--border) var(--fill, 30%));
}

.slider::-webkit-slider-thumb {
  appearance: none;
  width: 30px;
  height: 30px;
  margin-top: -11px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: grab;
}

.slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
  cursor: grab;
}

.slider::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  background: var(--border);
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

.keyboard-hint {
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.6;
  text-align: center;
}

@media (hover: none) and (pointer: coarse) {
  .keyboard-hint {
    display: none;
  }
}

.btn-play {
  display: flex;
  width: 100%;
  min-height: 66px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.015em;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 20%, transparent);
  transition: transform 80ms ease, background-color 120ms ease;
}

.btn-play:active {
  transform: scale(0.985);
}

.btn-play.running {
  background: var(--danger);
  color: #fff;
}

.play-icon,
.pause-icon {
  width: 21px;
  height: 21px;
}

.pause-icon {
  display: none;
}

.btn-play.running .play-icon {
  display: none;
}

.btn-play.running .pause-icon {
  display: block;
}

.status-line {
  min-height: 1.4em;
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.5;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.btn-tap {
  display: flex;
  width: 100%;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.3;
  transition: background-color 80ms ease, transform 80ms ease;
}

.btn-tap svg {
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  color: var(--accent-strong);
}

.btn-tap span {
  min-width: 0;
  max-width: 100%;
  text-align: center;
}

.btn-tap:active,
.btn-tap.flash {
  transform: scale(0.99);
  background: var(--surface-raised);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.tab {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.3;
  transition: background-color 120ms ease, color 120ms ease;
}

@media (max-width: 460px) {
  .tab {
    min-height: 52px;
    gap: 4px;
    padding: 4px 2px;
    font-size: 0.78rem;
  }

  .tab .icon {
    width: 16px;
    height: 16px;
  }
}

.tab.active {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}

@media (min-width: 760px) {
  .tempo {
    min-height: 100%;
    justify-content: center;
    padding: 28px;
  }

  .bpm-display {
    min-height: 160px;
  }
}

@media (min-width: 1100px) {
  .tempo {
    min-height: 340px;
  }
}

.panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
}

.settings-heading {
  align-items: flex-start;
}

.settings-heading > div {
  min-width: 0;
}

.settings-hint,
.wake-lock-status {
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.5;
}

.settings-hint {
  max-width: 48%;
  overflow-wrap: anywhere;
  color: var(--accent-strong);
  text-align: right;
}

.setting-grid {
  display: grid;
  gap: 22px;
}

.setting-group {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-raised);
}

.setting-group h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  line-height: 1.45;
  text-transform: uppercase;
}

.setting-group h3 .icon {
  width: 16px;
  height: 16px;
}

.field-row {
  display: flex;
  min-height: var(--touch);
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.field-row:last-child {
  border-bottom: 0;
}

.field-row label {
  min-width: 0;
  flex: 1 1 auto;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
  overflow-wrap: normal;
}

.field-row .icon-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.field-row .icon-label .icon {
  width: 15px;
  height: 15px;
}

.field-row select,
.field-row input[type="number"] {
  width: min(48%, 160px);
  min-width: 90px;
  flex: 0 1 160px;
  min-height: 48px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: center;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  appearance: none;
}

.field-row select {
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a0a5b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 9px center;
  background-repeat: no-repeat;
}

.field-row input[type="range"] {
  width: min(100%, 200px);
  min-height: 44px;
  accent-color: var(--accent);
  touch-action: pan-x;
}

.range-control {
  display: flex;
  min-width: 0;
  width: min(58%, 250px);
  flex: 0 1 250px;
  align-items: center;
  gap: 10px;
}

.range-control output {
  min-width: 3.2em;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  text-align: right;
}

.field-row input[type="number"] {
  -moz-appearance: textfield;
}

.field-row input[type="number"]::-webkit-outer-spin-button,
.field-row input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.field-row input[type="checkbox"] {
  position: relative;
  width: 60px;
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  appearance: none;
  transition: background-color 150ms ease;
}

.field-row input[type="checkbox"]::before {
  position: absolute;
  top: 6px;
  left: 4px;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  background: var(--border);
  content: "";
  transition: background-color 150ms ease;
}

.field-row input[type="checkbox"]::after {
  position: absolute;
  top: 9px;
  left: 7px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  content: "";
  transition: transform 150ms ease;
}

.field-row input[type="checkbox"]:checked {
  background: transparent;
}

.field-row input[type="checkbox"]:checked::before {
  background: var(--accent);
}

.field-row input[type="checkbox"]:checked::after {
  transform: translateX(20px);
}

.speedloop-only {
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.speedloop-inputs {
  display: grid;
  min-width: 0;
  gap: 0 16px;
}

.speedloop-settings-group {
  min-width: 0;
}

.endurance-only {
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.endurance-settings-group {
  min-width: 0;
}

.endurance-progress {
  display: grid;
  gap: 14px;
  color: var(--text-dim);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  text-align: center;
}

.endurance-progress.is-entering {
  animation: endurance-enter 320ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.endurance-progress.is-exiting {
  animation: endurance-exit 180ms ease-in both;
}

@keyframes endurance-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes endurance-exit {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(4px) scale(0.99);
  }
}

.endurance-stage {
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.4;
}

.endurance-command {
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--beat-on) 42%, var(--border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--beat-on) 14%, var(--surface));
  color: var(--beat-on);
  font-size: clamp(1.6rem, 7vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-align: center;
  text-shadow: 0 0 18px color-mix(in srgb, var(--beat-on) 24%, transparent);
}

.endurance-progress[data-phase="rest"] .endurance-command {
  border-color: color-mix(in srgb, var(--danger) 48%, var(--border));
  background: color-mix(in srgb, var(--danger) 16%, var(--surface));
  color: var(--danger);
  text-shadow: 0 0 18px color-mix(in srgb, var(--danger) 26%, transparent);
}

.endurance-timer {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding-block: 2px;
}

.endurance-timer-label {
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  line-height: 1.3;
}

.endurance-countdown {
  color: var(--beat-on);
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.endurance-progress[data-phase="rest"] .endurance-countdown {
  color: var(--danger);
}

.progress-elapsed {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .endurance-progress.is-entering,
  .endurance-progress.is-exiting {
    animation-duration: 1ms;
  }
}

.history-panel {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.history-panel summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 700;
}

.history-panel summary::-webkit-details-marker {
  display: none;
}

.history-panel summary::after {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin-left: auto;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  content: "";
  transform: rotate(45deg) translateY(-2px);
  transition: transform 150ms ease;
}

.history-panel[open] summary::after {
  transform: rotate(225deg) translateY(-2px);
}

.history-content {
  display: grid;
  gap: 12px;
  padding-top: 14px;
}

.history-empty,
.history-list li span {
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.6;
}

.history-list {
  display: grid;
  gap: 10px;
  list-style: none;
}

.history-list li {
  display: grid;
  min-width: 0;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-raised);
}

.history-list li strong {
  font-size: 0.84rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.history-clear {
  display: inline-flex;
  justify-self: start;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.4;
}

.loop-hint {
  padding-top: 4px;
  color: var(--text-dim);
  font-size: 0.82rem;
  line-height: 1.6;
}

.loop-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
}

.loop-progress.is-entering {
  animation: loop-enter 320ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.loop-progress.is-exiting {
  animation: loop-exit 180ms ease-in both;
}

@keyframes loop-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes loop-exit {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: translateY(4px) scale(0.99);
  }
}

.loop-progress-heading {
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-align: center;
}

.progress-track {
  width: 100%;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(to right, var(--accent), var(--accent-strong));
  transition: width 250ms linear;
}

.progress-text {
  color: var(--accent-strong);
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.progress-elapsed {
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.45;
}

@media (prefers-reduced-motion: reduce) {
  .loop-progress.is-entering,
  .loop-progress.is-exiting {
    animation-duration: 1ms;
  }
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

@media (min-width: 800px) {
  .panel {
    padding: 24px;
  }

  .setting-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 620px) {
  .speedloop-inputs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 460px) {
  .panel {
    gap: 16px;
    padding: 16px;
  }

  .setting-grid {
    gap: 12px;
  }

  .setting-group {
    padding: 12px;
  }

  .setting-group h3 {
    margin-bottom: 8px;
  }

  .field-row {
    gap: 10px;
    padding: 5px 0;
  }

  .field-row .icon-label {
    gap: 6px;
  }

  .volume-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 8px 0;
  }

  .volume-row > label {
    flex: initial;
  }

  .volume-row .range-control {
    width: 100%;
    max-width: none;
    flex: initial;
    gap: 12px;
  }

  .volume-row input[type="range"] {
    max-width: none;
  }

  .speedloop-inputs .field-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(90px, 36%);
    gap: 10px;
  }

  .speedloop-inputs .field-row label {
    flex: initial;
  }
}

@media (hover: hover) {
  .btn-step:not(:disabled):hover,
  .tab:not(:disabled):hover {
    filter: brightness(1.08);
  }

  .btn-tap:not(:disabled):hover {
    border-color: var(--accent);
  }
}

.readout {
  min-height: 1.5em;
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.6;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.readout.alert {
  color: var(--danger);
  animation: blink 0.5s steps(2, start) infinite;
}

@keyframes blink {
  to { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
