:root {
  --bg: #f7f6f3;
  --fg: #1a1a19;
  --muted: #8a8984;
  --line: #dddcd7;
  --chip: #ecebe6;
  --good: #1f9d55;
  --off: #d9822b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --fg: #ededea;
    --muted: #7c7b76;
    --line: #2b2b29;
    --chip: #1d1d1b;
    --good: #3ecf7a;
    --off: #f0a04b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 ui-sans-serif, -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  min-height: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 28px;
}

header { display: flex; justify-content: space-between; align-items: center; }
[hidden] { display: none !important; }

.tabs { display: inline-flex; background: var(--chip); border-radius: 10px; padding: 3px; }
.tabs button {
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--fg); background: var(--bg); font-weight: 500; }

.view { flex: 1; display: flex; flex-direction: column; gap: 28px; }
select {
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--chip);
  border: 0;
  border-radius: 8px;
  padding: 6px 10px;
}

.readout { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.note {
  font-size: clamp(96px, 34vw, 148px);
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}
.note sub { font-size: .28em; color: var(--muted); vertical-align: baseline; margin-left: 2px; }
.hz, .cents { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; min-height: 1.4em; }
.hz { margin-top: 8px; }

.meter { position: relative; width: 100%; height: 44px; margin: 28px 0 8px; }
.ticks {
  position: absolute; inset: 14px 0;
  background: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px calc(10% - 0.1px));
  border-right: 1px solid var(--line);
}
.center { position: absolute; left: 50%; top: 4px; bottom: 4px; width: 2px; margin-left: -1px; background: var(--muted); border-radius: 1px; }
.needle {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 4px; margin-left: -2px;
  border-radius: 2px;
  background: var(--fg);
  opacity: 0;
  transform: translateX(0);
  transition: transform .12s linear, background .2s, opacity .3s;
}

body.active .needle { opacity: 1; }
body.in-tune .note, body.in-tune .cents { color: var(--good); }
body.in-tune .needle { background: var(--good); }
body.out .needle { background: var(--off); }
body.idle .note { color: var(--muted); }

.level { width: 72px; height: 3px; margin-top: 14px; border-radius: 2px; background: var(--line); overflow: hidden; }
.level i { display: block; height: 100%; background: var(--muted); transform: scaleX(0); transform-origin: left; }
.debug { margin: -16px 0 0; font: 11px/1.4 ui-monospace, Menlo, monospace; color: var(--muted); white-space: pre-wrap; text-align: center; }

.strings { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.strings button {
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  background: var(--chip);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 0 10px;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.strings button small { display: block; font-size: 10px; color: var(--muted); }
.strings button.target { border-color: var(--fg); }
body.in-tune .strings button.target { border-color: var(--good); color: var(--good); }
.strings button.playing { background: var(--line); }

.primary, .secondary {
  font: inherit;
  font-weight: 500;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  touch-action: manipulation;
}
.primary { color: var(--bg); background: var(--fg); }
.secondary { color: var(--fg); background: var(--chip); }
.hint { margin: -12px 0 0; text-align: center; color: var(--muted); font-size: 13px; min-height: 1.4em; }

/* ---- Metronome ---------------------------------------------------------- */
.tempo { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.bpm {
  font-size: clamp(96px, 34vw, 148px);
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.bpm small { font-size: 14px; color: var(--muted); margin-left: 6px; letter-spacing: .06em; }
.tempo-name { margin-top: 8px; color: var(--muted); font-size: 14px; }

.beats { display: flex; gap: 14px; margin-top: 36px; height: 18px; align-items: center; }
.beats span {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--line);
  transition: background .08s, transform .08s;
}
.beats span.accent { width: 16px; height: 16px; }
.beats span.on { background: var(--fg); transform: scale(1.15); }
.beats span.accent.on { background: var(--good); }

.tempo-controls { display: flex; align-items: center; gap: 14px; }
.tempo-controls input { flex: 1; accent-color: var(--fg); height: 28px; }
.step {
  font: inherit;
  font-size: 22px;
  line-height: 1;
  width: 44px; height: 44px;
  color: var(--fg);
  background: var(--chip);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.meters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.meters button {
  font: inherit;
  font-size: 15px;
  color: var(--muted);
  background: var(--chip);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 0;
  cursor: pointer;
}
.meters button[aria-checked="true"] { color: var(--fg); border-color: var(--fg); }

.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
#tap { user-select: none; -webkit-user-select: none; transition: background .1s; }
#tap.pressed { background: var(--line); }
body.ticking #play { color: var(--fg); background: var(--chip); }
