:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --ink: #191919;
  --muted: #5a5a55;
  --line: #d6d4cb;
  --accent: #1f4fd8;
  --on-accent: #ffffff;
  --ok: #0b7a37;
  --ok-bg: #cfeadb;
  --off: #b13d08;
  --field: #ffffff;
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --card: #1b1b1a;
    --ink: #f2f1ed;
    --muted: #a9a79f;
    --line: #363531;
    --accent: #86a8ff;
    --on-accent: #0a1330;
    --ok: #55d68a;
    --ok-bg: #163c27;
    --off: #ff9a5c;
    --field: #232322;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  padding: 0 16px 32px;
  max-width: 1040px;
  margin-inline: auto;
}
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 5; }

.top { padding: 20px 0 12px; }
.top h1 { font-size: 1.35rem; font-weight: 700; }
.top p { color: var(--muted); font-size: .95rem; }

.layout { display: grid; gap: 16px; }
.col-main, .col-side { display: grid; gap: 16px; align-content: start; min-width: 0; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; }
}

.panel, .tuner {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  min-width: 0;
}
.panel > h2 { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.panel[hidden] { display: none; }
.intro { color: var(--muted); font-size: .95rem; margin-bottom: 12px; }

.row { display: flex; gap: 12px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; align-items: center; margin: 12px 0; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 360px) and (max-width: 899px) {
  .grid2 { grid-template-columns: 1fr 1fr; }
}
.stepper { display: flex; gap: 6px; }
.stepper input { min-width: 0; padding-inline: 4px; }
.stepper .btn { padding-inline: 0; flex: 0 0 44px; }

.field { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.field > span, .field > label { font-weight: 600; }
select, input[type="number"] {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 8px;
  min-height: 44px; padding: 6px 10px; width: 100%;
}
input[type="number"] { text-align: center; font-variant-numeric: tabular-nums; }

.btn {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 8px;
  min-height: 44px; min-width: 44px; padding: 6px 16px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.block { width: 100%; }
.btn[aria-pressed="true"] { outline: 2px solid var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.check { display: flex; gap: 8px; align-items: center; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.error {
  margin-top: 12px; padding: 12px; border-radius: 8px;
  border: 1px solid var(--off); color: var(--ink); font-size: .92rem;
}
.error[hidden] { display: none; }
.error strong { color: var(--off); }
.error ul { margin: 6px 0 0; padding-left: 1.2em; }
.error li { margin: 4px 0; }

/* 讀數 */
.tuner { padding: 16px 16px 14px; }
.note-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.note {
  font-size: clamp(84px, 26vw, 140px);
  line-height: 1; font-weight: 700; letter-spacing: -.02em;
  min-width: 0; white-space: nowrap;
}
.note .octave { font-size: .38em; font-weight: 600; margin-left: .06em; color: var(--muted); }
.numbers { margin: 0; display: grid; gap: 8px; text-align: right; }
.numbers dt { font-size: .8rem; color: var(--muted); }
.numbers dd { margin: 0; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.numbers small { font-size: .75em; font-weight: 500; color: var(--muted); }

.gauge { display: block; width: 100%; height: auto; margin-top: 8px; }
.gauge #zone { fill: var(--line); opacity: .55; }
.gauge .tick { stroke: var(--muted); stroke-width: 1; }
.gauge .tick.major { stroke: var(--ink); stroke-width: 1.4; }
.gauge text { fill: var(--muted); font: 9px var(--font); text-anchor: middle; }
.needle { transition: transform .09s linear, opacity .2s; transform: translateX(120px); }
.needle line { stroke: var(--off); stroke-width: 3; stroke-linecap: round; }
.needle path { fill: var(--off); }
.status { text-align: center; font-size: 1.25rem; font-weight: 700; min-height: 1.9em; margin-top: 4px; }
.target { text-align: center; color: var(--muted); font-size: .95rem; font-variant-numeric: tabular-nums; }
.target[hidden] { display: none; }

.tuner[data-state="idle"] .needle { opacity: 0; }
.tuner[data-state="idle"] .note, .tuner[data-state="idle"] .numbers dd { color: var(--muted); }
.tuner[data-state="idle"] .status { font-weight: 500; color: var(--muted); }
.tuner[data-state="in-tune"] { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }
.tuner[data-state="in-tune"] .note, .tuner[data-state="in-tune"] .status { color: var(--ok); }
.tuner[data-state="in-tune"] #zone { fill: var(--ok-bg); opacity: 1; }
.tuner[data-state="in-tune"] .needle line { stroke: var(--ok); }
.tuner[data-state="in-tune"] .needle path { fill: var(--ok); }

.trace { display: block; width: 100%; height: 150px; }

/* 弦 */
.strings { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; }
.string-btn {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 8px; min-height: 60px;
  padding: 6px; cursor: pointer; display: grid; gap: 0; justify-items: center; align-content: center;
}
.string-btn b { font-size: 1.15rem; }
.string-btn small { color: var(--muted); font-variant-numeric: tabular-nums; }
.string-btn[aria-current="true"] { border: 2px solid var(--accent); padding: 5px; }
.string-btn.done { border-color: var(--ok); }

/* 節拍器 */
.bpm-row { display: flex; gap: 8px; align-items: center; justify-content: center; margin-bottom: 8px; }
.bpm-box { display: flex; align-items: baseline; gap: 6px; }
.bpm-box input { width: 104px; font-size: 1.8rem; font-weight: 700; min-height: 52px; }
.bpm-box small { color: var(--muted); }
#bpm-range { width: 100%; accent-color: var(--accent); min-height: 32px; }
.dots { display: flex; gap: 10px; justify-content: center; margin: 4px 0 12px; min-height: 20px; }
.dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--muted); }
.dot.first { border-color: var(--ink); }
.dot.on { background: var(--ink); }
.dot.first.on { background: var(--off); border-color: var(--off); }

.foot { margin-top: 24px; color: var(--muted); font-size: .85rem; display: grid; gap: 4px; }
.foot a { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .needle { transition: none; }
}

.grid2 .field:has(#a4) { grid-column: 1 / -1; }
