:root {
  /* 弹琴吧风格:米色底 + 绿色点缀 + 亮色 */
  --bg: #f6f1e6;          /* 米色背景 */
  --panel: #ffffff;
  --panel2: #f1ede3;
  --line: #e4ddcd;
  --text: #2f3a34;
  --muted: #8a9089;
  --accent: #34b767;      /* 主绿 */
  --accent-d: #2aa25b;
  --go: #34b767;
  --warn: #e0952a;
  --bad: #e2574c;
  --good: #34b767;
  --hand-r: #3d7bff;      /* 右手蓝 */
  --hand-l: #ff8a2b;      /* 左手橙 */
  --key-wrong: #e2574c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}
body {
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  flex: 0 0 auto; background: var(--panel);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .5px; color: var(--accent-d); }
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status--off .dot { background: #c2bdaf; }
.status--on { color: var(--good); }
.status--on .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.status--err { color: var(--bad); }
.status--err .dot { background: var(--bad); }

#app { flex: 1 1 auto; overflow-y: auto; padding: 16px; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px; margin-bottom: 14px;
  box-shadow: 0 2px 10px rgba(120,110,80,.05);
}
.row { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.lbl { font-size: 14px; color: var(--muted); min-width: 40px; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 4px 0 2px; }

.debuglog {
  display: none; background: #2d322c; color: #9fe6b6; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font-size: 11px; line-height: 1.5;
  max-height: 200px; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
  margin: 6px 0 0; font-family: ui-monospace, Menlo, Consolas, monospace;
}
.debuglog.show { display: block; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); font-size: 15px; font-weight: 600;
  padding: 12px 18px; border-radius: 11px; cursor: pointer; flex: 1 1 auto;
  transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--go { background: var(--go); border-color: var(--go); color: #fff; }

.select {
  flex: 1 1 auto; appearance: none; background: var(--panel2);
  color: var(--text); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 14px; font-size: 15px;
}

.segmented { display: flex; gap: 6px; flex: 1 1 auto; }
.seg {
  flex: 1 1 0; appearance: none; border: 1px solid var(--line);
  background: var(--panel2); color: var(--muted);
  padding: 10px 6px; border-radius: 10px; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.seg--active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* practice */
.ptitle { font-size: 18px; font-weight: 700; }
.pmeta { font-size: 13px; color: var(--muted); margin-top: 4px; }
#progressWrap { height: 8px; background: var(--panel2); border-radius: 6px; margin: 14px 0; overflow: hidden; }
#progressBar { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }

.livestats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--panel2); border-radius: 11px; padding: 12px 6px; text-align: center; }
.stat__v { font-size: 20px; font-weight: 700; }
.stat__l { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.nexthud { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; }
.nexthud__label { font-size: 13px; color: var(--muted); }
.nexthud__note { font-size: 28px; font-weight: 800; }

/* result */
.rtitle { font-size: 15px; color: var(--muted); }
.bigscore { font-size: 56px; font-weight: 800; text-align: center; margin: 6px 0; }
.rdetail { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.rdetail .cell { background: var(--panel2); border-radius: 10px; padding: 10px 12px; }
.rdetail .cell b { font-size: 18px; }
.rdetail .cell span { display: block; font-size: 12px; color: var(--muted); }
.weaklist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.weakitem { background: var(--panel2); border-left: 3px solid var(--warn); border-radius: 8px; padding: 9px 12px; font-size: 13.5px; }

/* ============ 练习页顶栏(弹琴吧风格图标条) ============ */
#playBar {
  display: none; align-items: center; gap: 4px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
#playBar .grp { display: flex; align-items: center; gap: 4px; }
#playBar .spacer { flex: 1 1 auto; }
.iconbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-width: 52px; padding: 4px 6px; border: none; background: transparent;
  color: var(--accent-d); font-size: 11px; cursor: pointer; border-radius: 10px;
}
.iconbtn .ic {
  width: 34px; height: 34px; border-radius: 50%; background: #eaf6ee;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.iconbtn.on .ic { background: var(--accent); color: #fff; }
.iconbtn:active { background: #eef2ea; }
#playBarTitle { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ============ 音符路线进度条(替代五线谱) ============ */
#roadmap {
  display: none; height: 78px; background: #fbf7ee;
  border-bottom: 1px solid var(--line); overflow: hidden; position: relative; flex: 0 0 auto;
}
#roadmapTrack {
  display: flex; align-items: center; height: 100%; gap: 6px;
  padding: 0 50%; transition: transform .18s ease-out; will-change: transform;
}
.rmNote {
  flex: 0 0 auto; min-width: 30px; height: 44px; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #ece5d5; color: #a89a7c; font-size: 11px; font-weight: 700;
  border: 2px solid transparent; position: relative;
}
.rmNote small { font-size: 9px; opacity: .7; }
.rmNote.rm-L { background: #ffe6cf; color: var(--hand-l); }
.rmNote.rm-R { background: #dbe7ff; color: var(--hand-r); }
.rmNote.rm-done { opacity: .35; }
.rmNote.rm-cur {
  transform: scale(1.15); border-color: var(--accent);
  box-shadow: 0 3px 10px rgba(52,183,103,.35); color: var(--accent-d); background: #eafaf0;
}
#roadmapCenter {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
  background: var(--accent); transform: translateX(-50%); opacity: .5; pointer-events: none;
}

/* ============ 钢琴键盘 ============ */
#pianoWrap {
  flex: 0 0 auto; background: #efe8d8; border-top: 1px solid var(--line);
  padding: 8px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
}
#piano { position: relative; height: 150px; display: flex; width: 100%; min-width: 100%; }
.wkey {
  position: relative; flex: 1 1 0; min-width: 0; height: 150px;
  background: linear-gradient(#ffffff, #f4f1ea);
  border-right: 1px solid #cfc8b8; border-bottom: 2px solid #b9b1a0;
  border-radius: 0 0 4px 4px;
}
.wkey:first-child { border-left: 1px solid #cfc8b8; }
.wkey .lbl { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 10px; color: #b3ac9c; pointer-events: none; }
.bkey {
  position: absolute; top: 0;
  /* 黑键宽度 = 白键宽度的 0.62 倍(白键宽 = 100%/白键数) */
  width: calc(62% / var(--whites, 52)); height: 60%; z-index: 2;
  transform: translateX(-50%);
  background: linear-gradient(#3a3f43, #14181b);
  border: 1px solid #0a0d0f; border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 3px 4px rgba(0,0,0,.35);
}
/* 指尖标记(圆润椭圆,像弹琴吧那种指腹感) */
.dot {
  position: absolute; bottom: 10%; left: 50%; transform: translateX(-50%);
  width: 80%; max-width: 22px; height: 20%; min-height: 16px; max-height: 26px;
  /* 上窄下宽的圆润椭圆:顶部半径大,底部更圆润 */
  border-radius: 50% 50% 48% 48% / 62% 62% 40% 40%;
  opacity: 0; transition: opacity .12s, transform .12s; pointer-events: none; box-sizing: border-box;
}
.bkey .dot { bottom: 8%; width: 82%; max-width: 16px; }
.dot--show { opacity: 1; }
/* 左手橙 / 右手蓝,带柔和高光和阴影,像立体指尖 */
.dot--L {
  background: radial-gradient(120% 90% at 50% 30%, #ffc38a 0%, var(--hand-l) 55%, #e6741a 100%);
  box-shadow: 0 2px 5px rgba(230,116,26,.5), inset 0 1px 2px rgba(255,255,255,.55);
}
.dot--R {
  background: radial-gradient(120% 90% at 50% 30%, #9ec0ff 0%, var(--hand-r) 55%, #2a5fd6 100%);
  box-shadow: 0 2px 5px rgba(42,95,214,.5), inset 0 1px 2px rgba(255,255,255,.55);
}
/* 按下/对错 */
.wkey.hi { background: linear-gradient(#d7f0e0, #b6e4c8); }
.bkey.hi { background: linear-gradient(#3f8f5f, #2c7a4c); }
.wkey.ok { background: linear-gradient(#c7f0d5, #8fe0aa) !important; }
.bkey.ok { background: linear-gradient(#3f9f63, #2c8a4c) !important; }
.wkey.wrong { background: linear-gradient(#ffd0cb, #f5a49c) !important; }
.bkey.wrong { background: linear-gradient(#c0392f, #a02a22) !important; }

/* ============ 横屏:极简全键盘练习模式 ============ */
@media (orientation: landscape) {
  #app { padding: 8px 12px; }
  #piano, .wkey { height: 42vh; min-height: 150px; }
  #pianoWrap { padding: 6px; overflow-x: hidden; }

  body.playing #topbar { display: none; }
  body.playing #app { display: none; }             /* 练习中隐藏设置滚动区 */
  body.playing #playBar { display: flex; }
  body.playing #roadmap { display: block; }
  body.playing #pianoWrap { flex: 1 1 auto; display: flex; align-items: stretch; }
  body.playing #piano, body.playing .wkey { height: 100%; min-height: 0; }
}
/* 竖屏也能显示练习顶栏/路线(方便竖屏测试) */
body.playing #playBar { display: flex; }
body.playing #roadmap { display: block; }

.toast {
  position: fixed; left: 50%; bottom: 180px; transform: translateX(-50%);
  background: #2f3a34ee; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 14px; z-index: 50; max-width: 80%; text-align: center;
}
