:root {
  color-scheme: dark;
  --bg: #090d12;
  --surface: #111820;
  --surface-2: #17212b;
  --line: #263442;
  --text: #f3f7fa;
  --muted: #8fa0ad;
  --cyan: #44d7d0;
  --amber: #ffba49;
  --danger: #ff6b61;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  /* Disable double-tap zoom for repeated taps while retaining pinch zoom. */
  touch-action: manipulation;
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 5%, rgba(68, 215, 208, .11), transparent 27rem),
    radial-gradient(circle at 90% 90%, rgba(255, 186, 73, .08), transparent 25rem),
    var(--bg);
}
button, input, select { font: inherit; }
button, select { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 680px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.eyebrow { margin: 0 0 .25rem; color: var(--cyan); font-size: .75rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(1.45rem, 6vw, 2rem); line-height: 1.1; letter-spacing: -.035em; }
h1 span { color: var(--muted); font-weight: 400; }
.status-pill { display: flex; align-items: center; gap: .45rem; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .78rem; white-space: nowrap; }
.status-pill span { width: .45rem; height: .45rem; border-radius: 50%; background: var(--muted); }
.status-pill.live { color: var(--cyan); border-color: rgba(68, 215, 208, .35); }
.status-pill.live span { background: var(--cyan); box-shadow: 0 0 0 .25rem rgba(68, 215, 208, .12); }

.mode-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; padding: .3rem; margin-bottom: 1rem; border: 1px solid var(--line); border-radius: 1rem; background: rgba(17, 24, 32, .82); }
.tab { min-height: 3rem; border: 0; border-radius: .72rem; color: var(--muted); background: transparent; font-weight: 750; cursor: pointer; }
.tab.active { color: var(--text); background: var(--surface-2); box-shadow: 0 1px 6px rgba(0, 0, 0, .35); }
.panel { animation: rise .24s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.tuner-card, .metronome-card { padding: clamp(1rem, 4vw, 1.6rem); border: 1px solid var(--line); border-radius: 1.35rem; background: linear-gradient(155deg, rgba(23, 33, 43, .96), rgba(13, 19, 26, .98)); box-shadow: 0 22px 60px rgba(0, 0, 0, .28); }
.reference-row, .signature-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: .9rem; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: .7rem; overflow: hidden; background: var(--bg); }
.stepper button { width: 2.6rem; height: 2.35rem; border: 0; color: var(--text); background: transparent; font-size: 1.25rem; cursor: pointer; }
.stepper output { min-width: 6rem; text-align: center; color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }

