:root, html[data-theme="cozy"] {
  --bg: #faf6ef;
  --panel: #ffffff;
  --panel-2: #f3ece1;
  --text: #3d3229;
  --muted: #9a8c7a;
  --accent: #e07a3f;
  --accent-2: #3f7ae0;
  --bubble-me: #e07a3f;
  --bubble-me-text: #fff8f2;
  --bubble-other: #f3ece1;
  --bubble-agent: #eaf1e6;
  --border: #e8dfd2;
  --shadow: 0 2px 10px rgba(80, 60, 30, .08);
  --radius: 14px;
  --font: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
html[data-theme="cyber"] {
  --bg: #0b0e17;
  --panel: #131828;
  --panel-2: #1b2238;
  --text: #d8e2ff;
  --muted: #6b7a9e;
  --accent: #00e5c7;
  --accent-2: #ff2d95;
  --bubble-me: #00e5c7;
  --bubble-me-text: #04110f;
  --bubble-other: #1b2238;
  --bubble-agent: #241b38;
  --border: #26304d;
  --shadow: 0 0 14px rgba(0, 229, 199, .12);
  --radius: 10px;
  --font: "Consolas", "Cascadia Code", "Microsoft YaHei", monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  height: 100dvh; display: flex; flex-direction: column;
}
a { color: var(--accent-2); }
button { font-family: inherit; }
.muted { color: var(--muted); }

/* gate */
.gate { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 10; padding: 20px; }
.gate-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 36px 32px; max-width: 380px; width: 100%; text-align: center; }
.gate-card h1 { margin: 0 0 6px; font-size: 28px; }
.gate-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.gate-card input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); color: var(--text); font-size: 15px; margin-bottom: 12px; }
.gate-note { margin-top: 18px; font-size: 12.5px; color: var(--muted); }
.gate-note a { color: var(--accent); }

/* topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 26px; color: var(--accent); }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge { font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 20px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost.small { font-size: 12px; padding: 4px 10px; }
.btn-primary { background: var(--accent); border: none; color: var(--bubble-me-text); padding: 11px 22px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; }
.btn-primary:disabled { opacity: .55; cursor: default; }

/* layout */
.app { display: flex; flex-direction: column; height: 100dvh; }
.layout { flex: 1; display: grid; grid-template-columns: 1fr 300px; gap: 0; min-height: 0; }
.chat-pane { display: flex; flex-direction: column; min-height: 0; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.empty-hint { margin: auto; text-align: center; color: var(--muted); }

.msg { max-width: 72%; align-self: flex-start; }
.msg.me { align-self: flex-end; }
.msg-head { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.msg.me .msg-head { justify-content: flex-end; }
.msg-sender { font-weight: 700; }
.bubble { padding: 9px 14px; border-radius: var(--radius); background: var(--bubble-other); border: 1px solid var(--border); line-height: 1.55; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-color: transparent; }
.msg.agent .bubble { background: var(--bubble-agent); }
.tag-agent { font-size: 10px; background: var(--accent-2); color: #fff; border-radius: 4px; padding: 1px 5px; }

/* composer */
.composer { display: flex; gap: 10px; padding: 12px 18px; background: var(--panel); border-top: 1px solid var(--border); }
.composer input { flex: 1; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); color: var(--text); font-size: 15px; }
.composer-error { margin: 0 18px 8px; color: var(--accent-2); font-size: 13px; background: var(--panel); }

/* side */
.side-pane { background: var(--panel); border-left: 1px solid var(--border); padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card-title { margin: 0 0 10px; font-size: 14px; }
.card-sub { font-size: 11px; color: var(--muted); font-weight: 400; }
.card-text { margin: 6px 0; font-size: 13px; line-height: 1.6; }
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.member-list li { display: flex; align-items: center; gap: 7px; }
.avatar-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.curl-box { background: #10141f; color: #7ee6b8; font-size: 11.5px; padding: 10px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: 8px 0; }
html[data-theme="cyber"] .curl-box { background: #05070d; box-shadow: 0 0 8px rgba(0,229,199,.2); }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .side-pane { display: none; }
  .msg { max-width: 88%; }
}

/* v1.2a: profile + mentions */
.gate-profile-row { display: flex; gap: 8px; margin: 8px 0; }
.gate-profile-row input { flex: 1; min-width: 0; }
.gate-profile-row #gate-avatar { max-width: 110px; text-align: center; }
.mention { color: var(--accent, #b4552d); background: rgba(180, 85, 45, .1); border-radius: 6px; padding: 0 3px; font-weight: 600; }
.mention.me { background: rgba(230, 57, 70, .16); outline: 1px solid rgba(230, 57, 70, .4); }
.msg.me .bubble .mention { color: #7a2e0d; background: rgba(255, 255, 255, .55); outline: 1px solid rgba(122, 46, 13, .35); }
.member-list li:hover { background: var(--panel-2); }

/* v1.3: toast / dialog / conflict / sound */
.toast { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--panel); color: var(--text); border: 1px solid var(--accent); box-shadow: 0 6px 24px rgba(0,0,0,.18); border-radius: 12px; padding: 10px 18px; font-size: 14px; max-width: 82vw; }
.dialog-mask { position: fixed; inset: 0; z-index: 50; background: rgba(10,10,16,.55); display: flex; align-items: center; justify-content: center; padding: 18px; }
.dialog-mask .gate-card { width: min(420px, 94vw); }
.gate-conflict { background: var(--panel-2); border: 1px dashed var(--accent); border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: 13.5px; }
.gate-conflict p { margin: 0 0 8px; }
.gate-conflict .gate-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.btn-primary.small { padding: 8px 14px; font-size: 13.5px; }
.topbar-right { flex-wrap: wrap; }
.topbar-right .btn-ghost { font-size: 12.5px; padding: 6px 10px; }

/* v1.4: links / code blocks / search / welcome */
.msg-link { color: var(--accent); text-decoration: underline; word-break: break-all; }
.msg-sender.sender-click { cursor: pointer; }
.msg-sender.sender-click:hover { color: var(--accent); text-decoration: underline; }
.code-block { margin: 6px 0; padding: 8px 10px; background: var(--code-bg, rgba(0,0,0,.28)); border: 1px solid var(--border); border-radius: 8px; font-family: Consolas, Menlo, monospace; font-size: 12.5px; line-height: 1.5; white-space: pre; overflow-x: auto; max-width: 100%; }
.code-lang { display: block; font-size: 11px; opacity: .6; margin-bottom: 4px; }
.search-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; margin-bottom: 10px; background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; font-size: 13px; }
.search-form { display: flex; gap: 8px; }
.search-form input { flex: 1; min-width: 0; }
.welcome-list { margin: 10px 0 14px; padding-left: 20px; font-size: 13.5px; line-height: 1.9; text-align: left; }

/* ---- v1.5 版块与互动 ---- */
.topbar { flex-wrap: wrap; }
.board-tabs { display: flex; gap: 8px; margin: 10px 0 4px; flex-basis: 100%; }
.board-tab { position: relative; flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.board-tab.active { border-color: currentColor; font-weight: 700; }
.board-badge { position: absolute; top: -6px; right: -4px; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #e2574c; color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.board-badge.flash { animation: badgeflash 1s ease-in-out 3; }
@keyframes badgeflash { 50% { opacity: .35; transform: scale(1.15); } }
.msg-acts { display: flex; gap: 10px; margin-top: 4px; }
.msg.me .msg-acts { justify-content: flex-end; }
.act-btn { border: none; background: transparent; color: inherit; opacity: .72; font: inherit; font-size: 12px; cursor: pointer; padding: 2px 4px; }
.act-btn:hover { opacity: 1; }
.act-btn.disabled { opacity: .35; }
.comment-box { margin: 6px 0 2px; padding: 6px 10px; border-left: 3px solid var(--border); font-size: 13px; }
.comment-line { margin: 3px 0; }
.comment-time { opacity: .5; font-size: 11px; margin-left: 6px; }
.comment-input-row { display: flex; gap: 6px; margin-top: 6px; }
.comment-input-row input { flex: 1; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: inherit; }
.composer { flex-wrap: wrap; }
.mask-row { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .8; margin: 2px 0; flex-basis: 100%; }
.composer .mask-row input[type="checkbox"] { flex: none; width: auto; padding: 0; margin: 0; accent-color: var(--accent); }

/* ---- v1.5 任务8：转发/分支/permalink/代码块复制 ---- */
.quote-ref { font-size: 12px; opacity: .8; border-left: 3px solid var(--border); padding: 2px 8px; margin-bottom: 4px; }
.branch-note { font-size: 12px; opacity: .8; margin: 2px 0; cursor: pointer; }
.code-wrap { position: relative; }
.code-copy { position: absolute; top: 4px; right: 4px; border: none; border-radius: 6px; padding: 2px 6px; background: rgba(128,128,128,.25); color: inherit; font-size: 11px; cursor: pointer; opacity: .6; }
.code-copy:hover { opacity: 1; }
.single-card { margin: 12px auto; max-width: 680px; }
#single-view { flex: 1; min-height: 0; overflow-y: auto; padding: 0 14px 20px; }
#fwd-dialog #fwd-text { margin-bottom: 4px; }
