/* ═══════════════════════════════════════════════════════════
   音域测试器 · 样式
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #07090f;
  --surface: #0f131c;
  --surface-2: #151b28;
  --surface-3: #1c2434;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  --text: #e9edf6;
  --muted: #8a94aa;
  --muted-dim: #5c6579;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --radius: 18px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1100px 620px at 12% -12%, rgba(124, 92, 255, 0.20), transparent 62%),
    radial-gradient(900px 560px at 102% -4%, rgba(34, 211, 238, 0.13), transparent 58%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", "PingFang SC", "Helvetica Neue", "Microsoft YaHei", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, select { font: inherit; color: inherit; }

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ── 布局 ── */

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px clamp(14px, 2.4vw, 34px) 30px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 13px; }

.logo {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--accent), #4c2fd6 60%, #1f6b9e);
  box-shadow: 0 8px 26px -8px rgba(124, 92, 255, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  color: #fff;
}
.logo svg { width: 23px; height: 23px; }

.brand-text h1 { font-size: 21px; line-height: 1.2; }
.brand-text p { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

.toolbar { display: flex; align-items: center; gap: 10px; }

/* ── 通用控件 ── */

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 11px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, transform 0.1s, box-shadow 0.16s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: rgba(255, 255, 255, 0.22); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #5b3ee8);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 26px -12px rgba(124, 92, 255, 0.95);
}
.btn.primary:hover { background: linear-gradient(135deg, #8b6dff, #6a4cf0); }

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

.btn.lg { padding: 13px 30px; font-size: 15px; border-radius: 13px; }

.segmented, .chips {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.segmented button, .chips button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 15px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segmented button:hover, .chips button:hover { color: var(--text); }
.segmented button.active, .chips button.active {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.95), rgba(91, 62, 232, 0.95));
  color: #fff;
  box-shadow: 0 4px 14px -6px rgba(124, 92, 255, 0.9);
}

.chips button { padding: 5px 11px; font-size: 12px; }

/* ── 卡片 ── */

.card {
  background: linear-gradient(180deg, rgba(23, 29, 42, 0.85), rgba(13, 17, 25, 0.9));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 22px 60px -32px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.045);
  backdrop-filter: blur(14px);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  grid-template-areas:
    "stage panel"
    "keyboard keyboard";
  gap: 16px;
  align-items: start;
}

.stage { grid-area: stage; padding: 22px 24px 16px; }
.panel { grid-area: panel; padding: 6px 20px 16px; }
.keyboard-card { grid-area: keyboard; padding: 16px 20px 22px; }

/* ═══════════ 实时舞台 ═══════════ */

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.note-block { min-width: 190px; }

