:root {
  --bg: #12100e;
  --surface: #1d1a16;
  --surface-2: #2a2621;
  --line: #3d372f;
  --text: #f5f1ea;
  --muted: #b3aa9c;
  --green: #34d399;
  --amber: #fbbf24;
  --red-text: #f87171;
  --accent: #d9a54c;
  --tabbar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: radial-gradient(120% 80% at 50% 0%, #2a231b 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* Seite steht fest: Kopf, Inhalt und Leiste teilen sich genau die Bildschirmhöhe */
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.tn-header {
  position: relative; flex: none;
  padding: calc(10px + env(safe-area-inset-top)) 20px 6px;
  text-align: center;
}
.tn-mic {
  position: absolute; right: 12px; top: calc(2px + env(safe-area-inset-top));
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 36px; padding: 0 12px; border-radius: 18px;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
}
.tn-mic::before { content: ""; position: absolute; inset: -4px -2px; } /* Antippfläche ≥ 44 px */
.tn-mic-dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; box-shadow: 0 0 6px #ef4444; }
.tn-header h1 { margin: 0; font-size: 17px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }

main { flex: 1 1 auto; min-height: 0; width: 100%; max-width: 520px; margin: 0 auto; padding: 0 16px 10px; display: flex; flex-direction: column; overflow: hidden; }
.tn-view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: clamp(6px, 1.3dvh, 14px); }

/* ---------- Knöpfe ---------- */
.tn-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.tn-btn:active { transform: scale(.97); }
.tn-btn-primary { background: linear-gradient(#e6b660, #c38f36); border-color: #b9842d; color: #1d1405; }
.tn-round { padding: 0; width: 48px; height: 48px; border-radius: 24px; font-size: 18px; }
.tn-small { padding: 0 12px; font-size: 14px; color: var(--muted); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Instrumentwahl ---------- */
.tn-segment {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-radius: 12px; padding: 4px; gap: 4px;
}
.tn-segment button {
  min-height: 44px; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer;
}
.tn-segment button[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.4); }

/* ---------- Analoges Messinstrument ---------- */
/* Das Meter nimmt den freien Platz und bleibt dabei im Seitenverhältnis */
.tn-gauge-box { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; container-type: size; }
.tn-gauge-wrap {
  position: relative;
  width: min(100cqw, calc(100cqh * 440 / 372));
  filter: drop-shadow(0 14px 22px rgba(0,0,0,.55)) drop-shadow(0 2px 3px rgba(0,0,0,.6));
}
.vm { display: block; width: 100%; height: auto; }
.vm text { font-family: "Avenir Next", "Futura", "Helvetica Neue", Helvetica, Arial, sans-serif; }

#vm-dim { transition: opacity .6s; }
.is-on #vm-dim { opacity: 0; }                 /* Beleuchtung an, sobald das Mikrofon läuft */

.vm-arc { fill: none; stroke: #1c180f; stroke-width: 2.2; }
.vm-arc.thin { stroke-width: 1.2; }
.vm-tick { stroke: #1c180f; stroke-width: 1.4; }
.vm-tick.major { stroke-width: 2.6; }
.vm-dot { fill: #1c180f; }
.vm-band { fill: none; stroke-width: 7; }
.vm-band-red { stroke: #d9531e; }
.vm-band-green { stroke: #1f9d4c; stroke-width: 9; }
.vm-num { fill: #1c180f; font-size: 19px; font-weight: 500; text-anchor: middle; }
.vm-num.red { fill: #c2410c; }
.vm-num.zero { font-size: 22px; font-weight: 700; }

.vm-print { fill: #2a2416; }
.vm-unit { font-size: 15px; letter-spacing: .12em; font-weight: 600; }
.vm-flat, .vm-sharp { font-size: 40px; text-anchor: middle; }
.vm-brand { font-size: 14px; font-style: italic; fill: #5a4f35; letter-spacing: .02em; }
.vm-a4 { font-size: 14px; text-anchor: end; fill: #3d3523; font-weight: 500; }

.vm-note { fill: #16130b; font-size: 62px; font-weight: 700; text-anchor: middle; transition: opacity .3s;
  paint-order: stroke; stroke: #f4ebc2; stroke-width: 9px; stroke-linejoin: round; }
.vm-oct { font-size: 28px; font-weight: 600; fill: #4a4130; }
.vm-meta { fill: #3d3523; font-size: 16px; font-weight: 600; text-anchor: middle; font-variant-numeric: tabular-nums;
  paint-order: stroke; stroke: #f2e8bd; stroke-width: 6px; stroke-linejoin: round; }
.is-fading .vm-note, .is-fading .vm-meta { opacity: .45; }

.vm-needle { stroke: #0d0d0d; stroke-width: 2.8; stroke-linecap: round; }

/* Pegellampe: aus = dunkles Glas, nah dran = schwach, gestimmt = hell leuchtend */
.vm-lamp-on, .vm-lamp-glow { opacity: 0; transition: opacity .18s; }
.is-close .vm-lamp-on { opacity: .35; }
.is-tuned .vm-lamp-on { opacity: 1; }
.is-tuned .vm-lamp-glow { opacity: .85; }

.tn-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.tn-hint {
  text-align: center; font-size: 20px; font-weight: 700; min-height: 28px; line-height: 28px;
  color: var(--muted); letter-spacing: .01em;
}
.tn-hint.is-off { color: var(--red-text); }
.tn-hint.is-close { color: var(--amber); }
.tn-hint.is-tuned { color: var(--green); }

.tn-start {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(18,16,14,.78);
  border-radius: 7%;
  padding: 24px;
  text-align: center;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.tn-start .tn-btn { min-height: 52px; padding: 0 28px; font-size: 17px; }
.tn-start-msg { margin: 0; color: var(--muted); font-size: 14px; max-width: 300px; }
.tn-start-msg.is-error { color: var(--red-text); }

/* ---------- Saiten ---------- */
.tn-strings-wrap { display: flex; flex-direction: column; gap: 2px; }
.tn-strings { display: flex; gap: 8px; justify-content: center; }
.tn-string {
  flex: 1 1 0; max-width: 64px; min-height: 50px;
  border-radius: 14px; border: 2px solid var(--line); background: var(--surface);
  font-size: 22px; font-weight: 700; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.tn-string sub { font-size: 12px; color: var(--muted); font-weight: 600; vertical-align: baseline; }
.tn-string.is-active { border-color: var(--accent); }
.tn-string.is-tuned { border-color: var(--green); background: rgba(52,211,153,.15); }
.tn-string[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #1d1405; }
.tn-string[aria-pressed="true"] sub { color: #1d1405; }
.tn-auto {
  position: relative; align-self: center; min-height: 30px; padding: 0 14px;
  background: none; border: 0; color: var(--muted); font-size: 13px; cursor: pointer;
}
.tn-auto::before { content: ""; position: absolute; inset: -7px 0; } /* Antippfläche 44 px */
.tn-auto[aria-pressed="false"] { color: var(--accent); text-decoration: underline; }

/* ---------- Referenzton ---------- */
.tn-tone {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border-radius: 14px; padding: 6px 8px 6px 12px; min-height: 56px;
}
.tn-tone-text { display: flex; flex-direction: column; min-width: 0; }
.tn-tone-label { font-weight: 600; font-size: 15px; white-space: nowrap; }
.tn-tone-icon { font-size: 14px; }
.tn-tone-hint { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tn-tone-ctrl { display: flex; align-items: center; gap: 6px; flex: none; }
.tn-tone-ctrl .tn-round { width: 44px; height: 44px; font-size: 15px; }
.tn-tone-play { min-width: 84px; min-height: 44px; padding: 0 10px; font-size: 17px; }
.tn-tone-play sub { font-size: 11px; vertical-align: baseline; }
.tn-tone-play.is-playing { background: linear-gradient(#e6b660, #c38f36); border-color: #b9842d; color: #1d1405; }

.tn-switch {
  position: relative; width: 60px; height: 36px; flex: none; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; padding: 0;
  transition: background .2s, border-color .2s;
}
.tn-switch::before { content: ""; position: absolute; inset: -5px; }  /* Antippfläche ≥ 44 px */
.tn-switch-knob {
  position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(#f3efe8, #bdb6aa); box-shadow: 0 1px 3px rgba(0,0,0,.5); transition: transform .2s;
}
.tn-switch[aria-checked="true"] { background: linear-gradient(#e6b660, #c38f36); border-color: #b9842d; }
.tn-switch[aria-checked="true"] .tn-switch-knob { transform: translateX(24px); }

/* Saitentasten im Referenzton-Modus */
.tn-strings.is-tone .tn-string { border-style: dashed; border-color: #6b5a3a; }
.tn-strings.is-tone .tn-string.is-playing {
  border-style: solid; border-color: var(--accent); background: rgba(217,165,76,.22);
  animation: tn-pulse 1.2s ease-in-out infinite;
}
@keyframes tn-pulse { 50% { box-shadow: 0 0 0 6px rgba(217,165,76,.18); } }

/* ---------- Kammerton ---------- */
.tn-a4 {
  display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border-radius: 14px; padding: 6px 8px 6px 12px; min-height: 56px;
}
.tn-a4-label { color: var(--muted); font-size: 14px; }
.tn-a4-controls { display: flex; align-items: center; gap: 6px; }
.tn-a4-controls .tn-round { width: 44px; height: 44px; }
.tn-a4-value { min-width: 64px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Metronom ---------- */
#view-metro { justify-content: space-evenly; }
.mt-dots { display: flex; justify-content: center; gap: 12px; min-height: 26px; flex-wrap: wrap; }
.mt-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--line); transition: background .05s; }
.mt-dot.first { border-color: var(--muted); }
.mt-dot.on { background: var(--accent); border-color: var(--accent); }
.mt-dot.first.on { background: var(--amber); border-color: var(--amber); }

.mt-bpm { text-align: center; }
.mt-bpm-value { font-size: clamp(56px, 11dvh, 88px); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.mt-bpm-unit { color: var(--muted); font-size: 14px; margin-top: 6px; }

.mt-adjust { display: flex; justify-content: center; gap: 12px; }
.mt-adjust .tn-round { width: 54px; height: 54px; border-radius: 27px; font-size: 16px; }

.mt-slider { width: 100%; height: 44px; accent-color: var(--accent); margin: 0; }

.mt-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 14px; padding: 4px 12px; min-height: 54px;
}
.mt-row-label { margin-right: auto; }
.mt-row-value { min-width: 28px; text-align: center; font-size: 20px; font-weight: 700; }
.mt-check { cursor: pointer; }
.mt-check input { width: 28px; height: 28px; accent-color: var(--accent); margin: 8px; }

.mt-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mt-actions .tn-btn { min-height: 56px; font-size: 18px; }
#mt-toggle.is-running { background: var(--red-text); border-color: var(--red-text); color: #1a0b0b; }

/* ---------- Untere Leiste ---------- */
.tn-tabbar {
  flex: none;
  display: flex; justify-content: center;
  background: rgba(22,19,16,.94);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.tn-tab {
  flex: 0 1 180px; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
}
.tn-tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tn-tab[aria-current="page"] { color: var(--accent); }

/* Sehr kleine Bildschirme (z. B. iPhone SE): etwas enger */
@media (max-height: 700px) {
  .tn-segment button { min-height: 40px; }
  .tn-string { min-height: 44px; font-size: 20px; }
  .tn-hint { font-size: 18px; min-height: 24px; line-height: 24px; }
  .tn-tone, .tn-a4 { min-height: 50px; padding-top: 3px; padding-bottom: 3px; }
  .mt-row { min-height: 48px; }
  .mt-actions .tn-btn { min-height: 50px; }
}
