/* ============ 钢琴学习助手 · 暖纸色主题 ============ */
:root {
  --bg: #f7f2e9;
  --bg-card: #fffdf8;
  --bg-soft: #f0e8da;
  --ink: #3d3629;
  --ink-soft: #7a7060;
  --line: #e2d8c6;
  --accent: #c96f4a;      /* 陶土橙 */
  --accent-dark: #a8532f;
  --teal: #3e7d75;
  --teal-soft: #dcebe8;
  --gold: #b98a2f;
  --ok: #4a8f5d;
  --bad: #c14f3d;
  --shadow: 0 2px 10px rgba(90, 70, 40, .10);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  font-size: 15.5px;
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  background: linear-gradient(135deg, #4a3f30, #6b5a40);
  color: #f5efe4;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 8px rgba(60, 45, 20, .25);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand-icon { font-size: 22px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.tab {
  background: rgba(255, 255, 255, .08); color: #e8dfcd;
  border: none; border-radius: 999px;
  padding: 7px 16px; font-size: 14.5px; cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.tab:hover { background: rgba(255, 255, 255, .18); }
.tab.active { background: #f5efe4; color: #4a3f30; font-weight: 700; }
.icon-btn {
  background: rgba(255, 255, 255, .12); border: none; color: #f5efe4;
  font-size: 18px; border-radius: 8px; padding: 5px 10px; cursor: pointer;
}
.top-actions { display: flex; align-items: center; gap: 6px; }
.audio-test-btn { font: inherit; font-size: 12px; color: #f5efe4; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); border-radius: 8px; padding: 7px 9px; cursor: pointer; }
.audio-notice { background: var(--teal-soft); color: var(--ink); padding: 8px 16px; font-size: 13px; }
.audio-notice[hidden] { display: none; }

/* ---------- 主区 ---------- */
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 22px 16px 40px; }
.page { display: none; }
.page.active { display: block; }

.foot {
  text-align: center; color: var(--ink-soft); font-size: 12.5px;
  padding: 14px; border-top: 1px solid var(--line);
}

/* ---------- 卡片与通用组件 ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  margin-bottom: 18px;
}
.card h2, .card h3 { margin-top: 0; color: #4a3f30; }
h1 { font-size: 24px; color: #4a3f30; margin: 6px 0 14px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }

.btn {
  background: var(--accent); color: #fff;
  border: none; border-radius: 9px;
  padding: 9px 20px; font-size: 15px; cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { background: #cbbfae; cursor: not-allowed; }
.btn.secondary {
  background: var(--teal-soft); color: var(--teal);
  border: 1px solid #bcd6d0;
}
.btn.secondary:hover { background: #cfe3de; }
.btn.ghost {
  background: transparent; color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--bg-soft); }
.btn.small { padding: 5px 12px; font-size: 13.5px; }
.btn.danger { background: var(--bad); }

select, input[type="number"], input[type="text"] {
  font-family: inherit; font-size: 14.5px;
  padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink);
}
input[type="range"] { accent-color: var(--accent); }

.tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12.5px; background: var(--bg-soft); color: var(--ink-soft);
  margin-right: 6px;
}
.tag.teal { background: var(--teal-soft); color: var(--teal); }
.tag.gold { background: #f3e8cf; color: var(--gold); }

.hr { border: none; border-top: 1px dashed var(--line); margin: 18px 0; }

.muted { color: var(--ink-soft); font-size: 13.5px; }
.center { text-align: center; }

/* ---------- 课程 ---------- */
.level-head {
  display: flex; align-items: baseline; gap: 10px; margin: 26px 0 10px;
}
.lv-badge {
  background: var(--teal); color: #fff; border-radius: 8px;
  padding: 2px 12px; font-weight: 700; font-size: 15px;
  white-space: nowrap; flex-shrink: 0;
}
.level-head .lv-badge { display: inline-block; }
.level-head .lv-title { font-size: 19px; font-weight: 700; }
.lesson-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 16px; margin-bottom: 8px;
  cursor: pointer; transition: all .15s;
}
.lesson-item:hover { border-color: var(--accent); transform: translateX(3px); }
.lesson-item .done-mark { color: var(--ok); font-weight: 700; }
.lesson-item .go { margin-left: auto; color: var(--ink-soft); }

.lesson-body h1 { margin-top: 0; }
.lesson-body p { margin: 10px 0; }
.lesson-body .tip {
  background: var(--teal-soft); border-left: 4px solid var(--teal);
  border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 14px 0;
  font-size: 14.5px;
}
.lesson-body .note {
  background: #f6ecd9; border-left: 4px solid var(--gold);
  border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 14px 0;
  font-size: 14.5px;
}
.demo-box {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px; margin: 14px 0;
}
.demo-box .demo-title { font-weight: 700; color: #4a3f30; margin-bottom: 8px; font-size: 14.5px; }
.demo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.staff-wrap { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: inline-block; }
.staff-wrap svg { display: block; }
.staff-note-hit { cursor: pointer; }
.staff-note-hit:focus { outline: 2px solid var(--accent); }
.lesson-body h2 { margin: 24px 0 10px; font-size: 19px; }
.note-anatomy { max-width: 380px; background: #fff; border-radius: 8px; margin: 8px 0; }
.note-anatomy svg { display: block; width: 100%; }
.note-value-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.triad-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.score-wrap { display: block; margin: 6px 0 12px; }
.staff-note.playing ellipse:not(.staff-note-hit) { stroke: var(--accent); stroke-width: 3; }
.note-value-card { padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.note-value-card h3 { margin: 0; font-size: 15px; }
.note-value-card p { font-size: 13.5px; }
.duration-bar { height: 10px; border-radius: 5px; background: var(--bg-soft); overflow: hidden; }
.duration-bar span { display: block; height: 100%; background: var(--teal); }
.duration-question + .duration-question { border-top: 1px dashed var(--line); margin-top: 16px; padding-top: 8px; }
.rhythm-cells { display: flex; gap: 2px; margin: 12px 0 8px; }
.rhythm-scroller { overflow-x: auto; }
.rhythm-timeline { position: relative; }
.rhythm-cell { background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; text-align: center; }
.rhythm-cell svg { width: 100%; height: 95px; display: block; }
.rhythm-cell-label { font-size: 12px; overflow-wrap: anywhere; }
.beat-grid { display: grid; gap: 2px; margin: 6px 0; }
.beat-cell { padding: 5px 0; text-align: center; color: var(--ink-soft); border-radius: 4px; background: #fff; font-size: 12px; }
.beat-start { font-weight: 700; border-left: 2px solid var(--teal); }
.rhythm-cell.playing, .beat-cell.playing { background: #ffd9a8; border-color: var(--accent); color: var(--ink); }
.rhythm-status { min-height: 28px; font-size: 13.5px; color: var(--teal); }
.staff-wrap { max-width: 100%; overflow-x: auto; vertical-align: top; }
@media (max-width: 480px) {
  .card { padding: 14px 10px; }
  .demo-box { padding: 12px 8px; }
  .rhythm-cell svg { height: 80px; }
  .rhythm-cell-label, .beat-cell { font-size: 10px; }
}
.staff-note-hit:hover ellipse { fill: var(--accent) !important; }

video-embed iframe, .bili-frame {
  width: 100%; aspect-ratio: 16 / 9; border: none; border-radius: 10px;
  background: #000; display: block;
}
.video-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 8px; background: #fff;
}
.video-item .v-title { flex: 1; cursor: pointer; }
.video-item .v-title:hover { color: var(--accent); }
.add-video-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.add-video-row input { flex: 1; min-width: 220px; }

/* ---------- 虚拟键盘 ---------- */
.kb-wrap { position: relative; user-select: none; touch-action: pan-x pan-y; }
.kb-scroller { overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }
.kb-key {
  position: absolute; top: 0;
  border: 1px solid #b8ad99; border-top: none;
  background: linear-gradient(#fffef9, #f4eee1);
  border-radius: 0 0 5px 5px;
  cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center;
  color: #9a8f7c; font-size: 11.5px; padding-bottom: 5px;
}
.kb-key:hover { background: linear-gradient(#fff, #efe6d4); }
.kb-key.black {
  background: linear-gradient(#4c4437, #2b251c);
  border: 1px solid #1c1812; border-radius: 0 0 4px 4px;
  z-index: 2; color: transparent;
}
.kb-key.black:hover { background: linear-gradient(#5d5343, #332c22); }
/* 相邻十二键组交替着色（展示分组规律） */
.kb-key.alt { background: linear-gradient(#fbf1dc, #ecdfc2); }
.kb-key.alt:hover { background: linear-gradient(#fff, #e8d9ba); }
.kb-key.black.alt { background: linear-gradient(#5a4f3f, #352d22); }
.kb-key.black.alt:hover { background: linear-gradient(#6b5e4b, #40372a); }
.kb-key.hl { background: linear-gradient(#ffd9a8, #f5b877) !important; color: #7a4a1d; }
.kb-key.black.hl { background: linear-gradient(#c96f4a, #a8532f) !important; color: transparent; }
.kb-key.ok { background: #bfe3c6 !important; }
.kb-key.bad { background: #f0b9ad !important; }

/* ---------- 训练页 ---------- */
.trainer-grid { display: flex; gap: 18px; flex-wrap: wrap; }
.trainer-grid .settings-col { flex: 0 0 260px; min-width: 240px; }
.trainer-grid .main-col { flex: 1; min-width: 320px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.setting-row label { font-size: 14px; color: var(--ink-soft); white-space: nowrap; }
.setting-row select { flex: 1; min-width: 0; }

.q-card { min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.q-staff { margin: 10px 0 16px; }
.q-feedback { min-height: 30px; font-size: 16.5px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.q-feedback.ok { color: var(--ok); }
.q-feedback.bad { color: var(--bad); }

.stat-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  background: var(--bg-soft); border-radius: 9px; padding: 7px 14px;
  font-size: 13.5px; color: var(--ink-soft);
}
.chip b { color: var(--ink); font-size: 15.5px; margin-left: 4px; }

.choice-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.choice-btn {
  background: #fff; border: 1.5px solid var(--line); border-radius: 9px;
  padding: 9px 16px; font-size: 15px; cursor: pointer; font-family: inherit;
  transition: all .12s;
}
.choice-btn:hover { border-color: var(--accent); background: #fff7ef; }
.choice-btn.ok { background: #d8efd9; border-color: var(--ok); color: var(--ok); font-weight: 700; }
.choice-btn.bad { background: #f7d4cc; border-color: var(--bad); color: var(--bad); }
.choice-btn:disabled { cursor: default; }

.ear-controls { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }

/* ---------- 目标页 ---------- */
.goal-level {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-card); margin-bottom: 14px; overflow: hidden;
}
.goal-level.current { border-color: var(--accent); box-shadow: 0 0 0 2px #e8c4ae; }
.goal-level-head {
  display: flex; align-items: center; gap: 12px; padding: 13px 18px; cursor: pointer;
}
.goal-level-head:hover { background: #fdf8ee; }
.goal-level-head .lv-name { font-weight: 700; font-size: 16px; }
.goal-level-head .lv-desc { color: var(--ink-soft); font-size: 13px; flex: 1; }
.goal-level-body { border-top: 1px dashed var(--line); padding: 6px 18px 14px; background: #fffdf6; }
.task-row { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; font-size: 14.5px; }
.task-row .tk { margin-top: 2px; }
.task-row.done .task-label { text-decoration: line-through; color: var(--ink-soft); }
.task-row .auto-mark { font-size: 12px; color: var(--teal); }

.progress-track {
  height: 8px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; flex: 0 0 130px;
}
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #e0955f); border-radius: 99px; transition: width .3s; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; max-width: 340px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 7px; background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--ink-soft);
}
.cal-cell.on { background: var(--teal); color: #fff; font-weight: 700; }
.cal-cell.today { outline: 2px solid var(--accent); }

.mistake-list { font-size: 13.5px; color: var(--ink-soft); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(50, 40, 25, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg-card); border-radius: 14px; padding: 26px 30px;
  max-width: 480px; width: 92%; box-shadow: 0 10px 40px rgba(50, 40, 20, .3);
  max-height: 85vh; overflow: auto;
}
.modal h2 { margin-top: 0; }

@media (max-width: 720px) {
  .trainer-grid { flex-direction: column; }
  .trainer-grid .settings-col { flex: 1 1 auto; }
  .topbar-inner { gap: 10px; }
}
