/* 星港 · 界面
   设计基准来自 harness（DeepSeek Harness）：
   文字 #0f1115 / 背景 #f9fafb / 边框 rgb(0 0 0 / 10%) / 圆角 8-20px
   字体 -apple-system, "PingFang SC", "Microsoft YaHei"
   强调色用 DeepSeek 品牌蓝 #4d6bfe */

:root {
  --bg: #f9fafb;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f3f5;
  --surface-3: #e9eaee;
  --text: #0f1115;
  --text-dim: rgba(15, 17, 21, 0.56);
  --text-faint: rgba(15, 17, 21, 0.38);
  --border: rgba(0, 0, 0, 0.10);
  --border-soft: rgba(0, 0, 0, 0.06);
  --brand: #4d6bfe;
  --brand-soft: rgba(77, 107, 254, 0.10);
  --brand-bubble: rgba(77, 107, 254, 0.09);
  --danger: #d94a45;
  --r-sm: 8px;
  --r: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

/* 深色 */
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #131417;
    --bg-elev: #1a1b1f;
    --surface: #1c1d22;
    --surface-2: #24262b;
    --surface-3: #2c2e34;
    --text: #e9eaee;
    --text-dim: rgba(233, 234, 238, 0.58);
    --text-faint: rgba(233, 234, 238, 0.38);
    --border: rgba(255, 255, 255, 0.12);
    --border-soft: rgba(255, 255, 255, 0.07);
    --brand: #6b86ff;
    --brand-soft: rgba(107, 134, 255, 0.16);
    --brand-bubble: rgba(107, 134, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  }
}
html[data-theme="dark"] {
  --bg: #131417;
  --bg-elev: #1a1b1f;
  --surface: #1c1d22;
  --surface-2: #24262b;
  --surface-3: #2c2e34;
  --text: #e9eaee;
  --text-dim: rgba(233, 234, 238, 0.58);
  --text-faint: rgba(233, 234, 238, 0.38);
  --border: rgba(255, 255, 255, 0.12);
  --border-soft: rgba(255, 255, 255, 0.07);
  --brand: #6b86ff;
  --brand-soft: rgba(107, 134, 255, 0.16);
  --brand-bubble: rgba(107, 134, 255, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- 布局 ---------- */
.layout { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 264px; flex: 0 0 264px;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--border-soft);
  padding: 14px 12px;
  gap: 10px;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; }
.brand { font-weight: 600; letter-spacing: .02em; display: flex; align-items: center; gap: 7px; }
.mark { color: var(--brand); }

.new-chat {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--r); padding: 10px 12px; text-align: left;
  cursor: pointer; transition: background .15s;
}
.new-chat:hover { background: var(--surface-2); }

