/* =====================================================
   みやびチューナー 見た目
   スマホ縦画面を優先。黒地に白・黄色の高コントラスト
   ===================================================== */
:root {
  --bg: #0b0b0f;
  --panel: #1a1a22;
  --line: #3a3a46;
  --text: #ffffff;
  --sub: #c8c8d0;
  --accent: #ffd400;   /* 開始ボタン・選んだ項目の黄色 */
  --ok: #2ee66b;       /* 合ったときの緑 */
  --low: #4db8ff;      /* 低いときの青 */
  --high: #ff8a3d;     /* 高いときのオレンジ */
  --danger: #ff6b6b;
  --focus: #4db8ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 18px;
  line-height: 1.6;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

/* キーボード操作のとき、どこにいるかはっきり見えるようにする */
:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

/* 画面には出さず、読み上げソフトだけに伝える文字 */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- 開始ボタン ---- */
.start {
  display: block;
  width: 100%;
  min-height: 88px;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: #000;
  background: var(--accent);
  border: none;
  border-radius: 20px;
  cursor: pointer;
}
.start[aria-pressed="true"] {
  background: #ffffff;
}

.app-name {
  margin: 12px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--sub);
  text-align: center;
  letter-spacing: 0.1em;
}

/* ---- 判定結果 ---- */
.readout {
  margin-top: 16px;
  padding: 16px;
  background: var(--panel);
  border: 3px solid transparent;
  border-radius: 20px;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
/* 音が止まっているときは少し暗くする */
.readout.idle .note-name,
.readout.idle .meter,
.readout.idle .judge,
.readout.idle .numbers {
  opacity: 0.45;
}
/* 合ったときは緑に光らせる */
.readout.in-tune {
  border-color: var(--ok);
  box-shadow: 0 0 24px rgba(46, 230, 107, 0.55), inset 0 0 18px rgba(46, 230, 107, 0.25);
}

.target {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--sub);
}
.target-note { color: var(--text); }

.note-name {
  margin: 0;
  font-size: clamp(64px, 22vw, 104px);
  font-weight: 800;
  line-height: 1.05;
}

