:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --bg: #101311;
  --surface: #171b18;
  --surface-raised: #1d221e;
  --surface-soft: #232923;
  --line: #303730;
  --line-strong: #454d45;
  --text: #f2f4ef;
  --muted: #9ca59c;
  --accent: #b7f36b;
  --accent-strong: #8fd83b;
  --cyan: #69d7db;
  --amber: #f3bd5a;
  --danger: #ff6e66;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); }
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }

.app-shell { min-height: 100vh; }
.topbar { height: 74px; padding: 0 32px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--accent); color: #11170d; font-size: 12px; font-weight: 800; border-radius: 5px; }
.brand > span:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 15px; line-height: 1; }
.brand small { color: var(--muted); font-size: 10px; letter-spacing: 0; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.privacy-label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.privacy-label i, .live-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgb(183 243 107 / 10%); }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: var(--surface); cursor: pointer; }
.icon-button:hover { color: var(--text); border-color: var(--line-strong); }

.workspace { width: min(1460px, calc(100% - 64px)); margin: 0 auto; padding: 46px 0 56px; }
.workspace-head { display: flex; align-items: start; justify-content: space-between; gap: 32px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: 0; }
h1, h2, h3, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 32px; line-height: 1.2; font-weight: 650; }
.intro { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.source-controls { width: min(640px, 52%); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.device-picker { min-width: 0; display: grid; gap: 8px; }
.device-picker-wide, .source-help { grid-column: 1 / -1; }
.device-picker label { color: var(--muted); font-size: 12px; }
.source-help { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.select-wrap { position: relative; }
.select-wrap::after { content: "⌄"; position: absolute; right: 14px; top: 50%; transform: translateY(-55%); color: var(--muted); pointer-events: none; }
select { width: 100%; height: 44px; padding: 0 42px 0 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; appearance: none; cursor: pointer; text-overflow: ellipsis; }
select:disabled { cursor: not-allowed; opacity: .55; }

.permission-panel { min-height: 420px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; display: grid; place-items: center; align-content: center; text-align: center; padding: 56px 24px; }
.permission-visual { height: 98px; display: flex; align-items: center; gap: 5px; margin-bottom: 26px; }
.permission-visual i { display: block; width: 5px; height: 24px; border-radius: 2px; background: var(--line-strong); }
.permission-visual i:nth-of-type(2), .permission-visual i:nth-of-type(4) { height: 46px; }
.permission-visual i:nth-of-type(3) { height: 70px; background: var(--accent); }
.mic-glyph { width: 40px; height: 64px; border: 3px solid var(--text); border-radius: 20px 20px 15px 15px; margin-right: 20px; position: relative; }
.mic-glyph::after { content: ""; position: absolute; left: 50%; bottom: -16px; width: 22px; height: 11px; transform: translateX(-50%); border-bottom: 3px solid var(--text); border-left: 3px solid var(--text); border-right: 3px solid var(--text); border-radius: 0 0 12px 12px; }
.permission-copy { max-width: 560px; }
.permission-copy h2 { margin: 0; font-size: 23px; font-weight: 650; }
.permission-copy p:last-child { margin: 12px 0 28px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.primary-button, .secondary-button { min-height: 44px; padding: 0 18px; border-radius: 5px; font-weight: 700; cursor: pointer; }
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #11170d; }
.primary-button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.primary-button:disabled { cursor: wait; opacity: .65; }
.secondary-button { border: 1px solid var(--line-strong); background: transparent; color: var(--text); }
.secondary-button:hover { background: var(--surface-soft); }
.button-dot { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border: 2px solid currentColor; border-radius: 50%; }
.permission-error { min-height: 20px; max-width: 640px; margin: 16px 0 0; color: var(--danger); font-size: 13px; }

.analyzer-view { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(360px, .85fr); gap: 16px; }
.live-panel, .test-panel, .device-panel { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; }
.live-panel { padding: 24px; min-width: 0; }
.test-panel { padding: 24px; min-height: 520px; }
.device-panel { grid-column: 1 / -1; padding: 20px 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-head h2 { margin: 0; font-size: 18px; font-weight: 650; }
.live-state { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.live-state i { animation: pulse 1.8s ease-in-out infinite; }
.live-state.paused i { background: var(--muted); box-shadow: none; animation: none; }
@keyframes pulse { 50% { opacity: .45; } }

.meter-layout { display: grid; grid-template-columns: 128px minmax(0, 1fr); align-items: end; gap: 26px; margin: 30px 0; }
.level-readout { display: grid; grid-template-columns: auto auto; align-items: end; }
.level-readout span { grid-column: 1 / -1; margin-bottom: 3px; color: var(--muted); font-size: 11px; }
.level-readout strong { font-size: 34px; line-height: 1; font-weight: 600; }
.level-readout small { margin: 0 0 2px 5px; color: var(--muted); font-size: 11px; }
.level-meter-wrap { min-width: 0; }
.meter-scale { height: 18px; display: flex; justify-content: space-between; color: #788178; font-size: 9px; font-variant-numeric: tabular-nums; }
.level-meter { height: 16px; position: relative; overflow: hidden; background: #282e29; border-radius: 2px; }
.recommended-zone { position: absolute; left: 90%; width: 8.4%; height: 100%; background: rgb(183 243 107 / 10%); }
.level-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--cyan); transition: width 80ms linear, background-color 120ms; }
.level-fill.warm { background: var(--amber); }
.level-fill.hot { background: var(--danger); }
.peak-marker { position: absolute; top: 0; bottom: 0; left: 0; width: 2px; background: var(--text); transition: left 80ms linear; }
.meter-note { display: flex; justify-content: space-between; gap: 16px; margin-top: 10px; color: var(--muted); font-size: 10px; }
.zone-key { display: inline-block; width: 8px; height: 8px; margin-right: 5px; background: var(--accent); opacity: .65; }
#clipState.is-clipping { color: var(--danger); font-weight: 700; }

.live-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 24px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.live-stats > div { min-width: 0; display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 4px; padding: 12px 14px; border-left: 1px solid var(--line); }
.live-stats > div:first-child { border-left: 0; }
.live-stats span { color: var(--muted); font-size: 10px; }
.live-stats strong { font-size: 15px; }
.live-stats small { color: var(--muted); font-size: 9px; }

.visual-grid { display: grid; gap: 14px; }
.signal-chart { min-width: 0; margin: 0; padding-top: 17px; border-top: 1px solid var(--line); }
.signal-chart figcaption { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 9px; color: var(--text); font-size: 11px; }
.signal-chart output { color: var(--muted); }
.signal-chart canvas { display: block; width: 100%; height: 128px; background: #121613; border-radius: 3px; }
.spectrum-chart canvas { height: 150px; }
.frequency-labels { display: flex; justify-content: space-between; padding-top: 6px; color: #788178; font-size: 9px; }

.test-counter { color: var(--muted); font-size: 12px; }
.test-idle { min-height: 410px; display: flex; flex-direction: column; justify-content: center; }
.test-sequence { display: grid; grid-template-columns: 1fr 34px 1fr; align-items: center; margin: 28px 0 42px; }
.test-sequence > div { min-width: 0; }
.test-sequence > div > span { width: 30px; height: 30px; display: grid; place-items: center; margin-bottom: 12px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--accent); font-size: 10px; }
.test-sequence strong, .test-sequence small { display: block; }
.test-sequence strong { margin-bottom: 5px; font-size: 13px; }
.test-sequence small { color: var(--muted); font-size: 10px; white-space: nowrap; }
.test-sequence > i { height: 1px; background: var(--line-strong); }
.test-button { width: 100%; }
.test-running { min-height: 410px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.phase-visual { margin-bottom: 22px; }
#phaseRing { --phase: 0deg; width: 112px; height: 112px; padding: 5px; border-radius: 50%; background: conic-gradient(var(--accent) var(--phase), var(--line) 0); }
#phaseRing::before { content: ""; position: absolute; }
#phaseRing span { width: 100%; height: 100%; display: grid; place-items: center; border-radius: 50%; background: var(--surface); color: var(--text); font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.test-running h3 { margin: 0; font-size: 21px; }
.test-running > p:not(.eyebrow) { margin: 8px 0 26px; color: var(--muted); font-size: 12px; }
.test-progress { width: 100%; height: 5px; overflow: hidden; background: var(--line); border-radius: 2px; }
.test-progress i { display: block; width: 0; height: 100%; background: var(--accent); transition: width 100ms linear; }
.text-button { margin-top: 20px; padding: 8px; color: var(--muted); background: none; border: 0; cursor: pointer; }
.text-button:hover { color: var(--text); }

.test-result { padding-top: 22px; }
.score-row { display: grid; grid-template-columns: 118px 1fr; align-items: center; gap: 22px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.score-gauge { --score: 0deg; width: 118px; height: 118px; padding: 7px; border-radius: 50%; background: conic-gradient(var(--accent) var(--score), var(--line) 0); }
.score-gauge > div { height: 100%; border-radius: 50%; background: var(--surface); display: grid; place-content: center; text-align: center; }
.score-gauge strong { display: block; font-size: 32px; line-height: 1; }
.score-gauge span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.score-copy > span { color: var(--muted); font-size: 10px; }
.score-copy h3 { margin: 5px 0 7px; font-size: 20px; }
.score-copy p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.result-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; margin: 1px 0 18px; background: var(--line); }
.result-metrics > div { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 3px; padding: 13px 12px; background: var(--surface); }
.result-metrics span { color: var(--muted); font-size: 10px; }
.result-metrics strong { font-size: 15px; }
.result-metrics small { color: var(--muted); font-size: 9px; }
.findings-list { display: grid; gap: 8px; margin-bottom: 18px; }
.finding { display: grid; grid-template-columns: 9px 1fr; gap: 9px; align-items: start; }
.finding > i { width: 7px; height: 7px; margin-top: 5px; border-radius: 50%; background: var(--accent); }
.finding.warning > i { background: var(--amber); }
.finding.problem > i { background: var(--danger); }
.finding strong { display: block; margin-bottom: 2px; font-size: 11px; }
.finding p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.test-result > .secondary-button { width: 100%; }

.device-specs { display: grid; grid-template-columns: 2fr repeat(3, 1fr); margin: 18px 0 0; }
.device-specs > div { min-width: 0; padding: 0 20px; border-left: 1px solid var(--line); }
.device-specs > div:first-child { padding-left: 0; border-left: 0; }
.device-specs dt { margin-bottom: 6px; color: var(--muted); font-size: 10px; }
.device-specs dd { margin: 0; overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 980px) {
  .workspace { width: min(100% - 36px, 760px); padding-top: 32px; }
  .analyzer-view { grid-template-columns: 1fr; }
  .device-panel { grid-column: auto; }
  .test-panel { min-height: auto; }
}

@media (max-width: 640px) {
  .topbar { height: 64px; padding: 0 18px; }
  .privacy-label { display: none; }
  .workspace { width: calc(100% - 24px); padding: 24px 0 36px; }
  .workspace-head { display: grid; gap: 22px; }
  h1 { font-size: 26px; }
  .source-controls { width: 100%; }
  .permission-panel { min-height: 390px; padding: 42px 18px; }
  .permission-copy h2 { font-size: 20px; }
  .live-panel, .test-panel, .device-panel { padding: 18px; }
  .meter-layout { grid-template-columns: 1fr; gap: 14px; margin: 25px 0; }
  .level-readout { width: 116px; }
  .meter-note { align-items: start; }
  .live-stats > div { grid-template-columns: 1fr; gap: 3px; padding: 11px 8px; }
  .live-stats small { display: none; }
  .signal-chart canvas { height: 110px; }
  .spectrum-chart canvas { height: 135px; }
  .score-row { grid-template-columns: 94px 1fr; gap: 16px; }
  .score-gauge { width: 94px; height: 94px; }
  .score-gauge strong { font-size: 27px; }
  .device-specs { grid-template-columns: 1fr 1fr; gap: 18px 0; }
  .device-specs > div:nth-child(3) { padding-left: 0; border-left: 0; }
}

@media (max-width: 390px) {
  .brand small { display: none; }
  .source-controls { grid-template-columns: 1fr; }
  .device-picker-wide, .source-help { grid-column: auto; }
  .test-sequence { grid-template-columns: 1fr 22px 1fr; }
  .test-sequence small { white-space: normal; }
  .result-metrics { grid-template-columns: 1fr; }
  .score-row { grid-template-columns: 1fr; text-align: center; }
  .score-gauge { margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
