/* ========== Hermes 语音助教 · 深色科技风 ========== */
:root {
  --bg: #0a0e1a;
  --bg2: #0f1526;
  --card: #141b31;
  --card2: #1a2340;
  --line: #233058;
  --txt: #e8edf7;
  --sub: #8b97b8;
  --dim: #5d6a8c;
  --acc: #4f7cff;
  --acc2: #22d3ee;
  --gold: #f5b94a;
  --green: #34d399;
  --red: #f87171;
  --radius: 16px;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }

/* ========== 视图切换 ========== */
.view { position: fixed; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }

/* ========== 首页 ========== */
#view-home { align-items: center; justify-content: center; overflow: hidden; }

.grid-bg {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(79,124,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,124,255,.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 40%, #000 30%, transparent 75%);
}

.orb { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .35; }
.orb-1 { width: 420px; height: 420px; background: #2c4cb3; top: -120px; left: -120px; animation: float 9s ease-in-out infinite; }
.orb-2 { width: 360px; height: 360px; background: #0e7490; bottom: -100px; right: -100px; animation: float 11s ease-in-out infinite reverse; }
@keyframes float { 0%,100% { transform: translate(0,0); } 50% { transform: translate(30px, -30px); } }

.home-hero {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 32px 24px; max-width: 480px; width: 100%;
}

.avatar-wrap { position: relative; width: 148px; height: 148px; margin-bottom: 26px; }
.avatar { width: 148px; height: 148px; border-radius: 50%; box-shadow: 0 12px 48px rgba(79,124,255,.35); position: relative; z-index: 2; }
.avatar-ring {
  position: absolute; inset: -10px; border-radius: 50%;
  border: 1.5px solid rgba(34,211,238,.5);
  animation: ringPulse 3s ease-out infinite;
}
.avatar-ring.r2 { animation-delay: 1.5s; }
@keyframes ringPulse {
  0% { transform: scale(.92); opacity: 0; }
  40% { opacity: .8; }
  100% { transform: scale(1.35); opacity: 0; }
}

.home-hero h1 { font-size: 27px; font-weight: 700; letter-spacing: .5px; }
.tagline { color: var(--sub); font-size: 14px; margin-top: 6px; }

.badges { display: flex; gap: 8px; margin: 18px 0 30px; flex-wrap: wrap; justify-content: center; }
.badge {
  font-size: 12px; padding: 5px 13px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--acc2); background: rgba(34,211,238,.07);
  white-space: nowrap;
}
.badge-mem { color: var(--green); border-color: rgba(52,211,153,.35); background: rgba(52,211,153,.07); }

.home-actions { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; }

.btn-primary {
  width: 100%; padding: 15px 20px; border-radius: 14px;
  background: linear-gradient(135deg, var(--acc), #7c5cff);
  color: #fff; font-size: 16px; font-weight: 600; letter-spacing: .5px;
  box-shadow: 0 8px 28px rgba(79,124,255,.4);
  transition: transform .15s, box-shadow .15s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:active { transform: scale(.97); }
.btn-ico { font-size: 18px; }

.btn-ghost {
  width: 100%; padding: 13px 20px; border-radius: 14px;
  border: 1px solid var(--line); color: var(--sub); font-size: 14px;
  background: rgba(20,27,49,.6); transition: border-color .15s, color .15s;
}
.btn-ghost:active { border-color: var(--acc); color: var(--txt); }

.home-tip { margin-top: 26px; font-size: 12px; color: var(--dim); }
.home-settings { margin-top: 14px; font-size: 13px; color: var(--acc2); text-decoration: none; }

/* HTTP 远程访问提示（麦克风将被浏览器禁用） */
.https-hint {
  margin-top: 18px; padding: 12px 14px; max-width: 420px; text-align: left;
  font-size: 12.5px; line-height: 1.7; color: #ffd9a8;
  background: rgba(255, 176, 32, 0.08); border: 1px solid rgba(255, 176, 32, 0.35);
  border-radius: 12px;
}
.https-hint code {
  padding: 1px 6px; border-radius: 5px; font-size: 11.5px;
  background: rgba(255, 176, 32, 0.15); color: #ffc46b;
}

/* ========== 对话页 ========== */
.chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(15,21,38,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); z-index: 10;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  color: var(--sub); font-size: 20px; flex-shrink: 0; text-decoration: none;
}
.icon-btn:active { background: var(--card2); }

.chat-avatar-wrap { position: relative; flex-shrink: 0; }
.chat-avatar { width: 38px; height: 38px; border-radius: 50%; }
.state-dot {
  position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--dim); border: 2px solid var(--bg2);
  transition: background .2s;
}
.state-dot.live { background: var(--green); }
.state-dot.listening { background: var(--acc2); animation: blink 1s infinite; }
.state-dot.thinking { background: var(--gold); animation: blink .6s infinite; }
.state-dot.speaking { background: var(--acc); animation: blink .8s infinite; }
@keyframes blink { 50% { opacity: .35; } }

.chat-title { flex: 1; min-width: 0; }
.chat-name { font-size: 15px; font-weight: 600; }
.chat-state { font-size: 11.5px; color: var(--sub); }

.mode-chips { display: flex; gap: 4px; background: var(--bg2); padding: 3px; border-radius: 10px; flex-shrink: 0; }
.mode-chips button {
  font-size: 12px; padding: 5px 9px; border-radius: 8px; color: var(--sub); transition: all .15s;
}
.mode-chips button.on { background: var(--acc); color: #fff; }

.chat-body {
  flex: 1; overflow-y: auto; padding: 16px 12px 20px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.chat-hint {
  text-align: center; font-size: 11.5px; color: var(--dim);
  padding: 8px 16px; background: rgba(20,27,49,.5); border-radius: 10px;
  border: 1px dashed var(--line); margin-bottom: 4px;
}

.msg { display: flex; gap: 8px; max-width: 100%; animation: msgIn .25s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user { flex-direction: row-reverse; }
.msg .m-avatar { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; margin-top: 2px; }
.bubble {
  padding: 10px 13px; border-radius: 14px; font-size: 14.5px; line-height: 1.65;
  max-width: min(78%, 520px); word-break: break-word; white-space: pre-wrap;
}
.msg.ai .bubble {
  background: var(--card); border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--acc), #6a5cff);
  color: #fff; border-top-right-radius: 4px;
}
.bubble.streaming { border-color: rgba(34,211,238,.4); }
.bubble .cursor { display: inline-block; width: 2px; height: 1em; background: var(--acc2); margin-left: 2px; vertical-align: -2px; animation: blink .8s infinite; }

/* 记忆命中卡片 */
.mem-card {
  max-width: min(88%, 560px); align-self: flex-start;
  background: rgba(34,211,238,.05); border: 1px dashed rgba(34,211,238,.4);
  border-radius: 12px; padding: 10px 13px; font-size: 12.5px; color: var(--sub);
  animation: msgIn .25s ease;
}
.mem-card .mem-head { color: var(--acc2); font-weight: 600; margin-bottom: 6px; font-size: 12.5px; }
.mem-card .mem-item { padding: 5px 0; border-top: 1px solid rgba(34,211,238,.12); }
.mem-card .mem-item:first-of-type { border-top: none; }
.mem-card .mem-src { color: var(--dim); font-size: 11px; }
.mem-card .mem-text { color: #a9b6d6; }

/* 系统提示行 */
.sys-line { align-self: center; font-size: 11.5px; color: var(--dim); padding: 3px 10px; }

/* 打字中的三点 */
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--sub); animation: tp 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes tp { 0%,60%,100% { transform: none; opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ========== 底部输入区 ========== */
.chat-footer {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(15,21,38,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
#wave { width: 100%; height: 36px; display: block; }

/* 语音识别中间结果浮动条 */
.interim {
  display: none; font-size: 12.5px; color: var(--acc2);
  padding: 6px 12px; margin-top: 4px;
  background: rgba(34,211,238,.07); border: 1px solid rgba(34,211,238,.25);
  border-radius: 10px; max-height: 44px; overflow: hidden;
}
.interim.show { display: block; }

.input-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.mic-btn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--card2); border: 1px solid var(--line); color: var(--acc2);
  transition: all .2s;
}
.mic-btn.rec { background: linear-gradient(135deg, #ef4444, #f97316); color: #fff; border-color: transparent; animation: micPulse 1.4s infinite; }
.mic-btn.live { background: linear-gradient(135deg, var(--acc), var(--acc2)); color: #fff; border-color: transparent; animation: micPulse 2s infinite; }
@keyframes micPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.45); } 50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); } }

#text-input {
  flex: 1; height: 44px; border-radius: 22px; padding: 0 16px;
  background: var(--card2); border: 1px solid var(--line); color: var(--txt);
  font-size: 14.5px; outline: none; min-width: 0;
}
#text-input:focus { border-color: var(--acc); }

.send-btn {
  height: 44px; padding: 0 18px; border-radius: 22px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--acc), #7c5cff); color: #fff; font-size: 14px; font-weight: 600;
}
.send-btn:active { transform: scale(.96); }

.usage { text-align: center; font-size: 10.5px; color: var(--dim); margin-top: 5px; min-height: 14px; }

/* ========== 设置页 ========== */
.settings-wrap { height: 100%; overflow-y: auto; padding: 0 16px 130px; max-width: 720px; margin: 0 auto; }
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; position: sticky; top: 0; background: var(--bg); z-index: 5;
  border-bottom: 1px solid var(--line); margin-bottom: 18px;
}
.settings-header h1 { font-size: 17px; font-weight: 600; }

.set-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.set-card h2 { font-size: 15.5px; margin-bottom: 4px; }
.set-desc { font-size: 12.5px; color: var(--sub); margin-bottom: 14px; }

.provider-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.provider-opt {
  text-align: left; padding: 13px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg2); transition: all .15s;
}
.provider-opt .po-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.provider-opt .po-desc { font-size: 11.5px; color: var(--sub); margin-top: 4px; line-height: 1.5; }
.provider-opt .po-price { font-size: 11px; color: var(--gold); margin-top: 6px; }
.provider-opt.on { border-color: var(--acc); background: rgba(79,124,255,.1); }
.provider-opt.on .po-name { color: var(--acc2); }
@media (max-width: 560px) { .provider-grid { grid-template-columns: 1fr; } }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; color: var(--sub); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--txt);
  font-size: 14px; outline: none; resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--acc); }

