/* 音高测试 — 深色、移动优先、无外部资源 */
:root {
  --bg: #0e1116;
  --card: #161b22;
  --card-soft: #1b222c;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e6edf3;
  --muted: #8b949e;
  --dim: #6e7681;
  --accent: #4ade80;
  --accent-2: #22d3ee;
  --amber: #fbbf24;
  --danger: #f87171;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
button { touch-action: manipulation; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 480px at 50% -12%, rgba(74, 222, 128, 0.10), transparent 62%),
    radial-gradient(720px 420px at 108% 4%, rgba(34, 211, 238, 0.07), transparent 58%),
    var(--bg);
  overflow-x: hidden;
}

[hidden] { display: none !important; }
code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 5px;
  padding: 1px 5px;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 18px calc(104px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 2px 12px;
  background: linear-gradient(180deg, rgba(14, 17, 22, 0.96) 55%, rgba(14, 17, 22, 0));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 18px;
  color: #06120b;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(74, 222, 128, 0.25);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: 0.01em; }
.brand-sub { font-size: 9px; letter-spacing: 0.22em; color: var(--dim); margin-top: 3px; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }

/* ---------- 页面 ---------- */
.main { flex: 1; }
.page { display: none; flex-direction: column; gap: 14px; }
.page.is-active { display: flex; animation: page-in 0.24s ease; }
@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.banner {
  margin: 0 0 12px;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.10);
  border: 1px solid rgba(251, 191, 36, 0.28);
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012)), var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.card-hint { font-size: 11px; font-weight: 400; color: var(--dim); }

/* ---------- 实时 ---------- */
.live-card { padding: 16px 18px 14px; }
.live-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}
.live-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dim);
}
.live-badge.is-live { color: var(--accent); border-color: rgba(74, 222, 128, 0.3); }
.live-badge.is-live::before { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: blink 1.4s infinite; }
.live-badge.is-error { color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }
.live-badge.is-error::before { background: var(--danger); }
@keyframes blink { 50% { opacity: 0.35; } }
.live-ref { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }

.note-wrap { text-align: center; padding: 14px 0 4px; }
.note-name {
  font-size: clamp(64px, 17vw, 94px);
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff 20%, #a9f2c4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  min-height: 1em;
  transition: opacity 0.15s;
}
.note-name.is-idle {
  background: none;
  color: var(--dim);
  -webkit-text-fill-color: var(--dim);
  opacity: 0.6;
}
.note-meta {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.note-meta .dot { color: var(--dim); }

/* 调音条 */
.tuner { margin-top: 18px; }
.tuner-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
}
.tuner-fill {
  position: absolute;
  top: 0; bottom: 0; left: 40%; width: 20%;
  border-radius: 999px;
  background: rgba(74, 222, 128, 0.16);
  box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.22);
}
.tuner-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 16px;
  border-radius: 1px;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.4);
}
.tuner-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 24px;
  border-radius: 3px;
  transform: translate(-50%, -50%);
  background: var(--accent);
  box-shadow: 0 0 14px rgba(74, 222, 128, 0.7);
  transition: left 0.09s linear, background 0.2s, box-shadow 0.2s;
  opacity: 0;
}
.tuner-needle.is-on { opacity: 1; }
.tuner-needle.is-off-pitch { background: var(--amber); box-shadow: 0 0 14px rgba(251, 191, 36, 0.6); }
.tuner-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  font-size: 10px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.tuner-labels span:nth-child(2) { color: var(--muted); }

.level {
  margin-top: 4px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  overflow: hidden;
}
.level-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.09s linear;
}

.graph {
  display: block;
  width: 100%;
  height: 140px;
  margin-top: 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.018);
  touch-action: none;
}
.graph-tall { height: 190px; margin-top: 0; }

.live-status {
  margin: 10px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  min-height: 17px;
}

/* 最高音卡 */
.best-card { display: flex; flex-direction: column; gap: 8px; }
.best-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.best-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.best-value { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.best-note {
  font-size: 30px;
  font-weight: 650;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.best-detail { font-size: 12px; color: var(--muted); line-height: 1.5; }
.best-card.is-new { animation: best-pop 0.7s ease; }
@keyframes best-pop {
  0% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.45); }
  100% { box-shadow: 0 0 0 14px rgba(251, 191, 36, 0); }
}

.link-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 2px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(255, 255, 255, 0.18);
}
.link-btn:hover { color: var(--text); }
.link-btn.danger { color: var(--danger); }
.link-btn.center { align-self: center; }

