/* ============================================================
   MusicPal · 乐器学习伙伴 —— 样式
   设计令牌（颜色/间距统一管理，想换风格改这里就行）
   ============================================================ */
:root {
  --bg:        #0f1419;      /* 深色背景，护眼、舞台感 */
  --bg-soft:   #1a2027;      /* 卡片背景 */
  --bg-soft2:  #222b35;      /* 更亮一层 */
  --line:      #2c3744;      /* 分割线 */
  --text:      #e8edf2;      /* 主文字 */
  --text-dim:  #8a99a8;      /* 次要文字 */
  --brand:     #ff8a3d;      /* 主题橙——温暖、有活力 */
  --brand-2:   #ffd23f;      /* 点缀黄 */
  --good:      #46d39a;      /* 成功绿 */
  --chord:     #6cc8ff;      /* 和弦蓝 */
  --danger:    #ff5d6c;
  --radius:    16px;
  --shadow:    0 6px 20px rgba(0,0,0,.35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + var(--safe-bottom));
  line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; }
.brand-logo { font-size: 22px; }
.brand-name { letter-spacing: .5px; }
.topbar-stats { display: flex; gap: 14px; font-size: 13px; color: var(--text-dim); }
.topbar-stats b { color: var(--brand-2); font-size: 15px; }

