:root {
  --bg: #0b0e14;
  --bg-2: #111621;
  --card: #161c28;
  --card-2: #1c2432;
  --line: #232c3d;
  --text: #e6edf7;
  --dim: #8a97ad;
  --dim-2: #5f6b80;
  --accent: #4f8cff;
  --accent-2: #2f6be0;
  --green: #3ddc97;
  --red: #ff6b6b;
  --amber: #ffb648;
  --radius: 14px;
}

* { 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, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.dim { color: var(--dim); font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- 口令门 ---------- */
.gate {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #16203300, #0b0e14 70%), var(--bg);
  padding: 24px;
}
.gate-box {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.gate-logo { color: var(--accent); margin-bottom: 6px; }
.gate-box h1 { font-size: 20px; margin: 6px 0 4px; }
.gate-sub { color: var(--dim); font-size: 13px; margin: 0 0 20px; }
.gate-tip { color: var(--dim-2); font-size: 12px; margin: 14px 0 0; line-height: 1.5; }

input, select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 10px;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--dim-2); }
select.inline-select { width: auto; margin: 0; padding: 6px 8px; font-size: 13px; }

.btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: #4a2530; color: var(--red); }

.icon-btn {
  background: transparent; border: none; color: var(--dim);
  padding: 6px; cursor: pointer; border-radius: 8px;
}
.icon-btn:active { background: var(--card-2); }

/* ---------- 主布局 ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-title { font-weight: 600; font-size: 15px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim-2); }
.dot.live { background: var(--green); box-shadow: 0 0 0 4px rgba(61,220,151,.15); animation: pulse 1.6s infinite; }
.dot.err { background: var(--red); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.chip {
  font-size: 12px; color: var(--dim);
  background: var(--card); border: 1px solid var(--line);
  padding: 3px 8px; border-radius: 20px;
}

.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: transparent; border: none; color: var(--dim);
  padding: 9px 4px; font-size: 14px; font-family: inherit; cursor: pointer;
  border-bottom: 2px solid transparent; position: relative;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block; min-width: 16px; height: 16px; line-height: 16px;
  background: var(--accent); color: #fff; border-radius: 8px;
  font-size: 10px; padding: 0 4px; margin-left: 4px; vertical-align: middle;
}

.page { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px 90px; display: none; }
.page.active { display: block; }

/* ---------- 波形 ---------- */
.wave-row { position: relative; margin-bottom: 8px; }
#wave { width: 100%; height: 46px; display: block; border-radius: 10px; background: var(--bg-2); }
.level-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.level-wrap { flex: 1; height: 3px; background: var(--bg-2); border-radius: 3px; overflow: hidden; }
.level-text { font-size: 12px; color: var(--dim); min-width: 40px; text-align: right; }
.level-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--green), var(--accent)); transition: width .1s; }

/* ---------- 转写 ---------- */
.transcript { min-height: 40vh; }
.empty-hint { text-align: center; color: var(--dim); padding: 40px 20px; }
.empty-hint svg { color: var(--dim-2); margin-bottom: 10px; }
.empty-hint p { margin: 4px 0; }

.line {
  display: flex; gap: 8px; margin-bottom: 10px;
  animation: fadein .25s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.line-time { color: var(--dim-2); font-size: 11px; min-width: 42px; padding-top: 3px; font-variant-numeric: tabular-nums; }
.line-text { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; }
.line.q .line-text { border-color: #3a4a6b; background: #16203a; }
.line.q .line-time { color: var(--amber); }
.line-text .qtag {
  display: inline-block; font-size: 11px; color: var(--amber);
  border: 1px solid #4b3a1c; background: #241d0e;
  padding: 1px 6px; border-radius: 6px; margin-right: 6px;
}
.interim {
  color: var(--dim); font-size: 14px; padding: 8px 14px 100px;
  min-height: 22px;
}

/* ---------- 作答 ---------- */
.qa-ask { display: flex; gap: 8px; margin-bottom: 12px; }
.qa-ask input { margin: 0; flex: 1; }
.qa-ask .btn { flex: none; }

.answer-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 12px;
  animation: fadein .3s ease;
}
.answer-card.fresh { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.12); }
.ac-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.ac-q { font-size: 13px; color: var(--amber); line-height: 1.5; }
.ac-time { color: var(--dim-2); font-size: 11px; white-space: nowrap; }
.ac-body { font-size: 15px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.ac-body.streaming::after { content: "▌"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.ac-foot { display: flex; gap: 8px; margin-top: 10px; }
.ac-foot .btn { font-size: 12px; padding: 5px 10px; }
.ac-meta { font-size: 11px; color: var(--dim-2); margin-top: 8px; }

/* ---------- 笔记 ---------- */
.notes-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.notes-body { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-height: 200px; font-size: 14px; line-height: 1.8; white-space: pre-wrap; }

/* ---------- 底部 ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(11,14,20,.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.mic-btn {
  width: 56px; height: 56px; flex: none; border-radius: 50%;
  border: none; background: var(--card-2); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.mic-btn.recording { background: var(--red); color: #fff; animation: pulse 1.6s infinite; }
.dock-actions { flex: 1; display: flex; gap: 8px; }
.dock-actions .btn { flex: 1; }

/* ---------- 设置抽屉 ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); }
.sheet-box {
  position: absolute; left: 0; right: 0; bottom: 0; top: 8%;
  background: var(--bg); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 16px; margin: 0; }
.sheet-body { flex: 1; overflow-y: auto; padding: 14px 16px 40px; }
.conn-status {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 16px;
  background: var(--bg-2); border: 1px solid var(--line);
  font-size: 13px; line-height: 1.5; color: var(--dim);
}
.conn-status .cs-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim-2); margin-top: 6px; flex: none; }
.conn-status.ok { border-color: #1f4a37; background: #10241c; color: #9fe0c0; }
.conn-status.ok .cs-dot { background: var(--green); }
.conn-status.err { border-color: #4a2530; background: #241218; color: #f0a9a9; }
.conn-status.err .cs-dot { background: var(--red); }
.conn-status b { color: inherit; }

.group { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px dashed var(--line); }
.group-title { display: block; font-size: 13px; color: var(--dim); margin-bottom: 8px; font-weight: 600; }
.hint { font-size: 12px; color: var(--dim-2); margin: 4px 0 0; }
.hint a { color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row select { flex: 1; margin-bottom: 0; }
.row .btn { flex: none; margin-bottom: 0; }
.test-result { font-size: 12px; color: var(--dim); word-break: break-all; }
.test-result.ok { color: var(--green); }
.test-result.err { color: var(--red); }
.save-tip { font-size: 13px; color: var(--green); text-align: center; margin: 10px 0 0; min-height: 18px; }

.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.seg-btn {
  flex: 1; background: transparent; border: none; color: var(--dim);
  padding: 9px 6px; font-size: 13px; font-family: inherit; cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; font-size: 14px; gap: 10px;
}
.switch-row input[type="checkbox"] { width: 44px; height: 24px; margin: 0; appearance: none; background: var(--card-2); border-radius: 12px; position: relative; cursor: pointer; transition: .2s; }
.switch-row input[type="checkbox"]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--dim); transition: .2s; }
.switch-row input[type="checkbox"]:checked { background: var(--accent-2); }
.switch-row input[type="checkbox"]:checked::after { left: 22px; background: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px);
  background: #232c3d; color: var(--text); border: 1px solid var(--line);
  padding: 9px 16px; border-radius: 20px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 80; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 700px) {
  .app { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .dock { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
  .sheet-box { max-width: 560px; left: 50%; transform: translateX(-50%); }
}
