:root {
  --bg: #10110f;
  --panel: #181a17;
  --panel-strong: #20231e;
  --ink: #f4efe2;
  --muted: #aaa293;
  --line: #34382f;
  --brass: #d0a14a;
  --brass-bright: #f0c767;
  --green: #58d68d;
  --red: #ef6b5e;
  --blue: #6aa7d8;
  --shadow: rgba(0, 0, 0, 0.28);
  --radius: 8px;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Roboto Mono", "SF Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  background:
    linear-gradient(90deg, transparent 0 12%, rgba(208, 161, 74, 0.08) 12.2% 12.55%, transparent 12.75% 23%),
    radial-gradient(circle at 50% 18%, rgba(208, 161, 74, 0.12), transparent 32%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

button {
  font: inherit;
}

.app {
  width: min(100%, 520px);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 2px;
}

.eyebrow {
  color: var(--brass-bright);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.16em;
}

.brand {
  margin-top: 2px;
  font-size: clamp(1.32rem, 7vw, 2rem);
  line-height: 1;
  font-weight: 760;
  letter-spacing: 0;
}

.brand span {
  color: var(--muted);
  font-weight: 560;
}

.ref-control {
  display: grid;
  grid-template-columns: 34px minmax(82px, auto) 34px;
  align-items: center;
  gap: 5px;
}

.ref {
  min-width: 82px;
  padding: 9px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(24, 26, 23, 0.72);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.74rem;
  text-align: center;
  white-space: nowrap;
}

.ref span {
  color: var(--brass-bright);
}

.icon-btn,
.mode,
.btn,
.string-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease, transform 70ms ease;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--brass-bright);
  font-family: var(--mono);
  font-size: 1rem;
  line-height: 1;
}

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

.mode {
  min-height: 38px;
  color: var(--muted);
  font-weight: 690;
}

.mode.active {
  border-color: rgba(208, 161, 74, 0.78);
  background: rgba(208, 161, 74, 0.15);
  color: var(--brass-bright);
}

.display {
  position: relative;
  flex: 1;
  min-height: 365px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 18px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 36%),
    var(--panel);
  box-shadow: 0 18px 42px var(--shadow);
  overflow: hidden;
}

.display::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0 16%, rgba(208, 161, 74, 0.16) 16.15% 16.45%, transparent 16.65% 32%),
    linear-gradient(90deg, transparent 0 49.75%, rgba(244, 239, 226, 0.18) 49.9% 50.1%, transparent 50.25% 100%),
    linear-gradient(90deg, transparent 0 83.3%, rgba(208, 161, 74, 0.16) 83.55% 83.85%, transparent 84.05% 100%);
  opacity: 0.55;
}

.signal,
.note-block,
.frequency,
.meter,
.hint {
  position: relative;
  z-index: 1;
}

.signal {
  align-self: flex-start;
  padding: 6px 8px;
  border: 1px solid rgba(106, 167, 216, 0.28);
  border-radius: var(--radius);
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.66rem;
}

.app[data-tune="ok"] .signal {
  border-color: rgba(88, 214, 141, 0.42);
  color: var(--green);
}

.app[data-tune="up"] .signal,
.app[data-tune="down"] .signal {
  border-color: rgba(208, 161, 74, 0.42);
  color: var(--brass-bright);
}

.note-block {
  min-height: 142px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.note {
  color: rgba(244, 239, 226, 0.42);
  font-family: var(--mono);
  font-size: clamp(5.8rem, 28vw, 8.8rem);
  font-weight: 820;
  line-height: 0.86;
  letter-spacing: 0;
  transition: color 140ms ease, text-shadow 140ms ease;
}

.note.active {
  color: var(--brass-bright);
}

.note.tuned {
  color: var(--green);
  text-shadow: 0 0 28px rgba(88, 214, 141, 0.38);
}

.octave {
  min-height: 1.15em;
  margin-top: 5px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 1.02rem;
}

.string-name {
  min-height: 1.2em;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

.frequency {
  min-height: 1.2em;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1rem;
}

.meter {
  width: 100%;
  max-width: 380px;
}

.meter-scale {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.tick.zero {
  color: var(--brass-bright);
}

.dial {
  position: relative;
  height: 82px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(239, 107, 94, 0.12), transparent 34%, rgba(88, 214, 141, 0.1) 48%, rgba(88, 214, 141, 0.1) 52%, transparent 66%, rgba(239, 107, 94, 0.12)),
    var(--panel-strong);
  overflow: hidden;
}

.dial::before {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 50%;
  height: 1px;
  background: rgba(244, 239, 226, 0.14);
}

.dial-center {
  position: absolute;
  left: 50%;
  top: 8px;
  bottom: 8px;
  width: 2px;
  margin-left: -1px;
  background: var(--green);
  box-shadow: 0 0 18px rgba(88, 214, 141, 0.44);
}

.needle {
  position: absolute;
  left: 50%;
  top: 7px;
  bottom: 7px;
  width: 4px;
  margin-left: -2px;
  border-radius: 4px;
  background: rgba(244, 239, 226, 0.42);
  transform: translateX(0);
  transition: transform 70ms linear, background 140ms ease, box-shadow 140ms ease;
}

.needle.off {
  background: var(--brass-bright);
}

.needle.tuned {
  background: var(--green);
  box-shadow: 0 0 18px rgba(88, 214, 141, 0.58);
}

.cents {
  min-height: 1.2em;
  margin-top: 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.86rem;
  text-align: center;
}

.hint {
  min-height: 1.3em;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 720;
  text-align: center;
}

.hint.ok {
  color: var(--green);
}

.hint.up,
.hint.down {
  color: var(--brass-bright);
}

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

.string-chip {
  min-height: 66px;
  padding: 9px 4px;
  text-align: center;
}

.string-chip:active,
.btn:active,
.mode:active,
.icon-btn:active {
  transform: scale(0.98);
}

.string-chip .sc-note {
  display: block;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 1.08rem;
  font-weight: 820;
  line-height: 1;
}

.string-chip .sc-label,
.string-chip .sc-hz {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.58rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.string-chip .sc-label {
  margin-top: 5px;
}

.string-chip.target {
  border-color: rgba(208, 161, 74, 0.85);
  background: rgba(208, 161, 74, 0.14);
}

.string-chip.target .sc-note {
  color: var(--brass-bright);
}

.string-chip.done {
  border-color: rgba(88, 214, 141, 0.9);
  background: rgba(88, 214, 141, 0.12);
}

.string-chip.done .sc-note {
  color: var(--green);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
}

.btn {
  min-height: 54px;
  border-color: rgba(208, 161, 74, 0.7);
  background: rgba(208, 161, 74, 0.11);
  color: var(--brass-bright);
  font-size: 1.02rem;
  font-weight: 760;
}

.btn.primary.on {
  border-color: rgba(88, 214, 141, 0.9);
  background: rgba(88, 214, 141, 0.16);
  color: var(--green);
}

.status {
  min-height: 1.2em;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.74rem;
}

.status.error {
  color: var(--red);
}

.status.live {
  color: var(--green);
}

.status.warn {
  color: var(--brass-bright);
}

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

@media (max-width: 380px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .ref-control {
    grid-template-columns: 38px 1fr 38px;
  }

  .ref {
    min-width: 0;
  }

  .strings {
    gap: 5px;
  }

  .string-chip {
    min-height: 62px;
    padding-inline: 2px;
  }

  .string-chip .sc-label,
  .string-chip .sc-hz {
    font-size: 0.53rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}
