/* Visual Tuner POC v0.3.4
   Theme values are intentionally separated from layout so later design variants
   can use the same working tuner logic without rebuilding the product. */

* { box-sizing: border-box; }

:root {
  color-scheme: dark;

  --bg: #06101a;
  --bg-2: #081522;
  --panel: rgba(11, 25, 39, 0.92);
  --panel-soft: rgba(15, 31, 48, 0.78);
  --panel-hover: rgba(22, 43, 65, 0.92);
  --border: rgba(161, 192, 220, 0.12);

  --text: #f3f7fb;
  --muted: #8296aa;
  --muted-2: #5e7185;

  --accent: #4d78ff;
  --accent-2: #725cff;
  --cyan: #27d5e8;
  --green: #43e6a1;
  --amber: #f2bf63;
  --danger: #ff667d;

  --centre-zone: rgba(67, 230, 161, 0.12);
  --shadow: 0 26px 90px rgba(0, 0, 0, 0.34);

  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% -20%, rgba(58, 101, 255, 0.11), transparent 38%),
    radial-gradient(circle at 90% 10%, rgba(54, 216, 215, 0.06), transparent 34%),
    var(--bg);
  color: var(--text);
}

body { min-height: 100vh; }

button, select, input { font: inherit; }

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

button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

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

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

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 18px auto 34px;
}

.topbar {
  min-height: 72px;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 10px 14px 10px 18px;
  border: 1px solid var(--border);
  background: rgba(7, 18, 29, 0.88);
  backdrop-filter: blur(18px);
  border-radius: 22px 22px 0 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 30px;
  position: relative;
}

.brand-mark span {
  position: absolute;
  height: 4px;
  width: 28px;
  border-radius: 99px;
  transform-origin: left center;
}

.brand-mark span:nth-child(1) {
  top: 20px; left: 2px;
  background: var(--cyan);
  transform: rotate(-54deg);
}
.brand-mark span:nth-child(2) {
  top: 5px; left: 14px;
  background: #52b7ff;
  transform: rotate(53deg);
}
.brand-mark span:nth-child(3) {
  top: 20px; left: 27px;
  background: var(--accent-2);
  transform: rotate(-55deg);
}