.thread-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.thread-item {
  padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer;
  transition: background .12s;
}
.thread-item:hover { background: var(--surface-2); }
.thread-item.active { background: var(--surface-2); }
.thread-item .t { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-item .d { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.side-foot { border-top: 1px solid var(--border-soft); padding-top: 10px; }
.side-btn {
  width: 100%; text-align: left; border: 0; background: transparent;
  border-radius: var(--r-sm); padding: 9px 10px; cursor: pointer; color: var(--text-dim);
}
.side-btn:hover { background: var(--surface-2); color: var(--text); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.top {
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 16px;
  padding-top: var(--safe-t);
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 5;
}
.title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.title .name { font-weight: 600; }
.title .sub { color: var(--text-faint); font-size: 12.5px; }
.avatar-sm {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-size: 13px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #34c759; }
.dot.busy { background: var(--brand); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25 } }

.icon-btn {
  width: 36px; height: 36px; flex: 0 0 36px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-dim); cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.only-mobile { display: none; }

/* ---------- 消息 ---------- */
.msgs {
  flex: 1; overflow-y: auto;
  padding: 22px 16px 8px;
  display: flex; flex-direction: column; gap: 18px;
  scrollbar-width: thin;
}
.msg { display: flex; gap: 10px; max-width: 760px; width: 100%; margin: 0 auto; }
.msg .avatar {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--brand-soft); color: var(--brand);
  font-size: 13px; margin-top: 2px;
}
.msg .body { min-width: 0; flex: 1; }
.bubble { white-space: normal; word-break: break-word; }
.msg.you .bubble { padding-top: 3px; }

.msg.me { flex-direction: row-reverse; }
.msg.me .bubble {
  background: var(--brand-bubble);
  border: 1px solid var(--border);
  border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent);
  border-radius: var(--r-md);
  padding: 9px 13px; margin-left: auto; width: fit-content; max-width: 86%;
}
.msg.me .body { display: flex; flex-direction: column; align-items: flex-end; }

.meta { font-size: 11px; color: var(--text-faint); margin-top: 5px; }

/* Markdown */
.bubble pre {
  background: var(--surface-2); border: 1px solid var(--border-soft);
  padding: 11px 13px; border-radius: var(--r); overflow-x: auto; margin: 8px 0;
}
.bubble code { font-family: "SF Mono", "JetBrains Mono", Consolas, Menlo, monospace; font-size: 13px; }
.bubble pre code { font-size: 12.5px; }
.bubble a { color: var(--brand); }
.bubble .cursor {
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  background: var(--brand); border-radius: 1px; vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0 } }
.err { color: var(--danger); font-size: 13.5px; }

.empty { margin: auto; text-align: center; color: var(--text-faint); }
.empty .big { font-size: 26px; color: var(--brand); margin-bottom: 10px; }
.empty .t1 { font-size: 17px; color: var(--text-dim); }

/* ---------- 输入 ---------- */
.composer-wrap {
  padding: 10px 16px calc(12px + var(--safe-b));
  max-width: 800px; width: 100%; margin: 0 auto;
}
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--brand) 55%, transparent); }
.composer textarea {
  flex: 1; border: 0; outline: 0; background: transparent; resize: none;
  max-height: 160px; padding: 7px 0; line-height: 1.65;
}
.composer button {
  width: 34px; height: 34px; flex: 0 0 34px; border: 0; border-radius: 50%;
  background: var(--brand); color: #fff; display: grid; place-items: center;
  cursor: pointer; transition: opacity .15s, background .15s;
}
.composer button:disabled { opacity: .35; }
.composer button.stop { background: var(--danger); }
.foot-hint { text-align: center; font-size: 11.5px; color: var(--text-faint); margin: 8px 0 0; }

