/* =========================================================================
 * DeepSeek Piano — style.css
 * 深色录音棚风格 / 支持浅色主题 / 响应式
 * ========================================================================= */

/* ------------------------------- 设计变量 ------------------------------- */
:root {
  --bg: #07080e;
  --bg-2: #0d1018;
  --panel: rgba(21, 24, 36, 0.72);
  --panel-solid: #151926;
  --panel-2: rgba(31, 35, 51, 0.65);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e9ecf6;
  --text-dim: #b3b9cd;
  --muted: #858ca4;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-3: #f472b6;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.85);
  --glow: 0 0 0 1px rgba(124, 92, 255, 0.5), 0 8px 28px -6px rgba(124, 92, 255, 0.5);
  --key-white: linear-gradient(180deg, #fdfdff 0%, #eef0f8 62%, #d9dcea 100%);
  --key-white-active: linear-gradient(180deg, #cfd4ff 0%, #a9b0ff 60%, #7c5cff 100%);
  --key-black: linear-gradient(180deg, #3a3f52 0%, #1a1d28 55%, #0b0d13 100%);
  --key-black-active: linear-gradient(180deg, #6c5bff 0%, #4335b8 60%, #251d6b 100%);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

html[data-theme="light"] {
  --bg: #eef0f7;
  --bg-2: #f7f8fc;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --panel-2: rgba(240, 242, 250, 0.9);
  --line: rgba(16, 20, 40, 0.1);
  --line-strong: rgba(16, 20, 40, 0.2);
  --text: #171a26;
  --text-dim: #3c4256;
  --muted: #6b7288;
  --shadow: 0 18px 40px -20px rgba(20, 24, 60, 0.35);
  --key-white: linear-gradient(180deg, #ffffff 0%, #f0f2f8 70%, #dfe3ee 100%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1000px 600px at 12% -10%, rgba(124, 92, 255, 0.20), transparent 60%),
    radial-gradient(900px 520px at 88% 0%, rgba(34, 211, 238, 0.14), transparent 62%),
    radial-gradient(700px 500px at 50% 110%, rgba(244, 114, 182, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}

button, input, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }
b { font-weight: 650; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(140, 150, 190, 0.28); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(140, 150, 190, 0.5); background-clip: content-box; }

/* ------------------------------- 布局骨架 ------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  /* 极端矮窗口下的兜底：宁可滚动，也不让任何模块被裁掉或覆盖 */
  overflow-x: hidden;
  overflow-y: auto;
}

/* --------------------------------- 顶栏 -------------------------------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(12, 14, 22, 0.9), rgba(12, 14, 22, 0.55));
  backdrop-filter: blur(14px);
  z-index: 20;
}
html[data-theme="light"] .topbar { background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.6)); }

.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand .logo {
  font-size: 22px;
  filter: drop-shadow(0 2px 10px rgba(124, 92, 255, 0.7));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.12; }
.brand-text b {
  font-size: 15px;
  letter-spacing: 0.2px;
  background: linear-gradient(92deg, var(--text), var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-text small { color: var(--muted); font-size: 10.5px; letter-spacing: 0.5px; }

.preset-strip {
  flex: 1 1 auto;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 3px 2px;
  scrollbar-width: none;
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
.preset-strip::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
  transition: all 0.16s ease;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); transform: translateY(-1px); }
.chip.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(120deg, var(--accent), #5b46d6 60%, var(--accent-2));
  box-shadow: 0 6px 20px -8px var(--accent);
}
.chip .ico { font-size: 14px; }

.top-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.vol-box {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.vol-icon { font-size: 12px; opacity: 0.85; }
.vol-box input[type="range"] { width: 96px; }

/* --------------------------------- 按钮 -------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 12.5px;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { color: var(--text); border-color: var(--line-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.985); }
.btn-ghost { padding: 7px 10px; }
.btn-primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(120deg, var(--accent), #5b46d6);
  box-shadow: 0 8px 22px -10px var(--accent);
}
.btn-danger { color: #fff; border-color: transparent; background: linear-gradient(120deg, #ef4444, #b91c1c); }
.btn-ok { color: #04150f; border-color: transparent; background: linear-gradient(120deg, var(--ok), #0ea972); }
.btn-sm { padding: 5px 9px; font-size: 11.5px; }
.btn.on { color: #fff; border-color: transparent; background: linear-gradient(120deg, var(--accent), #4c37c9); box-shadow: 0 0 0 1px rgba(124,92,255,.4), 0 8px 20px -10px var(--accent); }
.btn.rec { color: #fff; border-color: transparent; background: linear-gradient(120deg, #ef4444, #b91c1c); animation: pulseRec 1.4s ease-in-out infinite; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; transform: none; }
@keyframes pulseRec { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); } 50% { box-shadow: 0 0 0 7px rgba(239,68,68,0); } }

kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
}

/* ------------------------------ 舞台 / 可视化 ---------------------------- */
/* 关键：flex-basis 必须为 0。若为 auto，面板内容高度会反过来挤压舞台，
   导致读数区被裁切、切换标签页时整个布局跳动。min-height 保证读数区完整。 */
.stage {
  flex: 1 1 0;
  min-height: 234px;          /* 读数区列布局内容 218px + 内边距 16px（实测） */
  max-height: min(420px, 52vh);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
  padding: 12px 16px 4px;
}

.viz-wrap {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(10, 12, 20, 0.75), rgba(10, 12, 20, 0.35));
  box-shadow: var(--shadow);
  min-height: 96px;
}
html[data-theme="light"] .viz-wrap { background: linear-gradient(180deg, rgba(255,255,255,.9), rgba(240,242,250,.6)); }
.viz-wrap canvas { display: block; width: 100%; height: 100%; }
.viz-caption {
  position: absolute;
  left: 10px;
  top: 9px;
  display: flex;
  gap: 6px;
  pointer-events: none;
}

.badge {
  font-size: 10.5px;
  letter-spacing: 0.3px;
  padding: 3px 8px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: rgba(10, 12, 20, 0.55);
  color: var(--text-dim);
  backdrop-filter: blur(6px);
}
.badge-soft { color: var(--muted); }
.badge-ok { color: var(--ok); border-color: rgba(52, 211, 153, 0.35); }
.badge-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); }

.readout {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}.chord-card {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  padding: 10px 14px;
  box-shadow: var(--shadow);
}
.chord-label {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.15;
  background: linear-gradient(100deg, var(--accent-2), var(--accent) 55%, var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  min-height: 32px;
  transition: opacity 0.2s;
}
.chord-label.flash { animation: chordIn 0.34s ease; }
.chord-label.empty {
  background: none;
  -webkit-text-fill-color: var(--muted);
  color: var(--muted);
  opacity: 0.55;
}
@keyframes chordIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chord-sub { color: var(--muted); font-size: 11px; margin-top: 2px; min-height: 14px; }

.readout-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.ro-item {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 6px 9px;
  min-width: 0;
}
.ro-k { display: block; font-size: 10px; color: var(--muted); letter-spacing: 0.4px; }
.ro-v { display: block; font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.beat-row {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 6px 10px;
}
.beat-dots { display: flex; gap: 6px; }
.beat-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  transition: transform 0.1s ease, background 0.14s ease;
}
.beat-dot.on { background: var(--accent); box-shadow: 0 0 12px var(--accent); transform: scale(1.45); }
.beat-dot.accent.on { background: var(--accent-2); box-shadow: 0 0 14px var(--accent-2); }
.beat-tempo { display: flex; align-items: baseline; gap: 3px; }
.beat-tempo b { font-size: 15px; font-family: var(--mono); }
.beat-tempo span { font-size: 9.5px; color: var(--muted); }

/* ------------------------------ 钢琴工具栏 ------------------------------ */
.piano-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 6px;
  flex-wrap: wrap;
}
.pb-group { display: flex; align-items: center; gap: 7px; }
.pb-right { margin-left: auto; }
.pb-label { font-size: 11px; color: var(--muted); letter-spacing: 0.3px; }
.pb-val {
  font-family: var(--mono);
  font-size: 12.5px;
  min-width: 46px;
  text-align: center;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.pb-group .btn-sm { padding: 5px 9px; }

/* --------------------------------- 琴键 -------------------------------- */
.piano-shell {
  flex: 0 0 auto;
  padding: 0 16px 8px;
}
.piano-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.24));
  box-shadow: inset 0 8px 24px -12px rgba(0, 0, 0, 0.9), var(--shadow);
  padding: 8px 8px 10px;
  scrollbar-width: thin;
}
html[data-theme="light"] .piano-scroll { background: linear-gradient(180deg, #d9ddea, #eef0f7); }

.piano {
  position: relative;
  height: 148px;
  margin: 0 auto;
  --kw: 23px;
  --bw: 14px;
  --bh: 62%;
  user-select: none;
  touch-action: none;
}
.keys-white, .keys-black { position: absolute; inset: 0; pointer-events: none; }
.keys-black { z-index: 3; }

.key {
  position: absolute;
  top: 0;
  pointer-events: auto;
  transition: background 0.06s linear, transform 0.06s ease, box-shadow 0.1s ease, opacity 0.2s ease;
  will-change: transform;
}
.key.white {
  width: var(--kw);
  height: 100%;
  border-radius: 0 0 6px 6px;
  border: 1px solid rgba(0, 0, 0, 0.42);
  border-top: none;
  background: var(--key-white);
  box-shadow: inset 0 -8px 12px -8px rgba(0, 0, 0, 0.45), inset 1px 0 0 rgba(255, 255, 255, 0.7);
}
.key.white:active { transform: translateY(1px); }
.key.black {
  width: var(--bw);
  height: var(--bh);
  border-radius: 0 0 5px 5px;
  border: 1px solid #05060a;
  background: var(--key-black);
  box-shadow: 0 5px 10px -4px rgba(0, 0, 0, 0.9), inset 0 -4px 6px -3px rgba(255, 255, 255, 0.16);
  z-index: 4;
}
.key.black:active { transform: translateY(1px); }

.key.white.active {
  background: var(--key-white-active);
  box-shadow: inset 0 -8px 16px -8px rgba(0, 0, 0, 0.4), 0 0 22px -2px rgba(124, 92, 255, 0.75);
  transform: translateY(1.5px);
}
.key.black.active {
  background: var(--key-black-active);
  box-shadow: 0 0 20px -2px rgba(124, 92, 255, 0.9), inset 0 -4px 8px -3px rgba(255, 255, 255, 0.25);
}
.key.sustaining { box-shadow: inset 0 -10px 18px -10px rgba(34, 211, 238, 0.9), 0 0 16px -4px rgba(34, 211, 238, 0.6); }
.key.ghost {
  background: linear-gradient(180deg, var(--accent-2), #0891b2);
  box-shadow: 0 0 26px -2px var(--accent-2);
  animation: ghostPulse 0.5s ease;
}
.key.black.ghost { background: linear-gradient(180deg, #67e8f9, #0e7490); }
@keyframes ghostPulse { from { filter: brightness(1.6); } to { filter: none; } }
.key.wrong { background: linear-gradient(180deg, #fca5a5, #dc2626) !important; }

/* 音阶高亮 */
.key.in-scale::after {
  content: "";
  position: absolute;
  left: 14%; right: 14%; bottom: 5px;
  height: 3px; border-radius: 2px;
  background: var(--accent-2);
  opacity: 0.75;
}
.key.root-note::after { background: var(--accent-3); height: 4px; opacity: 1; box-shadow: 0 0 10px var(--accent-3); }
.key.dim { opacity: 0.52; }
.key.black.in-scale::after { bottom: 4px; left: 18%; right: 18%; }

/* 键上文字 */
.key-label, .key-match {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  font-size: 9.5px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.key.white .key-label { bottom: 8px; color: #59607a; font-weight: 600; }
.key.black .key-label { bottom: 5px; color: rgba(255, 255, 255, 0.62); font-size: 8.5px; }
.key-match {
  bottom: 22px;
  font-family: var(--mono);
  font-size: 9px;
  padding: 0 4px;
  border-radius: 4px;
  color: #5a5f78;
  background: rgba(124, 92, 255, 0.14);
  border: 1px solid rgba(124, 92, 255, 0.24);
}
.key.black .key-match { bottom: 18px; color: rgba(190, 200, 255, 0.9); background: rgba(124, 92, 255, 0.26); }
.key.match-active .key-match { background: var(--accent); color: #fff; }

/* 踏板 */
.pedals {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  align-items: center;
}
.pedal {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  color: var(--text-dim);
  font-size: 12.5px;
  transition: all 0.12s ease;
}
.pedal:hover { border-color: var(--line-strong); color: var(--text); }
.pedal.on {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(120deg, var(--accent), #4b37c7);
  box-shadow: 0 0 0 1px rgba(124, 92, 255, 0.5), 0 10px 26px -12px var(--accent);
}
.pedal .pk { font-family: var(--mono); font-size: 10px; opacity: 0.75; }
.pedal-hint { font-size: 11px; color: var(--muted); flex: 0 0 auto; }

/* --------------------------------- 面板 -------------------------------- */
.panels {
  flex: 1 1 0;
  min-height: 142px;
  max-height: 46vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 16px 10px;
}
.panels-inner { display: block; }

.tabs {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tabbar {
  display: flex;
  gap: 2px;
  padding: 6px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.16);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.tab.active { color: #fff; background: linear-gradient(120deg, rgba(124, 92, 255, 0.9), rgba(80, 60, 200, 0.9)); box-shadow: 0 6px 18px -10px var(--accent); }
.tab-icon { font-size: 13px; }

.tabbody { padding: 12px; }
.tabpane { display: block; }
.tabpane[hidden] { display: none; }

.pane-section + .pane-section { margin-top: 12px; }
.pane-title {
  margin: 0 0 9px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pane-title::after { content: ""; flex: 1 1 auto; height: 1px; background: var(--line); }
.pane-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 10px 16px;
}

/* 控件 */
.ctl { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ctl-row { display: flex; gap: 10px; flex-wrap: wrap; }
.ctl-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ctl-label { display: flex; align-items: baseline; gap: 6px; cursor: pointer; min-width: 0; }
.ctl-name { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctl-hint { font-size: 10px; color: var(--muted); }
.ctl-val {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent-2);
  background: rgba(34, 211, 238, 0.1);
  padding: 1px 6px;
  border-radius: 6px;
  flex: 0 0 auto;
}
.ctl-toggle { flex-direction: row; align-items: center; gap: 8px; }
.ctl-seg { gap: 6px; }
.seg-name { margin-bottom: 1px; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; }
.seg-btn {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11.5px;
  transition: all 0.14s ease;
}
.seg-btn:hover { color: var(--text); border-color: var(--line-strong); }
.seg-btn.active { color: #fff; border-color: transparent; background: linear-gradient(120deg, var(--accent), #4b37c7); }

.select {
  width: 100%;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.select:focus { outline: none; border-color: var(--accent); }
option, optgroup { background: var(--panel-solid); color: var(--text); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg, rgba(124, 92, 255, 0.85), rgba(34, 211, 238, 0.5));
  outline: none;
  margin: 6px 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #b9a9ff 55%, var(--accent));
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.1s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #b9a9ff 55%, var(--accent));
  border: 1px solid rgba(0, 0, 0, 0.35); cursor: pointer;
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 99px; background: rgba(124, 92, 255, 0.5); }

.switch { position: relative; width: 36px; height: 20px; flex: 0 0 auto; }
.switch-input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch-knob {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid var(--line);
  transition: background 0.16s ease;
  pointer-events: none;
}
.switch-knob::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s cubic-bezier(0.4, 1.4, 0.5, 1);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.switch-input:checked + .switch-knob { background: linear-gradient(120deg, var(--accent), #4b37c7); border-color: transparent; }
.switch-input:checked + .switch-knob::after { transform: translateX(16px); }

/* 音色卡 */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 8px;
  grid-column: 1 / -1;
}
.preset-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  text-align: left;
  transition: all 0.15s ease;
}
.preset-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.preset-card.active {
  border-color: transparent;
  background: linear-gradient(120deg, rgba(124, 92, 255, 0.95), rgba(60, 44, 150, 0.9));
  color: #fff;
  box-shadow: 0 10px 26px -14px var(--accent);
}
.preset-card .pc-ico { font-size: 19px; flex: 0 0 auto; }
.preset-card .pc-txt { min-width: 0; }
.preset-card .pc-name { font-size: 12.5px; font-weight: 600; display: block; }
.preset-card .pc-desc { font-size: 10.5px; color: var(--muted); display: block; margin-top: 1px; line-height: 1.35; }
.preset-card.active .pc-desc { color: rgba(255, 255, 255, 0.72); }

/* 信息块 / 提示 */
.info-card {
  grid-column: 1 / -1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(34, 211, 238, 0.06);
  padding: 9px 12px;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.6;
}
.info-card b { color: var(--text); }
.info-card ul { margin: 5px 0 0; padding-left: 18px; }
.info-card li { margin: 2px 0; }
.info-card kbd { margin: 0 1px; }

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; grid-column: 1 / -1; }
.stat {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 7px 12px;
  min-width: 92px;
}
.stat b { display: block; font-size: 16px; font-family: var(--mono); }
.stat span { font-size: 10px; color: var(--muted); letter-spacing: 0.4px; }

.progress {
  grid-column: 1 / -1;
  height: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.progress .bar { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.1s linear; }

.song-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; grid-column: 1 / -1; }
.song-card {
  padding: 9px 11px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  text-align: left;
  transition: all 0.15s ease;
}
.song-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.song-card.active { border-color: transparent; background: linear-gradient(120deg, rgba(34, 211, 238, 0.9), rgba(20, 120, 150, 0.85)); color: #04141a; box-shadow: 0 10px 26px -14px var(--accent-2); }
.song-card .sc-name { font-size: 12.5px; font-weight: 600; display: block; }
.song-card .sc-meta { font-size: 10.5px; color: var(--muted); display: block; margin-top: 2px; }
.song-card.active .sc-meta { color: rgba(4, 20, 26, 0.7); }

/* --------------------------------- 状态栏 ------------------------------ */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 16px 7px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.status-right { display: flex; align-items: center; gap: 7px; font-family: var(--mono); }
.dot-sep { opacity: 0.45; }
#statusClock { color: var(--accent-2); }

/* --------------------------------- 浮层 -------------------------------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 5, 10, 0.68); backdrop-filter: blur(6px); }
.modal-card {
  position: relative;
  width: min(680px, 100%);
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: var(--panel-solid);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.9);
  overflow: hidden;
  animation: modalIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-body { padding: 14px 18px 20px; overflow: auto; font-size: 12.5px; line-height: 1.7; color: var(--text-dim); }
.modal-body h3 { font-size: 12.5px; color: var(--text); margin: 16px 0 6px; letter-spacing: 0.5px; }
.modal-body h3:first-child { margin-top: 0; }
.kbd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 6px 16px; }
.kbd-row { display: flex; align-items: center; gap: 8px; }
.kbd-row span { font-size: 12px; }

/* 手势提示 */
.gesture-hint {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  /* 提示层不拦截点击：第一次点击必须能直接落到它下面的控件上 */
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.gesture-hint[hidden] { display: none; }
.gesture-hint.out { opacity: 0; transform: translateX(-50%) translateY(14px); pointer-events: none; }
.gesture-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  border-radius: 14px;
  border: 1px solid rgba(124, 92, 255, 0.45);
  background: rgba(22, 18, 48, 0.92);
  box-shadow: 0 0 0 1px rgba(124, 92, 255, 0.18), 0 22px 50px -22px rgba(124, 92, 255, 0.8);
  animation: floatIn 0.4s ease;
}
html[data-theme="light"] .gesture-inner { background: rgba(255, 255, 255, 0.96); }
@keyframes floatIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }
.gesture-inner b { display: block; font-size: 13px; }
.gesture-inner small { color: var(--muted); font-size: 11px; }
.gh-icon { font-size: 22px; animation: tap 1.6s ease-in-out infinite; }
@keyframes tap { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* Toast */
.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(22, 25, 38, 0.95);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-width: 320px;
}
html[data-theme="light"] .toast { background: rgba(255, 255, 255, 0.98); }
.toast.in { opacity: 1; transform: none; }
.toast-ok { border-color: rgba(52, 211, 153, 0.5); }
.toast-err { border-color: rgba(248, 113, 113, 0.55); }
.toast-warn { border-color: rgba(251, 191, 36, 0.5); }

/* ------------------------------- 响应式 --------------------------------
 * 数值均由 .test/measure.js 实测校准（读数区内容高、各区块实际高度）。
 *
 * 宽度：≤1100 读数区收窄 → ≤860/≤740h 读数区转为横向条 → ≤780 工具栏换行
 *       → ≤560 工具栏单行横滚 → ≤520 顶栏两行 → ≤400 隐藏品牌文字与音量
 * 高度：≤740 精简读数 → ≤620 隐藏可视化
 * 每一档都同步下调 .stage / .panels / .piano 的尺寸，保证
 *     topbar + stage + piano-bar + piano-shell + panels + statusbar ≤ 视口高度
 * 任何模块都不会被压扁、裁切或覆盖；极端情况下由 .app 纵向滚动兜底。
 * ---------------------------------------------------------------------- */

/* A. 中窄屏：读数区收窄但仍纵向排列（内容高 193px + 内边距） */
@media (max-width: 1100px) {
  .stage { grid-template-columns: minmax(0, 1fr) 244px; min-height: 209px; }
  .piano { height: 132px; }
  .panels { min-height: 120px; }
  .readout { gap: 6px; }
  .chord-card { padding: 7px 12px; }
  .chord-label { font-size: 22px; min-height: 26px; }
  .chord-sub { font-size: 10.5px; }
  .ro-item { padding: 4px 8px; }
  .ro-v { font-size: 12px; }
}

/* B. 窄屏或较矮屏：读数区变成横向紧凑条（内容高 53px），与可视化上下排列 */
@media (max-width: 860px), (max-height: 740px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(64px, 1fr) auto;
    min-height: 168px;
    gap: 8px;
  }
  .readout { flex-direction: row; align-items: center; gap: 8px; }
  .chord-card { flex: 1 1 auto; padding: 6px 12px; min-width: 0; }
  .chord-label { font-size: 20px; min-height: 23px; }
  .chord-sub { font-size: 10px; }
  .readout-grid { display: none; }
  .beat-row { display: flex; margin-top: 0; flex: 0 0 auto; }
  .piano { height: 124px; }
  .panels { min-height: 104px; }
}

/* C. 窄屏：工具栏允许换行（保证每个按钮都可见），压缩内外边距 */
@media (max-width: 780px) {
  .brand-text small { display: none; }
  .vol-box input[type="range"] { width: 58px; }
  .stage { padding: 8px 10px 2px; }
  .piano-bar { padding: 7px 10px 4px; flex-wrap: wrap; row-gap: 6px; }
  .pb-right { margin-left: 0; }
  .piano-shell, .panels { padding-left: 10px; padding-right: 10px; }
  .panels { max-height: 52vh; }
  .pane-body { grid-template-columns: 1fr; }
  .statusbar { font-size: 10px; }
  .pedal-hint { display: none; }
  .gesture-inner { padding: 9px 14px; }
  .gesture-inner b { font-size: 12px; }
  .gesture-inner small { font-size: 10px; }
  .toast-host { left: 10px; right: 10px; align-items: stretch; }
  .toast { max-width: none; font-size: 12px; }
}

/* D. 手机：工具栏单行横滚（右侧渐隐提示），进一步压低纵向占用 */
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 7px 10px; }
  .brand .logo { font-size: 18px; }
  .brand-text b { font-size: 13px; }
  .vol-box { padding: 3px 8px; }
  .vol-box input[type="range"] { width: 46px; }
  .top-actions { gap: 6px; }
  .btn-ghost { padding: 6px 8px; }
  .piano-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
  }
  .piano-bar::-webkit-scrollbar { display: none; }
  .pb-group { flex: 0 0 auto; }
  .piano { height: 118px; }
  .panels { min-height: 112px; max-height: 56vh; }
  .tab { padding: 6px 10px; font-size: 11.5px; }
  .tab-icon { display: none; }
  .pane-title { font-size: 10.5px; }
  .preset-strip { mask-image: none; }
  .chip { padding: 5px 9px; font-size: 11.5px; }
  .pedals { gap: 6px; }
  .pedal { padding: 8px 8px; font-size: 11.5px; }
  .statusbar { padding: 4px 10px 6px; }
  .status-right { gap: 5px; }
}

/* E/F. 超窄：顶栏拆两行，品牌只留图标 */
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .preset-strip { order: 3; flex: 1 0 100%; }
}
@media (max-width: 400px) {
  .brand-text { display: none; }
  .vol-box { display: none; }
}

/* G. 较矮屏（≤740）：键盘与面板再收紧，工具栏可能两行的宽度也一并考虑 */
@media (max-height: 740px) {
  .pedal { padding: 7px 10px; }
  .statusbar { padding: 3px 16px 5px; }
  .pane-body { gap: 8px 14px; }
  .tabbar { padding: 5px; }
  .tabbody { padding: 10px; }
}

/* H. 极矮屏（≤620）：隐藏可视化（装饰性），只保留读数条 + 键盘 + 面板 */
@media (max-height: 620px) {
  .viz-wrap { display: none; }
  .stage {
    grid-template-rows: auto;
    min-height: 78px;
    max-height: 104px;          /* 只放读数条，剩余空间留给面板 */
    padding: 6px 16px 2px;
  }
  .chord-sub { display: none; }
  .chord-label { font-size: 18px; min-height: 21px; }
  .piano { height: 108px; }
  .panels { min-height: 96px; max-height: 54vh; }
  .piano-shell { padding-bottom: 4px; }
  .pedals { margin-top: 4px; }
  .pedal { padding: 6px 8px; }
  .statusbar { padding: 2px 16px 4px; }
}