.brand-name {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.build-label {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 2px;
}

.desktop-nav {
  display: flex;
  justify-content: center;
  min-width: 0;
  gap: 2px;
}

.nav-item {
  min-height: 42px;
  padding: 0 15px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.nav-item.active {
  color: #dce8ff;
  background: rgba(76, 120, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(91, 131, 255, 0.46);
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compact-control {
  display: grid;
  gap: 4px;
}

.compact-control > span {
  font-size: 0.6rem;
  color: var(--muted);
  padding-left: 5px;
}

.compact-control select,
.drone-grid select,
.settings-field select {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  min-height: 40px;
  padding: 0 34px 0 12px;
  border-radius: 10px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 15px) 17px,
    calc(100% - 11px) 17px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  color: #aac0d4;
  background: var(--panel-soft);
  border-radius: 11px;
  cursor: pointer;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
  border: 1px solid var(--border);
  border-top: 0;
  padding: 14px;
  border-radius: 0 0 22px 22px;
  background: rgba(5, 13, 22, 0.70);
  box-shadow: var(--shadow);
}

.main-column {
  min-width: 0;
  display: grid;
  gap: 14px;
}

.tuner-stage,
.trace-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.tuner-stage {
  position: relative;
  min-height: 550px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.reading-stack {
  position: relative;
  z-index: 4;
  text-align: center;
  padding-top: 30px;
  pointer-events: none;
}

.note-line {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
}

.note-name {
  font-size: clamp(5.2rem, 8vw, 8.8rem);
  line-height: 0.84;
  font-weight: 780;
  letter-spacing: -0.075em;
}

.note-octave {
  font-size: clamp(1.55rem, 2.2vw, 2.6rem);
  line-height: 1;
  margin-top: 9px;
  color: #c8d3df;
  font-weight: 700;
}

.cents-readout {
  margin-top: 18px;
  font-size: clamp(2rem, 3.6vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  color: var(--green);
}

.frequency-readout {
  margin-top: 5px;
  font-size: clamp(1.2rem, 1.7vw, 1.75rem);
  color: #aec3d7;
  font-variant-numeric: tabular-nums;
}

.pitch-state {
  margin-top: 6px;
  color: var(--muted);
  font-size: 1rem;
}

.visual-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 74px;
  height: 350px;
}

#visualCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.centre-marker {
  position: absolute;
  left: 50%;
  bottom: 12%;
  width: 18px;
  height: 116px;
  transform: translateX(-50%);
  pointer-events: none;
}

.centre-line {
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(transparent, rgba(67, 230, 161, 0.9) 28%, rgba(67,230,161,.9) 74%, transparent);
}

.centre-dot {
  position: absolute;
  left: 3px;
  top: 73%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e9fff7;
  border: 3px solid var(--green);
  box-shadow: 0 0 20px rgba(67, 230, 161, 0.65);
}

.cent-scale {
  position: absolute;
  z-index: 4;
  left: 17%;
  right: 17%;
  bottom: 66px;
  display: flex;
  justify-content: space-between;
  color: #8499ad;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.cent-scale::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -11px;
  height: 1px;
  background:
    linear-gradient(90deg,
      rgba(130,150,170,.16),
      rgba(130,150,170,.45) 50%,
      rgba(130,150,170,.16));
}

.cent-scale .zero {
  color: #d9f9ee;
}

.stage-actions {
  margin-top: auto;
  position: relative;
  z-index: 5;
  padding: 0 18px 16px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border-radius: 12px;
  font-weight: 750;
  cursor: pointer;
}

.primary-button {
  border: 0;
  background: linear-gradient(135deg, #5078ff, #5e55ee);
  color: white;
  padding: 0 18px;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 18px;
}

.trace-card {
  padding: 16px 16px 12px;
  overflow: hidden;
}

.section-heading,
.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.section-kicker {
  color: var(--muted);
  letter-spacing: 0.12em;
  font-size: 0.62rem;
  font-weight: 800;
}

.section-heading h2,
.panel h2,
.settings-sheet h2 {
  margin: 3px 0 0;
  font-size: 0.98rem;
  letter-spacing: -0.02em;
}

.trace-legend {
  display: flex;
  gap: 12px;
  color: var(--muted-2);
  font-size: 0.7rem;
}

.trace-legend .centre { color: var(--green); }

#traceCanvas {
  display: block;
  width: 100%;
  height: 190px;
  margin-top: 8px;
}

.side-column {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel {
  padding: 16px;
}

.panel-note {
  font-size: 0.66rem;
  color: var(--muted-2);
  max-width: 130px;
  text-align: right;
}

.visual-options {
  margin-top: 13px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.visual-option {
  min-width: 0;
  border: 1px solid var(--border);
  background: rgba(7, 18, 29, 0.68);
  border-radius: 12px;
  padding: 7px;
  color: #aebed0;
  cursor: pointer;
}

.visual-option.selected {
  border-color: rgba(83, 124, 255, 0.95);
  box-shadow: inset 0 0 0 1px rgba(83, 124, 255, 0.58);
  color: white;
  background: rgba(38, 63, 122, 0.33);
}

.preview-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 2.15 / 1;
  border-radius: 8px;
  background: #07111b;
  margin-bottom: 6px;
}

.visual-option span { font-size: 0.76rem; }

.status-pill {
  padding: 5px 8px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.68rem;
}

.signal-main {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  font-size: 0.88rem;
}

.signal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #5b6876;
  box-shadow: 0 0 0 4px rgba(120, 137, 153, .08);
  flex: 0 0 auto;
}

.signal-dot.good {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(67,230,161,.10), 0 0 16px rgba(67,230,161,.25);
}

.signal-dot.low {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(242,191,99,.10);
}

.signal-dot.searching {
  background: #5cb8ff;
  box-shadow: 0 0 0 4px rgba(92,184,255,.10);
}

.signal-meter {
  margin-top: 13px;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,.07);
}

.signal-meter span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2dddc4, #54e59c);
  transition: width 90ms linear;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 26px;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #253648;
  cursor: pointer;
  transition: 150ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #eef5fb;
  transition: 150ms ease;
}

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

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

.drone-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.drone-grid label,
.volume-control,
.settings-field {
  display: grid;
  gap: 7px;
}

.drone-grid label > span,
.volume-control > span,
.settings-field > span {
  font-size: 0.7rem;
  color: var(--muted);
}

.drone-grid select {
  width: 100%;
}

.volume-control {
  margin-top: 13px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.drone-warning {
  margin: 11px 0 0;
  color: var(--muted-2);
  font-size: 0.67rem;
  line-height: 1.45;
}

.developer-panel summary {
  cursor: pointer;
  color: #99aabd;
  font-size: 0.78rem;
}

.diagnostics {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.72rem;
}

.diagnostics strong {
  color: #b7c6d4;
  font-variant-numeric: tabular-nums;
}

.mobile-only,
.mobile-nav { display: none; }

dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  color: var(--text);
  background: #0a1724;
  width: min(92vw, 430px);
  box-shadow: 0 30px 100px rgba(0,0,0,.55);
}

dialog::backdrop {
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(5px);
}

.settings-sheet {
  padding: 20px;
  display: grid;
  gap: 18px;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.settings-field select {
  width: 100%;
}

.quick-reference {
  display: flex;
  gap: 8px;
}

.quick-reference button {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: #c6d5e3;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
}

@media (max-width: 1100px) {
  .app-shell {
    width: min(100% - 20px, 980px);
    margin-top: 10px;
  }

  .topbar {
    grid-template-columns: auto 1fr auto;
  }

  .desktop-nav .nav-item:not(.active) {
    display: none;
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr) 285px;
  }
}

@media (max-width: 760px) {
  body {
    background: var(--bg);
  }

  .app-shell {
    width: 100%;
    margin: 0;
    padding-bottom: 78px;
  }

  .topbar {
    min-height: 66px;
    grid-template-columns: 1fr auto;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 10px 14px;
    position: relative;
  }

  .brand-mark {
    width: 31px;
    transform: scale(.85);
    transform-origin: left center;
  }

  .brand-name { font-size: .92rem; }
  .build-label { font-size: .58rem; }

  .desktop-nav,
  .top-controls .compact-control {
    display: none;
  }

  .top-controls {
    grid-column: 2;
    grid-row: 1;
  }

  .content-grid {
    display: block;
    border: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .main-column {
    display: block;
  }

  .tuner-stage,
  .trace-card,
  .panel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .tuner-stage {
    min-height: 510px;
    border-top: 0;
  }

  .mobile-only { display: flex; }

  .stage-status {
    position: absolute;
    top: 12px;
    left: 14px;
    z-index: 6;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: .68rem;
  }

  .reading-stack {
    padding-top: 45px;
  }

  .note-name {
    font-size: clamp(4.9rem, 26vw, 7rem);
  }

  .note-octave {
    font-size: 1.55rem;
    margin-top: 6px;
  }

  .cents-readout {
    margin-top: 16px;
    font-size: 2.4rem;
  }

  .frequency-readout {
    font-size: 1rem;
  }

  .pitch-state {
    font-size: .8rem;
    margin-top: 4px;
  }

  .visual-wrap {
    height: 285px;
    bottom: 72px;
  }

  .cent-scale {
    left: 12%;
    right: 12%;
    bottom: 64px;
    font-size: .68rem;
  }

  .centre-marker {
    bottom: 11%;
    height: 92px;
  }

  .stage-actions {
    padding: 0 14px 12px;
  }

  .trace-card {
    margin-top: 8px;
    padding: 14px;
  }

  #traceCanvas {
    height: 150px;
  }

  .trace-legend {
    display: none;
  }

  .side-column {
    display: block;
  }

  .side-column .panel {
    margin-top: 8px;
  }

  .visual-panel {
    order: 0;
  }

  .panel-note {
    display: none;
  }

  .visual-options {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .preview-canvas {
    display: none;
  }

  .visual-option {
    padding: 10px 4px;
  }

  .signal-panel {
    display: none;
  }

  .drone-panel {
    padding-bottom: 18px;
  }

  .developer-panel {
    margin-bottom: 10px;
  }

  .mobile-nav {
    position: fixed;
    z-index: 30;
    left: 0;
    right: 0;
    bottom: 0;
    height: 70px;
    padding: 6px 7px calc(6px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: rgba(5, 13, 22, 0.94);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--border);
  }

  .mobile-nav-item {
    border: 0;
    background: transparent;
    color: #64778a;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 3px;
    font-size: .57rem;
  }

  .mobile-nav-item span {
    font-size: .95rem;
  }

  .mobile-nav-item.active {
    color: #6fa4ff;
  }
}

@media (max-width: 370px) {
  .note-name { font-size: 4.7rem; }
  .visual-options { grid-template-columns: 1fr 1fr; }
  .tuner-stage { min-height: 490px; }
}


/* --------------------------------------------------------------------------
   v0.3.2 usability pass
   - Main tuner + pitch trace fit within the active viewport.
   - Secondary controls remain available below the first phone screen.
   - In-tune tolerance is visible in the trace UI.
   -------------------------------------------------------------------------- */

body { min-height: 100dvh; }

.trace-meta {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.tolerance-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(67, 230, 161, 0.22);
  border-radius: 999px;
  background: rgba(67, 230, 161, 0.08);
  color: #8be9c2;
  font-size: 0.66rem;
  font-weight: 750;
  white-space: nowrap;
}

.drone-heading-controls {
  display: flex;
  align-items: center;
  gap: 9px;
}

@media (min-width: 761px) {
  body { overflow: hidden; }

  .app-shell {
    height: calc(100dvh - 20px);
    margin: 10px auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    min-height: 60px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .content-grid {
    min-height: 0;
    height: 100%;
    padding: 10px;
    gap: 10px;
    overflow: hidden;
  }

  .main-column {
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) 165px;
    gap: 10px;
  }

  .tuner-stage {
    min-height: 0;
  }

  .reading-stack {
    padding-top: 16px;
  }

  .note-name {
    font-size: clamp(4.2rem, 6.4vw, 7rem);
  }

  .note-octave {
    font-size: clamp(1.35rem, 1.8vw, 2rem);
  }

  .cents-readout {
    margin-top: 10px;
    font-size: clamp(1.9rem, 2.8vw, 2.9rem);
  }

  .frequency-readout {
    font-size: clamp(1rem, 1.35vw, 1.35rem);
  }

  .pitch-state {
    margin-top: 3px;
    font-size: .88rem;
  }

  .visual-wrap {
    bottom: 56px;
    height: min(300px, 58%);
  }

  .centre-marker {
    height: 96px;
  }

  .cent-scale {
    bottom: 50px;
  }

  .stage-actions {
    padding: 0 14px 8px;
  }

  .primary-button,
  .secondary-button {
    min-height: 38px;
  }

  .trace-card {
    min-height: 0;
    padding: 9px 12px 7px;
  }

  #traceCanvas {
    height: 108px;
    margin-top: 3px;
  }

  .section-heading h2,
  .panel h2 {
    font-size: .92rem;
  }

  .side-column {
    min-height: 0;
    overflow-y: auto;
    align-content: start;
    gap: 8px;
    scrollbar-width: thin;
  }

  .panel {
    padding: 11px;
  }

  .visual-options {
    margin-top: 8px;
    gap: 6px;
  }

  .preview-canvas {
    aspect-ratio: 2.75 / 1;
    margin-bottom: 4px;
  }

  .signal-main {
    margin-top: 9px;
  }

  .signal-meter {
    margin-top: 9px;
  }

  .drone-grid {
    margin-top: 9px;
    gap: 8px;
  }

  .volume-control {
    margin-top: 9px;
  }

  .drone-warning {
    margin-top: 7px;
  }
}

@media (max-width: 760px) {
  body {
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .app-shell {
    padding-bottom: 58px;
  }

  .topbar {
    min-height: 52px;
    padding: 6px 10px;
  }

  .brand-mark {
    transform: scale(.76);
  }

  .brand-name { font-size: .86rem; }
  .build-label { font-size: .54rem; }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .main-column {
    display: grid;
    grid-template-rows: minmax(0, 1fr) 142px;
    gap: 0;
    height: calc(100dvh - 52px - 58px);
    min-height: 0;
  }

  .tuner-stage {
    min-height: 0;
    height: auto;
    border-top: 0;
  }

  .stage-status {
    top: 8px;
    left: 10px;
    font-size: .62rem;
  }

  .reading-stack {
    padding-top: 26px;
  }

  .note-name {
    font-size: clamp(3.85rem, 19vw, 5.25rem);
  }

  .note-octave {
    font-size: 1.25rem;
    margin-top: 4px;
  }

  .cents-readout {
    margin-top: 8px;
    font-size: 1.85rem;
  }

  .frequency-readout {
    margin-top: 2px;
    font-size: .88rem;
  }

  .pitch-state {
    margin-top: 2px;
    font-size: .72rem;
  }

  .visual-wrap {
    top: 132px;
    bottom: 49px;
    height: auto;
  }

  .centre-marker {
    bottom: 9%;
    height: 70px;
  }

  .cent-scale {
    left: 11%;
    right: 11%;
    bottom: 45px;
    font-size: .62rem;
  }

  .stage-actions {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 5px;
    padding: 0;
  }

  .primary-button,
  .secondary-button {
    min-height: 36px;
    padding-left: 15px;
    padding-right: 15px;
    border-radius: 10px;
  }

  .trace-card {
    min-height: 0;
    margin-top: 0;
    padding: 7px 10px 5px;
    border-top: 1px solid var(--border);
  }

  .section-heading {
    align-items: center;
  }

  .section-kicker {
    font-size: .54rem;
  }

  .section-heading h2 {
    margin-top: 1px;
    font-size: .82rem;
  }

  .trace-meta {
    gap: 0;
  }

  .tolerance-badge {
    min-height: 21px;
    padding: 0 7px;
    font-size: .59rem;
  }

  #traceCanvas {
    height: 98px;
    margin-top: 1px;
  }

  .trace-legend {
    display: none;
  }

  .side-column {
    display: block;
  }

  .side-column .panel {
    margin-top: 8px;
  }

  .mobile-nav {
    height: 58px;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  }

  .mobile-nav-item {
    gap: 2px;
    font-size: .52rem;
  }

  .mobile-nav-item span {
    font-size: .86rem;
  }
}

@media (max-width: 760px) and (max-height: 650px) {
  .main-column {
    grid-template-rows: minmax(0, 1fr) 126px;
  }

  .reading-stack { padding-top: 20px; }
  .note-name { font-size: 3.65rem; }
  .cents-readout { font-size: 1.65rem; margin-top: 5px; }
  .visual-wrap { top: 112px; }
  #traceCanvas { height: 84px; }
}

/* v0.3.2.3 mobile viewport stability
   Use the stable viewport height on phones so Safari's address bar collapsing
   while scrolling does not stretch/compress the tuner and pitch trace. */
@media (max-width: 760px) {
  body {
    min-height: 100svh;
    overscroll-behavior-y: contain;
  }

  .main-column {
    height: calc(100svh - 52px - 58px);
  }
}

/* --------------------------------------------------------------------------
   v0.3.3 detector-first pass
   - Calm, information-led live visual: no decorative animated waveforms.
   - Flat / in-tune / sharp colours are deliberately distinct.
   - Pitch-tracking diagnostics remain hidden in the developer disclosure.
   -------------------------------------------------------------------------- */

:root {
  --flat: #58a9ff;
  --sharp: #ffad5c;
  --sharp-strong: #ff7283;
}

.signal-dot.holding {
  background: #78a8d8;
  box-shadow: 0 0 0 4px rgba(120,168,216,.10);
}

.visual-wrap {
  /* v0.3.3 uses the canvas as a stable horizontal cents field. */
  isolation: isolate;
}

.centre-marker {
  z-index: 2;
}

/* The fixed centre dot from earlier experimental visuals is no longer used. */
.centre-dot { display: none; }

.detector-copy {
  margin: 0;
  color: var(--muted-2);
  font-size: .68rem;
  line-height: 1.45;
}

@media (max-width: 760px) {
  .detector-copy { font-size: .64rem; }
}

/* --------------------------------------------------------------------------
   v0.3.4 pitch-history review controls
   -------------------------------------------------------------------------- */
.trace-title-block {
  min-width: 0;
}

.trace-title-block h2 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trace-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.trace-live-button {
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid rgba(111, 164, 255, .40);
  border-radius: 999px;
  background: rgba(79, 119, 218, .12);
  color: #9fc2ff;
  font-size: .66rem;
  font-weight: 800;
  cursor: pointer;
}

.trace-live-button[hidden] {
  display: none;
}

#traceCanvas {
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

#traceCanvas:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: -2px;
  border-radius: 8px;
}