/* ---------- 主区 ---------- */
.view { padding: 6px 16px 24px; max-width: 720px; margin: 0 auto; }
.section-title { font-size: 15px; color: var(--text-dim); margin: 22px 4px 12px; font-weight: 700; }
.section-title:first-child { margin-top: 8px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(18,23,29,.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px 0 calc(8px + var(--safe-bottom));
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; color: var(--text-dim); padding: 4px 18px; border-radius: 12px;
  transition: color .15s;
}
.tab-ico { font-size: 21px; filter: grayscale(.4) opacity(.7); transition: filter .15s, transform .15s; }
.tab.active { color: var(--brand); }
.tab.active .tab-ico { filter: none; transform: translateY(-1px) scale(1.08); }

/* ---------- 通用卡片 ---------- */
.card {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 12px; font-weight: 700; font-size: 14px;
  background: var(--bg-soft2); color: var(--text); transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--brand); color: #1a1206; }
.btn-good { background: var(--good); color: #06231a; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 10px; }

/* ---------- 首页 ---------- */
.hero {
  background: linear-gradient(135deg, #2a1c0e, #1a2027);
  border: 1px solid var(--line); border-radius: 20px; padding: 20px;
  margin-top: 8px;
}
.hero h1 { margin: 0 0 4px; font-size: 22px; }
.hero p { margin: 0; color: var(--text-dim); font-size: 14px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat-box { background: rgba(255,255,255,.04); border-radius: 14px; padding: 12px; text-align: center; }
.stat-box .num { font-size: 26px; font-weight: 800; color: var(--brand-2); }
.stat-box .lbl { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.stat-box .num.fire { color: var(--brand); }

.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.quick {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  text-align: left; transition: transform .1s, border-color .15s;
}
.quick:active { transform: scale(.97); }
.quick .q-ico { font-size: 26px; }
.quick .q-title { font-weight: 700; font-size: 15px; }
.quick .q-sub { font-size: 12px; color: var(--text-dim); }

/* ---------- 曲库 ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; margin: 4px 0 14px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text-dim);
}
.chip.active { background: var(--brand); color: #1a1206; border-color: var(--brand); }
.search-input {
  flex: 1; min-width: 120px; padding: 9px 13px; border-radius: 12px;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text); font-size: 14px;
}
.search-input::placeholder { color: var(--text-dim); }

.song-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 14px; margin-bottom: 10px; transition: transform .1s, border-color .15s;
}
.song-card:active { transform: scale(.985); }
.song-status {
  width: 8px; align-self: stretch; border-radius: 999px; flex: none;
}
.song-status.want { background: var(--text-dim); }
.song-status.learning { background: var(--brand); }
.song-status.done { background: var(--good); }
.song-main { flex: 1; min-width: 0; }
.song-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; display: flex; gap: 10px; align-items: center; }
.stars { color: var(--brand-2); letter-spacing: 1px; }
.song-key { background: rgba(108,200,255,.14); color: var(--chord); padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; }

/* ---------- 看谱页 ---------- */
.sheet-head { position: sticky; top: 52px; z-index: 20; background: var(--bg); padding: 8px 0 10px; }
.sheet-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.back-btn { font-size: 20px; padding: 4px 8px; }
.sheet-title { font-size: 20px; font-weight: 800; flex: 1; }
.sheet-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ctrl-group { display: flex; align-items: center; gap: 4px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.ctrl-group .lbl { font-size: 11px; color: var(--text-dim); padding: 0 6px; }
.step-btn { width: 30px; height: 30px; border-radius: 8px; background: var(--bg-soft2); font-size: 17px; font-weight: 800; display: grid; place-items: center; }
.ctrl-val { min-width: 30px; text-align: center; font-weight: 700; font-size: 14px; }

/* ChordPro 谱面排版 */
.sheet { font-size: 17px; line-height: 2.5; padding-bottom: 40vh; }
.sheet .cp-line { margin: 0 0 4px; white-space: pre-wrap; }
.sheet .cp-section { color: var(--brand-2); font-weight: 800; font-size: 14px; margin: 18px 0 6px; letter-spacing: 1px; }
.sheet .cp-slot { position: relative; display: inline-block; }
.sheet .cp-chord {
  position: absolute; top: -1.25em; left: 0;
  color: var(--chord); font-weight: 800; font-size: 14px; white-space: nowrap;
  cursor: pointer; line-height: 1;
}
.sheet .cp-chord:active { color: var(--brand-2); }
.sheet.chords-only .cp-lyric { display: none; }
.sheet.lyrics-only .cp-chord { display: none; }

/* 和弦速查条（谱子里出现的和弦图） */
.chord-bar { display: flex; gap: 14px; overflow-x: auto; padding: 12px 2px; margin-top: 6px; }
.chord-bar .chord-tile { flex: none; text-align: center; }

/* 自动滚动 / 计时浮条 */
.float-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-bottom)); z-index: 35;
  display: flex; align-items: center; gap: 10px;
  background: rgba(26,32,39,.96); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 10px; box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.float-bar .timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 15px; min-width: 52px; text-align: center; }

/* ---------- 工具箱 ---------- */
.tool-grid { display: grid; gap: 14px; }

/* 节拍器 */
.metro-bpm { text-align: center; }
.metro-bpm .bpm-num { font-size: 64px; font-weight: 800; line-height: 1; color: var(--brand); }
.metro-bpm .bpm-lbl { color: var(--text-dim); font-size: 13px; }
.beat-dots { display: flex; justify-content: center; gap: 12px; margin: 18px 0; }
.beat-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--bg-soft2); transition: transform .06s, background .06s; }
.beat-dot.accent { box-shadow: 0 0 0 2px var(--brand) inset; }
.beat-dot.on { background: var(--brand-2); transform: scale(1.5); }
.beat-dot.on.accent { background: var(--brand); }
.metro-slider { width: 100%; margin: 14px 0; accent-color: var(--brand); height: 28px; }

/* 调音器 */
.tuner-note { text-align: center; margin: 8px 0; }
.tuner-note .note-name { font-size: 60px; font-weight: 800; line-height: 1; }
.tuner-note .note-name.in-tune { color: var(--good); }
.tuner-note .note-freq { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.tuner-gauge { position: relative; height: 14px; background: var(--bg-soft2); border-radius: 999px; margin: 16px 0 6px; overflow: hidden; }
.tuner-gauge .center-line { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; background: var(--good); transform: translateX(-50%); }
.tuner-gauge .needle { position: absolute; top: -3px; width: 8px; height: 20px; border-radius: 4px; background: var(--brand); transition: left .08s linear; transform: translateX(-50%); }
.tuner-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); }
.string-row { display: flex; justify-content: center; gap: 8px; margin: 14px 0 4px; }
.string-pill { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--bg-soft2); border: 1px solid var(--line); }
.string-pill.lit { background: var(--good); color: #06231a; border-color: var(--good); }

/* 和弦字典 */
.dict-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.chord-tile { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; }
.chord-tile .ct-name { font-weight: 800; font-size: 15px; margin-top: 4px; color: var(--chord); }

/* ---------- 练琴记录 ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 8px; }
.cal-cell { aspect-ratio: 1; border-radius: 6px; background: var(--bg-soft2); display: grid; place-items: center; font-size: 10px; color: var(--text-dim); }
.cal-cell.l1 { background: #2d3b2f; } .cal-cell.l2 { background: #3a5a3f; }
.cal-cell.l3 { background: #4e8a54; } .cal-cell.l4 { background: var(--good); color: #06231a; }
.cal-cell.today { box-shadow: 0 0 0 2px var(--brand); }
.cal-week { display: grid; grid-template-columns: repeat(7,1fr); gap: 5px; font-size: 11px; color: var(--text-dim); text-align: center; margin-bottom: 6px; }

/* ---------- 通用小工具 ---------- */
.empty { text-align: center; color: var(--text-dim); padding: 40px 20px; }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.row { display: flex; gap: 10px; }
.row.between { justify-content: space-between; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--text-dim); font-size: 13px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: var(--bg-soft2); border: 1px solid var(--line); color: var(--text); font-size: 14px;
}
.field textarea { min-height: 160px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.7; resize: vertical; }