/* 记忆优先路由开关行 */
.router-row { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; color: var(--txt); cursor: pointer; user-select: none; }
.switch input {
  appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--line); position: relative; cursor: pointer; transition: border-color .2s, background .2s; flex: none;
}
.switch input::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--sub); transition: transform .2s, background .2s;
}
.switch input:checked { background: rgba(79,124,255,.18); border-color: var(--acc); }
.switch input:checked::after { transform: translateX(18px); background: var(--acc); }
.field-inline { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 0; }
.field-inline span { margin-bottom: 0; white-space: nowrap; }
.field-inline input { width: 76px; padding: 7px 10px; }

.mem-status { font-size: 12px; color: var(--green); background: rgba(52,211,153,.07); border: 1px solid rgba(52,211,153,.25); border-radius: 10px; padding: 9px 12px; margin-bottom: 12px; }
.mem-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.btn-small {
  padding: 8px 14px; border-radius: 9px; font-size: 12.5px;
  background: var(--card2); border: 1px solid var(--line); color: var(--acc2);
}
.btn-small:active { border-color: var(--acc); }

.mem-search { display: flex; gap: 8px; margin-bottom: 10px; }
.mem-search input { flex: 1; padding: 9px 12px; border-radius: 9px; background: var(--bg2); border: 1px solid var(--line); color: var(--txt); font-size: 13px; outline: none; }
.mem-results { display: flex; flex-direction: column; gap: 8px; }
.mem-result { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }
.mem-result .mr-src { color: var(--acc2); font-size: 11px; margin-bottom: 4px; }
.mem-result .mr-text { color: #a9b6d6; }

.settings-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-width: 720px; margin: 0 auto;
  background: rgba(10,14,26,.94); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.save-tip { text-align: center; font-size: 12px; color: var(--green); margin-top: 8px; min-height: 16px; }

/* ========== Toast ========== */
#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(20,27,49,.95); border: 1px solid var(--line); color: var(--txt);
  padding: 10px 18px; border-radius: 12px; font-size: 13px; z-index: 99;
  opacity: 0; pointer-events: none; transition: all .25s; max-width: 86%; text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: rgba(248,113,113,.5); color: #fca5a5; }

/* ========== 访问暗号弹窗 ========== */
.auth-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(6,9,18,.88); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-mask[hidden] { display: none; }
.auth-box {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--card, #121a30); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 26px 26px;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.auth-logo { font-size: 40px; margin-bottom: 10px; }
.auth-box h2 { font-size: 18px; margin-bottom: 8px; }
.auth-box p { font-size: 12.5px; color: var(--dim); line-height: 1.7; margin-bottom: 18px; }
.auth-box input {
  width: 100%; box-sizing: border-box; margin-bottom: 12px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; color: var(--txt); font-size: 14px;
  outline: none; text-align: center; letter-spacing: 2px;
}
.auth-box input:focus { border-color: var(--acc, #4f7cff); }
.auth-box .btn-primary { width: 100%; }
.auth-err { min-height: 18px; margin-top: 10px; font-size: 12px; color: #fca5a5; }

/* 设置页：暗号字段行 */
.field-row { display: flex; gap: 8px; align-items: center; }
.field-row .field { flex: 1; }
.field-row .btn-small { white-space: nowrap; }

@media (min-width: 760px) {
  .chat-body { padding: 20px 8%; }
  .home-hero { transform: scale(1.06); }
}