@media (max-width: 760px) {
  .trace-title-block {
    max-width: 62%;
  }

  .trace-title-block h2 {
    font-size: .76rem;
  }

  .trace-live-button {
    min-height: 21px;
    padding: 0 7px;
    font-size: .59rem;
  }
}

/* --------------------------------------------------------------------------
   v0.3.5 detail + stability pass
   - Two traces share one detector/history stream: phrase history + close detail.
   - The main signal status is visually latched through normal articulation gaps.
   - Settings gain musically useful controls with compact explainers.
   -------------------------------------------------------------------------- */

.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 3px;
  padding-top: 4px;
  border-top: 1px solid rgba(161, 192, 220, 0.08);
}

.detail-heading h3 {
  margin: 1px 0 0;
  font-size: .78rem;
  font-weight: 750;
  letter-spacing: -0.015em;
}

.detail-range-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border: 1px solid rgba(124, 229, 220, .20);
  border-radius: 999px;
  background: rgba(124, 229, 220, .06);
  color: #9ddfd9;
  font-size: .58rem;
  font-weight: 800;
  white-space: nowrap;
}

#detailCanvas {
  display: block;
  width: 100%;
  height: 64px;
  margin-top: 1px;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.settings-field small {
  color: var(--muted-2);
  font-size: .66rem;
  line-height: 1.4;
}

.settings-group {
  display: grid;
  gap: 12px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
}

.settings-group-title {
  color: #b9cbe0;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.settings-sheet {
  max-height: min(82svh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

@media (min-width: 761px) {
  .main-column {
    grid-template-rows: minmax(0, 1fr) 212px;
  }

  .trace-card {
    padding: 8px 12px 6px;
  }

  #traceCanvas {
    height: 82px;
  }

  #detailCanvas {
    height: 62px;
  }
}

@media (max-width: 760px) {
  .main-column {
    grid-template-rows: minmax(0, 1fr) 190px;
  }

  .trace-card {
    padding: 6px 10px 4px;
  }

  #traceCanvas {
    height: 70px;
  }

  #detailCanvas {
    height: 58px;
  }

  .detail-heading {
    margin-top: 1px;
    padding-top: 2px;
  }

  .detail-heading h3 {
    font-size: .68rem;
  }

  .detail-range-badge {
    min-height: 18px;
    font-size: .54rem;
  }

  .settings-sheet {
    max-height: 82svh;
    padding: 16px;
    gap: 14px;
  }

  .settings-field small {
    font-size: .62rem;
  }
}

@media (max-width: 760px) and (max-height: 650px) {
  .main-column {
    grid-template-rows: minmax(0, 1fr) 166px;
  }

  #traceCanvas { height: 58px; }
  #detailCanvas { height: 48px; }
  .detail-heading h3 { font-size: .64rem; }
}

/* Keep both trace canvases inside their allocated first-screen row. */
@media (min-width: 761px) {
  .main-column { grid-template-rows: minmax(0, 1fr) 228px; }
}
@media (max-width: 760px) {
  .main-column { grid-template-rows: minmax(0, 1fr) 194px; }
}
@media (max-width: 760px) and (max-height: 650px) {
  .main-column { grid-template-rows: minmax(0, 1fr) 170px; }
}

/* --------------------------------------------------------------------------
   v0.4.0 — clearer pitch graph + metronome
   -------------------------------------------------------------------------- */

[hidden] { display: none !important; }

/* Pitch graph: one view at a time. */
.trace-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 5px;
}

.trace-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.trace-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,.025);
}

.trace-tab {
  min-height: 28px;
  min-width: 72px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: .67rem;
  font-weight: 800;
  cursor: pointer;
}

.trace-tab.active {
  color: #dbe8ff;
  background: rgba(77,120,255,.16);
  box-shadow: inset 0 0 0 1px rgba(92,133,255,.36);
}

.trace-view {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.trace-title-block,
.detail-heading {
  min-height: 27px;
}

.detail-heading {
  margin: 0;
  padding: 0;
  border: 0;
}

#traceCanvas,
#detailCanvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
}

#detailCanvas {
  pointer-events: none;
}

@media (min-width: 761px) {
  .main-column { grid-template-rows: minmax(0, 1fr) 156px; }
  .trace-card { padding: 8px 12px 7px; }
  #traceCanvas, #detailCanvas { height: 100%; }
}

@media (max-width: 760px) {
  .main-column { grid-template-rows: minmax(0, 1fr) 142px; }
  .trace-card { padding: 6px 10px 5px; }
  .trace-mode-row { gap: 6px; }
  .trace-tabs { padding: 2px; }
  .trace-tab {
    min-height: 25px;
    min-width: 62px;
    padding: 0 8px;
    font-size: .61rem;
  }
  .trace-title-block { max-width: 100%; }
  .trace-title-block h2 { font-size: .72rem; }
  .trace-meta { gap: 4px; }
  .tolerance-badge { font-size: .55rem; }
  .detail-heading h3 { font-size: .70rem; }
}

@media (max-width: 760px) and (max-height: 650px) {
  .main-column { grid-template-rows: minmax(0, 1fr) 126px; }
  .trace-tab { min-height: 23px; }
  .trace-title-block, .detail-heading { min-height: 23px; }
}

/* Keep Tune + Metronome reachable on tablet widths where the legacy layout
   used to hide every inactive desktop nav item. */
@media (min-width: 761px) and (max-width: 1100px) {
  .desktop-nav [data-mode] { display: inline-flex !important; align-items: center; }
}

/* Metronome ---------------------------------------------------------------- */
.metronome-view {
  border: 1px solid var(--border);
  border-top: 0;
  padding: 14px;
  border-radius: 0 0 22px 22px;
  background: rgba(5,13,22,.70);
  box-shadow: var(--shadow);
}

.metronome-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
}

.metronome-main-card,
.metronome-controls-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
}

.metronome-main-card {
  min-height: 610px;
  padding: 22px;
  display: flex;
  flex-direction: column;
}

.metronome-controls-card {
  padding: 18px;
  align-self: start;
}

.metronome-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.metronome-card-header h1 {
  margin: 4px 0 0;
  font-size: 1.1rem;
  letter-spacing: -.025em;
}

.tempo-control {
  margin-top: 38px;
  display: grid;
  grid-template-columns: 62px minmax(150px, 270px) 62px;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.tempo-step {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  /* Treat rapid + / − taps as UI interaction, not Safari double-tap zoom. */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tempo-step:active { transform: translateY(1px); }

.bpm-readout {
  display: grid;
  justify-items: center;
  gap: 0;
}

.bpm-readout input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  text-align: center;
  font-size: clamp(4.4rem, 9vw, 7.6rem);
  line-height: .9;
  font-weight: 800;
  letter-spacing: -.065em;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

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

.bpm-readout > span {
  margin-top: 7px;
  color: #b6c7d8;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .14em;
}

.bpm-readout small {
  margin-top: 5px;
  color: var(--muted);
  font-size: .72rem;
}

.bpm-slider {
  width: min(620px, 88%);
  margin: 28px auto 0;
  accent-color: var(--accent);
}

.beat-visual {
  flex: 1;
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 24px;
}

.beat-pulse {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 1px solid rgba(114,145,184,.22);
  background: radial-gradient(circle, rgba(77,120,255,.12), rgba(77,120,255,.025) 64%, transparent 65%);
  display: grid;
  place-items: center;
  align-content: center;
  transition: transform 90ms ease, border-color 90ms ease, background 90ms ease;
}

.beat-pulse strong {
  font-size: 2.55rem;
  line-height: .95;
  font-variant-numeric: tabular-nums;
}

.beat-pulse span {
  margin-top: 5px;
  color: var(--muted);
  font-size: .65rem;
}

.beat-pulse.hit {
  transform: scale(1.055);
  border-color: rgba(102,151,255,.72);
  background: radial-gradient(circle, rgba(77,120,255,.28), rgba(77,120,255,.06) 64%, transparent 65%);
}

.beat-pulse.accent-hit {
  transform: scale(1.075);
  border-color: rgba(242,191,99,.78);
  background: radial-gradient(circle, rgba(242,191,99,.26), rgba(242,191,99,.05) 64%, transparent 65%);
}

.beat-dots {
  width: min(440px, 82%);
  min-height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
}

.beat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #314457;
  box-shadow: 0 0 0 3px rgba(120,145,170,.04);
  transition: transform 80ms ease, background 80ms ease;
}

.beat-dot.accent-dot { box-shadow: 0 0 0 1px rgba(242,191,99,.32); }
.beat-dot.active {
  transform: scale(1.45);
  background: #77a5ff;
}
.beat-dot.active.accent-dot { background: var(--amber); }

.metronome-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 10px;
  width: min(520px, 94%);
  margin: 0 auto;
}

