@font-face { font-family: 'Geist'; src: url(../fonts/geist-latin.woff2) format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Geist Mono'; src: url(../fonts/geistmono-latin.woff2) format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Instrument Serif'; src: url(../fonts/instrumentserif-0.woff2) format('woff2'); font-display: swap; }

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --hair: rgba(255, 255, 255, .07);
  --hair-2: rgba(255, 255, 255, .13);
  --ink: #ecebe7;
  --ink-2: #a5a39e;
  --muted: #6b6965;
  --accent: #e6dcc0;          /* ivory, from the binding */
  --tune: #8fd6a8;
  --flat: #93aac6;
  --sharp: #d69c7c;
  --serif: 'Instrument Serif', 'Times New Roman', serif;
  --sans: 'Geist', -apple-system, system-ui, sans-serif;
  --mono: 'Geist Mono', ui-monospace, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
body {
  font-family: var(--sans); font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overflow: hidden;
  background: radial-gradient(90% 55% at 50% 78%, #161514 0%, var(--bg) 70%);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.app {
  height: 100dvh; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 10px) 20px 0;
  max-width: 480px; margin: 0 auto; position: relative;
}

/* ---------- header ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; height: 34px; }
.brand { font-family: var(--serif); font-size: 22px; letter-spacing: .005em; color: var(--accent); }

.seg { position: relative; display: flex; padding: 2px; border-radius: 9px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--hair); }
.seg-btn { position: relative; z-index: 1; height: 28px; padding: 0 12px; font-size: 12.5px; font-weight: 500; color: var(--muted); transition: color .25s var(--ease); }
.seg-btn.is-on { color: var(--ink); }
.seg-thumb { position: absolute; top: 2px; bottom: 2px; left: 0; border-radius: 7px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--hair-2);
  transition: transform .35s var(--ease), width .35s var(--ease); }

.controls { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.tuning {
  flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 3px;
  padding: 9px 14px 10px; border-radius: 12px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--hair);
  transition: background .2s;
}
.tuning:active { background: var(--surface-2); }
.tuning-name { display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; color: var(--ink-2); letter-spacing: .01em; }
.tuning-name svg { width: 12px; height: 12px; color: var(--muted); }
.tuning-notes { display: flex; justify-content: space-between; max-width: 230px; font-size: 19px; font-weight: 500; letter-spacing: .01em; line-height: 1.15; }
.tuning-notes span { min-width: 1.1em; }
.tuning-notes sup { font-size: .6em; font-weight: 500; }
.tuning-notes .sh { color: var(--accent); }

.auto { display: flex; align-items: center; gap: 9px; font-size: 12.5px; font-weight: 500; color: var(--muted); padding: 6px 0; }
.switch { width: 38px; height: 23px; border-radius: 12px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--hair-2); position: relative; transition: background .25s var(--ease); }
.knob { position: absolute; top: 2.5px; left: 2.5px; width: 18px; height: 18px; border-radius: 50%; background: #77756f; transition: transform .3s var(--ease), background .25s; }
.auto[aria-pressed="true"] { color: var(--ink); }
.auto[aria-pressed="true"] .switch { background: var(--accent); box-shadow: none; }
.auto[aria-pressed="true"] .knob { transform: translateX(15px); background: #0a0a0a; }

body.chromatic .tuning, body.chromatic .auto { opacity: .3; pointer-events: none; }
.tuning, .auto { transition: opacity .3s var(--ease), background .2s; }

/* ---------- meter ---------- */
.meter { margin-top: 10px; }
.readout { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; height: 62px; }
.side { font-family: var(--serif); font-size: 24px; color: var(--muted); text-align: center; opacity: .45; transition: color .2s, opacity .2s; }
.meter[data-dir="flat"] .flat { color: var(--flat); opacity: 1; }
.meter[data-dir="sharp"] .sharp { color: var(--sharp); opacity: 1; }
.note { justify-self: center; display: flex; align-items: flex-start; font-family: var(--serif); line-height: .85; transition: color .25s, opacity .3s; }
#noteLetter { font-size: 56px; }
.acc { font-size: 26px; margin-left: 1px; }
.oct { align-self: flex-end; font-family: var(--mono); font-size: 11px; color: var(--muted); margin: 0 0 4px 3px; }
.meter.idle .note { opacity: .2; }
.meter.in-tune .note { color: var(--tune); }

