:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #dde2e8;
  --text: #1b2026;
  --muted: #697381;
  --accent: #2f6fed;
  --good: #17914f;
  --warn: #c2410c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.mode-select {
  display: flex;
  gap: 6px;
}

.mode-btn {
  flex: 1 1 0;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

.mode-btn.on {
  color: var(--accent);
  background: #eef3ff;
  border-color: var(--accent);
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stage[hidden] {
  display: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

button.primary {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
}

button.primary.on { background: #3d434b; }
button.primary:disabled { opacity: 0.6; cursor: progress; }

.status {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
  flex: 1 1 12rem;
}

.status.ok { color: var(--good); }
.status.error { color: var(--warn); }

.notice {
  margin: 0;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.4;
}

.tuner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.tuner-target {
  font-size: 0.8rem;
  color: var(--muted);
}

.tuner-note {
  font-size: clamp(1.9rem, 9vw, 2.7rem);
  font-weight: 700;
  line-height: 1;
}

.tuner-meter {
  position: relative;
  width: 100%;
  height: 12px;
  background: #eef1f5;
  border-radius: 6px;
  margin-top: 4px;
}

.meter-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: #b8c0ca;
}

.meter-needle {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
  transition: left 0.08s linear, opacity 0.15s;
}

.meter-scale {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--muted);
}

.tuner-cents {
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tuner-cents .unit {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--muted);
}

.judge {
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1.1em;
}

.judge.good {
  color: var(--good);
  font-weight: 600;
}

.strings {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.string-row {
  display: grid;
  grid-template-columns: auto minmax(3.6rem, auto) 1fr 2.8rem;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
}

.string-row.active { border-color: var(--accent); }
.string-row.in-tune { border-color: var(--good); }

.ref-btn {
  font: inherit;
  font-size: 0.85rem;
  line-height: 1;
  color: var(--accent);
  background: #eef3ff;
  border: 1px solid #d5e2ff;
  border-radius: 6px;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  cursor: pointer;
}

.ref-btn.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.string-label {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.string-label b {
  color: var(--text);
  font-size: 0.9rem;
}

.bar {
  position: relative;
  height: 8px;
  background: #eef1f5;
  border-radius: 4px;
}

.bar-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: #b8c0ca;
}

.bar-needle {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
  transition: left 0.08s linear, opacity 0.15s;
}

.string-cents {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.string-row.active .string-cents {
  color: var(--text);
  font-weight: 600;
}

/* ---------- 튜닝 진행 ---------- */

.strings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.progress {
  font-size: 0.75rem;
  color: var(--muted);
}

.progress.all-done {
  color: var(--good);
  font-weight: 700;
}

button.ghost {
  font: inherit;
  font-size: 0.72rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  cursor: pointer;
}

.string-row.done {
  border-color: var(--good);
  background: #ecf9f1;
}

.string-row.done .string-label,
.string-row.done .string-label b,
.string-row.done .string-cents {
  color: var(--good);
}

.string-row.done .bar {
  background: #d3efdf;
}

.string-row.done .bar-needle {
  background: var(--good);
}

/* ---------- 코드 확인 ---------- */

.chord {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chord[hidden] {
  display: none;
}

.chord-title {
  margin: 0;
  font-size: 0.92rem;
}

.chord-help {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}

.chord-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font: inherit;
  font-size: 0.78rem;
  color: var(--accent);
  background: #eef3ff;
  border: 1px solid #d5e2ff;
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}

.chip.on {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chord-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.chord-input {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  width: 7rem;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.chord-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chord-status {
  font-size: 0.75rem;
  color: var(--muted);
}

.chord-notes {
  font-size: 0.78rem;
  min-height: 1.1em;
}

.chord-result {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.chord-result p {
  margin: 0 0 2px;
}

.chord-result .chord-head {
  font-weight: 700;
  color: var(--text);
}

.chord-result.good .chord-head {
  color: var(--good);
}

.chord-result.bad .chord-head {
  color: var(--warn);
}