.metro-action {
  min-height: 54px;
  font-size: .92rem;
}

.metro-start.running {
  background: rgba(255,102,125,.12);
  color: #ff92a2;
  box-shadow: inset 0 0 0 1px rgba(255,102,125,.36);
}

.metronome-hint {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--muted-2);
  text-align: center;
  font-size: .66rem;
}

.metronome-control-grid {
  display: grid;
  gap: 15px;
  margin-top: 18px;
}

.metronome-toggle-row {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.metronome-toggle-row > div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.metronome-toggle-row strong { font-size: .78rem; }
.metronome-toggle-row small,
.metronome-note {
  color: var(--muted-2);
  font-size: .65rem;
  line-height: 1.45;
}

.metronome-volume { margin-top: 20px; }
.metronome-note { margin: 17px 0 0; }

@media (max-width: 1100px) and (min-width: 761px) {
  .metronome-grid { grid-template-columns: minmax(0,1fr) 285px; }
}

@media (max-width: 760px) {
  .metronome-view {
    border: 0;
    padding: 0 0 78px;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .metronome-grid { display: block; }

  .metronome-main-card,
  .metronome-controls-card {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .metronome-main-card {
    min-height: calc(100svh - 66px - 70px);
    padding: 16px 14px 18px;
  }

  .metronome-card-header h1 { font-size: .98rem; }

  .tempo-control {
    margin-top: 24px;
    grid-template-columns: 52px minmax(130px, 220px) 52px;
    gap: 9px;
  }

  .tempo-step {
    width: 52px;
    height: 52px;
    border-radius: 15px;
    font-size: 1.7rem;
  }

  .bpm-readout input {
    font-size: clamp(4rem, 22vw, 6rem);
  }

  .bpm-slider {
    width: 92%;
    margin-top: 20px;
  }

  .beat-visual {
    min-height: 210px;
    gap: 20px;
  }

  .beat-pulse {
    width: 116px;
    height: 116px;
  }

  .beat-pulse strong { font-size: 2.25rem; }

  .beat-dots { width: 92%; gap: 11px; }

  .metronome-actions {
    width: 100%;
    grid-template-columns: 1fr 1.15fr;
  }

  .metronome-controls-card {
    margin-top: 8px;
    padding: 16px 14px 22px;
  }

  .metronome-hint { font-size: .62rem; }
}

@media (max-width: 370px) {
  .tempo-control { grid-template-columns: 46px minmax(116px, 1fr) 46px; }
  .tempo-step { width: 46px; height: 46px; }
  .beat-dots { gap: 8px; }
}

/* --------------------------------------------------------------------------
   v0.4.1 — mobile first-screen fit / stable visual viewport
   The primary Tune and Metronome workspaces must fit between the app header
   and fixed bottom mode bar on a phone. Secondary controls remain below.
   JavaScript supplies --app-viewport-height from visualViewport on first load
   and only refreshes it after a genuine width/orientation change, avoiding the
   Safari address-bar stretch that previously made the layout warp on scroll.
   -------------------------------------------------------------------------- */

@media (max-width: 760px) {
  :root {
    --app-viewport-height: 100svh;
    --app-topbar-height: 52px;
    --app-mobile-nav-height: 58px;
  }

  html,
  body {
    min-height: var(--app-viewport-height);
  }

  .app-shell {
    min-height: var(--app-viewport-height);
    padding-bottom: var(--app-mobile-nav-height);
  }

  .topbar {
    min-height: 0;
  }

  .mobile-nav {
    height: var(--app-mobile-nav-height);
  }

  /* Tune: one complete working screen = live tuner + one graph. */
  #tunerView .main-column {
    height: calc(var(--app-viewport-height) - var(--app-topbar-height) - var(--app-mobile-nav-height));
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) 126px;
    overflow: hidden;
  }

  #tunerView .tuner-stage {
    min-height: 0;
    overflow: hidden;
  }

  #tunerView .reading-stack {
    padding-top: 18px;
  }

  #tunerView .note-name {
    font-size: clamp(3.55rem, 17vw, 4.75rem);
  }

  #tunerView .note-octave {
    font-size: 1.12rem;
  }

  #tunerView .cents-readout {
    margin-top: 5px;
    font-size: 1.62rem;
  }

  #tunerView .frequency-readout {
    font-size: .82rem;
  }

  #tunerView .pitch-state {
    margin-top: 1px;
    font-size: .68rem;
  }

  #tunerView .visual-wrap {
    top: 112px;
    bottom: 43px;
  }

  #tunerView .centre-marker {
    height: 62px;
  }

  #tunerView .cent-scale {
    bottom: 39px;
    font-size: .59rem;
  }

  #tunerView .stage-actions {
    bottom: 3px;
  }

  #tunerView .primary-button,
  #tunerView .secondary-button {
    min-height: 33px;
    padding-left: 14px;
    padding-right: 14px;
  }

  #tunerView .trace-card {
    min-height: 0;
    height: 126px;
    padding: 5px 10px 4px;
    overflow: hidden;
  }

  #tunerView .trace-mode-row {
    min-height: 27px;
  }

  #tunerView .trace-tab {
    min-height: 23px;
  }

  #tunerView .trace-title-block,
  #tunerView .detail-heading {
    min-height: 22px;
  }

  #tunerView .trace-title-block h2,
  #tunerView .detail-heading h3 {
    font-size: .66rem;
  }

  #tunerView #traceCanvas,
  #tunerView #detailCanvas {
    min-height: 0;
    height: 100%;
  }

  /* Metronome: all core controls visible before scrolling. */
  .metronome-view {
    padding-bottom: var(--app-mobile-nav-height);
  }

  .metronome-main-card {
    box-sizing: border-box;
    height: calc(var(--app-viewport-height) - var(--app-topbar-height) - var(--app-mobile-nav-height));
    min-height: 0;
    max-height: none;
    padding: 10px 14px 8px;
    overflow: hidden;
  }

  .metronome-card-header {
    min-height: 38px;
    align-items: center;
  }

  .metronome-card-header .section-kicker {
    font-size: .50rem;
  }

  .metronome-card-header h1 {
    margin-top: 1px;
    font-size: .86rem;
  }

  .metronome-card-header .status-pill {
    padding: 4px 7px;
    font-size: .60rem;
  }

  .tempo-control {
    margin-top: 8px;
    grid-template-columns: 46px minmax(126px, 190px) 46px;
    gap: 8px;
  }

  .tempo-step {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    font-size: 1.55rem;
  }

  .bpm-readout input {
    font-size: clamp(3.4rem, 19vw, 4.9rem);
    line-height: .86;
  }

  .bpm-readout > span {
    margin-top: 4px;
    font-size: .68rem;
  }

  .bpm-readout small {
    margin-top: 2px;
    font-size: .62rem;
  }

  .bpm-slider {
    width: 94%;
    margin-top: 9px;
  }

  .beat-visual {
    flex: 1 1 auto;
    min-height: 0;
    gap: 10px;
    padding: 5px 0;
  }

  .beat-pulse {
    width: clamp(82px, 24vw, 104px);
    height: clamp(82px, 24vw, 104px);
  }

  .beat-pulse strong {
    font-size: 2rem;
  }

  .beat-pulse span {
    margin-top: 3px;
    font-size: .58rem;
  }

  .beat-dots {
    min-height: 14px;
    gap: 9px;
  }

  .beat-dot {
    width: 8px;
    height: 8px;
  }

  .metronome-actions {
    gap: 8px;
  }

  .metro-action {
    min-height: 42px;
    font-size: .78rem;
  }

  .metronome-hint {
    min-height: 13px;
    margin-top: 4px;
    font-size: .56rem;
    line-height: 1.25;
  }

  /* Secondary rhythm controls deliberately begin below the first screen. */
  .metronome-controls-card {
    margin-top: 8px;
  }
}

/* Extra compression for short visual viewports while preserving touch size. */
@media (max-width: 760px) and (max-height: 700px) {
  #tunerView .main-column {
    grid-template-rows: minmax(0, 1fr) 112px;
  }

  #tunerView .trace-card {
    height: 112px;
  }

  #tunerView .reading-stack { padding-top: 13px; }
  #tunerView .note-name { font-size: 3.35rem; }
  #tunerView .visual-wrap { top: 102px; bottom: 40px; }

  .metronome-main-card {
    padding-top: 7px;
    padding-bottom: 6px;
  }

  .metronome-card-header { min-height: 32px; }
  .tempo-control { margin-top: 4px; }
  .bpm-readout input { font-size: 3.2rem; }
  .bpm-slider { margin-top: 5px; }
  .beat-pulse { width: 76px; height: 76px; }
  .beat-visual { gap: 6px; padding: 2px 0; }
  .metro-action { min-height: 39px; }
  .metronome-hint { display: none; }
}

/* --------------------------------------------------------------------------
   v0.4.2 — metronome practice tools
   Secondary controls remain below the first-screen metronome workspace so
   the mobile fit from v0.4.1 is preserved.
   -------------------------------------------------------------------------- */

.metronome-control-grid--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.metronome-control-grid .settings-field small,
.beat-pattern-heading small,
.trainer-toggle-row small {
  color: var(--muted-2);
  font-size: .62rem;
  line-height: 1.4;
}

