:root {
  --bg: #16161a;
  --surface: #21212a;
  --surface-2: #2c2c38;
  --text: #f2f2f5;
  --text-dim: #9a9aa8;
  --accent: #6ea8fe;
  --right: #3ddc84;
  --wrong: #ff6b6b;
  --line: #35353f;
  --radius: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f8;
    --surface: #ffffff;
    --surface-2: #ececf1;
    --text: #1a1a1f;
    --text-dim: #6b6b78;
    --accent: #1f6feb;
    --right: #1a9c5b;
    --wrong: #d93a3a;
    --line: #dcdce3;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen[hidden] { display: none; }

/* ---------- 上部バー ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.bar-title { font-size: 17px; margin: 0; font-weight: 600; }

.metrics { display: flex; gap: 14px; font-size: 14px; color: var(--text-dim); }
.metric {
  color: var(--text);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  background: var(--surface-2);
  color: var(--text);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* 歯車などの記号だけのボタン。言語に依存しないので読めない人でも押せる */
.icon-glyph {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 19px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 出題の向きの切替（クイズ画面） ---------- */
.dir-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 16px 0;
  flex: 0 0 auto;
}
/* 常時出るものなので、逆引きの一覧を押し出さないよう控えめな高さにする */
.dir-switch .chip {
  min-width: 0;
  min-height: 36px;
  padding: 7px 6px;
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
}

/* ---------- 中央のステージ ---------- */
.stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* 入りきらないとき（小さい画面での逆引きなど）は中央寄せをやめてスクロールさせる。
     center のままだと上にはみ出した分に手が届かない */
  justify-content: safe center;
  overflow-y: auto;
  padding: 14px 20px;
  min-height: 0;
}

.stage-scroll {
  justify-content: flex-start;
  align-items: stretch;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#quiz-body { text-align: center; }

.question {
  margin: 0;
  font-size: clamp(30px, 10vw, 52px);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.35;
  /* 「弦：6」「フレット：3」を改行で2行に出す */
  white-space: pre-line;
}

.answer { margin: 28px 0 0; }
.answer[hidden] { display: none; }

/* ポジション→音名の答え（大きく1つ） */
.answer-note {
  display: block;
  font-size: clamp(46px, 16vw, 84px);
  font-weight: 800;
  color: var(--accent);
  line-height: 1.15;
}

/* 音名→ポジションの答え（弦ごとの一覧） */
.pos-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.pos-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 10px 6px 14px;
  background: var(--surface);
  border-radius: 10px;
  min-height: 52px;
}
.pos-string {
  flex: 0 0 auto;
  min-width: 5.2em;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
}
.pos-slot {
  flex: 1 1 auto;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.pos-frets {
  font-size: clamp(20px, 6vw, 26px);
  font-weight: 700;
  color: var(--accent);
}
.pos-none { color: var(--text-dim); font-weight: 400; font-size: 17px; }

/* 弦ごとの「見る」ボタン */
.pos-reveal {
  min-height: 40px;
  padding: 8px 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pos-reveal:active { filter: brightness(0.85); }

/* セットモードの進捗バー */
.progress {
  flex: 0 0 auto;
  height: 3px;
  background: var(--surface-2);
}
.progress[hidden] { display: none; }
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.warning {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 16px;
  background: rgba(255, 107, 107, 0.15);
  color: var(--wrong);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}
.warning[hidden] { display: none; }

.empty-note {
  text-align: center;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.8;
}
.empty-note[hidden] { display: none; }

/* ---------- 下部のボタン ---------- */
.actions {
  flex: 0 0 auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  width: 100%;
  min-height: 60px;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.97); filter: brightness(0.9); }
.btn[hidden] { display: none; }
.btn:disabled { opacity: 0.4; }

.btn-primary { background: var(--accent); }
.btn-right { background: var(--right); }
.btn-wrong { background: var(--wrong); }

.judge { display: flex; gap: 12px; }
.judge[hidden] { display: none; }

/* フィードバックの点滅（画面全体を一瞬色づけする） */
@keyframes flash-right {
  from { background: rgba(61, 220, 132, 0.22); }
  to { background: transparent; }
}
@keyframes flash-wrong {
  from { background: rgba(255, 107, 107, 0.22); }
  to { background: transparent; }
}
.flash-right { animation: flash-right 0.35s ease-out; }
.flash-wrong { animation: flash-wrong 0.35s ease-out; }

/* ---------- 設定 ---------- */
.group {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.group h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.sub-label { margin-top: 16px !important; }
.group h2 .value {
  color: var(--text);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips[hidden] { display: none; }

/* 弦は6本を必ず1行に並べる */
.chips-strings {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.chips-strings .chip {
  min-width: 0;
  padding: 8px 2px;
  font-size: 13px;
  text-align: center;
}

.chips-notes { display: grid; grid-template-columns: repeat(4, 1fr); }
/* 音名チップは「ド / C」を2行で見せる */
.chips-notes .chip {
  white-space: pre-line;
  line-height: 1.25;
  font-size: 14px;
  padding: 7px 4px;
  min-height: 50px;
}

.chip {
  flex: 1 1 auto;
  min-width: 52px;
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip.accidental:not(.on) { color: var(--text-dim); opacity: 0.75; }

.presets { display: flex; gap: 8px; margin-bottom: 10px; }

.btn-mini {
  padding: 8px 14px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger { color: var(--wrong); }

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text-dim);
}
.slider-row span { flex: 0 0 32px; }
.slider-row input { flex: 1 1 auto; accent-color: var(--accent); }

.hint {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
  margin: 10px 0 0;
}
.hint[hidden] { display: none; }

/* ---------- 結果画面 ---------- */
.result-score { text-align: center; padding: 24px 0 28px; }

.result-rate {
  margin: 0;
  font-size: clamp(56px, 20vw, 96px);
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.result-detail {
  margin: 10px 0 0;
  font-size: 16px;
  color: var(--text-dim);
}

.miss-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.miss-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
}
.miss-q { font-size: 15px; font-weight: 600; }
.miss-a {
  font-size: 14px;
  color: var(--accent);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pool-info {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  padding-bottom: 24px;
}