/* ---------- 面板 ---------- */
.scrim { display: none; }
.sheet {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .35);
  display: grid; place-items: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.sheet-inner {
  width: min(440px, 100%); background: var(--surface);
  border: 1px solid var(--border-soft); border-radius: var(--r-md);
  padding: 20px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow);
}
.sheet-inner h2 { margin: 0; font-size: 18px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-inner label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.sheet-inner input, .sheet-inner select {
  padding: 10px 12px; border-radius: var(--r); background: var(--bg);
  border: 1px solid var(--border); outline: none;
}
.sheet-inner input:focus, .sheet-inner select:focus { border-color: color-mix(in srgb, var(--brand) 55%, transparent); }
.primary {
  border: 0; border-radius: var(--r); padding: 11px; font-weight: 600; color: #fff;
  background: var(--brand); cursor: pointer;
}
.ghost-btn {
  border: 1px solid var(--border); background: transparent; border-radius: var(--r-sm);
  padding: 6px 12px; cursor: pointer; color: var(--text-dim);
}
.danger {
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  background: transparent; color: var(--danger);
  border-radius: var(--r); padding: 10px; cursor: pointer;
}
.hint { color: var(--text-faint); font-size: 12.5px; margin: 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }

/* ---------- 他留的话 ---------- */
.note-banner {
  max-width: 760px; margin: 16px auto 0; width: calc(100% - 32px);
  background: linear-gradient(160deg, var(--brand-bubble), transparent 70%);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-radius: var(--r-md); padding: 14px 16px;
}
.note-head { font-size: 12.5px; color: var(--brand); letter-spacing: .06em; margin-bottom: 8px; }
.note-body { font-size: 15.5px; line-height: 1.85; margin-bottom: 10px; }
.note-banner .ghost-btn { font-size: 12.5px; padding: 5px 12px; }

/* ---------- 他自己 ---------- */
.self-room { flex: 1; min-height: 0; overflow-y: auto; }
.self-block { max-width: 34em; margin: 0 auto 34px; }
.self-label {
  font-size: 12px; letter-spacing: .1em; color: var(--text-faint);
  padding-bottom: 8px; margin-bottom: 12px; border-bottom: 1px solid var(--border-soft);
}
.self-moods { display: flex; flex-wrap: wrap; gap: 8px; }
.mood-chip {
  font-size: 13px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
}
.self-history .h-item {
  font-size: 13px; color: var(--text-dim); padding: 7px 0;
  border-bottom: 1px dashed var(--border-soft);
}
#selfText { max-width: none; }

/* ---------- 视图切换 ---------- */
.view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.view[hidden] { display: none !important; }

/* ---------- 日记：一间屋子 ---------- */
.diary-room { flex: 1; display: flex; min-height: 0; }

.diary-index {
  width: 250px; flex: 0 0 250px; display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-elev); border-right: 1px solid var(--border-soft);
}
.diary-index-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; font-size: 12.5px; color: var(--text-faint);
  border-bottom: 1px solid var(--border-soft); flex: 0 0 auto;
}
.faint { color: var(--text-faint); }
.diary-dates { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 1px; }
.month-label {
  font-size: 11.5px; color: var(--text-faint); letter-spacing: .08em;
  padding: 14px 10px 5px; position: sticky; top: 0; background: var(--bg-elev);
}
.diary-item {
  border: 0; background: transparent; text-align: left; cursor: pointer;
  border-radius: var(--r-sm); padding: 9px 10px; color: var(--text); width: 100%;
}
.diary-item:hover { background: var(--surface-2); }
.diary-item.active { background: var(--brand-soft); }
.diary-item .d1 { font-size: 13.5px; font-weight: 500; }
.diary-item .d2 {
  font-size: 11.5px; color: var(--text-faint); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.diary-item.active .d1 { color: var(--brand); }

.diary-pane { flex: 1; min-width: 0; overflow-y: auto; padding: 42px 30px 90px; }
.diary-title {
  max-width: 34em; margin: 0 auto 24px; font-size: 13px;
  color: var(--text-faint); letter-spacing: .05em;
}
.diary-body { max-width: 34em; margin: 0 auto; font-size: 16.5px; line-height: 2.05; }
.diary-body .sec {
  display: block; font-size: 12.5px; letter-spacing: .1em;
  color: var(--text-faint); margin: 26px 0 8px;
}
.diary-body .sec:first-child { margin-top: 0; }
.diary-body .empty { text-align: center; color: var(--text-faint); padding: 90px 0; line-height: 1.9; }

@media (max-width: 860px) {
  .diary-index {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(80vw, 300px); flex: none;
    transform: translateX(-102%); transition: transform .22s ease;
    padding-top: var(--safe-t); box-shadow: 0 0 40px rgba(0, 0, 0, .18);
  }
  .diary-index.open { transform: none; }
  .diary-pane { padding: 24px 18px 90px; }
  .diary-body { font-size: 16px; line-height: 1.95; }
}

/* ---------- 手机 ---------- */
@media (max-width: 860px) {
  .only-mobile { display: inline-grid; place-items: center; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(84vw, 300px); flex: none;
    transform: translateX(-102%); transition: transform .22s ease;
    padding-top: calc(14px + var(--safe-t));
    box-shadow: 0 0 40px rgba(0, 0, 0, .18);
  }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .msg { max-width: 100%; }
  .msg.me .bubble { max-width: 88%; }
  .foot-hint { display: none; }
}