.beat-pattern-block {
  margin-top: 19px;
  padding-top: 17px;
  border-top: 1px solid var(--border);
}

.beat-pattern-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.beat-pattern-heading > div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.beat-pattern-heading strong,
.trainer-toggle-row strong {
  font-size: .78rem;
}

.beat-pattern-key {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 7px;
  color: var(--muted-2);
  font-size: .55rem;
}

.beat-pattern-key i {
  width: 7px;
  height: 7px;
  display: inline-block;
  border-radius: 50%;
  background: #50657a;
}

.beat-pattern-key i.accent { background: var(--amber); }
.beat-pattern-key i.normal { background: #77a5ff; }
.beat-pattern-key i.mute {
  background: transparent;
  border: 1px solid #52677a;
}

.beat-pattern-buttons {
  margin-top: 11px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 7px;
}

.beat-pattern-button {
  min-width: 0;
  min-height: 48px;
  padding: 7px 6px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(7,18,29,.68);
  color: #b6c7d8;
  cursor: pointer;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
}

.beat-pattern-button strong {
  font-size: .86rem;
  line-height: 1;
}

.beat-pattern-button span {
  color: var(--muted);
  font-size: .54rem;
}

.beat-pattern-button.accent {
  border-color: rgba(242,191,99,.42);
  background: rgba(242,191,99,.08);
  color: #f4d18e;
}

.beat-pattern-button.normal {
  border-color: rgba(119,165,255,.24);
}

.beat-pattern-button.mute {
  opacity: .58;
  border-style: dashed;
}

.beat-pattern-button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.metronome-volume-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 18px;
  padding-top: 17px;
  border-top: 1px solid var(--border);
}

.metronome-volume-grid .metronome-volume {
  margin-top: 0;
}

.trainer-section {
  margin-top: 21px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.trainer-section-heading h3 {
  margin: 3px 0 3px;
  font-size: .86rem;
  letter-spacing: -.02em;
}

.trainer-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(7,18,29,.52);
}

.trainer-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.trainer-toggle-row > div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.trainer-controls {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  transition: opacity 140ms ease;
}

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

.trainer-controls[aria-disabled="true"] {
  opacity: .38;
}

.number-field {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 11px;
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.number-field:disabled,
.trainer-controls select:disabled {
  cursor: default;
}

.beat-dot.accent {
  box-shadow: 0 0 0 1px rgba(242,191,99,.38);
}

.beat-dot.mute {
  background: transparent;
  border: 1px solid #42566a;
  box-shadow: none;
}

.beat-dot.active.accent { background: var(--amber); }
.beat-dot.active.normal { background: #77a5ff; }
.beat-dot.active.mute {
  background: transparent;
  border-color: #8499ad;
  transform: scale(1.25);
}

.beat-pulse.muted-hit {
  transform: scale(1.025);
  border-color: rgba(132,153,173,.32);
  background: radial-gradient(circle, rgba(132,153,173,.10), rgba(132,153,173,.02) 64%, transparent 65%);
}

.beat-pulse.silent {
  transform: none;
  border-color: rgba(132,153,173,.10);
  background: radial-gradient(circle, rgba(132,153,173,.025), transparent 65%);
}

@media (max-width: 1100px) and (min-width: 761px) {
  .metronome-control-grid--three {
    grid-template-columns: 1fr;
  }

  .metronome-volume-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .metronome-control-grid--three,
  .metronome-volume-grid,
  .trainer-controls,
  .trainer-controls--two {
    grid-template-columns: 1fr;
  }

  .beat-pattern-heading {
    display: grid;
  }

  .beat-pattern-key {
    justify-content: flex-start;
  }

  .beat-pattern-buttons {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .beat-pattern-button {
    min-height: 46px;
  }

  .trainer-card {
    padding: 12px 10px;
  }
}

@media (max-width: 370px) {
  .beat-pattern-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* --------------------------------------------------------------------------
   v0.4.3 — regression fix: fit + readable history
   Keep the primary Tune and Metronome controls inside the visible workspace.
   Use CSS small-viewport units on phones so Safari's initial browser chrome
   cannot leave us with a stale oversized JavaScript height.
   -------------------------------------------------------------------------- */

/* Desktop/laptop: the primary working card must fit without hiding controls. */
@media (min-width: 761px) {
  #tunerView .main-column {
    height: min(760px, calc(100vh - 124px));
    min-height: 540px;
    grid-template-rows: minmax(0, 1fr) 180px;
  }

  #tunerView .tuner-stage {
    min-height: 0;
  }

  #tunerView .trace-card {
    min-height: 0;
    height: 180px;
  }

  .metronome-main-card {
    height: min(680px, calc(100vh - 124px));
    min-height: 520px;
    padding: 16px 20px 14px;
    overflow: hidden;
  }

  .metronome-main-card .tempo-control {
    margin-top: 16px;
  }

  .metronome-main-card .bpm-slider {
    margin-top: 14px;
  }

  .metronome-main-card .beat-visual {
    min-height: 120px;
    gap: 14px;
  }

  .metronome-main-card .beat-pulse {
    width: 112px;
    height: 112px;
  }

  .metronome-main-card .metronome-actions {
    flex: 0 0 auto;
  }

  .metronome-main-card .metronome-hint {
    margin-top: 6px;
  }
}

/* Short laptop screens get a denser core view rather than losing Start. */
@media (min-width: 761px) and (max-height: 760px) {
  #tunerView .main-column {
    height: calc(100vh - 108px);
    min-height: 500px;
    grid-template-rows: minmax(0, 1fr) 164px;
  }

  #tunerView .trace-card { height: 164px; }

  .metronome-main-card {
    height: calc(100vh - 108px);
    min-height: 500px;
    padding-top: 12px;
    padding-bottom: 10px;
  }

  .metronome-main-card .tempo-control { margin-top: 8px; }
  .metronome-main-card .bpm-readout input { font-size: clamp(3.8rem, 8vw, 6rem); }
  .metronome-main-card .bpm-slider { margin-top: 8px; }
  .metronome-main-card .beat-visual { min-height: 90px; gap: 8px; }
  .metronome-main-card .beat-pulse { width: 94px; height: 94px; }
  .metronome-main-card .beat-pulse strong { font-size: 2rem; }
  .metronome-main-card .metro-action { min-height: 46px; }
  .metronome-main-card .metronome-hint { margin-top: 3px; }
}

@media (max-width: 760px) {
  :root {
    /* `svh` is deliberately authoritative here. It represents the smallest
       stable Safari viewport with browser chrome present and avoids locking a
       too-tall first measurement during page load. */
    --app-viewport-height: 100svh !important;
  }

  html,
  body,
  .app-shell {
    min-height: 100svh;
  }

  /* The first Tune screen is deliberately shared between the live tuner and a
     genuinely useful graph instead of letting the live visual consume nearly
     all of the phone. */
  #tunerView .main-column {
    height: calc(100svh - var(--app-topbar-height, 52px) - var(--app-mobile-nav-height, 58px));
    min-height: 0;
    grid-template-rows: minmax(0, 1.35fr) minmax(0, 1fr);
    overflow: hidden;
  }

  #tunerView .tuner-stage,
  #tunerView .trace-card {
    min-height: 0;
  }

  #tunerView .tuner-stage {
    overflow: hidden;
  }

  #tunerView .reading-stack {
    padding-top: 10px;
  }

  #tunerView .note-name {
    font-size: clamp(3rem, 15vw, 4.2rem);
  }

  #tunerView .note-octave { font-size: 1rem; }
  #tunerView .cents-readout { margin-top: 3px; font-size: 1.45rem; }
  #tunerView .frequency-readout { font-size: .76rem; }
  #tunerView .pitch-state { margin-top: 1px; font-size: .64rem; }

  #tunerView .visual-wrap {
    top: 94px;
    bottom: 39px;
  }

  #tunerView .centre-marker { height: 54px; }
  #tunerView .cent-scale { bottom: 36px; font-size: .56rem; }
  #tunerView .stage-actions { bottom: 2px; }

  #tunerView .trace-card {
    height: auto;
    padding: 6px 10px 5px;
    overflow: hidden;
  }

  #tunerView .trace-mode-row { min-height: 28px; }
  #tunerView .trace-view { min-height: 0; }
  #tunerView .trace-title-block,
  #tunerView .detail-heading { min-height: 24px; }

  #tunerView #traceCanvas,
  #tunerView #detailCanvas {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 88px;
  }

  /* Metronome core screen: Start/Stop and Tap are always above the mode bar. */
  .metronome-main-card {
    box-sizing: border-box;
    height: calc(100svh - var(--app-topbar-height, 52px) - var(--app-mobile-nav-height, 58px));
    min-height: 0;
    padding: 9px 14px 8px;
    overflow: hidden;
  }

  .metronome-main-card .metronome-card-header { min-height: 34px; }
  .metronome-main-card .tempo-control {
    margin-top: 5px;
    grid-template-columns: 44px minmax(120px, 182px) 44px;
  }
  .metronome-main-card .tempo-step { width: 44px; height: 44px; }
  .metronome-main-card .bpm-readout input { font-size: clamp(3rem, 18vw, 4.5rem); }
  .metronome-main-card .bpm-readout > span { margin-top: 2px; font-size: .62rem; }
  .metronome-main-card .bpm-readout small { margin-top: 1px; font-size: .58rem; }
  .metronome-main-card .bpm-slider { width: 94%; margin-top: 5px; }

  .metronome-main-card .beat-visual {
    flex: 1 1 auto;
    min-height: 78px;
    gap: 6px;
    padding: 2px 0;
  }
  .metronome-main-card .beat-pulse {
    width: clamp(74px, 21vw, 92px);
    height: clamp(74px, 21vw, 92px);
  }
  .metronome-main-card .beat-pulse strong { font-size: 1.85rem; }
  .metronome-main-card .beat-pulse span { font-size: .54rem; }
  .metronome-main-card .beat-dots { min-height: 12px; gap: 8px; }

  .metronome-main-card .metronome-actions {
    width: 100%;
    gap: 7px;
  }
  .metronome-main-card .metro-action {
    min-height: 40px;
    font-size: .75rem;
  }
  .metronome-main-card .metronome-hint {
    min-height: 11px;
    margin-top: 2px;
    font-size: .53rem;
    line-height: 1.15;
  }
}

