:root {
  color-scheme: light dark;
  --bg: #f5f2ec;
  --surface: #ffffff;
  --text: #1f1b16;
  --muted: #6b645a;
  --line: #e2dcd2;
  --accent: #b4530a;
  --on-accent: #ffffff;
  --ok: #177a3c;
  --ok-bg: #e7f5ec;
  --bad: #b3261e;
  --bad-bg: #fcebe9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1f1c19;
    --text: #f2ede6;
    --muted: #a69e93;
    --line: #37312b;
    --accent: #f5a524;
    --on-accent: #1f1400;
    --ok: #5fd68a;
    --ok-bg: #15301f;
    --bad: #ff8a80;
    --bad-bg: #381a18;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  gap: 12px;
}

/* 顶部 */
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 12px; }
h1 { margin: 0 auto 0 0; font-size: 20px; font-weight: 700; }

.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--line); justify-self: start; }
.seg button {
  min-width: 60px; height: 40px; padding: 0 10px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); font-size: 15px;
}
.seg button[aria-selected="true"], .seg button[aria-checked="true"] {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}

/* 按钮 */
.btn {
  height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.link { display: inline-flex; align-items: center; color: var(--text); text-decoration: none; }

/* 练习时长 */
.session { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.session-pick { color: var(--muted); font-size: 15px; }
.session .mic-device { flex: 0 0 auto; }
.session-clock { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.session .mic-hint { color: var(--text); font-size: 15px; font-weight: 600; }

/* 麦克风那一行外面的容器：电脑上不起作用，手机上是固定在底部的一条 */
.bar { display: contents; }
.more-btn { display: none; }

/* 麦克风 */
.mic { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; min-height: 44px; }
.heard { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.heard b { display: inline-block; min-width: 2ch; color: var(--text); font-size: 19px; }
.meter { width: 56px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter i { display: block; width: 0; height: 100%; background: var(--ok); transition: width 0.08s linear; }
.mic-error { flex-basis: 100%; margin: 0; color: var(--bad); font-size: 14px; }
.mic-device {
  flex: 0 1 260px; min-width: 0; max-width: 100%; height: 44px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px;
}
.mic-hint { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 14px; }
.mic-hint.diag { font-family: ui-monospace, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }

/* 目标与反馈 */
.panel {
  display: grid; gap: 12px; padding: 16px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  transition: background-color 0.15s, border-color 0.15s;
}
.panel.ok { border-color: var(--ok); background: var(--ok-bg); }
.panel.bad { border-color: var(--bad); background: var(--bad-bg); }

.chips { display: grid; grid-template-columns: repeat(14, 1fr); gap: 8px 4px; }
.chips.five { grid-template-columns: repeat(5, 1fr); gap: 8px; }
.chips.six { grid-template-columns: repeat(6, 1fr); gap: 8px; }
.chips.seven { grid-template-columns: repeat(7, 1fr); gap: 8px; }
.chip {
  height: 46px; padding: 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 18px; font-weight: 600;
}
.chip[aria-checked="true"] { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.chip:disabled { opacity: 0.3; cursor: default; }

.quiz-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.quiz-target { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
#quizListen, .ask-row { align-items: center; gap: 10px 14px; }
.run-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.quiz-label { color: var(--muted); font-size: 15px; }
.quiz-ask { font-size: 20px; font-weight: 700; line-height: 1.3; }
.quiz-note { font-size: 52px; font-weight: 700; line-height: 1; letter-spacing: -0.01em; }
.score { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.shapes { display: grid; gap: 12px; }
.shape-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.shape-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.shape-info strong { font-size: 18px; }
.shape-info span { color: var(--muted); font-size: 15px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 0; color: var(--muted); font-size: 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: #ffffff; border: 3px solid #ffb224; }
.legend-dot.tonic { background: #2f6fed; border-color: #2f6fed; }
.legend-dot.up { background: #ffb224; }
.legend-dot.down { background: #33241b; }

.region { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.region-label { color: var(--muted); font-size: 14px; }
.string-toggles { display: inline-flex; gap: 4px; }
.string-toggles button {
  width: 40px; height: 40px; padding: 0; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); font-size: 15px; font-weight: 600;
}
.string-toggles button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: transparent; }

.status { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.feedback { font-size: 18px; font-weight: 600; transform-origin: left center; }
.feedback.idle { color: var(--muted); font-size: 15px; font-weight: 400; }
.feedback.info { color: var(--muted); font-size: 16px; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

/* 指板 */
.fretboard { position: relative; min-width: 0; border-radius: 12px; }
.fb { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; }
.fb text { text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.fb .board { fill: #33241b; }
.fb .inlay { fill: #4d3a2e; }
.fb .fret { stroke: #a39c8f; stroke-width: 2; }
.fb .nut { stroke: #efe9db; stroke-width: 5; stroke-linecap: round; }
.fb .string { stroke: #dcd4c2; }
.fb .num, .fb .open-name { fill: var(--muted); font-size: 12px; }
.fb .open-name { font-size: 13px; font-weight: 600; }
.fb .hit { fill: transparent; cursor: pointer; }
.fb.static .hit { pointer-events: none; }
.fb .band { fill: rgb(255 178 36 / 0.12); stroke: #ffb224; stroke-width: 2; pointer-events: none; }
.fb .region { fill: rgb(255 178 36 / 0.14); stroke: #ffb224; stroke-width: 1.5; pointer-events: none; }

.fb .mark { pointer-events: none; transform-box: fill-box; transform-origin: center; animation: mark-in 0.18s ease-out; }
.fb .mark circle { fill: #ffb224; stroke: #201400; stroke-width: 1.5; }
.fb .mark text { fill: #201400; font-size: 14px; font-weight: 700; }
.fb .mark text.small { font-size: 12px; }
.fb .mark.root circle { fill: #ffffff; stroke: #ffb224; stroke-width: 3; }
.fb .mark.tonic circle { fill: #2f6fed; stroke: #0b2a6b; }
.fb .mark.tonic text { fill: #ffffff; }
.fb .mark.low circle { fill: #33241b; stroke: #ffb224; stroke-width: 2.5; }
.fb .mark.low text { fill: #ffb224; }
.fb .mark.ask circle, .fb .mark.now circle { fill: #ffffff; stroke: #2f6fed; stroke-width: 3.5; }
.fb .mark.now { animation: mark-now 1s ease-in-out infinite; }
.fb .mark.miss circle { fill: #e5484d; stroke: #3b0a0c; }
.fb .mark.miss text { fill: #ffffff; }
.fb .mark.temp { animation: mark-temp 1.1s ease-out forwards; }
.fb .marks.pulse .mark { animation: mark-pulse 0.6s ease-out; }
.fb .marks.pulse .mark circle { animation: mark-win 0.9s ease-out; }

@keyframes mark-now { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.22); } }
@keyframes mark-in { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes mark-pulse { 0% { transform: scale(1); } 35% { transform: scale(1.55); } 60% { transform: scale(0.92); } 100% { transform: scale(1); } }
@keyframes mark-win { 0%, 55% { fill: #3ddc84; stroke: #0b3d20; } 100% { fill: #ffb224; stroke: #201400; } }
@keyframes mark-temp { 0% { transform: scale(0.5); opacity: 0; } 12% { transform: scale(1); opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

/* 答对、答错的动效：面板弹一下或左右晃，指板四周亮一圈绿光或红光 */
.panel.cue-ok { animation: cue-pop 0.5s ease-out; }
.panel.cue-bad { animation: cue-shake 0.45s ease-in-out; }
.panel.cue-ok .feedback, .panel.cue-bad .feedback { animation: text-pop 0.4s ease-out; }
.fretboard::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0;
}
.fretboard.cue-ok::after { box-shadow: inset 0 0 0 5px #3ddc84, inset 0 0 48px rgb(61 220 132 / 0.6); animation: glow 0.9s ease-out; }
.fretboard.cue-bad::after { box-shadow: inset 0 0 0 5px #e5484d, inset 0 0 48px rgb(229 72 77 / 0.6); animation: glow 0.7s ease-out; }

@keyframes cue-pop {
  0% { transform: scale(1); box-shadow: 0 0 0 0 var(--ok); }
  30% { transform: scale(1.03); box-shadow: 0 0 0 6px var(--ok); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}
@keyframes cue-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-9px); }
  35% { transform: translateX(8px); }
  55% { transform: translateX(-6px); }
  75% { transform: translateX(3px); }
}
@keyframes text-pop { 0% { transform: scale(0.75); } 55% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes glow { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }

/* 设置 */
.options .mic-hint { flex-basis: 100%; }
.options { display: flex; flex-wrap: wrap; gap: 4px 24px; }
.options label { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 15px; cursor: pointer; }
.options input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .fb .mark, .fb .mark.now, .fb .marks.pulse .mark { animation: none; }
  .panel.cue-ok, .panel.cue-bad, .panel.cue-ok .feedback, .panel.cue-bad .feedback { animation: none; }
  .fb .mark.temp { animation: mark-temp 1.1s steps(1, end) forwards; }
  .panel, .meter i { transition: none; }
}

/* ---------- 一屏布局：所有屏幕上都不用上下翻，指板占满剩下的高度 ---------- */
html, body { height: 100%; overflow: hidden; }
/* 这是一屏的练习工具，不需要缩放：关掉双指缩放和双击放大，只保留上下左右滑动。 */
html { touch-action: pan-x pan-y; }
.app {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow-y: auto; /* 屏幕实在太矮、连指板的最小高度都放不下时，才允许滚动 */
  overflow-x: hidden; /* 答错时面板左右晃，不要带出横向滚动条 */
}
.fretboard { flex: 1 1 0; min-height: 205px; overflow: hidden; }

/* 屏幕窄或者矮：次要设置收进“设置”，把高度留给指板 */
@media (max-width: 559px), (max-height: 880px) {
  .app { gap: 10px; padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .panel { gap: 8px; padding: 12px; }
  .shapes { gap: 8px; }
  .bar { display: flex; align-items: center; gap: 8px; }
  .bar .mic { flex: 1 1 auto; min-width: 0; }
  .more-btn { display: inline-flex; align-items: center; margin-left: auto; }
  .app:not(.expanded) .extra,
  .app:not(.expanded) .session:not(.active) { display: none !important; }
  /* 展开设置时指板让位。 */
  .app.expanded .fretboard { display: none; }
}

/* 手机横屏这类又宽又矮的屏幕：左边一栏放页签、题目和控件，右边整栏给指板 */
@media (min-width: 560px) and (max-height: 520px) {
  .app {
    display: grid; max-width: none;
    grid-template-columns: minmax(270px, 36%) 1fr;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    gap: 8px 12px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    overflow: hidden;
  }
  .app.expanded { grid-template-columns: 1fr; overflow-y: auto; }
  h1 { display: none; }
  .top { grid-column: 1; grid-row: 1; flex-wrap: nowrap; gap: 8px; }
  .top .seg { flex: 1 1 auto; min-width: 0; }
  .top .seg button { flex: 1; min-width: 0; padding: 0 4px; height: 36px; }
  .fs-btn { flex: none; height: 40px; padding: 0 12px; }
  .session { grid-column: 1; grid-row: 2; }
  .panel { grid-column: 1; grid-row: 3; align-content: start; overflow-y: auto; padding: 10px 12px; }
  .options { grid-column: 1; grid-row: 4; }
  .bar { grid-column: 1; grid-row: 5; }
  .fretboard { grid-column: 2; grid-row: 1 / 6; min-height: 0; }

  .chips, .chips.five, .chips.six, .chips.seven { gap: 6px 4px; }
  .chip { height: 38px; font-size: 16px; }
  .btn { height: 40px; padding: 0 12px; }
  .quiz-note { font-size: 36px; }
  .quiz-ask { font-size: 17px; }
  .status { min-height: 36px; }
  .feedback { font-size: 15px; }
  .feedback.idle, .feedback.info { font-size: 14px; }
}

/* 手机竖屏：页签在最上，麦克风和“设置”固定在最下 */
@media (max-width: 559px) {
  .app { gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }

  h1 { display: none; }
  /* 页签占满一行，全屏按钮跟在右边。 */
  .top { flex-wrap: nowrap; gap: 8px; }
  .top .seg { flex: 1 1 auto; min-width: 0; }
  .top .seg button { flex: 1; min-width: 0; padding: 0 4px; }
  .fs-btn { flex: none; padding: 0 12px; }
  .seg button { height: 38px; }

  .top { order: 0; }
  .session { order: 1; }
  .panel { order: 2; padding: 10px 12px; }
  .fretboard { order: 3; min-height: 200px; }
  .options { order: 4; }
  .bar { order: 5; }

  .chips, .chips.five, .chips.six, .chips.seven { gap: 6px 4px; }
  .chip { height: 42px; font-size: 17px; }
  .btn { height: 42px; padding: 0 14px; }
  .quiz-note { font-size: 40px; }
  .quiz-ask { font-size: 18px; }
  .status { min-height: 38px; }
  .feedback { font-size: 16px; }
  .feedback.idle, .feedback.info { font-size: 14px; }

  .fb .mark text { font-size: 15px; }
  .fb .mark text.small { font-size: 13px; }
}
