:root {
  --bg: #0b1020;
  --card: #151b31;
  --card-2: #1c2440;
  --line: #2a3355;
  --text: #e8ecff;
  --muted: #8f9bc7;
  --accent: #4f7cff;
  --accent-2: #8b5cf6;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 16px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: rgba(11, 16, 32, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

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

.sprite {
  display: none;
}

/* 图标统一用内联 SVG：emoji 在不同手机上长得不一样，SVG 不会。 */
.ic {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.logo {
  display: flex;
  align-items: center;
  font-size: 26px;
}

.logo .ic {
  width: 26px;
  height: 26px;
}

.icon-btn .ic {
  width: 18px;
  height: 18px;
  margin: 0 auto;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.15);
}

.dot[data-state='ok'] {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.dot[data-state='err'] {
  background: var(--err);
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.15);
}

.icon-btn {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
}

main {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hidden {
  display: none !important;
}

/* 页面初始化完成前显示；如果脚本出错，这里会变成错误信息而不是白屏 */
.boot {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.muted.small {
  font-size: 11px;
  word-break: break-all;
}

.error {
  color: var(--err);
  font-size: 13px;
  margin: 8px 0 0;
}

.error.pending {
  color: #9db2ff;
}

/* ---- 证书引导页（mic.html）---- */
.guide {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 18px calc(env(safe-area-inset-bottom) + 60px);
}

.guide h1 {
  font-size: 22px;
  line-height: 1.3;
  margin: 10px 0 14px;
}

.guide h2 {
  font-size: 16px;
  color: #cdd6ff;
  margin: 28px 0 8px;
}

.guide p {
  font-size: 14px;
  line-height: 1.75;
  color: #b9c3e6;
  margin: 0 0 12px;
}

.guide b {
  color: #eef1ff;
}

.guide a {
  color: #8fb0ff;
}

.guide pre {
  background: #0a0e1c;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 14px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  color: #d7e0ff;
  white-space: pre-wrap;
  word-break: break-word;
}

.guide .notice {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 18px 0;
}

.guide .notice p {
  color: #e6d7a6;
  font-size: 13px;
  margin: 0;
}

.guide .back {
  display: inline-block;
  margin-top: 30px;
  font-size: 13px;
}

.pair-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

input,
select {
  flex: 1;
  min-width: 0;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

#pairInput {
  letter-spacing: 8px;
  font-size: 22px;
  text-align: center;
  font-weight: 600;
}

button.primary,
button.ghost {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  white-space: nowrap;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

button:active {
  transform: scale(0.97);
}

.mic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0 4px;
}

.mic-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-icon .ic {
  width: 54px;
  height: 54px;
  stroke-width: 1.7;
}

.mic {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 30% 30%, #6b8dff, #3f5fd8 60%, #2a3f9e);
  color: #fff;
  font-size: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 40px rgba(79, 124, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
  touch-action: none;
  user-select: none;
}

.mic.listening {
  transform: scale(1.06);
  background: radial-gradient(circle at 30% 30%, #ff7a7a, #e04545 60%, #a32020);
  box-shadow: 0 0 0 12px rgba(248, 113, 113, 0.16), 0 14px 40px rgba(248, 113, 113, 0.35);
  animation: pulse 1.1s infinite;
}

.mic.disabled {
  filter: grayscale(0.8);
  opacity: 0.5;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.35), 0 14px 40px rgba(248, 113, 113, 0.3);
  }
  100% {
    box-shadow: 0 0 0 26px rgba(248, 113, 113, 0), 0 14px 40px rgba(248, 113, 113, 0.3);
  }
}

.mic-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  max-width: 360px;
  line-height: 1.6;
}

.mic-hint .mic-why {
  line-height: 1.6;
}

.mic-hint .mic-cta {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 11px;
  background: rgba(79, 124, 255, 0.16);
  border: 1px solid rgba(79, 124, 255, 0.45);
  color: #a9bdff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

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

.mic-hint .mic-alt {
  font-size: 12px;
  opacity: 0.85;
}

.live {
  min-height: 22px;
  font-size: 16px;
  color: #cdd6ff;
  text-align: center;
  padding: 0 8px;
  line-height: 1.4;
}

.input-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.chip {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 6px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.chip span:first-child {
  display: flex;
  align-items: center;
  justify-content: center;
}

.chip .ic {
  width: 19px;
  height: 19px;
}

.chip:active {
  background: var(--card-2);
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
}

.log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 40vh;
  overflow-y: auto;
}

.log-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
}

.log-item.err {
  border-left-color: var(--err);
}

.log-item .meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.log-item .body {
  white-space: pre-wrap;
  word-break: break-word;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
}

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-body {
  position: relative;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto 6px;
}

.sheet-body h2 {
  margin: 0;
  font-size: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field small {
  font-size: 11px;
  line-height: 1.5;
}

.help {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
}

.help summary {
  cursor: pointer;
  color: #a9bdff;
  font-weight: 600;
}

.help p {
  margin: 10px 0 0;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--muted);
}

.help b {
  color: #eef1ff;
}

.help .small {
  font-size: 11px;
  opacity: 0.9;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.toggle input {
  flex: none;
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  padding: 0;
}

.sheet-actions {
  display: flex;
  gap: 8px;
}

.sheet-actions button {
  flex: 1;
}