@media (max-width: 760px) and (max-height: 650px) {
  #tunerView .main-column {
    grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr);
  }

  #tunerView .reading-stack { padding-top: 6px; }
  #tunerView .note-name { font-size: 2.75rem; }
  #tunerView .visual-wrap { top: 82px; bottom: 35px; }
  #tunerView #traceCanvas,
  #tunerView #detailCanvas { min-height: 76px; }

  .metronome-main-card .metronome-card-header { min-height: 30px; }
  .metronome-main-card .tempo-control { margin-top: 2px; }
  .metronome-main-card .bpm-readout input { font-size: 2.8rem; }
  .metronome-main-card .beat-visual { min-height: 64px; gap: 4px; }
  .metronome-main-card .beat-pulse { width: 68px; height: 68px; }
  .metronome-main-card .metro-action { min-height: 38px; }
  .metronome-main-card .metronome-hint { display: none; }
}

/* Prevent browser default H2 margins from stealing most of the graph row. */
.trace-title-block {
  min-height: 24px !important;
  height: auto !important;
  align-self: start;
}
.trace-title-block h2 {
  margin: 2px 0 0 !important;
  line-height: 1.08;
  font-size: .82rem;
}
.detail-heading h3 {
  margin: 1px 0 0 !important;
  line-height: 1.08;
}
@media (max-width: 760px) {
  .trace-title-block h2 { font-size: .68rem; }
}

/* --------------------------------------------------------------------------
   v0.4.4 — phone workspace + louder metronome support
   On phones the metronome is now a genuinely single-screen workspace.
   Rhythm/trainers open as an overlay instead of extending the page below the
   fixed mode bar. Desktop retains the full two-column controls layout.
   -------------------------------------------------------------------------- */

.metro-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.metro-tools-button,
.metro-tools-mobile-header,
.metro-tools-backdrop {
  display: none;
}

@media (max-width: 760px) {
  /* Keep the metronome page itself from becoming taller than the visible app
     workspace. Secondary controls live in the Tools sheet below. */
  .metronome-view {
    box-sizing: border-box;
    height: calc(100svh - var(--app-topbar-height, 52px) - var(--app-mobile-nav-height, 58px));
    min-height: 0;
    padding: 0 !important;
    overflow: hidden;
  }

  .metronome-grid {
    height: 100%;
    min-height: 0;
    display: block;
  }

  .metronome-main-card {
    height: 100% !important;
    min-height: 0 !important;
    padding: 8px 14px 7px !important;
    overflow: hidden;
  }

  .metro-tools-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-soft);
    color: #c9d7e5;
    font-size: .62rem;
    font-weight: 750;
    cursor: pointer;
  }

  .metronome-main-card .metronome-card-header {
    min-height: 34px;
  }

  .metronome-main-card .tempo-control {
    margin-top: 4px;
  }

  .metronome-main-card .bpm-slider {
    margin-top: 4px;
  }

  /* The former flex:1 beat region created a large empty vertical void on
     iPhone. Give the visual a deliberate bounded size instead. */
  .metronome-main-card .beat-visual {
    flex: 0 0 auto;
    min-height: 0;
    height: clamp(108px, 18svh, 146px);
    padding: 4px 0;
    gap: 7px;
    justify-content: center;
  }

  .metronome-main-card .beat-pulse {
    width: clamp(76px, 20vw, 92px);
    height: clamp(76px, 20vw, 92px);
  }

  .metronome-main-card .metronome-actions {
    margin-top: auto;
  }

  .metronome-main-card .metronome-hint {
    display: none;
  }

  /* Mobile tools sheet. It reuses the exact same controls/IDs as desktop,
     avoiding duplicate state or a second set of metronome logic. */
  .metro-tools-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, .56);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
  }

  .metro-tools-backdrop.mobile-open {
    display: block;
  }

  .metronome-controls-card {
    display: none;
    position: fixed;
    z-index: 70;
    left: 10px;
    right: 10px;
    top: max(10px, env(safe-area-inset-top));
    bottom: auto;
    width: auto;
    height: calc(100svh - var(--app-mobile-nav-height, 58px) - 20px);
    max-height: calc(100svh - var(--app-mobile-nav-height, 58px) - 20px);
    margin: 0 !important;
    padding: 0 14px 22px !important;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid rgba(161,192,220,.20) !important;
    border-radius: 18px !important;
    background: #081624;
    box-shadow: 0 22px 80px rgba(0,0,0,.56);
  }

  .metronome-controls-card.mobile-open {
    display: block;
  }

  .metro-tools-mobile-header {
    position: sticky;
    z-index: 2;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 58px;
    margin: 0 -14px 12px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    background: rgba(8,22,36,.97);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }

  .metro-tools-mobile-header strong {
    display: block;
    margin-top: 2px;
    font-size: .88rem;
  }

  .metro-tools-close {
    min-height: 38px;
    padding: 0 14px;
  }

  body.metro-tools-open {
    overflow: hidden;
  }
}

@media (max-width: 760px) and (max-height: 700px) {
  .metronome-main-card .beat-visual {
    height: 92px;
  }

  .metronome-main-card .beat-pulse {
    width: 66px;
    height: 66px;
  }

  .metronome-main-card .bpm-readout input {
    font-size: 2.7rem;
  }

  .metro-tools-button {
    min-height: 30px;
  }
}

/* --------------------------------------------------------------------------
   v0.4.5 — fuller core metronome + stronger click
   Core rhythm controls now live in the main workspace so the phone screen
   feels intentional rather than empty. Advanced trainers remain in Tools.
   -------------------------------------------------------------------------- */

.metro-core-panel {
  width: min(650px, 94%);
  margin: 14px auto 0;
  padding: 11px 12px 10px;
  border: 1px solid rgba(161, 192, 220, .12);
  border-radius: 14px;
  background: rgba(11, 25, 39, .58);
}

.metro-core-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metro-core-field {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.metro-core-field > span,
.metro-volume-row > div > span {
  color: var(--muted);
  font-size: .62rem;
  font-weight: 750;
  letter-spacing: .02em;
}

.metro-core-field select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 0 28px 0 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  appearance: none;
  color: var(--text);
  background-color: rgba(8, 22, 36, .88);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 12px) 15px,
    calc(100% - 8px) 15px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  font-size: .72rem;
}

.metro-volume-row {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid rgba(161, 192, 220, .08);
  display: grid;
  grid-template-columns: minmax(120px, auto) minmax(140px, 1fr);
  align-items: center;
  gap: 12px;
}

.metro-volume-row > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.metro-volume-row small {
  overflow: hidden;
  color: var(--muted-2);
  font-size: .56rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.metro-volume-row input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

.metronome-volume-grid--subdivision-only {
  grid-template-columns: 1fr;
}

@media (min-width: 761px) {
  .metronome-main-card .tempo-control {
    margin-top: 12px;
  }

  .metronome-main-card .bpm-slider {
    margin-top: 10px;
  }

  .metronome-main-card .beat-visual {
    min-height: 105px;
    gap: 10px;
  }

  .metronome-main-card .beat-pulse {
    width: 100px;
    height: 100px;
  }

  .metro-core-panel {
    margin-top: 10px;
  }
}

@media (max-width: 760px) {
  .metronome-main-card {
    padding: 8px 14px 8px !important;
  }

  .metronome-main-card .metronome-card-header {
    min-height: 34px;
  }

  .metronome-main-card .tempo-control {
    width: min(330px, 100%);
    margin: 6px auto 0;
    grid-template-columns: 46px minmax(150px, 1fr) 46px;
    gap: 10px;
  }

  .metronome-main-card .tempo-step {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    font-size: 1.6rem;
  }

  /* Keep all three digits visible. The earlier build squeezed the editable
     number into too narrow a middle column on some phones. */
  .metronome-main-card .bpm-readout {
    min-width: 0;
  }

  .metronome-main-card .bpm-readout input {
    width: 100%;
    min-width: 0;
    font-size: clamp(4rem, 19vw, 5.2rem);
    line-height: .9;
    letter-spacing: -.045em;
  }

  .metronome-main-card .bpm-readout > span {
    margin-top: 1px;
    font-size: .6rem;
  }

  .metronome-main-card .bpm-readout small {
    margin-top: 0;
    font-size: .56rem;
  }

  .metronome-main-card .bpm-slider {
    width: 94%;
    margin-top: 4px;
  }

  .metro-core-panel {
    width: 100%;
    margin-top: 6px;
    padding: 7px 8px 7px;
    border-radius: 12px;
  }

  .metro-core-grid {
    gap: 6px;
  }

  .metro-core-field {
    gap: 3px;
  }

  .metro-core-field > span,
  .metro-volume-row > div > span {
    font-size: .54rem;
  }

  .metro-core-field select {
    min-height: 32px;
    padding: 0 23px 0 7px;
    background-position:
      calc(100% - 10px) 13px,
      calc(100% - 6px) 13px;
    font-size: .64rem;
  }

  .metro-volume-row {
    grid-template-columns: minmax(104px, .8fr) minmax(130px, 1.2fr);
    gap: 8px;
    margin-top: 6px;
    padding-top: 6px;
  }

  .metro-volume-row small {
    font-size: .49rem;
  }

  .metronome-main-card .beat-visual {
    flex: 1 1 auto;
    height: auto;
    min-height: 84px;
    padding: 3px 0;
    gap: 6px;
  }

  .metronome-main-card .beat-pulse {
    width: clamp(72px, 19vw, 86px);
    height: clamp(72px, 19vw, 86px);
  }

  .metronome-main-card .metronome-actions {
    margin-top: 4px;
  }

  .metronome-main-card .metro-action {
    min-height: 42px;
    font-size: .76rem;
  }
}

@media (max-width: 760px) and (max-height: 700px) {
  .metronome-main-card .metronome-card-header {
    min-height: 30px;
  }

  .metronome-main-card .tempo-control {
    margin-top: 2px;
    grid-template-columns: 42px minmax(142px, 1fr) 42px;
  }

  .metronome-main-card .tempo-step {
    width: 42px;
    height: 42px;
  }

  .metronome-main-card .bpm-readout input {
    font-size: clamp(3.45rem, 17vw, 4.2rem);
  }

  .metronome-main-card .bpm-slider {
    margin-top: 1px;
  }

  .metro-core-panel {
    margin-top: 3px;
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .metro-core-field select {
    min-height: 29px;
  }

  .metro-volume-row {
    margin-top: 4px;
    padding-top: 4px;
  }

  .metronome-main-card .beat-visual {
    min-height: 66px;
    gap: 3px;
  }

  .metronome-main-card .beat-pulse {
    width: 62px;
    height: 62px;
  }

  .metronome-main-card .beat-pulse strong {
    font-size: 1.65rem;
  }

  .metronome-main-card .metro-action {
    min-height: 38px;
  }
}


/* --------------------------------------------------------------------------
   v0.4.7 · trace onset guard + hard background microphone release
   -------------------------------------------------------------------------- */
.target-view {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 22px 22px;
  background: rgba(5, 13, 22, .70);
  box-shadow: var(--shadow);
}

.target-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
}

.target-main-card,
.target-controls-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
}

