:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-2: #121a33;
  --card: rgba(255, 255, 255, .045);
  --border: rgba(255, 255, 255, .08);
  --text: #e8ecf5;
  --muted: #8a93a8;
  --accent: #7c9cff;
  --ok: #34d399;
  /* Set by app.js: 140 (in tune, green) down to 0 (far off, red). */
  --tune-h: 140;
  --tune: hsl(var(--tune-h) 75% 60%);
  --radius: 20px;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

/* Feel like a native app, especially when launched from the iOS home screen. */
html {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

body {
  background:
    radial-gradient(120% 60% at 50% -10%, #1d2a55 0%, transparent 60%),
    linear-gradient(var(--bg), var(--bg-2));
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .15em; }

.app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header */
.top { text-align: center; padding-top: 4px; }
.top h1 { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

/* Meter */
.meter {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 8px);
  padding: 18px 12px 20px;
  overflow: hidden;
  isolation: isolate;
}
.meter::before {
  content: "";
  position: absolute;
  inset: 30% 15% auto;
  height: 70%;
  background: radial-gradient(closest-side, var(--tune), transparent);
  opacity: 0;
  filter: blur(30px);
  transition: opacity .3s, background .3s;
  z-index: -1;
}
[data-state="listening"] .meter::before { opacity: .18; }
[data-state="intune"] .meter::before { opacity: .45; }

.gauge { display: block; width: 100%; height: auto; }
.gauge .arc { opacity: .35; transition: opacity .3s; }
[data-state="listening"] .gauge .arc,
[data-state="intune"] .gauge .arc { opacity: .85; }
.gauge .tick { stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round; opacity: .55; }
.gauge .tick.major { stroke: var(--text); stroke-width: 2.5; opacity: .8; }
.gauge .tick-label { fill: var(--muted); font-size: 10px; text-anchor: middle; font-family: ui-monospace, Menlo, monospace; }

.needle {
  transform-box: view-box;
  transform-origin: 150px 160px;
  stroke: var(--tune);
  fill: var(--tune);
  transition: stroke .2s, fill .2s;
  filter: drop-shadow(0 0 6px hsl(var(--tune-h) 75% 60% / .6));
}
[data-state="idle"] .needle,
[data-state="silent"] .needle { stroke: var(--muted); fill: var(--muted); filter: none; }

.readout { text-align: center; margin-top: -8px; }
.note {
  font-size: clamp(4.5rem, 24vw, 6.5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  color: var(--text);
  transition: color .2s, transform .2s, text-shadow .2s;
}
[data-state="listening"] .note,
[data-state="intune"] .note { color: var(--tune); }
[data-state="intune"] .note { transform: scale(1.06); text-shadow: 0 0 28px hsl(var(--tune-h) 75% 60% / .55); }

.details {
  margin-top: 6px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: .95rem;
  display: flex;
  justify-content: center;
  gap: 8px;
}
.hint {
  margin: 12px 0 0;
  min-height: 1.4em;
  font-size: 1rem;
  font-weight: 500;
}
[data-state="intune"] .hint { color: var(--ok); }

/* Strings */
.strings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}
.strings-head h2 {
  margin: 0;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}

.string-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.string {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 4px 12px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s, background .2s, border-color .2s, box-shadow .2s;
}
.string:active { transform: scale(.96); }
.string .letter { font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.string .label { font-size: .72rem; color: var(--muted); }
/* The "string" itself: a thin line that vibrates while this string is heard. */
.string .wire {
  width: 2px;
  height: 22px;
  margin: 6px 0 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: .35;
}
.string[aria-checked="true"] {
  background: rgba(124, 156, 255, .14);
  border-color: var(--accent);
  box-shadow: 0 6px 24px -10px var(--accent);
}
.string[aria-checked="true"] .wire { opacity: .9; color: var(--accent); }
.string.ringing .wire { animation: vibrate .07s linear infinite alternate; }
.string.tuned::before,
.string.tuned::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  animation: pop .35s cubic-bezier(.3, 1.6, .5, 1);
}
.string.tuned::before { width: 16px; height: 16px; border-radius: 50%; background: var(--ok); }
/* Checkmark drawn with borders (CSP blocks data: images). */
.string.tuned::after {
  top: 11px;
  right: 13px;
  width: 5px;
  height: 8px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  rotate: 45deg;
}

@keyframes vibrate {
  from { transform: translateX(-1.5px); }
  to { transform: translateX(1.5px); }
}
@keyframes pop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 40px;
  height: 24px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .12);
  position: relative;
  transition: background .2s;
}
.switch .thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Actions */
.actions {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 16px;
  border: 0;
  border-radius: 18px;
  font-weight: 650;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .15s, background .2s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn.primary {
  background: linear-gradient(135deg, #7c9cff, #a78bfa);
  color: #0b1020;
  box-shadow: 0 10px 30px -12px #7c9cff;
}
.btn.secondary { background: var(--card); border: 1px solid var(--border); }
.btn.playing { background: rgba(124, 156, 255, .2); }
.app:not([data-state="idle"]) .btn.primary {
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  box-shadow: none;
}
.btn:focus-visible, .string:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Input level */
.level {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .06);
  overflow: hidden;
}
.level span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .08s linear;
}

/* iOS "Add to Home Screen" hint */
.install {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 456px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px 12px 16px;
  border-radius: 16px;
  background: rgba(30, 40, 75, .92);
  border: 1px solid var(--border);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px -12px rgba(0, 0, 0, .6);
  font-size: .9rem;
  line-height: 1.4;
  animation: slide-up .4s cubic-bezier(.2, .9, .3, 1);
}
.install[hidden] { display: none; }
.install p { margin: 0; flex: 1; }
.install svg {
  width: 18px;
  height: 18px;
  vertical-align: -3px;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.install button {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
}

@keyframes slide-up {
  from { transform: translateY(120%); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (min-width: 600px) {
  .app { padding-top: 40px; gap: 22px; }
}

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

/* Keep the action buttons reachable above the install hint. */
.app:has(.install:not([hidden])) { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