/* メーター */
.meter {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 4px auto 0;
}
.meter .tick { stroke: #8a8a96; stroke-width: 2; }
.meter .tick.major { stroke: #ffffff; stroke-width: 3; }
.meter .zone-ok { stroke: var(--ok); stroke-width: 10; fill: none; opacity: 0.6; }
.meter-label { fill: var(--sub); font-size: 16px; font-weight: 700; }
/* 針は太く。ずれの向きで色を変えて、傾きが小さくても見分けやすくする */
.needle-line {
  stroke: #ffffff;
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke 0.2s;
}
.needle-hub { fill: #ffffff; }
.readout[data-state="low"] .needle-line { stroke: var(--low); }
.readout[data-state="low"] .needle-hub { fill: var(--low); }
.readout[data-state="high"] .needle-line { stroke: var(--high); }
.readout[data-state="high"] .needle-hub { fill: var(--high); }
.readout.in-tune .needle-line { stroke: var(--ok); filter: drop-shadow(0 0 6px var(--ok)); }
.readout.in-tune .needle-hub { fill: var(--ok); }

.judge {
  margin: 4px 0 0;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.1em;
}
.judge.low { color: var(--low); }
.judge.high { color: var(--high); }
.judge.ok { color: var(--ok); }

.numbers {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.numbers .unit {
  margin-left: 0.15em;
  font-size: 0.7em;
  color: var(--sub);
}
.numbers .sep {
  margin: 0 0.5em;
  color: var(--line);
}

.level-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}
.level-row meter {
  width: 55%;
  height: 20px;
}

.status {
  margin: 16px 0 0;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}
.error {
  margin: 12px 0 0;
  padding: 12px 16px;
  border: 3px solid var(--danger);
  border-radius: 12px;
  color: #ffd0d0;
}

/* ---- 音声の処理が止まったときのお知らせ(タップで再開) ---- */
.tap-notice {
  margin: 12px 0 0;
  padding: 16px;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  color: #000;
  background: var(--accent);
  border-radius: 14px;
}
.tap-notice[hidden] { display: none; }
/* 録画で調べるための状態表示 */
.trace { font: 15px/1.4 ui-monospace, monospace; color: #9fe; white-space: pre-wrap; margin: 4px 0; }
.trace[hidden] { display: none; }

/* ---- 新しい版のお知らせ ---- */
.update-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 0;
  padding: 10px 12px 10px 16px;
  border: 2px solid var(--accent);
  border-radius: 12px;
  font-weight: 700;
}
.update-bar[hidden] { display: none; }
.update-bar button {
  min-height: 48px;
  padding: 0 16px;
  font-size: 18px;
  font-weight: 800;
  color: #000;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

/* ---- 設定のまとまり ---- */
.panel {
  margin: 20px 0 0;
  padding: 12px 16px 16px;
  border: 2px solid var(--line);
  border-radius: 16px;
}
.panel legend,
.panel h2 {
  padding: 0 6px;
  font-size: 20px;
  font-weight: 700;
}
.panel h2 { margin: 0 0 4px; padding: 0; }

/* 折りたたみ(テスト音モード) */
.panel summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--sub);
  cursor: pointer;
}
.panel[open] summary { margin-bottom: 8px; }

/* テスト音で動いているときの目印 */
.test-badge {
  margin: 0 0 8px;
  padding: 6px 10px;
  font-size: 16px;
  font-weight: 800;
  color: #000;
  background: var(--high);
  border-radius: 8px;
}
.test-badge[hidden] { display: none; }

/* 自動/手動の切り替え(ラジオボタンを大きなボタン風に見せる) */
.segmented {
  display: flex;
  gap: 8px;
}
.segmented input,
.strings input,
.presets input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label,
.strings label,
.presets label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  font-size: 22px;
  font-weight: 700;
  background: #2a2a34;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.segmented input:checked + label,
.strings input:checked + label,
.presets input:checked + label {
  color: #000;
  background: var(--accent);
  border-color: var(--accent);
}
/* 隠したラジオボタンにフォーカスが来たら、見えているボタンに枠を出す */
.segmented input:focus-visible + label,
.strings input:focus-visible + label,
.presets input:focus-visible + label {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

/* 手動のときの弦ボタン(6個を3×2で並べる) */
.strings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.strings label {
  flex-direction: column;
  line-height: 1.2;
  min-height: 64px;
}
.strings label small {
  font-size: 15px;
  font-weight: 600;
}
.strings[aria-disabled="true"] {
  display: none;
}

/* チューニングのプリセット(2列に並べる。音名を小さく添える) */
.presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.presets label {
  flex-direction: column;
  line-height: 1.25;
  min-height: 64px;
  font-size: 20px;
}
/* 5個目(半音下げ)は横いっぱいに広げて、音名が折り返さないようにする */
.presets label:last-of-type {
  grid-column: 1 / -1;
}
.presets label small {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* 基準音A4 */
.a4-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.a4-row input {
  width: 110px;
  min-height: 56px;
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  border-radius: 10px;
  border: 2px solid var(--line);
}
.a4-row .unit { font-size: 20px; color: var(--sub); }
.step {
  width: 64px;
  min-height: 56px;
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  background: #2a2a34;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

/* ---- テスト音モード ---- */
.note {
  margin: 0 0 12px;
  color: var(--sub);
  font-size: 16px;
}
.field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  flex-wrap: wrap;
}
.field input[type="checkbox"] {
  flex: none;
  width: 28px;
  height: 28px;
}
/* チェックボックスの横に説明を並べたまま、長い文は横で折り返す */
.field input[type="checkbox"] + label {
  flex: 1 1 0;
  min-width: 0;
}
.field select {
  min-height: 48px;
  font-size: 18px;
  padding: 0 8px;
  background: #fff;
  color: #000;
  border-radius: 8px;
  flex: 1 1 220px;
}

/* 状態の読み上げボタン(開発・撮影用の中) */
.diag {
  width: 100%;
  min-height: 56px;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  background: #2a2a34;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

/* 動きを減らす設定の人には、光り方の変化をなくす */
@media (prefers-reduced-motion: reduce) {
  .readout, .needle-line { transition: none; }
}