.target-main-card {
  min-height: 610px;
  padding: 18px 22px 20px;
  display: flex;
  flex-direction: column;
}

.target-controls-card { padding: 18px; }

.target-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.target-card-header h2,
.target-controls-card h2 {
  margin: 3px 0 0;
  font-size: 1.05rem;
  letter-spacing: -.025em;
}

.target-note-controls {
  width: min(560px, 100%);
  margin: 34px auto 0;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 18px;
}

.target-step {
  width: 58px;
  height: 58px;
  border: 1px solid rgba(132, 167, 205, .20);
  border-radius: 16px;
  background: rgba(9, 26, 43, .84);
  color: var(--text);
  font-size: 2rem;
  cursor: pointer;
}

.target-note-display { text-align: center; }
.target-note-display > span {
  display: block;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.target-note-display strong {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 5px;
  margin-top: 4px;
  font-size: clamp(5rem, 10vw, 8rem);
  line-height: .9;
  letter-spacing: -.07em;
}
.target-note-display strong small {
  margin-top: 9px;
  font-size: .28em;
  color: #c7d4df;
  letter-spacing: 0;
}
.target-note-display em {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: .74rem;
  font-style: normal;
}

.target-live-row {
  width: min(650px, 100%);
  margin: 22px auto 0;
  padding: 12px 14px;
  border: 1px solid rgba(161, 192, 220, .10);
  border-radius: 14px;
  background: rgba(7, 18, 29, .56);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}
.target-live-row > div:first-child { min-width: 76px; }
.target-live-row span {
  color: var(--muted-2);
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .11em;
}
.target-live-row > div:first-child strong {
  display: block;
  margin-top: 2px;
  font-size: 1.55rem;
}
.target-feedback-wrap { text-align: right; }
.target-feedback-wrap strong { display: block; font-size: .92rem; }
.target-feedback-wrap span { display: block; margin-top: 3px; letter-spacing: 0; font-size: .75rem; }

.target-lane {
  position: relative;
  width: min(720px, 100%);
  height: 54px;
  margin: 34px auto 0;
  border-top: 1px solid rgba(161, 192, 220, .18);
  border-bottom: 1px solid rgba(161, 192, 220, .18);
}
.target-lane-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 6%);
  width: 12%;
  background: linear-gradient(90deg, transparent, rgba(67,230,161,.14), transparent);
}
.target-lane-centre {
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  background: rgba(67, 230, 161, .82);
}
.target-pitch-marker {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(239, 250, 255, .9);
  border-radius: 50%;
  transition: left 80ms linear, background 100ms linear;
}
.target-lane-labels {
  width: min(720px, 100%);
  margin: 6px auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  color: var(--muted);
  font-size: .7rem;
}
.target-lane-labels strong { color: #ccfff0; }
.target-lane-labels span:last-child { text-align: right; }

.target-hold-block { width: min(650px, 100%); margin: 28px auto 0; }
.target-hold-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .72rem; }
.target-hold-meta strong { color: var(--text); }
.target-progress { height: 9px; margin-top: 8px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.07); }
.target-progress span { display: block; width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--green)); transition: width 90ms linear; }

.target-actions {
  width: min(650px, 100%);
  margin: auto auto 0;
  padding-top: 24px;
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
}
.target-actions > button { min-height: 48px; }
.target-actions #targetStopButton { grid-column: 2; }

.target-setting-row {
  margin-top: 18px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(161, 192, 220, .08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.target-setting-row > div { display: grid; gap: 4px; }
.target-setting-row strong { font-size: .82rem; }
.target-setting-row small,
.target-controls-card .settings-field small,
.target-note { color: var(--muted-2); font-size: .65rem; line-height: 1.45; }
.target-controls-card .settings-field { margin-top: 16px; }
.target-controls-card .settings-field select { width: 100%; }

.target-session-stats {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.target-session-stats > div {
  padding: 12px;
  border: 1px solid rgba(161, 192, 220, .10);
  border-radius: 12px;
  background: rgba(7, 18, 29, .54);
}
.target-session-stats span { display: block; color: var(--muted); font-size: .62rem; }
.target-session-stats strong { display: block; margin-top: 3px; font-size: 1.15rem; }
.target-note { margin: 18px 0 0; }

@media (max-width: 1100px) and (min-width: 761px) {
  .target-grid { grid-template-columns: minmax(0, 1fr) 285px; }
}

@media (max-width: 760px) {
  .target-view {
    height: calc(var(--app-viewport-height, 100svh) - var(--app-topbar-height, 52px) - var(--app-mobile-nav-height, 58px));
    padding: 0 0 var(--app-mobile-nav-height, 58px);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
  }
  .target-grid { height: 100%; display: block; }
  .target-main-card {
    height: 100%;
    min-height: 0;
    padding: 10px 14px 10px;
    border: 0;
    border-radius: 0;
    display: flex;
  }
  .target-controls-card {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
  .target-card-header { min-height: 34px; }
  .target-card-header h2 { font-size: .88rem; }
  .target-note-controls {
    width: min(330px, 100%);
    margin-top: 8px;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 10px;
  }
  .target-step { width: 44px; height: 44px; border-radius: 13px; font-size: 1.55rem; }
  .target-note-display strong { font-size: clamp(4rem, 20vw, 5.2rem); }
  .target-note-display > span { font-size: .56rem; }
  .target-note-display em { margin-top: 2px; font-size: .58rem; }
  .target-live-row { margin-top: 8px; padding: 8px 10px; gap: 10px; }
  .target-live-row > div:first-child { min-width: 58px; }
  .target-live-row > div:first-child strong { font-size: 1.15rem; }
  .target-feedback-wrap strong { font-size: .72rem; }
  .target-feedback-wrap span { font-size: .6rem; }
  .target-lane { height: 44px; margin-top: 12px; }
  .target-lane-labels { margin-top: 3px; font-size: .58rem; }
  .target-hold-block { margin-top: 12px; }
  .target-hold-meta { font-size: .6rem; }
  .target-progress { height: 7px; margin-top: 5px; }
  .target-actions { margin-top: auto; padding-top: 12px; gap: 8px; }
  .target-actions > button { min-height: 42px; font-size: .76rem; }
}

@media (max-width: 760px) and (max-height: 700px) {
  .target-main-card { padding-top: 6px; padding-bottom: 6px; }
  .target-note-controls { margin-top: 2px; }
  .target-note-display strong { font-size: 3.55rem; }
  .target-live-row { margin-top: 4px; padding-top: 5px; padding-bottom: 5px; }
  .target-lane { height: 34px; margin-top: 7px; }
  .target-hold-block { margin-top: 7px; }
  .target-actions { padding-top: 6px; }
  .target-actions > button { min-height: 38px; }
}


.target-header-actions { display: flex; align-items: center; gap: 8px; }
.target-tools-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(11, 29, 47, .82);
  color: #c6d5e3;
  font-weight: 750;
  cursor: pointer;
}
.target-tools-mobile-head { display: none; }
.target-tools-backdrop { display: none; }

@media (max-width: 760px) {
  .target-controls-card {
    position: fixed;
    z-index: 55;
    left: 10px;
    right: 10px;
    bottom: calc(var(--app-mobile-nav-height, 58px) + 8px);
    width: auto;
    height: auto;
    max-height: calc(100svh - var(--app-mobile-nav-height, 58px) - 28px);
    padding: 14px;
    overflow-y: auto;
    border-radius: 18px;
    transform: translateY(calc(100% + 90px));
    opacity: 0;
    pointer-events: none;
    transition: transform 180ms ease, opacity 150ms ease;
    box-shadow: 0 28px 90px rgba(0,0,0,.55);
  }
  .target-controls-card.mobile-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .target-tools-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
  }
  .target-tools-mobile-head strong { font-size: .88rem; }
  .target-tools-mobile-head button {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--panel-soft);
    color: var(--text);
    font-size: 1.25rem;
  }
  .target-tools-backdrop {
    position: fixed;
    z-index: 54;
    inset: 0;
    display: block;
    background: rgba(0,0,0,.52);
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease;
  }
  .target-tools-backdrop.mobile-open { opacity: 1; pointer-events: auto; }
  body.target-tools-open { overflow: hidden; }
}

/* --------------------------------------------------------------------------
   v0.4.10 · mobile tempo-control refinement
   - Only working tools appear in navigation.
   - Target adds a live approach trace and continuous challenge cues.
   - Metronome uses the centre of the screen as a purposeful beat stage.
   -------------------------------------------------------------------------- */

/* Three live tools only. */
.desktop-nav { gap: 6px; }
.mobile-nav { grid-template-columns: repeat(3, 1fr) !important; }
.mobile-nav-item { font-size: .64rem; }
.mobile-nav-item span { font-size: 1.05rem; }

/* Target: use the previously empty centre area for useful feedback. */
.target-direction-cue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  margin-top: 6px;
  padding: 0 9px;
  border: 1px solid rgba(109, 154, 255, .18);
  border-radius: 999px;
  background: rgba(77, 120, 255, .08);
  color: #9fbaff;
  font-size: .64rem;
  font-weight: 750;
  letter-spacing: .01em;
}