/* 主按钮 */
.primary-btn {
  width: 100%;
  height: 56px;
  border: 0;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 650;
  color: #04120a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 34px rgba(74, 222, 128, 0.22);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.primary-btn:active { transform: scale(0.985); }
.primary-btn.is-running {
  color: #1c0b0b;
  background: linear-gradient(135deg, var(--danger), var(--amber));
  box-shadow: 0 14px 34px rgba(248, 113, 113, 0.18);
}
.mic-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.primary-btn.is-running .mic-dot { border-radius: 2px; }

.hint { margin: 0; font-size: 11.5px; line-height: 1.6; color: var(--dim); }
.hint.center { text-align: center; }
.hint.left { text-align: left; }

.secondary-btn {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}
.secondary-btn:hover { border-color: rgba(255, 255, 255, 0.24); background: rgba(255, 255, 255, 0.07); }
.secondary-btn.full { width: 100%; }
.secondary-btn:disabled { opacity: 0.4; cursor: default; }
.secondary-btn:disabled:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.045); }

/* ---------- 文件页 ---------- */
.upload-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 30px 18px;
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.12);
  transition: border-color 0.18s, background 0.18s;
}
.upload-card.is-drag { border-color: var(--accent); background: rgba(74, 222, 128, 0.06); }
.upload-glyph {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 26px;
  color: var(--accent);
  background: rgba(74, 222, 128, 0.10);
  margin-bottom: 4px;
}
.upload-title { font-size: 15px; font-weight: 600; }
.upload-sub { font-size: 11.5px; color: var(--dim); margin-bottom: 8px; }

.file-name {
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  margin: 12px 0 9px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.2s ease;
}
.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.file-result { display: flex; flex-direction: column; gap: 14px; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-cell {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012)), var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.summary-label { font-size: 10.5px; letter-spacing: 0.12em; color: var(--muted); }
.summary-value {
  font-size: 24px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.summary-sub { font-size: 11px; color: var(--dim); }

.player { display: flex; align-items: center; gap: 11px; margin-top: 12px; }
.icon-btn.play { width: 38px; height: 38px; border-radius: 50%; color: var(--accent); background: rgba(74, 222, 128, 0.12); border-color: rgba(74, 222, 128, 0.2); }
.icon-btn.play svg { width: 18px; height: 18px; }
.seek { flex: 1; accent-color: var(--accent); height: 22px; }
.time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.notes-table { display: flex; flex-direction: column; gap: 9px; }
.note-row {
  display: grid;
  grid-template-columns: 46px 1fr 58px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text);
}
.note-row .n-name { color: var(--muted); font-variant-numeric: tabular-nums; }
.note-row .bar { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.note-row .bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(74, 222, 128, 0.45), var(--accent));
}
.note-row .dur { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }

.empty { padding: 18px 0 6px; text-align: center; font-size: 12.5px; color: var(--dim); }

/* ---------- 记录页 ---------- */
.record-card { align-items: flex-start; }
.record-note {
  font-size: 52px;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--amber);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}
.history li:last-child { border-bottom: 0; padding-bottom: 2px; }
.history .h-note { color: var(--amber); font-weight: 600; font-variant-numeric: tabular-nums; }
.history .h-source { color: var(--muted); font-size: 11px; }
.history .h-meta { color: var(--dim); font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(484px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px;
  border-radius: 18px;
  background: rgba(15, 19, 25, 0.88);
  border: 1px solid var(--line);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 30;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  height: 52px;
  border-radius: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-family: inherit;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.tab svg { width: 19px; height: 19px; }
.tab.is-active { color: var(--text); background: rgba(74, 222, 128, 0.11); }
.tab.is-active svg { color: var(--accent); }

/* ---------- 设置弹层 ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in 0.18s ease;
}
.sheet-panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(520px, 100%);
  background: #141a22;
  border-top: 1px solid var(--line-strong);
  border-radius: 24px 24px 0 0;
  padding: 10px 22px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  animation: sheet-up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  margin: 4px auto 16px;
}
.sheet-title { font-size: 16px; font-weight: 650; margin-bottom: 18px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
}
.setting-row output { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
#a4Range { width: 100%; margin: 14px 0 10px; accent-color: var(--accent); }
.about { margin: 26px 0 16px; font-size: 11px; line-height: 1.8; color: var(--dim); }
@keyframes sheet-up { from { transform: translate(-50%, 40px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  max-width: 86vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(26, 32, 41, 0.97);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 自适应 ---------- */
@media (min-width: 480px) {
  .app { padding-left: 22px; padding-right: 22px; }
  .graph { height: 160px; }
  .graph-tall { height: 210px; }
}

@media (max-height: 760px) {
  .note-name { font-size: clamp(50px, 13vw, 70px); }
  .note-wrap { padding: 8px 0 0; }
  .graph { height: 116px; margin-top: 10px; }
  .live-card { padding-top: 12px; padding-bottom: 10px; }
  .tuner { margin-top: 12px; }
  .live-status { margin-top: 6px; }
  .page { gap: 11px; }
  .best-card { padding: 14px 16px; }
  .primary-btn { height: 52px; }
}

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