.note-name {
  font-family: var(--mono);
  font-size: clamp(58px, 8.2vw, 86px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(160deg, #f4f7ff 10%, #a99bff 55%, #4fd8ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: opacity 0.18s;
}
.note-name.idle {
  background: linear-gradient(160deg, #3a4356, #262d3c);
  -webkit-background-clip: text;
  background-clip: text;
}

.note-meta {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.note-meta .sep { margin: 0 6px; color: var(--muted-dim); }

.meter-block {
  flex: 1 1 300px;
  max-width: 460px;
  min-width: 240px;
}

.cents {
  position: relative;
  height: 40px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}

.cents-track {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg,
      rgba(251, 113, 133, 0.20) 0%,
      rgba(52, 211, 153, 0.20) 42%,
      rgba(52, 211, 153, 0.20) 58%,
      rgba(251, 113, 133, 0.20) 100%);
}

.cents-ticks {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 6%;
  pointer-events: none;
}
.cents-ticks i {
  width: 1px;
  background: rgba(255, 255, 255, 0.10);
}
.cents-ticks i:nth-child(3) {
  background: rgba(255, 255, 255, 0.42);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.35);
}

.cents-needle {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 50%;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 3px;
  background: linear-gradient(180deg, #fff, var(--accent-2));
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.9);
  transition: left 0.07s linear, opacity 0.18s;
  opacity: 0;
}
.cents-needle.on { opacity: 1; }
.cents-needle.perfect { background: linear-gradient(180deg, #fff, var(--ok)); box-shadow: 0 0 16px rgba(52, 211, 153, 0.95); }

.cents-label {
  margin-top: 5px;
  text-align: right;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted-dim);
  font-variant-numeric: tabular-nums;
}

.level {
  margin-top: 9px;
  height: 4px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}
.level-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.07s linear;
}

/* 音高曲线 */
.contour {
  display: block;
  width: 100%;
  height: 152px;
  margin-top: 16px;
  border-radius: 13px;
  background:
    linear-gradient(180deg, rgba(124, 92, 255, 0.055), rgba(34, 211, 238, 0.025)),
    var(--surface);
  border: 1px solid var(--line);
}

/* 引导 HUD */
.guided-hud {
  margin-top: 14px;
  padding: 13px 16px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
}
.guided-target { display: flex; align-items: baseline; gap: 9px; }
.guided-dir {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(124, 92, 255, 0.18);
  color: #b9a9ff;
  font-weight: 600;
}
.guided-target strong {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.guided-hint { font-size: 12px; color: var(--muted); }
.guided-progress { height: 5px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.guided-progress > div {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.12s linear;
}
.guided-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stage-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 13px;
  flex-wrap: wrap;
}
.hint { font-size: 12px; color: var(--muted-dim); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 11px 4px 9px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted-dim);
  transition: background 0.2s, box-shadow 0.2s;
}
.badge.live { color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.badge.live i { background: var(--ok); box-shadow: 0 0 9px var(--ok); animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.82); }
}

/* ═══════════ 结果面板 ═══════════ */

.panel-section {
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}
.panel-section:last-of-type { border-bottom: 0; }

.panel-section h2 {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted-dim);
  font-weight: 600;
  margin-bottom: 8px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.section-head h2 { margin-bottom: 0; }

.range-big {
  font-family: var(--mono);
  font-size: 31px;
  font-weight: 700;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  line-height: 1.16;
  color: #f2f5ff;
}
.range-big.sm { font-size: 21px; color: #c9d2e6; }

.range-sub {
  font-size: 12px;
  color: var(--muted-dim);
  margin-top: 3px;
}

.voice { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.voice-name { font-size: 19px; font-weight: 600; }
.voice-en { font-family: var(--mono); font-size: 12px; color: var(--muted-dim); }
.voice-match {
  font-size: 11.5px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(52, 211, 153, 0.13);
  color: var(--ok);
}
.voice-match.low { background: rgba(251, 191, 36, 0.13); color: var(--warn); }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.field select {
  appearance: none;
  background: var(--surface-2) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' stroke='%238a94aa' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 7px 30px 7px 12px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.transpose { margin-top: 11px; }
.transpose-main {
  display: block;
  font-size: 17px;
  font-weight: 600;
  color: var(--accent-2);
}
.transpose-warn {
  display: block;
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--warn);
  line-height: 1.45;
}

.panel-actions {
  padding-top: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel-actions .btn { width: 100%; }

/* ═══════════ 钢琴键盘 ═══════════ */

.keyboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.keyboard-head h2 {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted-dim);
  font-weight: 600;
}
.legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 13px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .sw.range { background: linear-gradient(90deg, #7c5cff, #22d3ee); }
.legend .sw.comfort { background: #eafffb; box-shadow: 0 0 8px rgba(234, 255, 251, 0.7); }

.keyboard {
  position: relative;
  height: 156px;
  user-select: none;
  -webkit-user-select: none;
}

.key {
  position: absolute;
  top: 0;
  border-radius: 0 0 6px 6px;
  transition: background 0.22s, box-shadow 0.22s, transform 0.1s;
  will-change: background;
}
.key.white {
  height: 100%;
  background: #e8ecf4;
  border: 1px solid #b9c1d1;
  border-top: 0;
  box-shadow: inset 0 -7px 12px -9px rgba(0, 0, 0, 0.55);
  z-index: 1;
}
.key.white.range { border-color: rgba(124, 92, 255, 0.5); }
.key.black {
  height: 62%;
  background: #10141d;
  border: 1px solid #000;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 5px 9px -3px rgba(0, 0, 0, 0.85), inset 0 -4px 6px -4px rgba(255, 255, 255, 0.22);
  z-index: 2;
}
.key.black.range { border-color: rgba(34, 211, 238, 0.45); }

.key.active {
  transform: translateY(2px);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85), 0 0 26px rgba(124, 92, 255, 0.95) !important;
}
.key.hit { animation: keyHit 0.5s ease-out; }
.key.miss { animation: keyMiss 0.5s ease-out; }
@keyframes keyHit {
  0% { box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.95), 0 0 30px rgba(52, 211, 153, 0.9); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}
@keyframes keyMiss {
  0% { box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.95), 0 0 26px rgba(251, 113, 133, 0.8); }
  100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0); }
}

.key-label {
  position: absolute;
  bottom: 7px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 9.5px;
  color: #7d879c;
  pointer-events: none;
  letter-spacing: -0.02em;
}
.key.range .key-label { color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }

/* ═══════════ 页脚 ═══════════ */

.foot {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 11.5px;
  color: var(--muted-dim);
}
.foot-sep { opacity: 0.4; }

/* ═══════════ 麦克风门禁 ═══════════ */

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 6, 11, 0.82);
  backdrop-filter: blur(10px);
  transition: opacity 0.28s, visibility 0.28s;
}
.gate.hidden { opacity: 0; visibility: hidden; }

