:root {
  color-scheme: dark;
  --bg: #07111e;
  --bg-deep: #040b13;
  --surface: #101b2a;
  --surface-soft: #142131;
  --border: #293648;
  --text: #f5f7fb;
  --muted: #9aa8bd;
  --quiet: #6f8099;
  --accent: #ff7558;
  --accent-bright: #ff8b68;
  --accent-dark: #e95f44;
  --danger: #ffbf69;
  --success: #63d6ac;
  --level: 0;
  --volume-fill: 80%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(28, 49, 72, 0.34) 0, rgba(7, 17, 30, 0) 38%),
    linear-gradient(180deg, #081421 0%, var(--bg) 50%, var(--bg-deep) 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(255, 139, 104, 0.62);
  outline-offset: 4px;
}

.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 480px);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 22px calc(18px + env(safe-area-inset-bottom));
  isolation: isolate;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.topbar::after {
  content: "";
  position: absolute;
  right: -22px;
  bottom: -11px;
  left: -22px;
  border-bottom: 1px solid rgba(116, 136, 163, 0.14);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-size: 22px;
  font-weight: 710;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 33px;
  color: var(--accent);
}

.brand-mark path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button svg {
  width: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:active {
  background: rgba(255, 255, 255, 0.06);
}

.route-section {
  margin-top: 20px;
}

.connection-hint {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 6px 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

.connection-hint svg {
  flex: 0 0 auto;
  width: 22px;
  fill: none;
  stroke: #8da0bd;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 17px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: rgba(17, 28, 43, 0.76);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025);
  font-size: 15px;
  font-weight: 630;
}

.route-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-weight: 500;
}

.route-value svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.microphone-stage {
  position: relative;
  display: grid;
  flex: 1 0 276px;
  min-height: 276px;
  place-items: center;
  margin: 9px -22px 2px;
  overflow: hidden;
}

.acoustic-rings {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 318px;
  height: 318px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.acoustic-rings span {
  position: absolute;
  inset: 50% auto auto 50%;
  border: 1px solid rgba(255, 117, 88, 0.11);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.acoustic-rings span:nth-child(1) { width: 188px; height: 188px; border-color: rgba(255, 117, 88, 0.3); }
.acoustic-rings span:nth-child(2) { width: 226px; height: 226px; border-style: dashed; border-color: rgba(255, 117, 88, 0.18); }
.acoustic-rings span:nth-child(3) { width: 272px; height: 272px; }
.acoustic-rings span:nth-child(4) { width: 318px; height: 318px; border-color: rgba(151, 167, 190, 0.06); }

.mic-orb {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 174px;
  height: 174px;
  padding: 12px;
  border: 2px solid rgba(255, 124, 94, 0.64);
  border-radius: 50%;
  background: linear-gradient(145deg, #1c2938, #0d1724 66%);
  box-shadow:
    0 0 calc(10px + var(--level) * 22px) rgba(255, 117, 88, calc(0.17 + var(--level) * 0.35)),
    0 18px 35px rgba(0, 0, 0, 0.48),
    inset 0 1px 1px rgba(255, 255, 255, 0.13),
    inset 0 -10px 20px rgba(0, 0, 0, 0.28);
  color: var(--accent-bright);
  cursor: pointer;
  transition: transform 160ms ease, border-color 220ms ease, box-shadow 220ms ease, background 220ms ease;
}

.mic-orb::before {
  content: "";
  position: absolute;
  inset: -9px;
  border: 3px solid rgba(255, 117, 88, 0.58);
  border-radius: inherit;
  opacity: 0.7;
  transition: opacity 220ms ease, transform 220ms ease;
}

.mic-orb:active {
  transform: scale(0.97);
}

.mic-icon {
  width: 55px;
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 3px 7px rgba(255, 117, 88, 0.25));
}

.orb-status {
  margin-top: 10px;
  color: var(--text);
  font-size: 17px;
  font-weight: 650;
}

.waveform {
  position: absolute;
  z-index: 1;
  top: 50%;
  display: flex;
  align-items: center;
  gap: 5px;
  width: 95px;
  height: 72px;
  transform: translateY(-50%);
  opacity: 0.7;
}

.waveform-left { left: 0; justify-content: flex-end; }
.waveform-right { right: 0; }

.waveform i {
  display: block;
  width: 4px;
  height: var(--bar-height);
  border-radius: 99px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(255, 117, 88, 0.2);
  transform: scaleY(calc(0.55 + var(--level) * var(--bar-gain)));
  transition: transform 80ms linear, opacity 200ms ease;
  opacity: calc(0.45 + var(--level) * 0.55);
}

.controls {
  display: flex;
  align-items: stretch;
  flex-direction: column;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  align-self: center;
  justify-content: center;
  gap: 12px;
  width: min(100%, 230px);
  min-height: 64px;
  padding: 0 28px;
  border: 0;
  border-radius: 32px;
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  box-shadow: 0 13px 28px rgba(242, 91, 61, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 20px;
  font-weight: 720;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease, background 220ms ease;
}

.primary-button svg {
  width: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary-button:active {
  transform: scale(0.975);
  filter: brightness(0.95);
}

.volume-control {
  margin-top: 24px;
}

.control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 580;
}

.control-heading output {
  color: var(--accent-bright);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 680;
}

input[type="range"] {
  width: 100%;
  height: 26px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 7px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--volume-fill), #2a374a var(--volume-fill));
}

input[type="range"]::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -8.5px;
  appearance: none;
  -webkit-appearance: none;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: #f7f8fa;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

input[type="range"]::-moz-range-track {
  height: 7px;
  border: 0;
  border-radius: 99px;
  background: #2a374a;
}

input[type="range"]::-moz-range-progress {
  height: 7px;
  border-radius: 99px;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: #f7f8fa;
}

.mute-button {
  display: inline-flex;
  align-items: center;
  align-self: center;
  justify-content: center;
  gap: 9px;
  min-width: 155px;
  min-height: 48px;
  margin-top: 17px;
  padding: 0 24px;
  border: 1px solid #536278;
  border-radius: 25px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  font-weight: 620;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.mute-button svg {
  width: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mute-button:disabled {
  cursor: default;
  opacity: 0.46;
}

.mute-button[aria-pressed="true"] {
  border-color: rgba(255, 117, 88, 0.72);
  background: rgba(255, 117, 88, 0.1);
  color: var(--accent-bright);
}

.notices {
  display: grid;
  gap: 9px;
  margin-top: 24px;
  padding-bottom: 4px;
}

.notices p {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.notices svg {
  flex: 0 0 auto;
  width: 20px;
  fill: none;
  stroke: #8293ae;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notices .warning-icon {
  stroke: var(--danger);
}

.message {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: min(calc(100% - 40px), 420px);
  padding: 13px 16px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 14px;
  background: rgba(18, 29, 44, 0.96);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  transform: translateX(-50%);
}

.help-dialog {
  width: min(calc(100% - 36px), 420px);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: #111d2b;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.62);
  color: var(--text);
}

.help-dialog::backdrop {
  background: rgba(1, 6, 12, 0.72);
  backdrop-filter: blur(8px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-header h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.dialog-close {
  margin: -8px -8px -8px 0;
}

.help-dialog ol {
  display: grid;
  gap: 12px;
  margin: 22px 0 17px;
  padding-left: 24px;
  color: #dce3ee;
  font-size: 15px;
  line-height: 1.6;
}

.help-dialog p {
  margin: 0;
  padding: 13px 15px;
  border-radius: 14px;
  background: rgba(255, 191, 105, 0.08);
  color: #c7d0dd;
  font-size: 13px;
  line-height: 1.55;
}

.app-shell.is-active .mic-orb {
  border-color: var(--success);
  background: linear-gradient(145deg, #15352f, #0b211f 70%);
  color: #73e0b8;
}

.app-shell.is-active .mic-orb::before {
  border-color: rgba(99, 214, 172, 0.74);
  opacity: calc(0.7 + var(--level) * 0.3);
  transform: scale(calc(1 + var(--level) * 0.07));
}

.app-shell.is-active .acoustic-rings span:nth-child(1),
.app-shell.is-active .acoustic-rings span:nth-child(2) {
  border-color: rgba(99, 214, 172, calc(0.16 + var(--level) * 0.3));
}

.app-shell.is-active .waveform i {
  background: var(--success);
  box-shadow: 0 0 8px rgba(99, 214, 172, 0.24);
}

.app-shell.is-active .primary-button {
  background: #203044;
  box-shadow: inset 0 0 0 1px #394b61;
  color: #e6ebf2;
}

.app-shell.is-muted .mic-orb,
.app-shell.is-muted .waveform {
  opacity: 0.58;
}

@keyframes ring-breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(0.98); opacity: 0.55; }
  50% { transform: translate(-50%, -50%) scale(1.02); opacity: 1; }
}

.app-shell.is-active .acoustic-rings span:nth-child(3) {
  animation: ring-breathe 2.2s ease-in-out infinite;
}

@media (min-height: 820px) {
  .app-shell { padding-left: 26px; padding-right: 26px; }
  .route-section { margin-top: 25px; }
  .microphone-stage { min-height: 322px; }
  .mic-orb { width: 188px; height: 188px; }
  .acoustic-rings { width: 350px; height: 350px; }
  .acoustic-rings span:nth-child(1) { width: 202px; height: 202px; }
  .acoustic-rings span:nth-child(2) { width: 245px; height: 245px; }
  .acoustic-rings span:nth-child(3) { width: 296px; height: 296px; }
  .acoustic-rings span:nth-child(4) { width: 350px; height: 350px; }
}

@media (max-height: 700px) {
  .app-shell { padding-top: calc(8px + env(safe-area-inset-top)); }
  .route-section { margin-top: 8px; }
  .connection-hint { margin-bottom: 10px; }
  .route-row { min-height: 52px; }
  .microphone-stage { flex-basis: 232px; min-height: 232px; }
  .mic-orb { width: 148px; height: 148px; }
  .mic-icon { width: 46px; }
  .orb-status { margin-top: 7px; font-size: 15px; }
  .acoustic-rings { transform: translate(-50%, -50%) scale(0.82); }
  .primary-button { min-height: 56px; }
  .volume-control { margin-top: 16px; }
  .mute-button { min-height: 44px; margin-top: 10px; }
  .notices { margin-top: 14px; gap: 5px; }
}

@media (max-width: 360px) {
  .app-shell { padding-right: 17px; padding-left: 17px; }
  .brand { font-size: 20px; }
  .route-row { padding: 0 14px; font-size: 14px; }
  .connection-hint { font-size: 14px; }
  .microphone-stage { margin-right: -17px; margin-left: -17px; }
  .notices p { font-size: 11.5px; }
}

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