  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1e222b;
    --line: #272c37;
    --text: #e7e9ef;
    --muted: #8c94a7;
    --accent: #5b8cff;
    --danger: #ff6b6b;
    --radius: 14px;
    --glow: #1a1f2b;              /* 顶部径向渐变的亮部 */
    --bubble-font: 15px;          /* F3：消息气泡字号 */
    --ui-font: 15px;              /* F3：输入框与常用界面字号 */
  }
  /* F2 浅色主题：只覆盖颜色变量，布局一律不动 */
  html[data-theme="light"] {
    --bg: #f5f6f9;
    --panel: #ffffff;
    --panel-2: #eef0f5;
    --line: #dde1ea;
    --text: #1c2029;
    --muted: #6b7386;
    --accent: #3b6fe0;
    --danger: #d64545;
    --glow: #e6ebf7;
  }
  /* F3 四档字号 */
  html[data-font="s"] { --bubble-font: 13px; --ui-font: 14px; }
  html[data-font="m"] { --bubble-font: 15px; --ui-font: 15px; }
  html[data-font="l"] { --bubble-font: 17px; --ui-font: 16px; }
  html[data-font="xl"] { --bubble-font: 19px; --ui-font: 18px; }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { height: 100%; overflow: hidden; }
  body {
    margin: 0;
    background: radial-gradient(1200px 600px at 50% -10%, var(--glow) 0%, var(--bg) 60%);
    color: var(--text);
    font: var(--ui-font)/1.65 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
  }
  .hidden { display: none !important; }

  /* ---------- 登录 / 注册 ---------- */
  #auth {
    height: var(--app-h, 100dvh);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  }
  .card {
    width: 100%;
    max-width: 340px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 28px 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  }
  .card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: .5px; }
  .card .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
  .tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    padding: 4px;
    background: var(--panel-2);
    border-radius: 10px;
  }
  .tabs .tab {
    flex: 1;
    min-height: 36px;
    margin: 0;
    padding: 6px;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .tabs .tab.active { background: var(--panel); color: var(--text); }
  input[type=password], input[type=tel] {
    width: 100%;
    margin-top: 10px;
    padding: 13px 14px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font-size: 16px; /* 16px 起：避免 iOS 聚焦自动放大 */
    outline: none;
  }
  input[type=password]:focus, input[type=tel]:focus { border-color: var(--accent); }
  .card button[type=submit] {
    width: 100%;
    min-height: 46px;
    margin-top: 14px;
    padding: 12px;
    background: var(--accent);
    border: 0;
    border-radius: 10px;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
  }
  .card button[type=submit]:disabled { opacity: .55; cursor: default; }
  .err { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 13px; }
  .hint { margin: 14px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

  /* ---------- 聊天页 ---------- */
  #chat {
    position: relative;
    height: var(--app-h, 100dvh);
    display: flex;
    flex-direction: column;
    max-width: 820px;
    margin: 0 auto;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: max(12px, env(safe-area-inset-top)) 4px 12px;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    letter-spacing: .4px;
  }
  header .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 10px #4ade80;
  }
  #open-drawer, #open-search {
    width: 34px;
    height: 34px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
  }
  #open-search { flex: 0 0 auto; font-size: 14px; }
  #role-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #search-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  #search-bar input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font: inherit;
    font-size: 15px;
    outline: none;
  }
  #search-bar input:focus { border-color: var(--accent); }
  #search-count { flex: 0 0 auto; color: var(--muted); font-size: 12px; }
  #search-bar button {
    flex: 0 0 auto;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
  }
  .bubble.search-hide { display: none; }

  /* 对话列表：一个角色下可以有多条对话 */
  #thread-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 12px;
  }
  #thread-panel {
    flex: 0 0 auto;
    max-height: 46vh;
    overflow-y: auto;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
  }
  #thread-panel.hidden { display: none; }
  .thread-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--panel);
    z-index: 1;
  }
  .thread-head strong { flex: 1 1 auto; font-size: 14px; }
  .thread-head button {
    padding: 5px 10px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
  }
  .thread-head button.link { border-color: transparent; color: var(--muted); }
  .thread-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 12px;
    border-bottom: 1px solid var(--line);
  }
  .thread-row.active { background: rgba(255, 255, 255, .04); }
  .thread-name {
    flex: 1 1 auto;
    min-width: 0;
    padding: 11px 0;
    background: transparent;
    border: 0;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
  }
  .thread-row.active .thread-name { color: var(--accent); }
  .thread-act {
    flex: 0 0 auto;
    padding: 4px 7px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
  }
  .thread-act.danger { color: #e06c6c; }
  main {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 18px 2px 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
  }
  .bubble {
    max-width: min(86%, 620px);
    padding: 11px 14px;
    border-radius: var(--radius);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: var(--bubble-font);
    line-height: 1.7;
  }
  .bubble.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
  }
  .bubble.assistant {
    align-self: flex-start;
    background: var(--panel);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
  }
  .bubble .imgs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
  }
  .bubble .imgs:last-child { margin-bottom: 0; }
  .bubble .imgs img {
    display: block;
    max-width: 220px;
    max-height: 220px;
    border-radius: 10px;
    object-fit: cover;
  }
  .bubble.user .imgs img { background: rgba(255, 255, 255, .12); }
  .bubble .quote {
    margin-bottom: 8px;
    padding: 6px 10px;
    border-left: 3px solid currentColor;
    border-radius: 6px;
    background: rgba(127, 127, 127, .16);
    font-size: 12px;
    line-height: 1.5;
    opacity: .8;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }
  .bubble.streaming::after {
    content: "▍";
    color: var(--muted);
    animation: blink 1s steps(2, start) infinite;
  }
  @keyframes blink { to { visibility: hidden; } }

  /* 等待首个字：上游首字约 1.8s 且不可压缩，用三点跳动把这段空白显性化 */
  .bubble.waiting .dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    height: 1.2em;
    padding: 2px 0;
  }
  .bubble.waiting .dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: dotbounce 1.05s ease-in-out infinite;
  }
  .bubble.waiting .dots i:nth-child(2) { animation-delay: .15s; }
  .bubble.waiting .dots i:nth-child(3) { animation-delay: .3s; }
  @keyframes dotbounce {
    0%, 60%, 100% { opacity: .32; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
  }
  /* 首字之后停掉动效与闪烁光标：这两者叠加会显得比实际更慢 */
  .bubble.streaming.got-text::after { content: ""; animation: none; }

  /* ---------- F4 时间分组 ---------- */
  .day-sep {
    align-self: center;
    margin: 2px 0;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
  }

  /* ---------- F6 收藏标记 ---------- */
  .bubble.starred::before {
    content: "★";
    float: right;
    margin-left: 8px;
    color: #f2c94c;
    font-size: 12px;
    line-height: 1.4;
  }
  /* 从收藏列表定位过来时闪一下 */
  .bubble.flash {
    animation: flash 0.9s ease-out;
  }
  @keyframes flash {
    0% { box-shadow: 0 0 0 2px var(--accent); }
    100% { box-shadow: 0 0 0 2px transparent; }
  }

  /* ---------- F7 回到底部 ---------- */
  #to-bottom {
    position: absolute;
    right: 14px;
    bottom: 84px;
    z-index: 6;
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 17px;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
    cursor: pointer;
  }
  #to-bottom:active { color: var(--text); }

  /* ---------- F5 长按菜单 ---------- */
  #msg-menu {
    position: fixed;
    z-index: 40;
    min-width: 132px;
    padding: 6px;
    border-radius: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .38);
  }
  #msg-menu button {
    display: block;
    width: 100%;
    margin: 0;
    padding: 9px 12px;
    background: none;
    border: 0;
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
  }
  #msg-menu button:active { background: var(--panel-2); }

  /* ---------- F2/F3 外观：分段选择器 ---------- */
  .seg {
    display: flex;
    gap: 6px;
    margin: 8px 0 0;
  }
  .seg button {
    flex: 1 1 0;
    margin: 0;
    padding: 9px 4px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
  }
  .seg button.on {
    border-color: rgba(91, 140, 255, .65);
    background: rgba(91, 140, 255, .14);
    color: var(--text);
  }

  /* ---------- F6 收藏列表 ---------- */
  .fav-item {
    margin: 0 0 8px;
    padding: 9px 11px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.6;
  }
  .fav-item .fav-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 11px;
  }
  .fav-item .fav-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
  }
  .fav-item .fav-jump {
    margin-left: auto;
    padding: 0;
    background: none;
    border: 0;
    color: var(--accent);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
  }
  .fav-item .fav-del {
    padding: 0 2px;
    background: none;
    border: 0;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
  }

  #composer {
    flex: 0 0 auto;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding: 10px 0 max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
  }
  #input {
    flex: 1;
    min-height: 46px;
    max-height: 140px;
    padding: 12px 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--text);
    font: inherit;
    font-size: 16px; /* 同上：防 iOS 自动放大 */
    line-height: 1.5;
    resize: none;
    outline: none;
  }
  #input:focus { border-color: var(--accent); }
  #send {
    flex: 0 0 auto;
    min-width: 76px;
    height: 46px;
    padding: 0 18px;
    background: var(--accent);
    border: 0;
    border-radius: 12px;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
  }
  #send:disabled { opacity: .55; cursor: default; }
  #stop {
    flex: 0 0 auto;
    min-width: 76px;
    height: 46px;
    padding: 0 18px;
    background: transparent;
    border: 1px solid var(--danger);
    border-radius: 12px;
    color: var(--danger);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
  }
  #quote-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 7px 10px;
    background: var(--panel-2);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    font-size: 12px;
    color: var(--muted);
  }
  #quote-bar span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #quote-bar button {
    flex: 0 0 auto;
    padding: 0 4px;
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
  }
  #cmd-hint { padding: 6px 2px 8px; color: var(--muted); font-size: 12px; }

  /* ---------- 左侧抽屉 ---------- */
  #drawer { position: fixed; inset: 0; z-index: 20; }
  #drawer .drawer-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
  #drawer .drawer-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(92%, 720px);
    overflow-y: auto;
    padding: max(18px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
    background: var(--panel);
    border-right: 1px solid var(--line);
    box-shadow: 20px 0 50px rgba(0, 0, 0, .5);
    animation: slide-in .18s ease-out;
  }
  @keyframes slide-in { from { transform: translateX(-100%); } to { transform: none; } }
  .drawer-head { display: flex; align-items: center; margin-bottom: 18px; }
  .drawer-head strong { font-size: 19px; letter-spacing: .5px; }
  .drawer-head .back {
    width: 30px;
    height: 30px;
    margin-right: 10px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
  }
  .menu { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
  .menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 13px 14px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    text-align: left;
    cursor: pointer;
  }
  .menu button em {
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
  }
  .drawer-head .link {
    margin-left: auto;
    padding: 4px;
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
  }
  .drawer-account {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
  }
  .drawer-account .muted { color: var(--muted); }
  .drawer-account span:last-child { margin-left: auto; }
  .drawer-block { margin-top: 20px; }
  /* 抽屉加宽后：宽屏下内容多的页面分两列，窄屏仍是单列纵向滚动 */
  @media (min-width: 640px) {
    #view-role .drawer-cols { display: grid; grid-template-columns: 1fr 1fr;
      gap: 0 24px; align-items: start; }
    #view-role .drawer-cols > .drawer-block { margin-top: 0; }
    #view-role .drawer-cols { margin-top: 20px; }
  }
  /* 用量条：已用 / 额度，超额变红 */
  .quota-bar { height: 6px; margin-top: 8px; border-radius: 999px; background: var(--panel-2);
    border: 1px solid var(--line); overflow: hidden; }
  .quota-bar span { display: block; height: 100%; width: 0; background: var(--accent);
    transition: width .25s ease-out; }
  .quota-bar.full span { background: var(--danger); }
  .block-title { margin: 0 0 4px; color: var(--muted); font-size: 13px; letter-spacing: .3px; }
  .drawer-block input[type=password] { margin-top: 10px; }
  .drawer-block .primary, .drawer-block .ghost, #logout {
    width: 100%;
    min-height: 44px;
    margin-top: 12px;
    padding: 11px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
  }
  .drawer-block .primary { background: var(--accent); border: 0; color: #fff; }
  .drawer-block .primary:disabled { opacity: .55; cursor: default; }
  .drawer-block .ghost, #logout { background: transparent; border: 1px solid var(--line); color: var(--text); }
  #logout { margin-top: 24px; color: var(--danger); border-color: rgba(255, 107, 107, .35); }
  .switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    font-size: 14px;
  }
  .switch-row .badge {
    margin-left: auto;
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 11px;
  }
  .small { font-size: 12px; }
  .muted { color: var(--muted); }

  /* ---------- 角色 ---------- */
  .role-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
  .role-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 14px;
  }
  .role-item.active { border-color: var(--accent); background: rgba(91, 140, 255, .1); }
  /* 已选中但还没保存：虚线框，和「使用中」明确区分开 */
  .role-item.picked { border-style: dashed; border-color: var(--accent); }
  .role-item .rname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .role-item .rtag { color: var(--muted); font-size: 11px; }
  .role-item .rtag.picked { color: var(--accent); }
  .role-item button {
    padding: 3px 8px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
  }
  .drawer-block textarea, #role-input-name {
    width: 100%;
    margin-top: 10px;
    padding: 11px 12px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font: inherit;
    font-size: 15px;
    line-height: 1.5;
    outline: none;
    resize: vertical;
  }
  .drawer-block textarea:focus, #role-input-name:focus { border-color: var(--accent); }
  .role-import {
    display: block;
    margin-top: 8px;
    padding: 10px;
    text-align: center;
    border: 1px dashed var(--line);
    border-radius: 10px;
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
  }
  #role-card-file { display: none; }
  .role-templates { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
  .role-templates button {
    padding: 6px 11px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 20px;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
  }
  .role-templates button:hover { border-color: var(--accent); color: var(--accent); }
  .field-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    font-size: 13px;
  }
  .field-row select {
    flex: 1;
    padding: 8px 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    outline: none;
  }
  .field-row select:focus { border-color: var(--accent); }
  .mem-item .left { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
  .mem-group { margin: 12px 0 2px; color: var(--muted); font-size: 12px; letter-spacing: .3px; }

  /* ---------- 记忆 ---------- */
  label.switch-row { cursor: pointer; }
  label.switch-row > span:first-child { flex: 1; }
  .toggle { position: relative; flex: 0 0 auto; width: 46px; height: 26px; margin-left: auto; }
  .toggle input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
  }
  .toggle span {
    position: absolute;
    inset: 0;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    transition: background .15s, border-color .15s;
    pointer-events: none;
  }
  .toggle span::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform .15s, background .15s;
  }
  .toggle input:checked + span { background: rgba(91, 140, 255, .22); border-color: var(--accent); }
  .toggle input:checked + span::after { transform: translateX(20px); background: var(--accent); }
  .mem-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
  .mem-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 9px 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
  }
  .mem-item .layer {
    flex: 0 0 auto;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    font-size: 11px;
    line-height: 18px;
  }
  .mem-item .layer.fact { color: #7dd3fc; border-color: rgba(125, 211, 252, .35); }
  .mem-item .layer.rule { color: #fcd34d; border-color: rgba(252, 211, 77, .35); }
  .mem-item .layer.episode { color: #c4b5fd; border-color: rgba(196, 181, 253, .35); }
  .mem-item .txt { flex: 1; word-break: break-word; overflow-wrap: anywhere; }
  .mem-item .del {
    flex: 0 0 auto;
    padding: 0 2px;
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.2;
    cursor: pointer;
  }
  .mem-empty { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
  .mem-item .tools { flex: 0 0 auto; display: flex; gap: 2px; }
  .mem-item .tools button {
    padding: 0 2px;
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
    cursor: pointer;
  }
  .mem-item .tools .del { font-size: 16px; }
  .mem-item .txt[contenteditable="true"] {
    outline: 1px solid var(--accent);
    border-radius: 6px;
    padding: 2px 4px;
    background: rgba(91, 140, 255, .08);
  }
  .mem-item .left { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
  .mem-edit { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; width: 100%; }
  .mem-edit select, .mem-edit input[type="number"] {
    padding: 3px 6px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    font-size: 12px;
  }
  .mem-edit input[type="number"] { width: 56px; }
  .mem-edit button { padding: 3px 10px; font-size: 12px; border-radius: 7px; }
  .mem-add { display: flex; gap: 8px; margin-top: 10px; }
  .mem-add input {
    flex: 1;
    min-height: 36px;
    padding: 6px 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-size: 13px;
  }
  .mem-add button {
    flex: 0 0 auto;
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
  }
  .mem-conflicts, .mem-review { display: flex; flex-direction: column; gap: 8px; }
  .comp-add { display: flex; gap: 8px; margin-top: 10px; }
  .comp-add input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-size: 13px;
  }
  .comp-add button {
    flex: 0 0 auto;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
  }
  .mem-item.done .txt { color: var(--muted); text-decoration: line-through; }
  .mem-item.today .txt { color: #fcd34d; }
  .conflict {
    padding: 9px 10px;
    background: rgba(252, 211, 77, .08);
    border: 1px solid rgba(252, 211, 77, .35);
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
  }
  .conflict p { margin: 0 0 4px; }
  .conflict .new { color: #fcd34d; }
  .conflict .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
  .conflict .acts button, .review-group button {
    padding: 3px 10px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
  }
  .review-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
  .review-group .mem-item .tools button { font-size: 11px; padding: 0 6px; }
  .mem-actions { display: flex; gap: 8px; margin-top: 10px; }
  .mem-actions button, .mem-actions label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-size: 13px;
    text-align: center;
    cursor: pointer;
  }
  .mem-actions button:disabled { opacity: .55; cursor: default; }
  /* 导入用的文件框同样只做视觉隐藏，否则部分 WebView 点不动 */
  #mem-file, #doc-file {
    position: absolute;
    left: -9999px;
    top: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    overflow: hidden;
  }

  /* ---------- 网络状态 / iOS 引导 ---------- */
  #net-bar {
    flex: 0 0 auto;
    margin: 0 -2px;
    padding: 7px 12px;
    background: rgba(255, 107, 107, .14);
    border: 1px solid rgba(255, 107, 107, .35);
    border-radius: 9px;
    color: #ffb3b3;
    font-size: 12.5px;
    line-height: 1.4;
    text-align: center;
  }
  #ios-tip {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    z-index: 30;
    max-width: 520px;
    margin: 0 auto;
    padding: 13px 14px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
    font-size: 13px;
    line-height: 1.55;
  }
  #ios-tip strong { color: var(--accent); }
  #ios-tip button {
    margin-top: 9px;
    width: 100%;
    min-height: 38px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
  }
  .apk-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin-top: 12px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
  }
  .apk-link.wait { border-color: rgba(91, 140, 255, .45); color: var(--accent); }

  /* ---------- 图片输入 ---------- */
  #attach {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    padding: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
  }
  #attach:active { color: var(--text); }
  /* E4 文件、E1 语音、E5 联网：与「＋」同尺寸的圆形小按钮 */
  #attach-doc, #mic, #web-search {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    padding: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
  }
  #attach-doc:active, #mic:active, #web-search:active { color: var(--text); }
  #mic.on { border-color: rgba(91, 140, 255, .6); color: var(--accent); }
  #web-search.on { border-color: rgba(91, 140, 255, .6); color: var(--accent); }
  #doc-tip {
    margin: 6px 2px 0;
    font-size: 12px;
    color: var(--muted);
  }
  #doc-tip.err { color: #ff6b6b; }
  /* 文件选择框只做“视觉隐藏”：display:none 的 input 在部分 WebView 里点不动 */
  #file, #file-doc {
    position: absolute;
    left: -9999px;
    top: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    overflow: hidden;
  }
  #previews {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 8px 0 0;
    overflow-x: auto;
  }
  #previews .thumb { position: relative; flex: 0 0 auto; }
  #previews .thumb img {
    display: block;
    width: 62px;
    height: 62px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--line);
  }
  #previews .thumb button {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    padding: 0;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--text);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
  }

  /* ---------- 手机 ---------- */
  @media (max-width: 480px) {
    .bubble { max-width: 92%; padding: 10px 13px; }
    .card { padding: 24px 18px; border-radius: 16px; }
    #composer { gap: 8px; }
    #send { min-width: 68px; padding: 0 14px; }
    main { padding-top: 14px; gap: 12px; }
  }
  @media (max-width: 360px) {
    .bubble { max-width: 94%; }
    #send { min-width: 62px; padding: 0 12px; }
  }
  /* 横屏 / 软键盘弹起后高度很小时，压缩头部 */
  @media (max-height: 460px) {
    header { padding-top: 8px; padding-bottom: 6px; }
    main { padding-top: 10px; }
  }
