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

:root {
  --bg: #0d0d1a;
  --surface: #141428;
  --surface2: #1e1e38;
  --accent: #7c6af7;
  --red: #e94560;
  --green: #00d4aa;
  --text: #f0f0ff;
  --muted: #6b6b8a;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  padding: 1.5rem 1rem 0;
  text-align: center;
}

h1 {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

main {
  width: 100%;
  max-width: 380px;
  padding: 1rem 1.5rem 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

/* View toggle */
.view-toggle {
  display: flex;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
  width: 100%;
}

.vt-btn {
  flex: 1;
  padding: 0.45rem 0;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.vt-btn.active {
  background: var(--surface2);
  color: var(--text);
}

/* Utility */
.hidden { display: none !important; }

/* Meter */
.meter-wrap {
  width: 100%;
}

.meter {
  width: 100%;
  display: block;
  overflow: visible;
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  padding: 0 0.25rem;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 1rem;
}

/* Strobe view */
.strobe-view {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 0.25rem 0;
}

.strobe-outer {
  position: relative;
  width: 260px;
  height: 260px;
}

.strobe-disc {
  width: 260px;
  height: 260px;
  display: block;
  overflow: visible;
}

#strobe-wheel {
  transform-origin: 130px 130px;
  will-change: transform;
}

.strobe-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: #0d0d1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  pointer-events: none;
  z-index: 1;
}


/* Strings view */
.strings-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.25rem 0;
}

.sv-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sv-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  min-width: 2rem;
  text-align: right;
  transition: color 0.2s;
}

.sv-svg {
  flex: 1;
  display: block;
  overflow: visible;
}

.sv-path {
  fill: none;
  stroke: var(--surface2);
  stroke-linecap: round;
  transition: stroke 0.2s;
}

.sv-text {
  font-size: 10px;
  font-family: system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  fill: transparent;
}

/* Active string — being detected, not yet in tune */
.sv-row.active .sv-path  { stroke: var(--accent); }
.sv-row.active .sv-label { color: var(--accent); }
.sv-row.active .sv-text  { fill: var(--accent); }

/* In-tune string */
.sv-row.in-tune .sv-path  { stroke: var(--green); }
.sv-row.in-tune .sv-label { color: var(--green); }
.sv-row.in-tune .sv-text  { fill: var(--green); }

/* Note display */
.note-display {
  text-align: center;
}

.note-main {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  line-height: 1;
  gap: 0.2rem;
}

.note-name {
  font-size: 5.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition: color 0.25s;
  min-width: 1ch;
}

.note-octave {
  font-size: 1.6rem;
  font-weight: 400;
  color: var(--muted);
  padding-top: 0.6rem;
  transition: color 0.25s;
}

.note-meta {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  transition: color 0.25s;
}

.note-display.in-tune .note-name,
.note-display.in-tune .note-octave {
  color: var(--green);
}

.note-display.in-tune .note-meta {
  color: var(--green);
  opacity: 0.85;
}

/* Needle in-tune glow */
.meter.in-tune .needle {
  stroke: var(--green);
  filter: drop-shadow(0 0 4px var(--green));
}

.meter.in-tune .needle-pivot {
  fill: var(--green);
  filter: drop-shadow(0 0 4px var(--green));
}

/* Strings */
.strings-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.strings-label {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.strings {
  display: flex;
  gap: 0.5rem;
}

.string-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--surface2);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.string-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.string-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 14px rgba(124, 106, 247, 0.55);
}

.string-btn.in-tune {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  box-shadow: 0 0 14px rgba(0, 212, 170, 0.55);
}

/* Device picker */
.device-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.device-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.device-select {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--surface2);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b6b8a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 2rem;
  transition: border-color 0.15s;
}

.device-select:hover,
.device-select:focus {
  border-color: var(--accent);
}

.device-select option {
  background: #1e1e38;
}

/* Start button */
.start-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 2.25rem;
  border-radius: 50px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 4px 22px rgba(124, 106, 247, 0.4);
}

.start-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(124, 106, 247, 0.55);
}

.start-btn:active {
  transform: translateY(0);
}

.start-btn.listening {
  background: var(--red);
  box-shadow: 0 4px 22px rgba(233, 69, 96, 0.4);
}

.start-btn.listening:hover {
  box-shadow: 0 6px 28px rgba(233, 69, 96, 0.55);
}

.btn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  flex-shrink: 0;
}

.start-btn.listening .btn-dot {
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.7); }
}

/* Signal level bar */
.level-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.level-bar {
  flex: 1;
  height: 5px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.level-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: var(--muted);
  transition: width 0.05s linear, background 0.2s;
}

.level-num {
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 2.8ch;
  text-align: right;
}

/* Status */
.status {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.2em;
  transition: color 0.2s;
}

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