:root {
  --bg: #14110f;
  --panel: #1f1a17;
  --line: #3a312b;
  --text: #f2e8dc;
  --muted: #9c8e80;
  --brass: #e3a33b;
  --good: #5fd18a;
  --bad: #e2553a;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

body {
  background:
    radial-gradient(120% 60% at 50% 0%, #2a211b 0%, transparent 70%),
    var(--bg);
}

[hidden] { display: none !important; }

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

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

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.learn-link {
  color: var(--text); text-decoration: none; font-size: 0.85rem; font-weight: 600;
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); white-space: nowrap;
}
.brand { margin: 0; font-size: 1.05rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--brass); font-weight: 700; }

.tuning select {
  appearance: none;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239c8e80' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 34px 9px 14px;
  font: inherit;
  font-size: 0.9rem;
  max-width: 46vw;
}

.readout { text-align: center; margin-top: 8px; }
.note {
  font-size: clamp(5rem, 28vw, 7.5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  transition: color 0.2s;
}
.note sub { font-size: 0.3em; font-weight: 600; color: var(--muted); margin-left: 2px; }
.freq { color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 6px; font-size: 0.95rem; }

.app.in-tune .note { color: var(--good); }
.app.idle .note { color: var(--line); }

.gauge-wrap { position: relative; }
.gauge { width: 100%; display: block; }
.gauge .tick { stroke: var(--line); stroke-width: 2; }
.gauge .tick.major { stroke: var(--muted); stroke-width: 3; }
.gauge .tick.zero { stroke: var(--good); stroke-width: 4; }
.needle { transform-origin: 150px 150px; transition: opacity 0.3s; }
.needle line { stroke: var(--text); stroke-width: 4; stroke-linecap: round; }
.needle circle { fill: var(--brass); }
.app.idle .needle { opacity: 0.25; }
.app.in-tune .needle line { stroke: var(--good); }
.scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.78rem; padding: 0 6%; margin-top: -4px; }

.hint {
  text-align: center;
  margin: 4px 0 0;
  min-height: 1.5em;
  font-size: 1.15rem;
  font-weight: 600;
}
.hint.low, .hint.high { color: var(--brass); }
.hint.ok { color: var(--good); }

.level { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin: 0 20%; }
.level i { display: block; height: 100%; background: var(--brass); transform: scaleX(0); transform-origin: left; transition: transform 60ms linear; }

.strings {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: auto;
}
.string {
  position: relative;
  aspect-ratio: 1 / 1.25;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.12s, border-color 0.2s, background 0.2s;
}
.string small { font-size: 0.62rem; color: var(--muted); font-weight: 500; }
.string:active { transform: scale(0.95); }
.string.active { border-color: var(--brass); background: #2c231c; box-shadow: 0 0 0 1px var(--brass) inset; }
.string.done::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.7rem;
  color: var(--good);
}
.string.done { border-color: #2f5a40; }

.controls { display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.9rem;
  padding: 8px 16px; border-radius: 999px;
}
.seg button.on { background: var(--brass); color: #1b140e; font-weight: 700; }

.a4 { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.a4 b { color: var(--text); }
.a4 button {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 1.2rem; line-height: 1;
}

button:focus-visible, select:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.start {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 24px;
  background: rgba(10, 8, 7, 0.86);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.start[hidden] { display: none; }
.start-card { max-width: 340px; text-align: center; }
.start-icon { width: 72px; height: 72px; }
.start-card h2 { margin: 12px 0 8px; font-size: 1.5rem; }
.start-card p { color: var(--muted); line-height: 1.45; margin: 0 0 22px; }
.start-btn {
  width: 100%; border: 0; border-radius: 999px; padding: 16px;
  background: var(--brass); color: #1b140e; font: inherit; font-size: 1.1rem; font-weight: 800;
}
.start-btn:active { transform: scale(0.98); }
.err { color: var(--bad) !important; margin-top: 16px !important; }

@media (min-height: 760px) {
  .app { gap: 18px; }
}
