/* AKai：沿用圆桌派、制片厂的那套纸色和字。 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600&family=Inter:wght@400;500;600&family=Fira+Code:wght@400;500&display=swap');

:root {
  color-scheme: light;
  --bg: #f7f3eb;
  --paper: rgba(255,253,248,.78);
  --paper-strong: rgba(255,253,248,.95);
  --paper-soft: rgba(255,255,255,.5);
  --ink: #29241f;
  --ink-2: #6f665d;
  --muted: #968b80;
  --line: rgba(54,46,38,.14);
  --line-soft: rgba(54,46,38,.08);
  --claude: #b97a63;
  --claude-dim: rgba(185,122,99,.12);
  --k-dim: rgba(92,80,68,.08);
  --warn: #b0803a;
  --danger: #b85e5e;
  --danger-dim: rgba(184,94,94,.1);
  --shadow-soft: 0 10px 36px rgba(67,52,35,.07);
  --serif: "Noto Serif SC", "Songti SC", serif;
  --mono: "Fira Code", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(255,255,255,.88), transparent 28%),
    radial-gradient(circle at 87% 18%, rgba(184,205,217,.2), transparent 32%),
    radial-gradient(circle at 78% 92%, rgba(191,141,118,.11), transparent 30%),
    linear-gradient(135deg,#fbf8f1,#efe7da 56%,#f8f5ef);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .6;
  background-image: linear-gradient(rgba(70,60,50,.027) 1px, transparent 1px), linear-gradient(90deg, rgba(70,60,50,.022) 1px, transparent 1px);
  background-size: 42px 42px;
}

button, input, textarea, select { font: inherit; color: inherit; }
select { border: 1px solid var(--line); border-radius: 8px; background: var(--paper-strong); padding: 2px 4px; font-size: 12px; height: 26px; cursor: pointer; }

.btn {
  border: 1px solid var(--line); background: var(--paper-soft); border-radius: 999px;
  padding: 6px 16px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: var(--paper-strong); border-color: rgba(54,46,38,.3); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--ink); color: #fbf8f1; border-color: var(--ink); }
.btn.primary:hover:not(:disabled) { background: #3a332c; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover:not(:disabled) { background: var(--k-dim); border-color: transparent; }
.btn.wide { width: 100%; }
.btn.icon { padding: 4px 11px; font-size: 18px; line-height: 1.3; }
.link { border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; font-size: 12px; }
.link:hover { color: var(--ink); }
.grow { flex: 1; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--claude); flex: none; }

/* 布局 */
.app { position: relative; z-index: 1; display: grid; grid-template-columns: 264px minmax(0, 1fr); height: 100%; height: 100dvh; }
.side { display: flex; flex-direction: column; gap: 14px; padding: 22px 16px 16px; border-right: 1px solid var(--line-soft); background: var(--paper-soft); min-height: 0; }
.brand h1 { margin: 0; font-family: var(--serif); font-size: 26px; font-weight: 600; letter-spacing: .04em; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; padding: 0 6px; }
.chat-item { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 12px; padding: 8px 10px; cursor: pointer; }
.chat-item:hover { background: var(--k-dim); }
.chat-item.on { background: var(--paper-strong); box-shadow: var(--shadow-soft); }
.chat-item .t { display: block; font-family: var(--serif); font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .m { display: block; color: var(--muted); font-size: 11.5px; }
.chat-item .busy { color: var(--warn); font-weight: 500; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 4px; margin: 0; }
.foot { border-top: 1px solid var(--line-soft); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.seat { display: flex; align-items: center; gap: 6px; }
.seat select.model { flex: 1; min-width: 0; }
.foot-links { display: flex; gap: 14px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 6px; padding: 10px 20px; min-height: 52px; border-bottom: 1px solid var(--line-soft); }
.topbar .title { flex: 1; min-width: 0; font-family: var(--serif); font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
#sideToggle { display: none; }

.scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 20px 28px; -webkit-overflow-scrolling: touch; }
.thread { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.hello { margin: 16vh auto 0; text-align: center; color: var(--ink-2); }
.hello h2 { margin: 0 0 6px; font-family: var(--serif); font-size: 24px; font-weight: 600; color: var(--ink); }
.hello p { margin: 0; font-size: 13.5px; color: var(--muted); }

/* 一问一答 */
.msg.k { align-self: flex-end; max-width: 86%; }
.msg.k .bubble { background: var(--paper-strong); border: 1px solid var(--line-soft); border-radius: 18px 18px 6px 18px; padding: 10px 15px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow-soft); }
.msg.claude { align-self: stretch; }
.msg .meta { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.msg.k .meta { justify-content: flex-end; }
.msg .meta .steps { cursor: pointer; }
.msg .meta .steps:hover { color: var(--ink); }
.msg .working { display: flex; align-items: center; gap: 8px; color: var(--warn); font-size: 13px; margin-top: 4px; }
.msg .working::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); animation: pulse 1.2s ease-in-out infinite; flex: none; }
.msg .working span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.msg .problem { margin-top: 6px; padding: 8px 12px; border-radius: 10px; background: var(--danger-dim); color: var(--danger); font-size: 13px; }

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .75em; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; margin: 1.1em 0 .4em; line-height: 1.4; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17.5px; } .md h3 { font-size: 16px; } .md h4 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 .75em; padding-left: 1.4em; }
.md li { margin: .15em 0; }
.md blockquote { margin: 0 0 .75em; padding: 2px 0 2px 14px; border-left: 3px solid var(--line); color: var(--ink-2); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--k-dim); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--paper-strong); border: 1px solid var(--line-soft); border-radius: 12px; padding: 10px 12px; overflow-x: auto; margin: 0 0 .75em; }
.md pre code { background: none; padding: 0; }
.md a { color: inherit; text-decoration-color: var(--claude); text-underline-offset: 3px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md .table-wrap { overflow-x: auto; margin: 0 0 .75em; }
.md table { border-collapse: collapse; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--k-dim); font-weight: 500; }