/* scale: linear ±50¢ in the middle 80%, compressed "far" zones at the ends */
.scale { position: relative; height: 66px; margin-top: 6px; }
.ticks { position: absolute; top: 30px; bottom: 0; left: 10%; right: 10%; display: flex; justify-content: space-between; align-items: center; }
.ticks i { width: 1px; height: 10px; background: var(--hair-2); }
.ticks i.mid { height: 16px; background: rgba(255,255,255,.24); }
.ticks i.major { height: 22px; background: rgba(255,255,255,.34); }
.ticks i.center { width: 2px; height: 36px; background: var(--accent); }
.far { position: absolute; top: 30px; bottom: 0; width: 9%; display: grid; place-items: center; color: var(--hair-2); transition: color .2s; }
.far svg { width: 16px; height: 16px; }
.far-l { left: 0; } .far-r { right: 0; }
.meter.far-flat .far-l { color: var(--flat); }
.meter.far-sharp .far-r { color: var(--sharp); }
.needle { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; opacity: 0; transition: opacity .25s; will-change: transform; }
.needle::before { content: ''; position: absolute; top: 26px; bottom: -2px; left: -2px; width: 4px; border-radius: 2px; background: var(--needle, var(--ink)); }
.badge { position: absolute; top: 0; left: 0; transform: translateX(-50%); height: 26px; min-width: 52px; padding: 0 9px; border-radius: 13px;
  display: grid; place-items: center; background: var(--needle, var(--ink)); color: #0a0a0a;
  font-family: var(--mono); font-size: 13px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; transition: background .2s; }
.meter.live .needle { opacity: 1; }
.meter[data-dir="flat"] { --needle: var(--flat); }
.meter[data-dir="sharp"] { --needle: var(--sharp); }
.meter.in-tune { --needle: var(--tune); }

