/* 留白 · 纸墨风格：大量留白、宋体标题、朱砂印章色点缀 */
:root {
  --paper: #faf8f4; --panel: #f3efe7; --card: #ffffff; --ink: #1f1d1a; --ink-2: #5b564e; --line: #e4ded3;
  --seal: #b23a2b; --seal-soft: #f6e4df; --ok: #2f6b4f; --warn: #9a6a12;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --sans: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --radius: 14px; --side: 280px;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #191816; --panel: #211f1c; --card: #26231f; --ink: #ece7de; --ink-2: #a8a196; --line: #36322c; --seal-soft: #3a221d; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 15px/1.6 var(--sans); -webkit-text-size-adjust: 100%; overflow: hidden; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-2); } .small { font-size: 12.5px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 7px 14px; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon-only { padding: 4px 10px; }
.linkish { border: 0; background: none; padding: 0; color: var(--seal); cursor: pointer; font-size: 12.5px; }

.seal { display: inline-grid; place-items: center; width: 54px; height: 54px; border: 2px solid var(--seal); color: var(--seal); border-radius: 8px;
  font: 700 17px/1 var(--serif); letter-spacing: 1px; }
.seal.big { width: 76px; height: 76px; font-size: 24px; }
.boot { position: fixed; inset: 0; display: grid; place-items: center; font: 28px var(--serif); color: var(--ink-2); letter-spacing: 8px; }

/* 登录门 */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: var(--paper); z-index: 30; overflow: auto; }
.gate-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 26px; display: grid; gap: 10px; }
.gate-card h1 { margin: 6px 0 0; font: 600 22px var(--serif); }
.gate-card label { font-size: 13px; color: var(--ink-2); }
.gate-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.gate-note { margin: 0; color: var(--ink-2); font-size: 13px; }
.gate-error { margin: 0; color: var(--seal); min-height: 1.2em; font-size: 13px; }
.gate-back { color: var(--ink-2); font-size: 13px; }

/* 主布局 */
.app { display: flex; height: 100%; height: 100dvh; }
.side { width: var(--side); flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px; gap: 10px; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; }
.brand { font: 700 22px var(--serif); letter-spacing: 6px; color: var(--ink); }
.brand::after { content: "·文库私人画室"; font: 12px var(--sans); letter-spacing: 1px; color: var(--ink-2); margin-left: 6px; }
.side-close { display: none; }
.new-project { width: 100%; justify-content: flex-start; }
.search input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.projects { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.project-item { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 1px; width: 100%; border: 0; background: none;
  padding: 8px 10px; border-radius: 10px; cursor: pointer; min-width: 0; }
.project-item:hover { background: var(--card); }
.project-item.active { background: var(--card); box-shadow: inset 3px 0 0 var(--seal); }
.pi-title { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-meta { font-size: 12px; color: var(--ink-2); }
.pi-snippet { font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: var(--seal-soft); color: var(--seal); border-radius: 3px; padding: 0 1px; }
.empty { padding: 8px 10px; }
.side-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); min-width: 0; }
.menu { display: none; }
.project-title { margin: 0; flex: 1; min-width: 0; font: 600 18px var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }

.thread { flex: 1; overflow-y: auto; padding: 24px max(20px, calc((100% - 860px) / 2)); display: flex; flex-direction: column; gap: 26px; min-height: 0; scroll-behavior: smooth; }
.welcome { margin: auto; text-align: center; max-width: 460px; color: var(--ink-2); display: grid; justify-items: center; gap: 4px; }
.turn { display: flex; flex-direction: column; gap: 10px; border-radius: var(--radius); transition: box-shadow .4s; }
.turn.flash { box-shadow: 0 0 0 3px var(--seal-soft); }
.bubble.user { align-self: flex-end; max-width: min(640px, 92%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius) var(--radius) 4px var(--radius); padding: 10px 14px; }
.prompt-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.bubble-refs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.ref-thumb { height: 64px; width: auto; max-width: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

.result { align-self: flex-start; width: min(640px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 4px var(--radius) var(--radius) var(--radius); padding: 12px; display: grid; gap: 8px; }
.preview { display: block; width: 100%; height: auto; max-height: 72vh; object-fit: contain; border-radius: 10px; background: var(--panel); cursor: zoom-in; }
.result-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--ink-2); }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.status-text { margin: 0; font-weight: 600; }
.status-failed .status-text { color: var(--seal); } .status-cancelled .status-text { color: var(--ink-2); }
.error-text { margin: 0; color: var(--seal); font-size: 13px; overflow-wrap: anywhere; }
.bar { height: 4px; background: var(--panel); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--seal); transition: width .6s; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--seal); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 输入区 */
.composer { padding: 10px max(16px, calc((100% - 860px) / 2)) calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); display: grid; gap: 6px; }
.refs { display: flex; gap: 8px; flex-wrap: wrap; }
.ref-chip { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px 4px 4px; max-width: 100%; min-width: 0; }
.ref-chip img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: none; }
.ref-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--ink-2); padding: 2px 4px; }
.composer-box { display: flex; align-items: flex-end; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 8px; }
.composer-box:focus-within { border-color: var(--ink-2); }
.btn.plus { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 20px; flex: none; }
.composer textarea { flex: 1; min-width: 0; border: 0; outline: 0; resize: none; background: transparent; padding: 8px 4px; max-height: 220px; line-height: 1.5; }
.btn.send { flex: none; height: 38px; border-radius: 19px; background: var(--ink); color: var(--paper); border-color: var(--ink); padding: 0 16px; }
.composer-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 0 6px; }
.ratio { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.ratio select { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 3px 6px; }

/* 原图查看 */
.viewer { position: fixed; inset: 0; z-index: 40; background: rgba(16, 15, 13, .94); display: flex; flex-direction: column; color: #eee; }
.viewer-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px calc(10px); flex-wrap: wrap; }
.viewer-bar .btn { background: #2b2925; color: #eee; border-color: #444; }
.viewer-info { flex: 1; min-width: 0; font-size: 13px; overflow-wrap: anywhere; }
.viewer-stage { flex: 1; min-height: 0; overflow: auto; display: grid; place-items: center; padding: 8px; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-loading { color: #ccc; text-align: center; padding: 20px; }

/* 手机 */
@media (max-width: 760px) {
  .side { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 20; transform: translateX(-102%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.18); }
  .side-open .side { transform: none; }
  .side-close { display: inline-flex; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 15; }
  .menu { display: inline-flex; }
  .topbar { padding: 10px 12px; }
  .thread { padding: 16px 12px; gap: 20px; }
  .composer { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .bubble.user { max-width: 100%; }
  .composer textarea { font-size: 16px; } /* 防止 iOS 聚焦时自动放大 */
}
