/* Layout: one column — top bar, title with the instrument switch, the gauge card with the big note, the start button, then the strings and the A4 calibration */
:root {
  --bg: #17110e;
  --surface: #241a15;
  --surface-2: #2f231c;
  --line: #4a3a30;
  --accent: #ff6b2c;
  --accent-text: #ff8a55;
  --accent-deep: #b8461c;
  --on-accent: #17110e;
  --focus: #ffbd4a;
  --text: #f7ede1;
  --muted: #b5a191;
  --bust: #c0392b;
  --on-bust: #ffffff;
  --danger-text: #ff9a8f;
  --glow: rgba(255, 107, 44, .16);
  --scrim: rgba(8, 5, 4, .6);
  --shadow: rgba(0, 0, 0, .5);
  --toast-bg: #f3e7cf;
  --toast-ink: #2b1d14;
  --switch-off: #4a3a30;
  --switch-knob: #f7ede1;
  --good: #8ee08a;
  --on-good: #10200f;
  --good-glow: rgba(142, 224, 138, .32);
  --needle: #ffbd4a;
  --zone-off: rgba(255, 237, 214, .07);
  --track: #5e4a3d;
  --tick: #b5a191;
  --cat-fur: #f0a35e;
  --cat-line: #5a3524;
  --cat-ear: #f2a7a0;
  --cat-eye: #8fe3b0;
  --display: 'Bagel Fat One', 'Arial Black', system-ui, sans-serif;
  --body: 'Rethink Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --digits: var(--display);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; }
body {
  margin: 0; min-height: 100vh; overflow-x: hidden;
  background: radial-gradient(130% 55% at 50% 105%, var(--glow), transparent 62%), var(--bg);
  color: var(--text); font-family: var(--body); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.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 {
  max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
}

/* ---------- buttons and controls ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 52px; padding: 0 18px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 17px;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .6; cursor: default; transform: none; }
.btn svg { flex: none; width: 20px; height: 20px; }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 3px 0 var(--accent-deep); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn.bust { background: var(--bust); color: var(--on-bust); }
.btn.big { min-height: 64px; font-family: var(--display); font-weight: 400; font-size: 24px; }
.btn.big svg { width: 24px; height: 24px; }
.icon-btn { appearance: none; flex: none; width: 46px; height: 46px; border-radius: 14px; cursor: pointer; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.segmented { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 13px; background: var(--bg); max-width: 100%; }
.segmented button { appearance: none; border: 0; cursor: pointer; min-height: 44px; padding: 0 12px; border-radius: 10px; background: none; color: var(--muted); font-weight: 700; font-size: 15px; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.segmented.wrap { display: flex; flex-wrap: wrap; width: 100%; }
.segmented.wrap button { flex: 1 1 calc(50% - 2px); min-width: 0; padding: 0 6px; }
.mode-switch { display: flex; width: 100%; background: var(--surface); }
.mode-switch button { flex: 1 1 auto; min-width: 0; padding: 0 8px; font-size: 15px; }
.stepper { display: flex; align-items: center; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg); }
.stepper button { appearance: none; width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 24px; font-weight: 700; cursor: pointer; }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper output { min-width: 82px; text-align: center; font-family: var(--digits); font-size: 22px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.switch { position: relative; flex: none; width: 52px; height: 32px; border-radius: 999px; background: var(--switch-off); transition: background-color .2s ease; }
.switch::after { content: ''; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--switch-knob); box-shadow: 0 2px 4px var(--shadow); transition: translate .2s ease; }
[aria-checked="true"] > .switch { background: var(--accent); }
[aria-checked="true"] > .switch::after { translate: 20px 0; }
.chip { appearance: none; cursor: pointer; min-height: 44px; min-width: 64px; padding: 0 16px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface-2); color: var(--text); font-weight: 800; font-size: 15px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- top ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; }
.top-actions { display: flex; gap: 8px; flex: none; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--muted); font-weight: 700; text-decoration: none; }
.hero { display: grid; gap: 12px; }
.hero h1 { font-family: var(--display); font-weight: 400; font-size: clamp(40px, 12vw, 56px); line-height: 1; }
.box { background: var(--surface); border-radius: 18px; padding: 14px; display: grid; gap: 12px; min-width: 0; }
.box h2 { font-size: 17px; font-weight: 800; padding-left: 2px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 14.5px; font-weight: 600; }
.count-text { display: grid; gap: 2px; min-width: 0; }
.mode-hint { color: var(--muted); font-size: 14.5px; padding: 0 2px; text-align: center; }

/* ---------- tuner card ---------- */
.tuner-card {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 14px 14px 16px; border-radius: 26px; min-width: 0;
  background: radial-gradient(80% 60% at 50% 30%, var(--glow), transparent 70%), var(--surface);
  transition: box-shadow .35s ease;
}
.tuner-card.in-tune { box-shadow: inset 0 0 0 3px var(--good), 0 0 36px var(--good-glow); }
.gauge-wrap { position: relative; width: 100%; max-width: 360px; }
.gauge { display: block; width: 100%; height: auto; overflow: visible; }
.gauge .track { fill: none; stroke: var(--track); stroke-width: 4; stroke-linecap: round; }
.gauge .zone-flat, .gauge .zone-sharp { fill: none; stroke: var(--zone-off); stroke-width: 14; }
.gauge .zone-good { fill: none; stroke: var(--good); stroke-width: 14; opacity: .45; transition: opacity .3s ease; }
.in-tune .gauge .zone-good { opacity: 1; }
.gauge .tick { stroke: var(--tick); stroke-width: 2; stroke-linecap: round; }
.gauge .tick.major { stroke: var(--text); stroke-width: 3; }
.gauge .tick-label { fill: var(--muted); font-family: var(--body); font-weight: 700; font-size: 14px; }
.gauge .needle { transform-box: view-box; transform-origin: 150px 160px; }
.gauge .needle-line { stroke: var(--needle); stroke-width: 5; stroke-linecap: round; }
.gauge .needle-tip { fill: var(--needle); }
.gauge .pivot { fill: var(--needle); stroke: var(--surface); stroke-width: 4; }
.tuner-card:not(.live) .needle-line, .tuner-card:not(.live) .needle-tip { opacity: .35; }
.tuner-card.live .needle { transition: transform .12s linear; }
.in-tune .gauge .needle-line, .in-tune .gauge .needle-tip, .in-tune .gauge .pivot { fill: var(--good); stroke: var(--good); }
.in-tune .gauge .pivot { stroke: var(--surface); }
.gauge-cat .cat-head { fill: var(--cat-fur); stroke: var(--cat-line); stroke-width: 2; stroke-linejoin: round; }
.gauge-cat .cat-ear { fill: var(--cat-ear); }
.gauge-cat .cat-eye { fill: var(--cat-eye); }
.gauge-cat .cat-pupil { fill: #1a1210; }
.gauge-cat .cat-nose { fill: #e8848a; }
.gauge-cat .cat-whisker { stroke: var(--cat-line); stroke-width: 1.6; stroke-linecap: round; fill: none; opacity: .8; }
.in-tune .gauge-cat .cat-pupil { ry: 1.2; rx: 2.4; }

.note {
  margin-top: 2px; text-align: center; white-space: nowrap; font-family: var(--display); font-weight: 400; line-height: 1;
  font-size: clamp(88px, 28vw, 128px); font-variant-numeric: tabular-nums; color: var(--text); transition: color .25s ease;
}
.note sub { font-family: var(--body); font-weight: 800; font-size: .3em; vertical-align: baseline; margin-left: .04em; color: var(--muted); }
.tuner-card:not(.live) .note { color: var(--muted); font-family: var(--body); font-weight: 300; }
.in-tune .note { color: var(--good); }
.dir {
  position: absolute; bottom: 0; display: inline-flex; align-items: center; gap: 2px; min-height: 36px; padding: 0 10px; border-radius: 999px;
  color: var(--muted); font-weight: 800; font-size: 14px; white-space: nowrap; transition: background-color .15s ease, color .15s ease;
}
.dir svg { flex: none; width: 18px; height: 18px; }
.dir-flat { left: 0; padding-left: 4px; }
.dir-sharp { right: 0; padding-right: 4px; }
.dir.on { background: var(--accent); color: var(--on-accent); }
.tuner-card:not(.live) .readouts { visibility: hidden; }
.readouts { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; column-gap: 14px; row-gap: 2px; }
.cents { color: var(--muted); font-weight: 700; font-size: 16px; }
.cents b { font-family: var(--digits); font-weight: 400; font-size: 40px; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.in-tune .cents b { color: var(--good); }
.hz { color: var(--muted); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.status { min-height: 1.4em; margin-top: 4px; text-align: center; color: var(--muted); font-weight: 700; font-size: 16px; }
.live .status { color: var(--text); }
.in-tune .status { color: var(--good); font-size: 19px; font-weight: 800; }
.listening:not(.live) .status { animation: breathe 2.4s ease-in-out infinite; }

/* ---------- mic, strings, calibration ---------- */
.mic-area { display: grid; gap: 10px; }
.stop-btn { border-color: var(--accent); }
.alert {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 16px;
  background: var(--surface); border: 2px solid var(--danger-text); color: var(--text); font-size: 15px;
}
.alert svg { flex: none; width: 24px; height: 24px; color: var(--danger-text); margin-top: 1px; }
.alert-title { font-weight: 800; font-size: 17px; margin-bottom: 2px; }
.alert p:not(.alert-title) { color: var(--muted); }
.strings { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.strings.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.strings.n5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.string-btn {
  appearance: none; cursor: pointer; min-width: 0; min-height: 60px; padding: 6px 2px; border-radius: 14px;
  display: flex; align-items: baseline; justify-content: center; gap: 1px;
  border: 2px solid var(--line); background: var(--surface-2); color: var(--text);
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.string-name { font-family: var(--display); font-size: 24px; line-height: 1; }
.string-oct { font-weight: 800; font-size: 13px; color: var(--muted); }
.string-btn.hit { border-color: var(--accent); }
.string-btn.locked { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.string-btn.locked .string-oct { color: var(--on-accent); }
.string-btn.good { border-color: var(--good); background: var(--good); color: var(--on-good); }
.string-btn.good .string-oct { color: var(--on-good); }

/* ---------- sheets, modal, toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--scrim); animation: fade .2s ease; }
.sheet {
  position: fixed; z-index: 21; bottom: 0; left: 50%; translate: -50% 0; width: min(100%, 560px); max-height: 86%; overflow-y: auto;
  border-radius: 22px 22px 0 0; background: var(--surface); display: grid; gap: 14px;
  padding-top: 10px; padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px var(--shadow); animation: rise .25s cubic-bezier(.2, .9, .3, 1);
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); justify-self: center; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h3 { font-family: var(--display); font-weight: 400; font-size: 24px; }
.close-btn { appearance: none; border: 0; width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.close-btn svg { width: 18px; height: 18px; }
.menu-list { display: grid; gap: 6px; }
.menu-list:empty { display: none; }
.menu-item {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 54px; padding: 8px 14px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); text-align: left; font-weight: 700; font-size: 16.5px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.menu-item.static { cursor: default; }
.menu-item[role="switch"] { flex-wrap: nowrap; }
.menu-sub { display: block; color: var(--muted); font-size: 14px; font-weight: 600; }
.menu-item.home { color: var(--accent-text); }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--scrim); animation: fade .2s ease; }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; translate: -50% -50%; width: min(calc(100% - 48px), 360px);
  padding: 20px; border-radius: 20px; background: var(--surface); box-shadow: 0 20px 60px var(--shadow);
  display: grid; gap: 10px; animation: pop .2s ease;
}
.modal h3 { font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.1; }
.modal p { color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.modal-actions .btn { min-height: 48px; font-size: 16px; padding: 0 10px; }
.toast {
  position: fixed; z-index: 30; left: 50%; translate: -50% 0; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 32px), 528px); display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 16px; background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: 0 12px 30px var(--shadow); font-weight: 600; font-size: 15px; min-height: 52px;
}
.toast span { flex: 1; min-width: 0; }

@keyframes breathe { 50% { opacity: .55; } }
@keyframes rise { from { translate: -50% 30px; opacity: 0; } to { translate: -50% 0; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; scale: .95; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