.level { height: 2px; margin-top: 10px; border-radius: 1px; background: var(--hair); overflow: hidden; }
.level i { display: block; height: 100%; background: var(--ink-2); transform-origin: left; transform: scaleX(0); opacity: .6; }
.stats { display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; margin-top: 10px; font-variant-numeric: tabular-nums; }
.cents, .hz { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.hz { text-align: right; }
.hint { font-size: 14px; font-weight: 600; color: var(--ink-2); transition: color .2s; }
.meter.in-tune .hint { color: var(--tune); }

/* ---------- neck ---------- */
.neck { flex: 1; min-height: 0; position: relative; margin: 4px -12px 0; overflow: hidden; container-type: size; }
.stage { position: relative; margin: 0 auto; width: min(100cqw, calc(100cqh * 440 / 540)); aspect-ratio: 440 / 560; }
.headstock { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible;
  -webkit-mask-image: linear-gradient(180deg, #000 80%, transparent 99%); mask-image: linear-gradient(180deg, #000 80%, transparent 99%); }
.string-glow { stroke: transparent; transition: stroke .25s; }
.string.active .string-glow { stroke: rgba(230, 220, 192, .07); }
.string.active.done .string-glow { stroke: rgba(143, 214, 168, .09); }
.string.active .string-core { filter: drop-shadow(0 0 1.5px rgba(255,255,255,.35)); }
@keyframes ring { from { transform: translateX(-.5px); } to { transform: translateX(.5px); } }
.string.ringing .string-core { animation: ring .06s linear infinite alternate; }

.peg {
  position: absolute; width: 11.4%; min-width: 42px; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--hair-2);
  font-size: 18px; font-weight: 500; color: var(--ink);
  transition: box-shadow .25s var(--ease), color .25s, background .25s, transform .15s var(--ease);
}
.peg:active { transform: translate(-50%, -50%) scale(.94); }
.peg sup { font-size: .6em; }
.peg.active { background: var(--accent); color: #0a0a0a; box-shadow: none; }
.peg.done { color: var(--tune); box-shadow: inset 0 0 0 1px rgba(143,214,168,.5); }
.peg.active.done { background: var(--tune); color: #0a0a0a; box-shadow: none; }
.peg.done::after { content: ''; position: absolute; right: 2px; top: 2px; width: 7px; height: 7px; border-radius: 50%; background: var(--tune); box-shadow: 0 0 0 2px var(--bg); }
.peg.active.done::after { display: none; }
body.chromatic .peg { opacity: .45; }

/* ---------- start ---------- */
.start { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 22px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 20px 0 16px; border-radius: 23px; white-space: nowrap;
  background: var(--accent); color: #0a0a0a; font-size: 14.5px; font-weight: 600; z-index: 5;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.9);
  transition: opacity .35s var(--ease), transform .35s var(--ease); }
.start svg { width: 18px; height: 18px; }
body.listening .start { opacity: 0; transform: translate(-50%, 12px); pointer-events: none; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .3s var(--ease); }
.sheet { position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; height: calc(100dvh - var(--safe-t) - 24px);
  display: flex; flex-direction: column; border-radius: 18px 18px 0 0; background: #101010; box-shadow: inset 0 1px 0 var(--hair-2);
  transform: translateY(101%); transition: transform .42s var(--ease); }
body.sheet-open .sheet { transform: none; }
body.sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--hair-2); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 20px 0; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.sheet-close { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); background: var(--surface-2); }
.sheet-close svg { width: 18px; height: 18px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 14px 20px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 30px; padding: 0 12px; border-radius: 15px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); background: var(--surface); box-shadow: inset 0 0 0 1px var(--hair);
  transition: background .2s, color .2s; }
.chip.is-on { color: #0a0a0a; background: var(--accent); box-shadow: none; }

.legend { margin: 12px 20px 4px; font-size: 11.5px; color: var(--muted); }
.legend .up { color: var(--accent); }
.legend .down { color: var(--flat); margin: 0 6px 0 1px; }

.list { flex: 1; overflow-y: auto; padding: 6px 12px 16px; -webkit-overflow-scrolling: touch; }
.card { width: 100%; text-align: left; display: block; padding: 14px 14px 12px; border-radius: 14px; margin-bottom: 8px;
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--hair); transition: box-shadow .2s, transform .15s var(--ease); }
.card:active { transform: scale(.99); }
.card.is-on { box-shadow: inset 0 0 0 1.5px var(--accent); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-name { font-size: 15.5px; font-weight: 600; letter-spacing: -.005em; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 45%; }
.card-tags span { font-size: 10.5px; font-weight: 500; color: var(--ink-2); padding: 3px 7px; border-radius: 5px; background: var(--surface-2); }
.strings6 { display: grid; grid-template-columns: repeat(6, 1fr); margin-top: 12px; }
.s6 { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.s6-n { font-size: 20px; font-weight: 500; line-height: 1.2; }
.s6-n sup { font-size: .6em; }
.s6-d { height: 14px; font-family: var(--mono); font-size: 10.5px; display: flex; align-items: center; }
.s6-d.up { color: var(--accent); }
.s6-d.down { color: var(--flat); }
.s6-d.same::before { content: ''; width: 3px; height: 3px; border-radius: 50%; background: var(--hair-2); }

.calib { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px calc(var(--safe-b) + 12px); box-shadow: inset 0 1px 0 var(--hair); }
.calib-title { font-size: 13px; font-weight: 500; }
.calib-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stepper { display: flex; align-items: center; background: var(--surface); border-radius: 10px; box-shadow: inset 0 0 0 1px var(--hair); }
.stepper button { width: 36px; height: 34px; font-size: 17px; color: var(--ink-2); }
.stepper button:active { color: var(--ink); }
.a4 { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.a4 output { color: var(--ink); font-size: 13px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (max-height: 700px) {
  .readout { height: 52px; }
  #noteLetter { font-size: 46px; }
  .meter { margin-top: 8px; }
}