.gate-card {
  width: min(470px, 100%);
  padding: 34px 32px 26px;
  text-align: center;
  border-radius: 22px;
  background: linear-gradient(180deg, #171d2b, #0d1119);
  border: 1px solid var(--line-strong);
  box-shadow: 0 40px 90px -40px #000;
}
.gate-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 12px;
  filter: drop-shadow(0 6px 22px rgba(124, 92, 255, 0.6));
}
.gate-card h2 { font-size: 22px; margin-bottom: 12px; }
.gate-desc {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.75;
  text-align: left;
  margin: 0 0 22px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 12px;
  border: 1px solid var(--line);
}
.gate-err {
  margin: 14px 0 0;
  font-size: 12.5px;
  color: var(--bad);
  line-height: 1.6;
}
.gate-note { margin: 16px 0 0; font-size: 11.5px; color: var(--muted-dim); }

/* ═══════════ 分享图弹窗 ═══════════ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(4, 6, 11, 0.88);
  backdrop-filter: blur(8px);
}
.modal[hidden] { display: none; }

.modal-card {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: 100%;
  padding: 18px;
  border-radius: 20px;
  background: #0d1119;
  border: 1px solid var(--line-strong);
  box-shadow: 0 40px 100px -40px #000;
}
#shareCanvas {
  display: block;
  width: auto;
  height: min(70vh, 820px);
  max-width: 100%;
  border-radius: 12px;
  object-fit: contain;
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ═══════════ 响应式 ═══════════ */

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "panel" "keyboard";
  }
  .panel { padding: 6px 18px 16px; }
}

@media (max-width: 620px) {
  .app { padding: 16px 12px 24px; }
  .stage { padding: 18px 15px 14px; }
  .stage-head { gap: 14px; }
  .meter-block { flex-basis: 100%; min-width: 0; }
  .note-name { font-size: 62px; }
  .contour { height: 116px; }
  .keyboard { height: 118px; }
  .guided-hud { grid-template-columns: 1fr auto; }
  .guided-progress { grid-column: 1 / -1; order: 3; }
  .brand-text p { display: none; }
  .foot { flex-direction: column; align-items: center; gap: 4px; text-align: center; }
  .foot-sep { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