/* 文件 */
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.msg.k .files { justify-content: flex-end; }
.files:empty { display: none; }
.file { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 5px 12px 5px 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper-strong); font-size: 13px; color: inherit; text-decoration: none; }
a.file:hover { border-color: rgba(54,46,38,.34); }
.file .ext { display: grid; place-items: center; min-width: 34px; height: 26px; padding: 0 5px; border-radius: 7px; background: var(--claude-dim); color: var(--claude); font-size: 10.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; flex: none; }
.file .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 0 0 2px; }
.file .x:hover { color: var(--danger); }
.file.new { border-color: rgba(185,122,99,.5); }
.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-list .file { justify-content: flex-start; }
.file-list .file .when { margin-left: auto; padding-left: 10px; color: var(--muted); font-size: 11.5px; white-space: nowrap; }

/* 输入 */
.composer { padding: 0 20px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.composer .box, .composer .attach-row, .composer .note { max-width: 760px; margin-left: auto; margin-right: auto; }
.composer .box { border: 1px solid var(--line); border-radius: 20px; background: var(--paper-strong); padding: 10px 10px 8px 14px; box-shadow: var(--shadow-soft); }
.composer .box:focus-within { border-color: rgba(54,46,38,.38); }
.composer .box.drag { border-style: dashed; border-color: var(--claude); }
.composer textarea { display: block; width: 100%; border: 0; outline: 0; background: none; resize: none; padding: 2px 0; line-height: 1.6; max-height: 40vh; font-size: 16px; }
.box-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attach-row:empty { display: none; }
.composer .note { margin-top: 6px; margin-bottom: 0; color: var(--danger); font-size: 12.5px; }

/* 弹层 */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(41,36,31,.28); }
.modal-card { width: min(640px, 100%); max-height: min(80vh, 100%); display: flex; flex-direction: column; background: #fbf8f1; border-radius: 20px; box-shadow: 0 30px 80px rgba(41,36,31,.25); }
.modal-card header { display: flex; align-items: center; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--line-soft); }
.modal-card h3 { flex: 1; margin: 0; font-family: var(--serif); font-size: 17px; font-weight: 600; }
.modal-body { padding: 14px 20px 20px; overflow-y: auto; }
.trail { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.trail li { padding: 4px 0; border-bottom: 1px solid var(--line-soft); overflow-wrap: anywhere; }
.trail b { font-weight: 500; margin-right: 8px; }
.trail span { color: var(--ink-2); font-family: var(--mono); font-size: 12px; }

/* 登录 */
.login-page { display: grid; place-items: center; overflow: auto; }
.login { position: relative; z-index: 1; width: min(320px, calc(100% - 40px)); display: flex; flex-direction: column; gap: 12px; padding: 30px 28px; background: var(--paper); border: 1px solid var(--line-soft); border-radius: 22px; box-shadow: var(--shadow-soft); }
.login h1 { margin: 0 0 6px; font-family: var(--serif); font-size: 28px; font-weight: 600; letter-spacing: .04em; text-align: center; }
.login input { width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper-strong); outline: none; font-size: 16px; }
.login input:focus { border-color: rgba(54,46,38,.38); }
.login .btn { padding: 9px 16px; }
.login-error { margin: 0; color: var(--danger); font-size: 13px; }

.shade { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: min(290px, 84vw); z-index: 15; background: #fbf8f1; transform: translateX(-100%); padding-top: calc(22px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .side.open { transform: none; box-shadow: 20px 0 60px rgba(41,36,31,.18); }
  .shade { display: block; position: fixed; inset: 0; z-index: 14; background: rgba(41,36,31,.2); }
  #sideToggle { display: inline-block; }
  .topbar { padding: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top)); }
  .scroll { padding: 16px 14px 20px; }
  .composer { padding: 0 10px 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .msg.k { max-width: 92%; }
  .hello { margin-top: 12vh; }
}