.target-trace-card {
  width: min(720px, 100%);
  margin: 18px auto 0;
  padding: 12px 14px 10px;
  border: 1px solid rgba(161, 192, 220, .11);
  border-radius: 15px;
  background: linear-gradient(180deg, rgba(10, 28, 44, .72), rgba(7, 19, 31, .56));
}

.target-trace-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.target-trace-heading strong {
  display: block;
  margin-top: 3px;
  font-size: .84rem;
}
.target-trace-heading > span {
  padding: 4px 8px;
  border: 1px solid rgba(70, 218, 190, .24);
  border-radius: 999px;
  color: #a7d9d2;
  font-size: .62rem;
}
#targetTraceCanvas {
  display: block;
  width: 100%;
  height: 118px;
  margin-top: 7px;
}
.target-attempt-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 6px;
}
.target-attempt-stats > div {
  min-width: 0;
  padding: 8px 9px;
  border-radius: 10px;
  background: rgba(255,255,255,.025);
  text-align: center;
}
.target-attempt-stats span {
  display: block;
  color: var(--muted-2);
  font-size: .56rem;
}
.target-attempt-stats strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

/* Metronome: a proper visual beat stage rather than a small floating circle. */
.metronome-card-header h1 { font-size: 1.05rem; }
.beat-visual {
  position: relative;
  width: min(720px, 100%);
  margin: 10px auto 0;
  min-height: 190px;
  gap: 12px;
}
.beat-stage {
  position: relative;
  width: min(620px, 94%);
  height: 142px;
  border: 1px solid rgba(161,192,220,.10);
  border-radius: 28px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 100%, rgba(77,120,255,.12), transparent 48%),
    linear-gradient(180deg, rgba(11,28,45,.62), rgba(7,18,29,.35));
}
.beat-stage-line {
  position: absolute;
  left: 9%; right: 9%; top: 50%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(123,153,187,.20) 10%, rgba(123,153,187,.30) 50%, rgba(123,153,187,.20) 90%, transparent);
}
.beat-stage-left,
.beat-stage-right {
  position: absolute;
  top: calc(50% - 3px);
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(128,153,178,.38);
}
.beat-stage-left { left: 9%; }
.beat-stage-right { right: 9%; }
.beat-stage .beat-pulse {
  --beat-position: 50%;
  position: absolute;
  left: var(--beat-position);
  top: 50%;
  width: 96px;
  height: 96px;
  transform: translate(-50%, -50%);
  transition: left 105ms ease, transform 90ms ease, border-color 90ms ease, background 90ms ease, box-shadow 90ms ease;
  box-shadow: 0 0 0 10px rgba(77,120,255,.025), 0 14px 40px rgba(0,0,0,.18);
}
.beat-stage .beat-pulse.hit {
  transform: translate(-50%, -50%) scale(1.07);
  box-shadow: 0 0 0 13px rgba(77,120,255,.06), 0 0 32px rgba(77,120,255,.24);
}
.beat-stage .beat-pulse.accent-hit {
  transform: translate(-50%, -50%) scale(1.09);
  box-shadow: 0 0 0 14px rgba(242,191,99,.07), 0 0 34px rgba(242,191,99,.20);
}
.beat-stage .beat-pulse.silent { transform: translate(-50%, -50%) scale(.94); }

@media (max-width: 760px) {
  .mobile-nav-item { min-width: 0; }

  /* Target remains one-screen on iPhone while gaining a genuinely useful graph. */
  .target-main-card {
    padding: 7px 12px 7px;
  }
  .target-card-header { min-height: 29px; }
  .target-card-header .section-kicker { font-size: .48rem; }
  .target-card-header h2 { font-size: .78rem; }
  .target-header-actions .status-pill { font-size: .52rem; padding: 4px 6px; }
  .target-tools-button { min-height: 30px; padding: 0 10px; font-size: .65rem; }
  .target-note-controls {
    margin-top: 2px;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    gap: 8px;
  }
  .target-step { width: 40px; height: 40px; }
  .target-note-display strong { font-size: clamp(3.3rem, 17vw, 4.3rem); }
  .target-note-display em { font-size: .52rem; }
  .target-direction-cue { min-height: 20px; margin-top: 3px; padding: 0 7px; font-size: .52rem; }
  .target-live-row { margin-top: 4px; padding: 6px 9px; }
  .target-lane { height: 30px; margin-top: 7px; }
  .target-lane-labels { margin-top: 1px; }
  .target-hold-block { margin-top: 5px; }
  .target-progress { height: 6px; }
  .target-trace-card {
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 7px;
    padding: 6px 8px 6px;
    display: grid;
    grid-template-rows: auto minmax(54px, 1fr) auto;
  }
  .target-trace-heading .section-kicker { font-size: .46rem; }
  .target-trace-heading strong { margin-top: 1px; font-size: .64rem; }
  .target-trace-heading > span { padding: 2px 6px; font-size: .50rem; }
  #targetTraceCanvas { height: 100%; min-height: 54px; margin-top: 2px; }
  .target-attempt-stats { gap: 4px; margin-top: 2px; }
  .target-attempt-stats > div { padding: 4px 5px; }
  .target-attempt-stats span { font-size: .46rem; }
  .target-attempt-stats strong { font-size: .64rem; }
  .target-actions { margin-top: 5px; padding-top: 0; }
  .target-actions > button { min-height: 38px; }

  /* The metronome stage flexes into available space and visibly uses it. */
  .metronome-main-card .metronome-card-header { min-height: 30px; }
  .metronome-main-card .metronome-card-header h1 { font-size: .78rem; }
  .metronome-main-card .tempo-control { margin-top: 2px; }
  .metronome-main-card .beat-visual {
    flex: 1 1 auto;
    width: 100%;
    min-height: 110px;
    margin-top: 4px;
    padding: 0;
    gap: 5px;
  }
  .beat-stage {
    width: 100%;
    height: 100%;
    min-height: 88px;
    max-height: 150px;
    border-radius: 20px;
  }
  .beat-stage .beat-pulse {
    width: clamp(66px, 18vw, 82px);
    height: clamp(66px, 18vw, 82px);
  }
  .beat-stage .beat-pulse strong { font-size: 1.9rem; }
  .metronome-main-card .beat-dots { min-height: 10px; gap: 8px; }
}

@media (max-width: 760px) and (max-height: 700px) {
  .target-note-display strong { font-size: 3rem; }
  .target-live-row { padding-top: 4px; padding-bottom: 4px; }
  .target-lane { height: 25px; margin-top: 4px; }
  .target-trace-card { margin-top: 4px; grid-template-rows: auto minmax(38px, 1fr) auto; }
  #targetTraceCanvas { min-height: 38px; }
  .target-attempt-stats > div { padding: 3px; }
  .target-actions > button { min-height: 35px; }
  .beat-stage { min-height: 72px; max-height: 105px; }
  .beat-stage .beat-pulse { width: 58px; height: 58px; }
  .beat-stage .beat-pulse strong { font-size: 1.55rem; }
}

/* v0.4.10 retains v0.4.9 layout corrections and hardens rapid mobile tempo taps. */
.beat-visual {
  grid-template-columns: minmax(0, 1fr);
  justify-items: stretch;
}
.beat-stage {
  justify-self: stretch;
  min-width: 0;
}
.beat-dots { justify-self: center; }

@media (min-width: 761px) and (max-height: 950px) {
  .target-view { height: calc(100vh - 91px); min-height: 0; overflow: hidden; }
  .target-grid { height: 100%; align-items: stretch; }
  .target-main-card { height: 100%; min-height: 0; padding: 12px 18px 12px; overflow: hidden; }
  .target-controls-card { max-height: 100%; overflow: auto; }
  .target-note-controls { margin-top: 8px; }
  .target-note-display strong { font-size: clamp(4.2rem, 7vw, 5.8rem); }
  .target-live-row { margin-top: 8px; padding: 8px 12px; }
  .target-lane { height: 38px; margin-top: 10px; }
  .target-lane-labels { margin-top: 3px; }
  .target-hold-block { margin-top: 8px; }
  .target-trace-card {
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 8px;
    padding: 7px 10px 6px;
    display: grid;
    grid-template-rows: auto minmax(66px, 1fr) auto;
  }
  #targetTraceCanvas { height: 100%; min-height: 66px; margin-top: 3px; }
  .target-attempt-stats > div { padding: 5px 7px; }
  .target-actions { margin-top: 7px; padding-top: 0; }
  .target-actions > button { min-height: 40px; }
}
