/* ==========================================================================
   Tempo — iOS-inspired design system
   System typography, grouped surfaces, hairline separators, no web fonts.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Surfaces (iOS grouped background hierarchy).
     Cards and inset surfaces are translucent frosted glass: over the plain
     page they resolve to the original solid colours, and let a little of the
     disco light behind them show through. */
  --bg: #f2f2f7;
  --panel: rgba(255, 255, 255, 0.76);
  --paper: rgba(237, 237, 244, 0.72);   /* inset surface inside cards */
  --glass-blur: saturate(180%) blur(24px);
  --paper-light: #fff;
  --paper-deep: #e5e5ea;
  --seg-selected: #fff;
  --switch-off: #e9e9eb;
  --topbar-bg: rgba(242, 242, 247, 0.78);

  /* Labels */
  --ink: #1c1c1e;
  --ink-soft: #3a3a3c;
  --muted: #8e8e93;
  --tertiary: #c7c7cc;

  /* Fills & separators */
  --fill: rgba(118, 118, 128, 0.12);
  --fill-strong: rgba(118, 118, 128, 0.2);
  --track-off: rgba(120, 120, 128, 0.2);
  --line: rgba(60, 60, 67, 0.12);
  --line-strong: rgba(60, 60, 67, 0.26);

  /* System tints */
  --accent: #007aff;
  --accent-dark: #0066d6;
  --accent-tint: rgba(0, 122, 255, 0.1);
  --accent-tint-strong: rgba(0, 122, 255, 0.17);
  --indigo: #5856d6;
  --green: #34c759;
  --red: #ff3b30;
  --red-tint: rgba(255, 59, 48, 0.1);
  --red-tint-strong: rgba(255, 59, 48, 0.17);
  --orange: #ff9500;

  /* Depth */
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 8px 28px rgba(0, 0, 0, 0.045);
  --thumb-shadow: 0 0.5px 4px rgba(0, 0, 0, 0.12), 0 6px 13px rgba(0, 0, 0, 0.12);
  --seg-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);

  /* Type */
  --ui-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --display-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --condensed-font: var(--ui-font);

  /* Motion */
  --ease-out: cubic-bezier(0.25, 0.8, 0.25, 1);
  --ease-spring: cubic-bezier(0.3, 1.3, 0.5, 1);
}

body[data-theme="dark"] {
  color-scheme: dark;

  --bg: #000;
  --panel: rgba(37, 37, 40, 0.76);      /* ≈ #1c1c1e over black */
  --paper: rgba(50, 50, 53, 0.72);      /* ≈ #2c2c2e over the card */
  --paper-light: #1c1c1e;
  --paper-deep: #3a3a3c;
  --seg-selected: #636366;
  --switch-off: #39393d;
  --topbar-bg: rgba(0, 0, 0, 0.72);

  --ink: #f5f5f7;
  --ink-soft: #d1d1d6;
  --muted: #98989f;
  --tertiary: #48484a;

  --fill: rgba(118, 118, 128, 0.24);
  --fill-strong: rgba(118, 118, 128, 0.32);
  --track-off: rgba(120, 120, 128, 0.36);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);

  --accent: #0a84ff;
  --accent-dark: #409cff;
  --accent-tint: rgba(10, 132, 255, 0.16);
  --accent-tint-strong: rgba(10, 132, 255, 0.26);
  --indigo: #5e5ce6;
  --green: #30d158;
  --red: #ff453a;
  --red-tint: rgba(255, 69, 58, 0.16);
  --red-tint-strong: rgba(255, 69, 58, 0.26);
  --orange: #ff9f0a;

  --card-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.06);
  --seg-shadow: 0 3px 8px rgba(0, 0, 0, 0.24);
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 15px;
  line-height: 1.47;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 300ms ease, color 300ms ease;
}

button,
input,
select {
  font: inherit;
  letter-spacing: inherit;
}

button {
  color: inherit;
  cursor: pointer;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms var(--ease-out);
}

button:disabled {
  cursor: default;
  opacity: 0.4;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button,
a,
label,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

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

h2 {
  margin: 0;
  font-family: var(--display-font);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

/* English kickers duplicate the Chinese titles; iOS keeps headers single-line. */
.eyebrow {
  display: none;
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--fill);
  color: var(--ink-soft);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

/* Native controls pick up the system tint. */
input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="checkbox"]:not([role="switch"]) {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

input:disabled,
select:disabled {
  cursor: default;
  opacity: 0.45;
}

/* Filled text fields and pop-up buttons */
.sound-tone-control select,
.acceleration-fields input,
.acceleration-fields select,
.song-start-controls input,
.song-start-controls select,
.score-tracking-actions select {
  min-width: 0;
  min-height: 38px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background-color: var(--fill);
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  transition: box-shadow 160ms ease, background-color 160ms ease;
}

.sound-tone-control select,
.acceleration-fields select,
.song-start-controls select,
.score-tracking-actions select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%238e8e93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 4.5 6 2l2.5 2.5M3.5 7.5 6 10l2.5-2.5'/%3E%3C/svg%3E");
  background-position: right 11px center;
  background-repeat: no-repeat;
  background-size: 12px;
  cursor: pointer;
}

.sound-tone-control select:focus-visible,
.acceleration-fields input:focus-visible,
.acceleration-fields select:focus-visible,
.song-start-controls input:focus-visible,
.song-start-controls select:focus-visible,
.score-tracking-actions select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-tint-strong), inset 0 0 0 1px var(--accent);
}