/* 弹层 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60; display: grid; place-items: end center; }
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(24px + var(--safe-bottom)); animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 16px; font-size: 19px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--good); color: #06231a; font-weight: 700; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; z-index: 80; box-shadow: var(--shadow);
  animation: toastin .25s ease;
}
@keyframes toastin { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* ============================================================
   多乐器版新增样式
   ============================================================ */

/* 首次进入：选乐器 */
.instrument-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 18px;
}
.instrument-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 22px 10px; border-radius: 16px;
  background: var(--bg-soft2); border: 2px solid var(--line); color: var(--text);
  cursor: pointer; transition: all .15s ease; font-family: inherit;
}
.instrument-card .ins-icon { font-size: 36px; }
.instrument-card .ins-name { font-size: 15px; font-weight: 600; }
.instrument-card.active {
  border-color: var(--brand); background: var(--brand-soft, rgba(23,131,255,.12));
}
.instrument-card:active { transform: scale(.97); }

/* 乐器切换条 */
.ins-switcher {
  display: flex; gap: 6px; padding: 6px 14px; overflow-x: auto;
  background: var(--bg-soft2); border-bottom: 1px solid var(--line);
}
.ins-tab {
  padding: 5px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--text-dim); font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.ins-tab.active {
  background: var(--brand); color: #fff; border-color: var(--brand);
}

/* 纯文本谱（钢琴/小提琴等无和弦谱的乐器） */
.plain-score {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px; line-height: 2; white-space: pre-wrap; word-break: break-word;
  color: var(--text); background: transparent; padding: 4px 2px;
}

/* 页脚 */
.site-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center; align-items: center; gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: var(--bg-soft2); border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-dim); z-index: 30;
}
.site-footer a { color: var(--brand); text-decoration: none; }
.footer-sep { opacity: .5; }

/* 内嵌模式（StudyMap 集成）：隐藏品牌栏、底部导航、页脚 */
body.embed-mode .topbar,
body.embed-mode .tabbar,
body.embed-mode .site-footer { display: none; }
body.embed-mode .view { padding-bottom: 20px; }
