/* 移动端优先。桌面端只做等比放大，不另设一套布局。 */

:root {
  --bg: #0b0e14;
  --panel: #141922;
  --panel-2: #1a2130;
  --line: #232b3a;
  --text: #e6ebf5;
  --dim: #8b95a8;
  --accent: #4c9aff;
  --piano: #4c9aff;
  --guitar: #f59e0b;
  --voice: #a78bfa;
  --good: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 左右要分开算。横屏握机时刘海在一侧，两边取值不同，
     只取 left 会让另一侧的内容压到圆角或刘海下面。 */
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --tap: 44px;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC', system-ui, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
}

button, select, input { font: inherit; color: inherit; touch-action: manipulation; }
button { -webkit-appearance: none; appearance: none; border: 0; background: none; cursor: pointer; }

/* ---------------------------------------------------------------- 顶栏 */

.top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(52px + var(--safe-top));
  padding: var(--safe-top) max(12px, var(--safe-r)) 0 max(12px, var(--safe-l));
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #10151e, #0d1219);
}

.brand { display: flex; align-items: center; gap: 7px; min-width: 0; }
.brand-text {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--dim);
  white-space: nowrap;
}

.pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: #3a4356;
  flex: 0 0 auto;
  transition: background 0.2s, box-shadow 0.2s;
}
body.live .pulse {
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
  animation: ping 1.8s ease-out infinite;
}
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.readout {
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}
.note {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cents {
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--dim);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:active { background: var(--panel-2); color: var(--text); }

/* ---------------------------------------------------------------- 画布区 */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#chart { display: block; width: 100%; height: 100%; }

.overlay-top {
  position: absolute;
  top: 8px;
  left: max(12px, var(--safe-l));
  right: max(12px, var(--safe-r));
  pointer-events: none;
}

.src-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.src-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: color 0.2s;
}
.src-conf {
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.src-hint {
  font-size: 11px;
  line-height: 1.45;
  color: var(--dim);
  max-width: 42ch;
}

.chipbar {
  position: absolute;
  left: max(12px, var(--safe-l));
  right: max(12px, var(--safe-r));
  bottom: 8px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  pointer-events: none;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.chipbar::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border-radius: 12px;
  background: rgba(26, 33, 48, 0.82);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
  backdrop-filter: blur(6px);
}
.chip i {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.notice {
  position: absolute;
  left: max(12px, var(--safe-l));
  right: max(12px, var(--safe-r));
  bottom: 40px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fcd34d;
  font-size: 11px;
  line-height: 1.45;
  pointer-events: none;
}

/* ---------------------------------------------------------------- 底栏 */

.stat-bar {
  flex: 0 0 auto;
  height: 20px;
  padding: 0 max(12px, var(--safe-r)) 0 max(12px, var(--safe-l));
  font-size: 10px;
  line-height: 20px;
  color: #5d677b;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bottom {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px max(12px, var(--safe-r)) calc(8px + var(--safe-bottom)) max(12px, var(--safe-l));
  border-top: 1px solid var(--line);
  background: linear-gradient(0deg, #0d1219, #10151e);
}

.seg {
  flex: 1 1 auto;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.seg-btn {
  flex: 1 1 0;
  height: 36px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--dim);
  transition: background 0.15s, color 0.15s;
}
.seg-btn.on { background: var(--panel-2); color: var(--text); font-weight: 600; }

.fab {
  flex: 0 0 auto;
  height: 44px;
  min-width: 96px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 22px;
  background: var(--accent);
  color: #06121f;
  font-size: 14px;
  font-weight: 700;
  transition: transform 0.12s, background 0.15s, opacity 0.15s;
}
.fab:active { transform: scale(0.96); }
.fab[disabled] { opacity: 0.5; }
.fab .ic-stop { display: none; }
body.live .fab { background: #2a3446; color: var(--text); }
body.live .fab .ic-start { display: none; }
body.live .fab .ic-stop { display: block; }

/* ---------------------------------------------------------------- 抽屉 */

.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
}
.sheet-wrap[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, 0.62);
  backdrop-filter: blur(2px);
  animation: fade 0.18s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: relative;
  width: 100%;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes rise { from { transform: translateY(16px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

.sheet-grip {
  flex: 0 0 auto;
  width: 38px;
  height: 4px;
  margin: 8px auto 4px;
  border-radius: 2px;
  background: #2f3849;
}

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 16px;
}

.sheet h2 {
  margin: 16px 0 6px;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
}
.sheet h2:first-of-type { margin-top: 4px; }

.sheet-hint {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--dim);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}
.preset {
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--dim);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.preset.on {
  background: rgba(76, 154, 255, 0.16);
  border-color: rgba(76, 154, 255, 0.5);
  color: #9cc4ff;
}

.inst-group { margin-bottom: 12px; }
.group-label {
  font-size: 11px;
  color: #5d677b;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}
.inst-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.inst {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--dim);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.inst i {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
  opacity: 0.55;
}
.inst.on {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
}
.inst.on i { opacity: 1; }

.field {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  border-bottom: 1px solid var(--line);
}
.field > span { flex: 0 0 76px; font-size: 13px; color: var(--dim); }
.field > b { flex: 0 0 46px; text-align: right; font-size: 12px; color: var(--dim); font-weight: 500; font-variant-numeric: tabular-nums; }

.field input[type='range'] {
  flex: 1 1 auto;
  height: var(--tap);
  background: none;
  -webkit-appearance: none;
  appearance: none;
}
.field input[type='range']::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: #2b3446;
}
.field input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  margin-top: -8.5px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--panel);
  box-shadow: 0 0 0 1px #3a4356;
}
.field input[type='range']::-moz-range-track { height: 3px; border-radius: 2px; background: #2b3446; }
.field input[type='range']::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--panel);
}

.select {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border-radius: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
}

.legal {
  margin: 14px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: #5d677b;
}

.sheet-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.btn-primary {
  flex: 1 1 auto;
  height: var(--tap);
  border-radius: 12px;
  background: var(--accent);
  color: #06121f;
  font-size: 15px;
  font-weight: 700;
}
.btn-ghost {
  flex: 0 0 auto;
  min-width: 84px;
  height: var(--tap);
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 14px;
}

/* ---------------------------------------------------------------- 横屏 / 大屏 */

@media (orientation: landscape) and (max-height: 560px) {
  .top { height: calc(40px + var(--safe-top)); }
  .brand-text { display: none; }
  .note { font-size: 17px; }
  .stat-bar { height: 16px; line-height: 16px; }
  .bottom { padding-top: 6px; padding-bottom: calc(6px + var(--safe-bottom)); }
  .seg-btn { height: 32px; }
  .fab { height: 38px; min-width: 84px; font-size: 13px; }
  .sheet { max-height: 94dvh; }
}

@media (min-width: 720px) {
  .top { height: 56px; padding-top: 0; }
  .sheet {
    max-width: 560px;
    margin: 0 auto;
    border-radius: 20px 20px 0 0;
  }
  .chipbar, .overlay-top, .notice, .bottom, .stat-bar, .top {
    padding-left: max(24px, var(--safe-l));
    padding-right: max(24px, var(--safe-r));
  }
}

/* ---------- 练习评分 ---------- */
/* 结构和设置抽屉一致：底部上推的半屏卡片，拇指够得到，
   也方便用户在波形和分数之间来回看。 */

.score-wrap {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
}
.score-wrap[hidden] { display: none; }

.score-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, 0.62);
  backdrop-filter: blur(2px);
  animation: fade 0.18s ease-out;
}

.score-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--panel);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border-top: 1px solid var(--line);
  padding: 8px max(20px, var(--safe-r)) calc(16px + var(--safe-bottom)) max(20px, var(--safe-l));
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.score-grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 6px auto 14px;
}

.shd {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}
.sgrade {
  font-size: 14px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--accent);
}
.sgrade.g-S, .sgrade.g-A { color: var(--good); }
.sgrade.g-B { color: var(--accent); }
.sgrade.g-C { color: var(--warn); }
.sgrade.g-D { color: var(--danger); }
.stot {
  font-size: 38px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.sunit { font-size: 14px; color: var(--dim); }

.srow {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
}
.sn { font-size: 13px; color: var(--dim); }
.sb { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.sb i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}
.sb i.off { background: var(--line); }
.sv { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

.sfoot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--dim);
  line-height: 1.55;
}
.snote {
  margin-top: 8px;
  font-size: 12px;
  color: var(--warn);
  line-height: 1.6;
}
.sdis {
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--dim);
  opacity: 0.75;
  line-height: 1.5;
}

.score-close {
  width: 100%;
  height: var(--tap);
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
