:root {
  --bg: #0a0c0b;
  --panel: #101311;
  --line: #1c221e;
  --line-2: #29312c;
  --text: #e3eae5;
  --muted: #7b8880;
  --dim: #4b5650;
  --green: #35d07f;
  --green-soft: rgba(53, 208, 127, 0.08);
  --green-ink: #03140a;
  --radius: 4px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.app {
  max-width: 540px;
  min-height: 100dvh;
  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: 20px;
}

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.small { margin: 0; font-size: 12px; color: var(--dim); }

/* Header */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

[hidden] { display: none !important; }

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Tune / Listen switcher */

.tabs {
  display: flex;
  gap: 28px;
  margin-top: -6px;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  position: relative;
  padding: 0 0 11px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); }
.tabs button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--green);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-mark { width: 9px; height: 9px; background: var(--green); }

.ref { display: flex; align-items: center; gap: 8px; }
.ref output { min-width: 3ch; text-align: center; }

.step {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: transparent;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.step:hover { border-color: var(--muted); }

/* Display */

.display {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 28px 22px 20px;
}

.readout { text-align: center; }

.note {
  display: inline-flex;
  align-items: flex-start;
  font-size: clamp(96px, 30vw, 150px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.04em;
  transition: color 0.15s;
}
.note .acc { font-size: 0.42em; margin: 0.08em 0 0 0.03em; letter-spacing: 0; }
.note .oct {
  align-self: flex-end;
  margin: 0 0 0.06em 0.05em;
  font-size: 0.26em;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
}

.meta {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 14px;
  font-size: 14px;
  color: var(--muted);
}

.meter {
  position: relative;
  height: 80px;
  margin: 30px 12px 0;
}

.scale, .zone, .needle { position: absolute; top: 0; bottom: 22px; }
.scale { left: 0; right: 0; }

.tick {
  position: absolute;
  bottom: 0;
  width: 1px;
  height: 12px;
  margin-left: -0.5px;
  background: var(--line-2);
}
.tick.major { height: 24px; background: var(--dim); }
.tick.center { height: 100%; background: var(--line-2); }

.zone {
  left: 45%;
  width: 10%;
  background: var(--green-soft);
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
  transition: background 0.2s;
}

.needle {
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  transition: background 0.15s, opacity 0.3s;
}
.needle::before {
  content: "";
  position: absolute;
  top: -4px;
  left: -4px;
  width: 10px;
  height: 10px;
  background: inherit;
}

.scale-labels { position: absolute; left: 0; right: 0; bottom: 0; height: 14px; font-size: 11px; color: var(--dim); }
.scale-labels span { position: absolute; transform: translateX(-50%); }

.hint {
  min-height: 1.4em;
  margin: 18px 0 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.level {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.level .label { font-size: 10px; }
.level-track { flex: 1; height: 3px; background: var(--line); overflow: hidden; }
.level-fill {
  height: 100%;
  background: var(--green);
  opacity: 0.7;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.08s linear;
}

/* States */

[data-state="idle"] .note,
[data-state="listening"] .note { color: var(--dim); }
[data-state="idle"] .needle,
[data-state="listening"] .needle { opacity: 0.2; }

[data-state="intune"] .note { color: var(--green); }
[data-state="intune"] .needle { background: var(--green); }
[data-state="intune"] .zone {
  background: rgba(53, 208, 127, 0.16);
  border-color: rgba(53, 208, 127, 0.4);
}
[data-state="intune"] .hint { color: var(--green); }

/* Tuning + strings */

.panel { display: flex; flex-direction: column; gap: 12px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.select { position: relative; }
.select::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -5px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}
select {
  appearance: none;
  min-width: 180px;
  padding: 9px 34px 9px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
select:hover { border-color: var(--muted); }

.strings { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }

.string {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.string:hover { border-color: var(--muted); }
.string .n { font-size: 19px; font-weight: 500; line-height: 1; }
.string .n sub { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 1px; }
.string .f { font-size: 10px; color: var(--dim); }

.string.active { border-color: var(--green); color: var(--green); }

.string.locked { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.string.locked .n sub,
.string.locked .f { color: var(--green-ink); opacity: 0.65; }

.string.tuned::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  background: var(--green);
}
.string.locked.tuned::after { background: var(--green-ink); }

/* Listen */

.seg {
  display: inline-flex;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg button {
  padding: 8px 18px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--green); color: var(--green-ink); font-weight: 600; }

.display.listen { padding: 20px 20px 18px; }

.now {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.now-note {
  min-width: 2ch;
  font-size: 44px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--green);
}
.now-note sub { font-size: 0.4em; font-weight: 400; color: var(--muted); margin-left: 2px; vertical-align: baseline; }
.now-pos { font-size: 13px; color: var(--muted); text-align: right; }
.now[data-state="idle"] .now-note,
.now[data-state="listening"] .now-note,
.now[data-state="quiet"] .now-note { color: var(--dim); }

.tab {
  min-height: 150px;
  max-height: 46vh;
  margin-top: 16px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre;
  color: var(--dim);
}
.tab .sys + .sys { margin-top: 18px; }
.tab .line {
  width: max-content;
  color: var(--dim);
  background: linear-gradient(var(--dim), var(--dim)) left 50% / 100% 1px no-repeat;
}
.tab .lbl, .tab .fret { background: var(--panel); } /* the string line passes behind them */
.tab .lbl { color: var(--muted); }
.tab .fret { color: var(--text); }
.tab .fret.hot { color: var(--green); font-weight: 500; }
.tab-empty {
  margin: 0;
  padding: 52px 0;
  white-space: normal;
  text-align: center;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 14px;
  color: var(--dim);
}

.actions { align-items: flex-start; }
.actions .small { padding-top: 9px; }
.buttons { display: flex; gap: 8px; flex-shrink: 0; }
.ghost {
  padding: 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: transparent;
  font-size: 14px;
  cursor: pointer;
}
.ghost:hover:not(:disabled) { border-color: var(--muted); }
.ghost:disabled { color: var(--dim); cursor: default; }

/* Start */

.start {
  margin-top: auto;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--green);
  border-radius: var(--radius);
  background: var(--green);
  color: var(--green-ink);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.start:hover { filter: brightness(1.08); }
.start[aria-pressed="true"] { background: transparent; color: var(--text); border-color: var(--line-2); }
.start[aria-pressed="true"]:hover { border-color: var(--muted); filter: none; }

footer { text-align: center; }

@media (max-width: 380px) {
  .strings { gap: 6px; }
  .string .n { font-size: 17px; }
  select { min-width: 150px; }
}

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