.meter { position: relative; height: clamp(20rem, 62vh, 27rem); margin: 1rem 0; overflow: hidden; border: 1px solid var(--line); border-radius: 1.1rem; background: linear-gradient(180deg, rgba(5, 9, 13, .68), rgba(13, 19, 26, .9)); }
.meter::before { content: ""; position: absolute; left: 50%; top: 2.8rem; bottom: 1rem; width: 1px; background: linear-gradient(var(--cyan), transparent); opacity: .3; }
.meter-scale { position: absolute; z-index: 2; top: 1.15rem; left: 1rem; right: 1rem; display: flex; justify-content: space-between; color: #71818e; font-size: .7rem; font-variant-numeric: tabular-nums; }
.ticks { position: absolute; top: 2.3rem; left: 1rem; right: 1rem; height: 1.6rem; opacity: .65; background: repeating-linear-gradient(90deg, #61717d 0 1px, transparent 1px 5%); }
.target-band { position: absolute; top: 2.1rem; left: calc(50% - 4%); width: 8%; height: 2rem; border-radius: .25rem; background: rgba(68, 215, 208, .1); border-top: 2px solid var(--cyan); }
.needle { position: absolute; z-index: 3; top: 2.05rem; left: 50%; width: 3px; height: 2.4rem; border-radius: 2px; background: var(--amber); box-shadow: 0 0 14px rgba(255, 186, 73, .8); transform: translateX(-50%); transition: left 90ms linear, background-color .16s; }
.needle.tuned { background: var(--cyan); box-shadow: 0 0 14px rgba(68, 215, 208, .85); }
.note-wrap { position: absolute; top: 29%; left: 0; right: 0; display: flex; align-items: flex-start; justify-content: center; }
.note { font-size: clamp(7rem, 34vw, 12rem); line-height: .8; font-weight: 800; letter-spacing: -.09em; font-variant-numeric: tabular-nums; }
.octave { min-width: 2rem; margin: .25rem 0 0 .5rem; color: var(--muted); font-size: clamp(1.6rem, 7vw, 2.4rem); font-weight: 650; }
.cents { position: absolute; left: 0; right: 0; bottom: 4rem; text-align: center; color: var(--amber); font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cents.tuned { color: var(--cyan); }
.frequency { position: absolute; left: 0; right: 0; bottom: 1.7rem; text-align: center; color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; }

.primary-button { width: 100%; min-height: 3.65rem; display: flex; align-items: center; justify-content: center; gap: .75rem; border: 0; border-radius: .95rem; background: var(--cyan); color: #041211; font-weight: 850; cursor: pointer; box-shadow: 0 10px 24px rgba(68, 215, 208, .15); }
.primary-button:active { transform: translateY(1px); }
.primary-button.running { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.mic-icon { position: relative; width: .78rem; height: 1.25rem; border: 2px solid currentColor; border-radius: .5rem; }
.mic-icon::after { content: ""; position: absolute; left: -.38rem; right: -.38rem; bottom: -.45rem; height: .65rem; border: 2px solid currentColor; border-top: 0; border-radius: 0 0 .8rem .8rem; }
.privacy-note { margin: .8rem 0 0; color: var(--muted); text-align: center; font-size: .78rem; }

.tempo-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; }
.tempo-label { margin: 0 0 .2rem; color: var(--muted); font-size: .85rem; }
.tempo-value { display: flex; align-items: baseline; gap: .5rem; }
.tempo-value input { width: 3.2ch; min-width: 0; padding: 0; border: 0; border-bottom: 1px dashed var(--line); border-radius: 0; background: transparent; color: var(--text); font-size: clamp(4.2rem, 22vw, 7rem); line-height: 1; font-weight: 800; letter-spacing: -.07em; font-variant-numeric: tabular-nums; appearance: textfield; -moz-appearance: textfield; }
.tempo-value input::-webkit-inner-spin-button, .tempo-value input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.tempo-value span { color: var(--muted); font-size: .85rem; font-weight: 700; }
.tempo-name { margin-top: 1rem; padding: .45rem .65rem; border: 1px solid rgba(255, 186, 73, .3); border-radius: 999px; color: var(--amber); font-size: .8rem; }
.tempo-slider { width: 100%; height: 1.6rem; margin: 0; accent-color: var(--amber); cursor: pointer; }
.slider-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; }
.tempo-controls { display: grid; grid-template-columns: 3.2rem 1fr 3.2rem; gap: .7rem; margin: 1.7rem 0; }
.square-button, .tap-button { min-height: 3.2rem; border: 1px solid var(--line); border-radius: .8rem; color: var(--text); background: var(--bg); cursor: pointer; }
.square-button { font-size: 1.5rem; }
.tap-button { font-weight: 750; }
.signature-row { padding: 1rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.signature-row select { min-height: 2.6rem; padding: 0 2.2rem 0 .85rem; border: 1px solid var(--line); border-radius: .65rem; color: var(--text); background: var(--bg); }
.beat-dots { display: flex; align-items: center; justify-content: center; gap: 1rem; min-height: 6.5rem; }
.beat-dot { width: .75rem; height: .75rem; border: 2px solid #586875; border-radius: 50%; transition: transform .06s, background-color .06s; }
.beat-dot.active { transform: scale(1.45); border-color: var(--cyan); background: var(--cyan); box-shadow: 0 0 16px rgba(68, 215, 208, .55); }
.beat-dot.accent.active { border-color: var(--amber); background: var(--amber); box-shadow: 0 0 16px rgba(255, 186, 73, .55); }
.play-icon { width: 0; height: 0; border-top: .48rem solid transparent; border-bottom: .48rem solid transparent; border-left: .72rem solid currentColor; }
.running .play-icon { width: .75rem; height: .75rem; border: 0; background: currentColor; }

button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(68, 215, 208, .5); outline-offset: 2px; }
@media (min-width: 560px) {
  .app-shell { padding-top: 2rem; }
  .meter { height: 27rem; }
}
@media (max-width: 559px) {
  .app-shell {
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: .65rem;
    padding: max(.65rem, env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) max(.65rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
  }
  .topbar { margin: 0; gap: .5rem; flex-shrink: 0; }
  .topbar > div:first-child { min-width: 0; }
  h1 { font-size: clamp(1.15rem, 5vw, 1.5rem); }
  .eyebrow { display: none; }
  .status-pill { padding: .4rem .5rem; }
  .mode-tabs { margin: 0; flex-shrink: 0; }
  .tab { min-height: 2.75rem; }
  .panel:not([hidden]) { display: flex; flex: 1; min-height: min-content; }
  .tuner-card, .metronome-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: .8rem;
    box-shadow: none;
  }
  .tuner-card > :not(.meter), .metronome-card > :not(.beat-dots) { flex-shrink: 0; }
  .reference-row { gap: .5rem; }
  .stepper button { height: 2.75rem; }
  .stepper output { min-width: 5.4rem; }
  .meter { flex: 1; height: auto; min-height: 12rem; margin: .65rem 0; }
  .note-wrap { top: 4.5rem; bottom: 3.7rem; align-items: center; }
  .note { font-size: clamp(3.5rem, 15dvh, 8rem); }
  .octave { font-size: 1.6rem; }
  .cents { bottom: 2.3rem; }
  .frequency { bottom: .8rem; padding: 0 .3rem; }
  .primary-button { min-height: 3rem; }
  .privacy-note { margin-top: .5rem; line-height: 1.3; }
  .tempo-header { margin-bottom: .65rem; }
  .tempo-value input { font-size: clamp(3.5rem, 12dvh, 6rem); }
  .tempo-controls { margin: .75rem 0; }
  .signature-row { padding: .65rem 0; }
  .beat-dots { flex: 1; min-height: 2.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
