:root {
  --bg: #0e1013;
  --surface: #171a20;
  --surface-2: #20242c;
  --line: #2a2f38;
  --text: #f2f4f7;
  --muted: #8d96a6;
  --good: #3ddc84;
  --near: #ffb547;
  --far: #ff6b6b;
  --accent: #f2f4f7;
  --on-accent: #0e1013;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #e9ebef;
    --line: #d5d9e0;
    --text: #11141a;
    --muted: #5b6475;
    --good: #12a150;
    --near: #c77700;
    --far: #d23b3b;
    --accent: #11141a;
    --on-accent: #ffffff;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

button, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

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

/* Top bar */
.top { display: flex; gap: 8px; align-items: center; }
.select { flex: 1; min-width: 0; }
select {
  width: 100%;
  min-height: 44px;
  padding: 0 36px 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238d96a6' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  appearance: none;
  -webkit-appearance: none;
  text-overflow: ellipsis;
}
.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

/* Meter */
.meter {
  --tone: var(--muted);
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}
.meter.is-active { --tone: var(--far); }
.meter.is-near { --tone: var(--near); }
.meter.is-intune { --tone: var(--good); }

.gauge { display: block; width: 100%; max-height: 38vh; overflow: visible; }
.gauge .tick { stroke: var(--line); stroke-width: 2; stroke-linecap: round; }
.gauge .tick.major { stroke: var(--muted); stroke-width: 2.5; }
.gauge .tick.center { stroke: var(--good); stroke-width: 4; }
.gauge .zone { stroke: var(--good); stroke-width: 6; stroke-linecap: round; opacity: .28; }
.gauge .side { fill: var(--muted); font-size: 22px; }
.gauge .needle-line { stroke: var(--tone); stroke-width: 4; stroke-linecap: round; transition: stroke .15s; }
.gauge .pivot { fill: var(--tone); transition: fill .15s; }
.meter.is-idle .gauge #needle { opacity: .35; }

.readout { text-align: center; margin-top: 4px; }
.note {
  font-size: clamp(72px, 22vw, 112px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--tone);
  transition: color .15s;
  white-space: nowrap;
}
.meter.is-idle .note { color: var(--muted); font-weight: 200; }
.note sup, .note sub { font-size: .3em; font-weight: 600; letter-spacing: 0; line-height: 0; }
.note sup { vertical-align: top; position: relative; top: .55em; }
.note sub { vertical-align: baseline; }
.status {
  margin-top: 10px;
  min-height: 1.5em;
  font-size: 20px;
  font-weight: 600;
  color: var(--tone);
  font-variant-numeric: tabular-nums;
}
.meter.is-idle .status { color: var(--muted); font-weight: 500; }
.hz { min-height: 1.4em; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

/* Strings */
.strings-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.strings { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; width: 100%; }
.string {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 62px;
  padding: 6px 0;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  transition: border-color .15s, background .15s;
}
.string .s-note { font-size: 20px; font-weight: 700; line-height: 1; }
.string .s-note small { font-size: .55em; font-weight: 600; color: var(--muted); }
.string .s-num { font-size: 11px; color: var(--muted); }
.string.is-target { border-color: var(--text); background: var(--surface-2); }
.string.is-tuned { border-color: var(--good); }
.string.is-tuned .s-num { color: var(--good); }
.string.is-tuned::after {
  content: "";
  position: absolute; top: 5px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good);
}
.chip {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}
.chip[aria-pressed="true"] { color: var(--text); border-color: var(--text); }

/* Bottom */
.bottom { display: flex; flex-direction: column; gap: 8px; align-items: stretch; text-align: center; }
.message { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--muted); }
.message.is-error { color: var(--far); }
.privacy { margin: 0; font-size: 12px; color: var(--muted); }
.primary {
  min-height: 54px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 18px;
  font-weight: 700;
}
.primary:disabled { opacity: .6; }
.primary.is-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }

/* Settings dialog */
dialog {
  width: min(92vw, 400px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .55); }
dialog h2 { margin: 0 0 8px; font-size: 20px; }
dialog form { display: flex; flex-direction: column; gap: 4px; }
dialog .primary { margin-top: 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row-title { font-weight: 600; }
.row-sub { font-size: 13px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 44px; height: 44px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2);
  font-size: 22px;
}
.stepper output { min-width: 3.2ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
input[type="checkbox"][role="switch"] {
  appearance: none; -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 52px; height: 32px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: background .15s;
}
input[type="checkbox"][role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--text);
  transition: transform .15s;
}
input[type="checkbox"][role="switch"]:checked { background: var(--good); }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(20px); background: #fff; }

@media (max-height: 560px) {
  .gauge { max-height: 30vh; }
  .note { font-size: 64px; }
  .privacy { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

[hidden] { display: none !important; }