/* --------------------------------------------------------------------------
   Shell & navigation bar
   -------------------------------------------------------------------------- */

.app-shell {
  width: min(1280px, 100%);
  margin: auto;
  padding: 0 40px 40px;
}

.topbar,
.brand,
.topbar-actions,
.status-pill,
.theme-toggle {
  display: flex;
  align-items: center;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  justify-content: space-between;
  gap: 16px;
  margin: 0 -40px 20px;
  padding: 20px 40px 14px;
  background: var(--topbar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

/* Hairline fades in once content scrolls beneath the bar (progressive). */
@supports (animation-timeline: scroll()) {
  .topbar {
    animation: topbar-edge linear both;
    animation-timeline: scroll(root);
    animation-range: 0 40px;
  }

  @keyframes topbar-edge {
    from {
      box-shadow: 0 0.5px 0 transparent;
    }
    to {
      box-shadow: 0 0.5px 0 var(--line-strong);
    }
  }
}

.brand {
  gap: 12px;
  color: inherit;
  text-decoration: none;
  border-radius: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(180deg, #48484a 0%, #1c1c1e 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14), inset 0 0.5px 0 rgba(255, 255, 255, 0.18);
  color: #fff;
}

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

.brand-mark-weight {
  fill: var(--orange);
  stroke: none;
}

body[data-theme="dark"] .brand-mark {
  background: linear-gradient(180deg, #3a3a3c 0%, #1c1c1e 100%);
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.14);
}

.brand-copy {
  display: grid;
  gap: 0;
}

.brand-kicker {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.brand-title {
  white-space: nowrap;
  font-family: var(--display-font);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.topbar-actions {
  min-width: 0;
  gap: 10px;
}

.theme-toggle {
  flex-shrink: 0;
}

.status-pill {
  min-width: 0;
}

#statusText {
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-toggle {
  gap: 6px;
  min-height: 34px;
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.theme-toggle-icon {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
}

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

.theme-icon-sun,
body[data-theme="dark"] .theme-icon-moon {
  display: none;
}

body[data-theme="dark"] .theme-icon-sun {
  display: block;
  color: var(--orange);
}

.theme-icon-moon {
  color: var(--indigo);
}

/* --------------------------------------------------------------------------
   Disco mode: neon light layer flashing on each beat (driven by app.js).
   Background only: z-index -1 paints it right above the page background and
   beneath every card and control, so it shows through the gaps between them.
   -------------------------------------------------------------------------- */

.disco-toggle .theme-toggle-icon {
  color: #ff2bd6;
}

.theme-toggle.disco-toggle[aria-pressed="true"] {
  background: linear-gradient(120deg, #ff2bd6 0%, #9d4dff 50%, #00e5ff 100%);
  box-shadow: 0 0 16px -2px var(--disco-color, #ff2bd6);
  color: #fff;
}

.theme-toggle.disco-toggle[aria-pressed="true"] .theme-toggle-icon {
  color: #fff;
}

.disco-overlay {
  position: fixed;
  inset: 0;
  z-index: -1;
  display: none;
  opacity: 0;
  pointer-events: none;
  /* Near-white hot spots over a full-screen two-colour neon wash. */
  background:
    radial-gradient(ellipse 45% 40% at 8% 10%, color-mix(in srgb, var(--disco-color, #ff00d4) 45%, #fff), transparent 70%),
    radial-gradient(ellipse 45% 40% at 92% 90%, color-mix(in srgb, var(--disco-color-2, #00f0ff) 45%, #fff), transparent 70%),
    radial-gradient(ellipse 40% 35% at 85% 5%, color-mix(in srgb, var(--disco-color-2, #00f0ff) 60%, #fff), transparent 70%),
    radial-gradient(ellipse 40% 35% at 12% 95%, color-mix(in srgb, var(--disco-color, #ff00d4) 60%, #fff), transparent 70%),
    linear-gradient(135deg, var(--disco-color, #ff00d4) 0%, var(--disco-color-2, #00f0ff) 100%);
  will-change: opacity;
}

/* OKLCH interpolation keeps the wash saturated instead of passing through
   muddy grey between complementary neons (older browsers use the rule above). */
@supports (background: linear-gradient(in oklch, red, blue)) {
  .disco-overlay {
    background:
      radial-gradient(ellipse 45% 40% at 8% 10%, color-mix(in srgb, var(--disco-color, #ff00d4) 45%, #fff), transparent 70%),
      radial-gradient(ellipse 45% 40% at 92% 90%, color-mix(in srgb, var(--disco-color-2, #00f0ff) 45%, #fff), transparent 70%),
      radial-gradient(ellipse 40% 35% at 85% 5%, color-mix(in srgb, var(--disco-color-2, #00f0ff) 60%, #fff), transparent 70%),
      radial-gradient(ellipse 40% 35% at 12% 95%, color-mix(in srgb, var(--disco-color, #ff00d4) 60%, #fff), transparent 70%),
      linear-gradient(in oklch 135deg, var(--disco-color, #ff00d4) 0%, var(--disco-color-2, #00f0ff) 100%);
  }
}

body.is-disco .disco-overlay {
  display: block;
}

/* Let more of the light through the sticky top bar (blur keeps it legible). */
body.is-disco {
  --topbar-bg: rgba(242, 242, 247, 0.32);
}

body.is-disco[data-theme="dark"] {
  --topbar-bg: rgba(0, 0, 0, 0.3);
}

body.is-disco .beat-dot.is-active::before {
  --beat-color: var(--disco-color, #ff2bd6);
  box-shadow: 0 0 16px var(--disco-color, #ff2bd6);
}

.status-pill {
  gap: 8px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.status-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tertiary);
  transition: background-color 200ms ease;
}

.is-playing .status-pill {
  color: var(--ink);
}

.is-playing .status-dot {
  background: var(--green);
  animation: status-pulse 1.6s ease-out infinite;
}

@keyframes status-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.55);
  }
  100% {
    box-shadow: 0 0 0 7px rgba(52, 199, 89, 0);
  }
}

/* --------------------------------------------------------------------------
   Practice card (score workspace)
   -------------------------------------------------------------------------- */

.tempo-stage {
  padding: 32px 40px 40px;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
}

/* Frosted glass on every feature card and the floating tempo dock. */
.tempo-stage,
.panel,
.tempo-dock {
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}

/* --------------------------------------------------------------------------
   Floating tempo dock: tempo display + primary controls.
   Expanded shows every control; collapsed keeps only BPM and start/stop.
   -------------------------------------------------------------------------- */

body {
  /* Leave room so the collapsed dock never hides the end of the page. */
  padding-bottom: 88px;
}

.tempo-dock {
  --dock-gap: 24px;
  position: fixed;
  right: var(--dock-gap);
  bottom: var(--dock-gap);
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: min(1000px, calc(100vw - 2 * var(--dock-gap)));
  max-height: calc(100vh - 96px);
  max-height: calc(100dvh - 96px);
  border-radius: 28px;
  background: var(--panel);
  box-shadow:
    0 0 0 0.5px var(--line-strong),
    0 12px 32px rgba(0, 0, 0, 0.14),
    0 32px 72px -24px rgba(0, 0, 0, 0.28);
  animation: dock-in 240ms var(--ease-out);
}

@keyframes dock-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

.tempo-dock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 0 28px;
}

.tempo-dock-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tempo-dock-toggle {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  color: var(--ink-soft);
}

.tempo-dock-toggle svg {
  width: 18px;
  height: 18px;
  transition: transform 240ms var(--ease-out);
}

.tempo-dock-body {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 28px 40px;
  min-height: 0;
  padding: 4px 28px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Collapsed: a compact pill with the playback BPM and start/stop. */
.tempo-dock.is-collapsed {
  flex-direction: row;
  align-items: center;
  width: auto;
  max-width: calc(100vw - 2 * var(--dock-gap));
  padding: 8px;
  border-radius: 999px;
}

.tempo-dock.is-collapsed .tempo-dock-bar {
  order: 2;
  padding: 0 0 0 8px;
}

.tempo-dock.is-collapsed .tempo-dock-title {
  display: none;
}

.tempo-dock.is-collapsed .tempo-dock-toggle svg {
  transform: rotate(180deg);
}

.tempo-dock.is-collapsed .tempo-dock-body {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 0 0 16px;
  overflow: visible;
}

.tempo-dock.is-collapsed .tempo-visual,
.tempo-dock.is-collapsed .tempo-controls {
  display: contents;
}

.tempo-dock.is-collapsed .tempo-visual > :not(.tempo-metrics, .tempo-visual-heading),
.tempo-dock.is-collapsed .tempo-metric:not(.tempo-metric--primary),
.tempo-dock.is-collapsed .tempo-metric--primary > span,
.tempo-dock.is-collapsed .tempo-controls > :not(.transport-button, .bpm-stepper),
.tempo-dock.is-collapsed .stepper-copy > label {
  display: none;
}

/* Stopped: the collapsed BPM is the editable stepper (−, input, +).
   Playing: it switches to the read-only playback BPM. */
body:not(.is-playing) .tempo-dock.is-collapsed .tempo-metric--primary,
body.is-playing .tempo-dock.is-collapsed .bpm-stepper {
  display: none;
}

.tempo-dock.is-collapsed .bpm-stepper {
  order: 0;
  grid-template-columns: 32px auto 32px;
  gap: 4px;
  margin: 0;
}

.tempo-dock.is-collapsed .step-button {
  width: 32px;
  height: 32px;
  font-size: 20px;
}

.tempo-dock.is-collapsed .stepper-input-shell {
  gap: 4px;
}

.tempo-dock.is-collapsed .bpm-number-input {
  width: 3.2ch;
  font-size: 34px;
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.tempo-dock.is-collapsed .stepper-input-shell > span {
  font-size: 11px;
}

.tempo-dock.is-collapsed .tempo-metric--primary {
  order: 0;
  padding: 0;
}

.tempo-dock.is-collapsed .tempo-metric--primary strong {
  font-size: 34px;
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1;
}

.tempo-dock.is-collapsed .tempo-metric--primary small {
  margin-left: 5px;
  font-size: 11px;
}

.tempo-dock.is-collapsed .transport-button {
  order: 1;
  flex-shrink: 0;
  min-height: 44px;
  margin: 0;
  padding: 0 20px;
  border-radius: 999px;
  font-size: 15px;
}

/* Left column is a 4-column grid; the metrics wrapper dissolves into it so
   the big number, beat capsules and metric row can be ordered freely. */
.tempo-visual {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-content: center;
}

.tempo-visual-heading {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.tempo-visual-heading h1 {
  margin: 0;
}

.tempo-metrics {
  display: contents;
}

.tempo-metric {
  order: 3;
  min-width: 0;
  display: grid;
  gap: 3px;
  align-content: start;
  justify-items: center;
  padding: 2px 8px;
  text-align: center;
}

.tempo-metric--primary ~ .tempo-metric {
  border-left: 1px solid var(--line);
}

.tempo-metric > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.tempo-metric strong {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.tempo-metric:nth-child(3) strong {
  font-size: 13px;
}

.tempo-metric small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tempo-metric--primary {
  order: 1;
  grid-column: 1 / -1;
  gap: 0;
  padding: 4px 0 20px;
}

.tempo-metric--primary > span {
  font-size: 13px;
  letter-spacing: 0.02em;
}

.tempo-metric--primary strong {
  display: flex;
  align-items: baseline;
  justify-content: center;
  font-family: var(--display-font);
  font-size: clamp(88px, 9vw, 116px);
  font-weight: 200;
  line-height: 1.02;
  letter-spacing: -0.045em;
}

.tempo-metric--primary small {
  margin-left: 10px;
  font-family: var(--ui-font);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* Beat capsules — height encodes accent level, colour lights on the beat.
   Each capsule is also a button: click cycles 强 → 次强 → 弱 (app.js).
   Activation is instant (duration 0 on the target state) and the release
   fades, which reads as a soft afterglow without delaying the beat. */
.beat-strip {
  order: 2;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(var(--beat-count, 4), minmax(0, 1fr));
  align-items: start;
  gap: 8px;
  width: min(100%, calc(var(--beat-count, 4) * 64px));
  margin: 0 auto 28px;
  contain: layout; /* not paint: that would clip the active beat's glow */
}

.beat-dot {
  --beat-color: var(--accent);
  --bar-height: 14px;
  display: grid;
  grid-template-rows: 24px auto;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 0 0 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.beat-dot::before {
  height: var(--bar-height);
  border-radius: 999px;
  background: var(--fill-strong);
  content: "";
  transition:
    background-color 320ms ease,
    box-shadow 320ms ease,
    height 200ms var(--ease-out),
    transform 320ms var(--ease-out);
}

.beat-dot[data-level="heavy"] {
  color: var(--ink-soft);
  font-weight: 600;
}

.beat-dot[data-level="secondary"] {
  --beat-color: var(--indigo);
  --bar-height: 10px;
}

.beat-dot[data-level="light"] {
  --beat-color: var(--ink-soft);
  --bar-height: 6px;
}

.beat-dot:active:not(:disabled) {
  transform: none;
}

.beat-dot.is-active::before {
  background: var(--beat-color);
  box-shadow: 0 0 14px color-mix(in srgb, var(--beat-color) 50%, transparent);
  transform: scaleY(1.3);
  transition-duration: 0s;
}

.beat-dot[data-level="light"].is-active::before {
  box-shadow: none;
}

@media (hover: hover) {
  .beat-dot:hover {
    color: var(--ink);
  }

  .beat-dot:not(.is-active):hover::before {
    background: var(--line-strong);
  }
}

/* Right column */
.tempo-controls {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 14px;
  align-content: center;
}

.tempo-shift-control,
.time-signature-control {
  min-width: 0;
  border-radius: 20px;
  background: var(--paper);
}

.tempo-shift-control {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 18px;
}

.tempo-shift-heading {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.tempo-shift-heading strong {
  font-size: 15px;
  font-weight: 600;
}

.tempo-shift-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
}

.tempo-shift-actions output {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.restore-tempo-button {
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
}

.restore-tempo-button:disabled {
  opacity: 0;
  pointer-events: none;
}

.tempo-shift-labels,
.range-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.tempo-shift-labels {
  position: relative;
  height: 16px;
  margin-top: 2px;
}

.tempo-shift-labels span {
  position: absolute;
  transform: translateX(-50%);
}

.tempo-shift-labels span:nth-child(1) {
  left: 0;
  transform: none;
}

.tempo-shift-labels span:nth-child(2) {
  left: 20%;
  color: var(--ink-soft);
  font-weight: 500;
}

.tempo-shift-labels span:nth-child(3) {
  left: 60%;
}

.tempo-shift-labels span:nth-child(4) {
  right: 0;
  transform: none;
}

.tempo-shift-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* Narrow slider (e.g. inside the floating dock): keep the end labels apart. */
@container (max-width: 250px) {
  .tempo-shift-labels {
    font-size: 10px;
  }

  .tempo-shift-labels span:nth-child(3) {
    display: none;
  }
}

/* iOS sliders (the app keeps --range-progress / --shift-* / --sound-progress
   in sync, so the filled part of the track follows the value). */
.tempo-range,
.tempo-shift-range,
.sound-slider {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  height: 30px;
  background: transparent;
}

.tempo-range {
  --track: linear-gradient(to right, var(--accent) 0 var(--range-progress, 31%), var(--track-off) 0);
}

.sound-slider {
  --track: linear-gradient(to right, var(--accent) 0 var(--sound-progress, 43%), var(--track-off) 0);
}

.tempo-shift-range {
  --track: linear-gradient(
    to right,
    var(--track-off) 0 var(--shift-start, 20%),
    var(--accent) 0 var(--shift-end, 20%),
    var(--track-off) 0
  );
}

.tempo-range::-webkit-slider-runnable-track,
.tempo-shift-range::-webkit-slider-runnable-track,
.sound-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--track);
}

.tempo-range::-moz-range-track,
.tempo-shift-range::-moz-range-track,
.sound-slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--track);
}

.tempo-range::-webkit-slider-thumb,
.tempo-shift-range::-webkit-slider-thumb,
.sound-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -11px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--thumb-shadow);
  transition: transform 180ms var(--ease-out), box-shadow 180ms ease;
}

.tempo-range::-moz-range-thumb,
.tempo-shift-range::-moz-range-thumb,
.sound-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--thumb-shadow);
}

.tempo-range:active::-webkit-slider-thumb,
.tempo-shift-range:active::-webkit-slider-thumb,
.sound-slider:active::-webkit-slider-thumb {
  transform: scale(1.1);
}

.tempo-range:focus-visible,
.tempo-shift-range:focus-visible,
.sound-slider:focus-visible {
  outline: none;
}

.tempo-range:focus-visible::-webkit-slider-thumb,
.tempo-shift-range:focus-visible::-webkit-slider-thumb,
.sound-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: var(--thumb-shadow), 0 0 0 4px var(--accent-tint-strong);
}

.tempo-range:focus-visible::-moz-range-thumb,
.tempo-shift-range:focus-visible::-moz-range-thumb,
.sound-slider:focus-visible::-moz-range-thumb {
  box-shadow: var(--thumb-shadow), 0 0 0 4px var(--accent-tint-strong);
}

/* Wheel-style meter picker (option height 40px / offset 56px are shared
   with app.js — keep them in sync). */
.time-signature-control {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 216px;
  align-content: center;
  justify-items: center;
  padding: 30px 12px 34px;
  overflow: hidden;
}

.time-signature-control > .eyebrow {
  display: block;
  position: absolute;
  top: 16px;
  left: 18px;
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.time-signature-picker {
  position: relative;
  display: grid;
  width: min(100%, 260px);
  height: 152px;
  grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr);
  align-items: center;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  isolation: isolate;
}

.time-signature-picker::before {
  position: absolute;
  top: 56px;
  right: 0;
  left: 0;
  z-index: -1;
  height: 40px;
  border-radius: 10px;
  background: var(--fill);
  content: "";
}

body[data-theme="dark"] .time-signature-picker::before {
  background: rgba(118, 118, 128, 0.28);
}

.signature-wheel {
  position: relative;
  height: 152px;
  overflow: hidden;
  outline: none;
  cursor: ns-resize;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0,
    rgba(0, 0, 0, 0.5) 22%,
    #000 38%,
    #000 62%,
    rgba(0, 0, 0, 0.5) 78%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    rgba(0, 0, 0, 0.5) 22%,
    #000 38%,
    #000 62%,
    rgba(0, 0, 0, 0.5) 78%,
    transparent 100%
  );
}

.signature-wheel:focus-visible::after {
  position: absolute;
  inset: 56px 2px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  content: "";
  pointer-events: none;
}

.signature-wheel-list {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  transform: translateY(var(--wheel-offset, -104px));
  transition: transform 260ms var(--ease-out);
}

.signature-wheel-option {
  display: grid;
  width: 100%;
  height: 40px;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--display-font);
  font-size: 20px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  opacity: 0.55;
  cursor: pointer;
  transition: color 200ms ease, opacity 200ms ease, font-size 200ms ease;
}

.signature-wheel-option:active:not(:disabled) {
  transform: none;
}

.signature-wheel-option.is-selected {
  color: var(--ink);
  font-size: 24px;
  font-weight: 600;
  opacity: 1;
}

.signature-slash {
  z-index: 2;
  color: var(--muted);
  font-family: var(--display-font);
  font-size: 24px;
  font-weight: 300;
  text-align: center;
}

.time-signature-control > p:last-child {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
  text-wrap: balance;
}

/* BPM stepper */
.bpm-stepper {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  margin-top: 6px;
}

.step-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
}

.stepper-copy {
  text-align: center;
}

.stepper-copy > label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.stepper-input-shell {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
}

.bpm-number-input {
  width: 3.4ch;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-family: var(--display-font);
  font-size: 38px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.15;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
  transition: background-color 160ms ease;
}

.bpm-number-input:focus-visible {
  outline: none;
  background: var(--fill);
}

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

.stepper-input-shell > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.range-wrap {
  grid-column: 1 / -1;
}

.range-labels {
  padding: 0 4px;
}

/* Primary action */
.transport-button {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
  margin-top: 4px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  box-shadow: 0 10px 24px -12px var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.transport-icon {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid currentColor;
  border-radius: 2px;
}

.is-playing .transport-button {
  background: var(--red-tint);
  box-shadow: none;
  color: var(--red);
}

.is-playing .transport-icon {
  width: 12px;
  height: 14px;
  border: 0;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
  border-radius: 1px;
}

.count-in-control {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px 14px 18px;
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}

.count-in-copy {
  display: grid;
  gap: 1px;
}

.count-in-copy strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.count-in-copy small {
  color: var(--muted);
  font-size: 12px;
}

.count-in-control .acceleration-switch {
  flex-shrink: 0;
}

.count-in-control:has(input:disabled) {
  opacity: 0.55;
  cursor: default;
}

.count-in-control input:disabled {
  cursor: default;
}

.shortcut-hint {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (hover: none) {
  .shortcut-hint {
    display: none;
  }
}

/* iOS switch */
.acceleration-switch {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.acceleration-switch input {
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  width: 51px;
  height: 31px;
  border-radius: 999px;
  background: var(--switch-off);
  pointer-events: none;
  transition: background-color 240ms ease;
}

.switch-track::after {
  display: block;
  width: 27px;
  height: 27px;
  margin: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  content: "";
  transition: transform 260ms var(--ease-spring);
}

.acceleration-switch input:checked + .switch-track {
  background: var(--green);
}

.acceleration-switch input:checked + .switch-track::after {
  transform: translateX(20px);
}

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

/* --------------------------------------------------------------------------
   Buttons shared by secondary actions
   -------------------------------------------------------------------------- */

.image-action-button,
.image-mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, transform 180ms var(--ease-out);
}

.text-button {
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
}

@media (hover: hover) {
  .image-action-button:hover:not(:disabled),
  .step-button:hover {
    background: var(--accent-tint-strong);
  }

  .transport-button:hover:not(:disabled) {
    background: var(--accent-dark);
  }

  .is-playing .transport-button:hover:not(:disabled) {
    background: var(--red-tint-strong);
  }

  .theme-toggle:hover,
  .tempo-dock-toggle:hover,
  .bpm-number-input:hover {
    background: var(--fill-strong);
  }

  .text-button:hover,
  .restore-tempo-button:hover {
    opacity: 0.7;
  }

  .history-chip:hover {
    background: var(--accent-tint);
  }

  .signature-wheel-option:hover {
    color: var(--ink);
    opacity: 0.8;
  }
}

/* --------------------------------------------------------------------------
   Practice score workspace
   -------------------------------------------------------------------------- */

.phrase-workspace {
  min-width: 0;
}

.phrase-workspace-heading,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.phrase-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.phrase-actions:has(#phraseImageInput:focus-visible) label[for="phraseImageInput"],
.phrase-actions:has(#phrasePdfInput:focus-visible) label[for="phrasePdfInput"] {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.section-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.phrase-image-stage {
  position: relative;
  min-height: 240px;
  overflow: hidden;
  border: 1.5px dashed var(--line-strong);
  border-radius: 20px;
  background: var(--paper);
  touch-action: pan-y;
  transition: border-color 200ms ease, background-color 200ms ease;
}

.phrase-image-stage:has(.phrase-image:not([hidden])) {
  touch-action: none;
  min-height: 440px;
}

.phrase-image-stage:has(.phrase-pdf-viewer:not([hidden])) {
  min-height: 747px;
}

.phrase-image-stage:has(.phrase-placeholder[hidden]) {
  border-style: solid;
  border-color: var(--line);
}

.phrase-image-stage.is-dragging-over {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.phrase-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.phrase-placeholder-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
  color: var(--accent);
}

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

.phrase-placeholder strong {
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
}

.phrase-placeholder span:not(.phrase-placeholder-icon) {
  font-size: 13px;
}

.phrase-image {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  transform: translate(calc(-50% + var(--image-x, 0px)), calc(-50% + var(--image-y, 0px)))
    scale(var(--image-scale, 1));
  transform-origin: center;
  user-select: none;
  -webkit-user-drag: none;
}

.phrase-image-stage.is-adjusting .phrase-image {
  will-change: transform;
}

.phrase-image-stage[data-image-mode="move"] .phrase-image {
  cursor: grab;
}

.phrase-image-stage[data-image-mode="resize"] .phrase-image {
  cursor: ew-resize;
}

.phrase-image-stage.is-adjusting .phrase-image {
  cursor: grabbing;
}

.phrase-pdf-viewer {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: var(--paper-light);
  overscroll-behavior: contain;
  scroll-behavior: auto;
  overflow-anchor: none;
  scrollbar-color: var(--tertiary) transparent;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.phrase-pdf-viewer.is-pointer-scrolling {
  cursor: grabbing;
}

.phrase-pdf-viewer iframe {
  display: block;
  width: 100%;
  min-width: 100%;
  height: 100%;
  border: 0;
  background: var(--paper-light);
}

.phrase-pdf-pages {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  align-content: start;
  justify-items: center;
  min-height: 100%;
  padding: 14px;
}

.phrase-pdf-page {
  position: relative;
  width: min(100%, 1100px);
  max-width: 100%;
  padding: 0;
  background: #fff;
  border: 0;
}

.phrase-pdf-page canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto !important;
  pointer-events: none;
}

body[data-theme="dark"] .phrase-pdf-page {
  background: #f9faf7;
}

/* Grabber (iOS sheet handle) */
.phrase-image-stage.is-user-resized {
  min-height: 240px;
}

.phrase-resize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 24px;
  margin-top: 4px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: transparent;
  font-size: 0;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

.phrase-resize-handle::before {
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--tertiary);
  content: "";
  transition: width 200ms var(--ease-out), background-color 200ms ease;
}

.phrase-resize-handle:hover::before,
.phrase-resize-handle:focus-visible::before,
.phrase-resize-handle:active::before {
  width: 64px;
  background: var(--accent);
}

.phrase-resize-handle:active:not(:disabled) {
  transform: none;
}

.phrase-image-controls,
.phrase-pdf-controls {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
}

.pdf-auto-scroll-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  max-width: 340px;
}

.pdf-scroll-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* Segmented controls */
.image-mode-switch {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  border-radius: 10px;
  background: var(--fill);
}

.image-mode-button {
  min-height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.image-mode-button.is-active {
  background: var(--seg-selected);
  box-shadow: var(--seg-shadow);
  color: var(--ink);
  font-weight: 600;
}

.image-mode-button:active:not(:disabled) {
  transform: none;
  opacity: 0.7;
}

.image-zoom-control {
  display: grid;
  grid-template-columns: auto 1fr 52px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.image-zoom-control input {
  width: 100%;
}

.image-zoom-control output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.pdf-speed-control {
  grid-template-columns: auto 1fr 66px;
}

.phrase-image-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* Measure tracking (experimental) */
.score-tracking-controls {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: 16px;
  background: var(--paper);
}

.score-tracking-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  font-size: 13px;
}

.score-tracking-actions label {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.score-tracking-actions select {
  max-width: 100%;
  min-height: 34px;
  background-color: var(--panel);
}

#scoreRouteStatus:empty {
  display: none;
}

#scoreTrackingStatus {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
}

.score-tracking-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.score-measure,
.score-mark-preview {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  padding: 2px 5px;
  border: 1px solid rgba(0, 100, 220, 0.55);
  border-radius: 4px;
  background: rgba(0, 100, 220, 0.025);
  color: #0056b8;
  font: 700 13px system-ui;
  text-align: left;
  cursor: pointer;
}

.score-measure.is-current {
  background: rgba(0, 120, 240, 0.18);
  border: 3px solid #0076df;
}

.score-mark-preview {
  pointer-events: none;
  border: 2px dashed #0076df;
}

.is-marking-measures {
  touch-action: none;
  cursor: crosshair;
}

.is-marking-measures .score-measure {
  pointer-events: none;
}

/* Keep both practice histories above the score, with equal desktop widths. */
.practice-history-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 14px;
  align-items: stretch;
}

@media (max-width: 700px) {
  .practice-history-row { grid-template-columns: minmax(0, 1fr); }
}

.practice-history-row > .pdf-history,
.practice-history-row > .history-panel {
  min-width: 0;
  margin: 0;
  padding: 16px 18px;
  border-radius: 16px;
  background: var(--paper);
}

.practice-history-row .section-heading {
  margin-bottom: 12px;
  gap: 8px;
}

.practice-history-row h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.practice-history-row .text-button {
  flex-shrink: 0;
  padding: 0;
}

.pdf-history summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

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

.pdf-history summary::after {
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-right: 2px solid var(--tertiary);
  border-bottom: 2px solid var(--tertiary);
  content: "";
  transform: rotate(-45deg);
  transition: transform 220ms var(--ease-out);
}

.pdf-history[open] summary::after {
  transform: rotate(45deg);
}

.pdf-history-note,
.pdf-history-footer {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.pdf-history-note {
  margin: 8px 0 0;
}

.pdf-history-list {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  padding: 0;
  list-style: none;
}

.pdf-history-list:empty {
  display: none;
}

.pdf-history-list li {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.pdf-history-open {
  display: block;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 500;
  line-height: 34px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-history-list li > .image-action-button:not(.pdf-history-open) {
  border-radius: 10px;
  background: var(--red-tint);
  color: var(--red);
}

.pdf-history-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.practice-history-row .pdf-history-footer > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Recent BPM chips */
.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.empty-history {
  margin: 4px 0;
  color: var(--muted);
  font-size: 13px;
}

.history-chip {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 8px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
}

.history-chip strong {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.history-chip small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Settings cards
   -------------------------------------------------------------------------- */

.panel {
  padding: 28px;
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
}

.control-deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 20px;
}

/* Sound */
.sound-slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 8px;
}

.sound-slider-copy {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.sound-slider-copy strong {
  font-size: 15px;
  font-weight: 500;
}

.sound-slider-copy small,
.sound-slider-value {
  color: var(--muted);
  font-size: 13px;
}

.sound-slider-value {
  font-variant-numeric: tabular-nums;
}

.sound-slider {
  grid-column: 1 / -1;
}

.sound-tone-control {
  display: grid;
  gap: 8px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.sound-tone-control label {
  font-size: 15px;
  font-weight: 500;
}

.sound-tone-control select {
  width: 100%;
  min-height: 42px;
  font-size: 15px;
}

.sound-tone-control p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.sound-tone-control #soundStatus {
  color: var(--accent);
}

.sound-tone-control #soundStatus:empty {
  display: none;
}

/* Acceleration */
.acceleration-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  min-width: 0;
  margin: 4px 0 14px;
  padding: 0;
  border: 0;
  transition: opacity 200ms ease;
}

.acceleration-fields label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.acceleration-fields label > span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.acceleration-fields input,
.acceleration-fields select {
  width: 100%;
}

.acceleration-fields input:disabled,
.acceleration-fields select:disabled {
  opacity: 1;
}

.acceleration-fields select {
  flex-shrink: 0;
  width: 84px;
}

.acceleration-fields:disabled {
  opacity: 0.45;
}

.acceleration-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.acceleration-status {
  display: inline-flex;
  margin: 12px 0 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
}

.acceleration-panel:has(#accelerationEnabled:checked) .acceleration-status {
  background: var(--accent-tint);
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   Local song
   -------------------------------------------------------------------------- */

.song-panel {
  margin-top: 20px;
}

.song-panel .section-heading {
  flex-wrap: wrap;
  gap: 12px;
}

.song-file-action {
  position: relative;
  flex-shrink: 0;
}

.song-file-action input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.song-file-action input:disabled + label {
  opacity: 0.4;
  cursor: default;
}

#songName {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.song-start-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 16px 0 12px;
  font-size: 13px;
}

.song-start-controls label span {
  color: var(--muted);
}

.song-start-controls > label[for="songZoom"] {
  margin-left: 8px;
  color: var(--muted);
}

.song-start-controls input,
.song-start-controls select {
  min-height: 34px;
}

#songStart {
  width: 104px;
  text-align: center;
}

.song-wave-viewport {
  overflow-x: auto;
  margin-bottom: 10px;
  border-radius: 16px;
  background: var(--paper);
  scrollbar-color: var(--tertiary) transparent;
}

.song-wave {
  position: relative;
  height: 172px;
  min-width: 100%;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
}

#songWaveSvg {
  position: absolute;
  top: 30px;
  left: 0;
  width: 100%;
  height: 120px;
  color: var(--accent);
}

#songWavePath {
  stroke: currentColor;
  stroke-width: 1;
  fill: none;
  opacity: 0.6;
}

.song-wave-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.song-wave-ticks span {
  position: absolute;
  top: 152px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
}

.song-wave-ticks span:first-child {
  transform: none;
}

.song-wave-ticks span:last-child {
  transform: translateX(-100%);
}

.song-marker {
  position: absolute;
  top: 0;
  bottom: 22px;
  z-index: 2;
  width: 2px;
  background: var(--accent);
  cursor: ew-resize;
}

.song-marker::before {
  position: absolute;
  inset: 0 -10px;
  content: "";
}

.song-marker span {
  position: absolute;
  top: 6px;
  left: 0;
  padding: 3px 9px;
  border-radius: 0 999px 999px 0;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

.song-marker.is-near-end span {
  right: 0;
  left: auto;
  border-radius: 999px 0 0 999px;
}

.song-playhead {
  position: absolute;
  top: 30px;
  bottom: 22px;
  width: 2px;
  border-radius: 1px;
  background: var(--orange);
  pointer-events: none;
}

.song-wave-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.song-transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

#songSeek {
  flex: 1;
  min-width: 120px;
}

#songTime {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#songClear {
  background: var(--red-tint);
  color: var(--red);
}

#songStatus {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
}

#songStatus:empty {
  display: none;
}

.song-volume-control {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 380px;
  margin: 14px 0;
  font-size: 14px;
}

.song-volume-control label {
  flex-shrink: 0;
}

#songVolume {
  flex: 1;
  min-width: 0;
}

#songVolumeValue {
  min-width: 4ch;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.app-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 20px;
  padding: 32px 4px 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.app-footer p {
  margin: 0;
}

.noscript-message {
  text-align: center;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (min-width: 1500px) {
  .app-shell {
    max-width: 1440px;
  }
}

@media (max-width: 1000px) {
  .app-shell {
    padding: 0 24px 32px;
  }

  .topbar {
    margin: 0 -24px 16px;
    padding: 16px 24px 12px;
  }

  .tempo-stage {
    padding: 28px;
  }

  .tempo-metric--primary strong {
    font-size: 88px;
  }

  .section-heading .section-note {
    display: none;
  }
}

@media (max-width: 860px) {
  .tempo-dock-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .tempo-metric--primary strong {
    font-size: 96px;
  }
}

@media (max-width: 700px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    padding: 0 16px 24px;
  }

  .topbar {
    margin: 0 -16px 12px;
    padding: 12px 16px 10px;
  }

  .brand-kicker,
  #themeToggleLabel,
  #discoToggleLabel {
    display: none;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  .brand-title {
    font-size: 17px;
  }

  .theme-toggle {
    width: 34px;
    padding: 0;
    justify-content: center;
  }

  .status-pill {
    padding: 0 12px;
    font-size: 12px;
  }

  .tempo-stage {
    padding: 24px 18px;
    border-radius: 24px;
  }

  .tempo-dock {
    --dock-gap: 12px;
    max-height: calc(100vh - 72px);
    max-height: calc(100dvh - 72px);
    border-radius: 24px;
  }

  .tempo-dock-bar {
    padding: 12px 12px 0 20px;
  }

  .tempo-dock-body {
    gap: 20px;
    padding: 4px 18px 20px;
  }

  .tempo-dock.is-collapsed .tempo-dock-body {
    gap: 12px;
    padding-left: 12px;
  }

  .tempo-dock.is-collapsed .tempo-metric--primary strong,
  .tempo-dock.is-collapsed .bpm-number-input {
    font-size: 30px;
  }

  .tempo-metric--primary {
    padding-bottom: 12px;
  }

  .tempo-metric--primary strong {
    font-size: clamp(72px, 22vw, 96px);
  }

  .tempo-metric {
    padding: 2px 4px;
  }

  .tempo-metric:not(.tempo-metric--primary) strong {
    font-size: 14px;
  }

  .tempo-metric:nth-child(3) strong {
    font-size: 12px;
  }

  .beat-strip {
    margin-bottom: 24px;
    gap: 6px;
  }

  .tempo-controls {
    gap: 12px;
  }

  .tempo-shift-control {
    padding: 16px;
  }

  .phrase-workspace-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .phrase-actions {
    gap: 6px;
  }

  .image-action-button {
    min-height: 36px;
  }

  .phrase-image-stage {
    min-height: 220px;
  }

  .control-deck {
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 16px;
  }

  .panel {
    padding: 22px 18px;
    border-radius: 22px;
  }

  .song-panel {
    margin-top: 16px;
  }

  .phrase-image-controls,
  .phrase-pdf-controls {
    grid-template-columns: 1fr;
  }

  .image-mode-switch {
    justify-self: start;
  }

  .app-footer {
    flex-direction: column;
    gap: 4px;
  }

  /* Keep the primary action ahead of advanced controls on narrow screens. */
  .bpm-stepper { order: -4; margin-top: 0; }
  .range-wrap { order: -3; }
  .transport-button { order: -2; }
  .shortcut-hint { order: -1; }
}

@media (max-width: 560px) {
  .tempo-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .time-signature-control {
    min-height: 208px;
  }
}

@media (max-width: 600px) {
  .song-start-controls {
    gap: 6px;
  }

  .song-start-controls > label:first-child {
    width: 100%;
  }

  .song-start-controls > label[for="songZoom"] {
    margin-left: 4px;
  }
}

@media (max-width: 420px) {
  .tempo-shift-labels {
    font-size: 10px;
  }
}

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