:root {
    --bg: #f5f6fa;
    --panel: #ffffff;
    --line: #e6e8f0;
    --text: #1f2430;
    --dim: #7a8095;
    --accent: #4f6bed;
    --accent2: #9b5cf6;
    --accent-weak: #eef1fe;
    --danger: #d64545;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(31,36,48,.06);
    --topH: 58px;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { height: 100%; }
  body {
    font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ================= 顶部通栏 ================= */
  .topbar {
    height: var(--topH);
    display: flex; align-items: center; gap: 18px;
    padding: 0 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    position: relative;
    z-index: 30;
  }
  .logo {
    display: flex; align-items: center; gap: 9px;
    font-weight: 800; font-size: 17px; letter-spacing: .5px;
    cursor: pointer; flex-shrink: 0;
  }
  .logo .dot {
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 14px; font-weight: 800;
  }
  .search {
    position: absolute; left: 50%; transform: translateX(-50%);
    width: min(520px, 46vw);
    display: flex; align-items: center; gap: 8px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 18px;
  }
  .search:focus-within { border-color: var(--accent); background: #fff; }
  .search input {
    border: none; outline: none; background: none;
    font-size: 13px; flex: 1; color: var(--text); font-family: inherit;
  }
  .search .ico { color: var(--dim); font-size: 14px; }
  .top-status {
    margin-left: auto; flex-shrink: 0;
    font-size: 12px; color: var(--dim);
    display: flex; align-items: center; gap: 8px;
  }
  .top-status .pill {
    padding: 4px 12px; border-radius: 999px;
    background: var(--accent-weak); color: var(--accent); font-weight: 600;
    cursor: pointer;
  }

  .body-row { flex: 1; min-height: 0; display: flex; }

  /* ================= 左侧窄导航 ================= */
  .rail {
    width: 172px;
    flex-shrink: 0;
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
  }
  .nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13.5px;
    color: var(--dim);
    cursor: pointer;
    border: none; background: none; width: 100%;
    text-align: left;
    font-family: inherit;
    flex-shrink: 0;
  }
  .nav-item:hover { background: var(--bg); color: var(--text); }
  .nav-item.on { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
  .nav-item .ico { font-size: 16px; width: 20px; text-align: center; }
  .nav-item .tag {
    margin-left: auto; font-size: 9.5px; padding: 2px 6px;
    border-radius: 99px; background: #f1f2f7; color: var(--dim);
  }
  .nav-group {
    font-size: 11px; color: #b3b8c6;
    padding: 14px 12px 4px;
    flex-shrink: 0;
  }
  .nav-sub { padding-left: 14px; }
  /* 创作下拉组 */
  .chev {
    margin-left: auto;
    font-size: 12px; color: var(--dim);
    transition: transform .2s;
    display: inline-block;
  }
  #create-toggle.folded .chev { transform: rotate(180deg); }
  #create-group.folded { display: none; }
  #create-toggle.on { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

  main { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; position: relative; }
  .page { display: none; min-height: 100%; }
  .page.on { display: block; }
  #page-chat.on, #page-image.on { display: flex; }

  .banner {
    margin: 12px 22px 0;
    padding: 10px 16px;
    border: 1px solid #f2d17c;
    background: #fdf6e3;
    color: #8a6d1a;
    border-radius: var(--radius);
    font-size: 13px; line-height: 1.6;
  }
  .banner.err { border-color: #efb9b9; background: #fdf0f0; color: var(--danger); }

  /* ================= 首页：瀑布流 ================= */
  .chip-row {
    display: flex; gap: 8px; flex-wrap: wrap;
    padding: 16px 22px 4px;
  }
  .chip {
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 12.5px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--dim);
    cursor: pointer;
    font-family: inherit;
  }
  .chip:hover { border-color: var(--accent); color: var(--accent); }
  .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

  .falls {
    column-count: 5;
    column-gap: 14px;
    padding: 14px 22px 110px;
  }
  @media (max-width: 1500px) { .falls { column-count: 4; } }
  @media (max-width: 1200px) { .falls { column-count: 3; } }
  @media (max-width: 900px)  { .falls { column-count: 2; } }
  .fall-item {
    break-inside: avoid;
    margin-bottom: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
    box-shadow: var(--shadow);
    position: relative;
  }
  .fall-item:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(31,36,48,.12); }
  .fall-item .thumb {
    width: 100%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 42px;
    position: relative;
  }
  .fall-item .thumb img {
    width: 100%; display: block;
  }
  .fall-item .kind-tag {
    position: absolute; top: 8px; left: 8px;
    font-size: 10px; padding: 2px 9px; border-radius: 99px;
    background: rgba(0,0,0,.35); color: #fff;
    backdrop-filter: blur(4px);
  }
  .fall-item .body { padding: 9px 12px 11px; }
  .fall-item .body b { font-size: 13px; display: block; margin-bottom: 3px; }
  .fall-item .body p {
    font-size: 11px; color: var(--dim); line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .fall-item .use {
    margin-top: 7px; font-size: 11px; color: var(--accent); font-weight: 600;
  }
  .falls .noresult {
    column-span: all;
    text-align: center; color: var(--dim); font-size: 13px; padding: 60px 0;
  }

  /* 底部悬浮输入条（仅首页） */
  .float-bar {
    position: fixed;
    left: 50%; bottom: 26px;
    transform: translateX(-50%);
    width: min(600px, 72vw);
    display: flex; align-items: center; gap: 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 8px 8px 20px;
    box-shadow: 0 10px 34px rgba(31,36,48,.16);
    z-index: 20;
  }
  .float-bar input {
    flex: 1; border: none; outline: none;
    font-size: 13.5px; background: none; color: var(--text); font-family: inherit;
  }
  .float-bar .go {
    width: 38px; height: 38px; border-radius: 50%;
    border: none; cursor: pointer; flex-shrink: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff; font-size: 16px;
  }
  .float-bar .go:hover { filter: brightness(1.1); }

  /* ================= 对话页 ================= */
  #page-chat { padding: 14px 22px 16px; gap: 14px; height: calc(100vh - var(--topH)); }
  .side2 {
    width: 200px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: flex; flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: var(--shadow);
  }
  .side2-head { padding: 10px; border-bottom: 1px solid var(--line); }
  .side2-head button {
    width: 100%; padding: 8px 0;
    border: 1px dashed var(--accent);
    color: var(--accent);
    background: var(--accent-weak);
    border-radius: 8px; cursor: pointer; font-size: 13px; font-family: inherit;
  }
  #conv-list { flex: 1; overflow-y: auto; padding: 6px; }
  .conv {
    padding: 8px 10px; border-radius: 8px; font-size: 13px;
    cursor: pointer; color: var(--dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; justify-content: space-between; align-items: center; gap: 6px;
  }
  .conv:hover { background: var(--bg); }
  .conv.on { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
  .conv .del {
    visibility: hidden; border: none; background: none; color: var(--dim);
    cursor: pointer; font-size: 14px; padding: 0 2px; flex-shrink: 0;
  }
  .conv:hover .del { visibility: visible; }
  .conv .del:hover { color: var(--danger); }

  .chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
  .chat-bar {
    display: flex; gap: 8px; align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 10px;
    box-shadow: var(--shadow);
  }
  .chat-bar select {
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    background: var(--panel);
    color: var(--text);
    max-width: 180px;
    font-family: inherit;
  }
  .chat-bar .spacer { flex: 1; }
  .chat-bar .hint { font-size: 12px; color: var(--dim); }

  #msgs {
    flex: 1; min-height: 0; overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 22px;
    box-shadow: var(--shadow);
  }
  .msg { margin-bottom: 16px; display: flex; }
  .msg.user { justify-content: flex-end; }
  .bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px; line-height: 1.7;
    word-break: break-word;
  }
  .msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
  .msg.ai .bubble { background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
  .msg.err .bubble { background: #fdf0f0; border-color: #efb9b9; color: var(--danger); }
  .bubble p { margin: 0 0 8px; }
  .bubble p:last-child { margin-bottom: 0; }
  .bubble pre {
    background: #1f2430; color: #e8eaf0;
    padding: 10px 12px; border-radius: 8px;
    overflow-x: auto; margin: 8px 0;
    font-size: 13px; line-height: 1.5;
  }
  .bubble code.inline {
    background: rgba(79,107,237,.1);
    color: var(--accent);
    padding: 1px 5px; border-radius: 4px; font-size: 13px;
  }
  .bubble pre code { background: none; color: inherit; padding: 0; }
  .bubble ul, .bubble ol { padding-left: 20px; margin: 6px 0; }
  .bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; font-size: 15px; }
  .bubble details {
    margin-bottom: 8px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--dim);
  }
  .bubble summary { cursor: pointer; user-select: none; }
  .bubble .cursor { display: inline-block; width: 8px; height: 15px; background: var(--accent); vertical-align: -2px; animation: blink .8s infinite; }
  @keyframes blink { 50% { opacity: 0; } }

  .input-bar {
    display: flex; gap: 10px; align-items: flex-end;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    box-shadow: var(--shadow);
  }
  #chat-input {
    flex: 1; border: none; outline: none; resize: none;
    font-size: 14px; line-height: 1.6;
    font-family: inherit;
    max-height: 160px;
    background: transparent;
    color: var(--text);
  }
  .btn {
    border: none;
    background: var(--accent);
    color: #fff;
    padding: 8px 22px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    font-family: inherit;
  }
  .btn:hover { filter: brightness(1.08); }
  .btn:disabled { opacity: .5; cursor: not-allowed; }

  /* ================= 生图页 ================= */
  #page-image { padding: 14px 22px 16px; gap: 14px; height: calc(100vh - var(--topH)); }
  .img-form {
    width: 280px; flex-shrink: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    overflow-y: auto;
    box-shadow: var(--shadow);
  }
  .img-form label { font-size: 12px; color: var(--dim); display: block; margin-bottom: 4px; }
  .img-form select, .img-form input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    background: var(--panel);
    color: var(--text);
    font-family: inherit;
  }
  #img-prompt {
    width: 100%;
    min-height: 110px;
    resize: vertical;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px; line-height: 1.6;
    font-family: inherit;
    color: var(--text);
  }
  .row2 { display: flex; gap: 8px; }
  .row2 > div { flex: 1; }
  #img-btn { width: 100%; padding: 10px 0; }

  .gallery {
    flex: 1; min-width: 0; overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
  }
  .gallery h3 { font-size: 13px; color: var(--dim); font-weight: 500; margin-bottom: 12px; }
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
  }
  .card img {
    width: 100%; display: block;
    border-radius: 10px;
    border: 1px solid var(--line);
    cursor: zoom-in;
    background: var(--bg);
  }
  .card .cap {
    font-size: 12px; color: var(--dim); margin-top: 5px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .empty { color: var(--dim); font-size: 13px; text-align: center; padding: 60px 0; }

  /* ================= 资产页 ================= */
  .assets { padding: 20px 22px 40px; }
  .asset-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
  .conv-asset {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    cursor: pointer;
    display: flex; align-items: center; gap: 14px;
    max-width: 860px;
  }
  .conv-asset:hover { border-color: var(--accent); }
  .conv-asset .emoji { font-size: 22px; }
  .conv-asset .t { font-size: 14px; font-weight: 600; }
  .conv-asset .s { font-size: 12px; color: var(--dim); margin-top: 2px; }
  .conv-asset .go { margin-left: auto; color: var(--accent); font-size: 12px; }

  /* ================= 视频页（占位） ================= */
  .video-soon {
    margin: 40px auto;
    max-width: 640px;
    text-align: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 60px 40px;
  }
  .video-soon .big { font-size: 52px; margin-bottom: 16px; }
  .video-soon h3 { font-size: 18px; margin-bottom: 10px; }
  .video-soon p { font-size: 13px; color: var(--dim); line-height: 1.8; }

  /* ================= 接入设置页 ================= */
  .setup { padding: 24px 22px 40px; max-width: 820px; }
  .setup h3 { font-size: 16px; margin: 20px 0 10px; }
  .prov-row {
    display: flex; align-items: center; gap: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
  }
  .prov-row .st { width: 9px; height: 9px; border-radius: 50%; background: #d7dae2; flex-shrink: 0; }
  .prov-row.ok .st { background: #2fbf71; }
  .prov-row b { font-size: 14px; }
  .prov-row span { font-size: 12px; color: var(--dim); margin-left: auto; }
  .setup .how {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 20px;
    font-size: 13px; line-height: 2;
    color: var(--dim);
  }
  .setup .how code {
    background: var(--accent-weak); color: var(--accent);
    padding: 1px 7px; border-radius: 5px; font-size: 12.5px;
  }

  /* ================= 本地程序嵌入页（WebUI / ComfyUI） ================= */
  .ext-wrap { height: calc(100vh - var(--topH)); display: flex; flex-direction: column; }
  .ext-detect { margin: 60px auto; text-align: center; color: var(--dim); font-size: 14px; }
  .ext-frame { flex: 1; border: none; width: 100%; background: #fff; }
  .ext-guide {
    margin: 40px auto; max-width: 680px;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 18px; padding: 32px 36px;
  }
  .ext-guide h3 { font-size: 17px; margin-bottom: 12px; }
  .ext-guide p { font-size: 13px; color: var(--dim); line-height: 2.1; }
  .ext-guide code { background: var(--accent-weak); color: var(--accent); padding: 1px 7px; border-radius: 5px; font-size: 12.5px; }
  .ext-guide .btn2 {
    display: inline-block; margin-top: 16px;
    background: var(--accent); color: #fff; text-decoration: none;
    padding: 9px 22px; border-radius: 999px; font-size: 13px; font-weight: 600;
  }

  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-thumb { background: #d6dae2; border-radius: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
