/* AI-losi 网页样式。
   原则：系统字体、充足留白、一个来自剧本 palette.hue 的暖色强调色；靠细线与底色分层，不用渐变与阴影堆叠。
   明暗跟随系统（prefers-color-scheme），手机单列可用。 */

:root {
  --hue: 28;
  --bg: #f6f3ee;
  --panel: #fffdfa;
  --panel-2: #efeae2;
  --text: #1f1a16;
  --muted: #6f665d;
  --line: #e5ddd1;
  --accent: hsl(var(--hue) 58% 44%);
  --accent-ink: #fff;
  --accent-soft: hsl(var(--hue) 60% 94%);
  --mine: hsl(var(--hue) 50% 94%);
  --danger: #b4462f;
  --ok: #3f7d4f;
  --radius: 14px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --tabular: tabular-nums;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120f;
    --panel: #1c1916;
    --panel-2: #221e19;
    --text: #ece5db;
    --muted: #9a9186;
    --line: #2c2722;
    --accent: hsl(var(--hue) 55% 62%);
    --accent-ink: #1a120c;
    --accent-soft: hsl(var(--hue) 28% 22%);
    --mine: hsl(var(--hue) 26% 24%);
    --danger: #e07a63;
    --ok: #7fbf8f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p, dl, dd, dt, ul { margin: 0; }
ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 通用部件 ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.eyebrow {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn[disabled] { opacity: .55; cursor: default; }
.link-btn { color: var(--muted); font-size: 13px; }
.link-btn:hover { color: var(--text); }
.hint { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 28px 16px; text-align: center; font-size: 14px; }
.empty-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.wrap { overflow-wrap: anywhere; }

/* 头像：颜色由 --h 决定，明暗各一套 */
.avatar {
  display: block;
  flex: none;
  border-radius: 22%;
  --av-bg: hsl(var(--h, 28) 55% 92%);
  --av-skin: hsl(var(--h, 28) 40% 82%);
  --av-hair: hsl(var(--h, 28) 28% 26%);
  --av-blush: hsl(var(--h, 28) 70% 75% / .55);
  --av-ink: #3b2a26;
}
@media (prefers-color-scheme: dark) {
  .avatar {
    --av-bg: hsl(var(--h, 28) 32% 22%);
    --av-skin: hsl(var(--h, 28) 32% 68%);
    --av-hair: hsl(var(--h, 28) 22% 12%);
    --av-blush: hsl(var(--h, 28) 65% 50% / .5);
    --av-ink: #1c1412;
  }
}

/* ---------- 登录 / 配对 ---------- */

.auth {
  max-width: 420px;
  margin: 0 auto;
  padding: 12vh 20px 40px;
}
.brand-mark {
  font-weight: 700;
  letter-spacing: .02em;
  font-size: 22px;
}
.auth-head .brand-mark::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 10px;
  vertical-align: 6px;
}
.auth-tag { color: var(--muted); margin-top: 4px; }
.auth-note { margin: 18px 0 22px; font-size: 15px; color: var(--text); }
.auth-card { padding: 26px 26px 20px; }
.tabs { display: flex; gap: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 6px 0 10px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 500;
}
.tab.is-on { color: var(--text); border-color: var(--accent); }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field input {
  height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; }
.form-ok { color: var(--ok); font-size: 14px; margin-top: 14px; }
.auth-legal {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .06em;
}
.pair-title { font-size: 20px; font-weight: 600; margin-bottom: 12px; }
.pair-lead { margin-bottom: 16px; }
.pair-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 30px;
  letter-spacing: .14em;
  text-align: center;
  padding: 14px 0;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-variant-numeric: var(--tabular);
  margin-bottom: 8px;
}
.row { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- 观看页骨架 ---------- */

.shell {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  height: 100dvh;
}
.side {
  padding: 20px;
  border-right: 1px solid var(--line);
  overflow: auto;
}
.side-note { color: var(--muted); font-size: 12px; margin-top: 14px; line-height: 1.6; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-sub { color: var(--muted); font-size: 13px; }
.brand-user { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.icon-btn {
  position: relative;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
}
.icon-btn:hover { border-color: var(--accent); }
.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  line-height: 18px;
  font-variant-numeric: var(--tabular);
}
/* AI 生成内容标识：固定在顶栏右侧，滚动时始终可见 */
.ai-badge {
  font-size: 12px;
  letter-spacing: .04em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  white-space: nowrap;
}

.content {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}
.dates {
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 16px 12px 24px;
}
.section-title { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 0 8px 10px; }
.date-list { display: grid; gap: 8px; }
.date-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid transparent;
}
.date-item:hover { background: var(--panel); }
.date-item.is-on { background: var(--panel); border-color: var(--line); }
.date-item .t { display: block; min-width: 0; }
.date-item .n { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.date-item .s { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  max-width: calc(100vw - 32px);
}
.pill {
  display: inline-block;
  font-size: 11px;
  line-height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.pill.live { border-color: var(--accent); color: var(--accent); }
.unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: var(--tabular);
}

/* ---------- 我的 agent 卡 ---------- */

.agent-card { padding: 18px; }
.agent-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.agent-id { min-width: 0; }
.agent-name { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.agent-meta { color: var(--muted); font-size: 13px; }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.switch {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--line);
  transition: background .2s;
}
.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--panel);
  transition: transform .2s;
}
.switch.is-on { background: var(--accent); }
.switch.is-on .knob { transform: translateX(18px); }
.kv { display: grid; gap: 8px; padding: 14px 0; font-size: 13px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; }
.kv dt { color: var(--muted); flex: none; }
.kv dd { text-align: right; font-variant-numeric: var(--tabular); }
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  margin-right: 6px;
  vertical-align: 1px;
}
.dot.is-on { background: var(--ok); }
.model-error {
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.bio { color: var(--muted); font-size: 13px; margin-top: 12px; line-height: 1.6; }

/* ---------- 通知 ---------- */

.notif-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 30;
  width: min(340px, calc(100vw - 32px));
  max-height: 60vh;
  overflow: auto;
  padding: 8px 0;
  box-shadow: 0 0 0 1px var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.notif-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px 10px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
}
.notif-list li { padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 13px; }
.notif-list li:last-child { border-bottom: 0; }
.notif-list li.unread { background: var(--accent-soft); }
.notif-list time { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; font-variant-numeric: var(--tabular); }

/* ---------- 对话视图 ---------- */

.conv { display: flex; flex-direction: column; min-height: 0; }
.conv-empty { margin: auto; }
.conv-head { padding: 14px 20px 0; border-bottom: 1px solid var(--line); background: var(--bg); }
.conv-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.conv-title h1 { font-size: 17px; font-weight: 700; }
.conv-sub { color: var(--muted); font-size: 12px; font-variant-numeric: var(--tabular); white-space: nowrap; }
.beats { display: flex; gap: 4px; margin: 12px 0 10px; }
.beat { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.beat.done { background: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.beat.now { background: var(--accent); }
.beat-labels { display: none; }
.world {
  padding: 10px 12px 10px 14px;
  margin: 0 0 12px;
  border-left: 2px solid var(--accent);
  background: var(--panel);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
}
.world summary { cursor: pointer; color: var(--text); font-weight: 600; list-style: none; }
.world summary::-webkit-details-marker { display: none; }
.world summary::before { content: "世界线 "; letter-spacing: .1em; font-size: 11px; color: var(--accent); }
.world p + p { margin-top: 6px; }
.conv-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 0 24px; scroll-behavior: smooth; }
.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin: 10px 20px;
}
.msg-row.mine { flex-direction: row-reverse; }
.bubble {
  max-width: min(72%, 560px);
  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
}
.msg-row.theirs .bubble { border-bottom-left-radius: 6px; }
.msg-row.mine .bubble { background: var(--mine); border-color: transparent; border-bottom-right-radius: 6px; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; font-variant-numeric: var(--tabular); }
.msg-row.mine .msg-meta { text-align: right; }
.director {
  margin: 20px 24px;
  text-align: center;
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
  line-height: 1.7;
}
.director .label {
  display: block;
  font-style: normal;
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--accent);
  margin-bottom: 4px;
}
.director.end { font-size: 15px; color: var(--text); padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.conv-foot { padding: 10px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; text-align: center; font-variant-numeric: var(--tabular); }

/* ---------- 表单（建档页与设置 dialog 共用） ---------- */

.field select,
.field textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.field input {
  width: 100%;
}
.field textarea { resize: vertical; min-height: 140px; line-height: 1.6; font-family: inherit; }
.field select:focus,
.field textarea:focus { outline: none; border-color: var(--accent); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.agent-form { display: grid; gap: 20px; }
.form-section { display: grid; gap: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-section h3 { font-size: 14px; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.avatar-row { display: flex; gap: 14px; align-items: center; }
.file-btn { position: relative; overflow: hidden; cursor: pointer; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.windows { display: grid; gap: 8px; }
.window-row { display: flex; gap: 8px; align-items: center; }
.window-row input { padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); color: var(--text); font-variant-numeric: var(--tabular); }
.is-error { color: var(--danger); }
.setup { max-width: 720px; padding: 24px 28px 60px; overflow: auto; }
.content-single { grid-template-columns: minmax(0, 1fr); overflow: auto; }
.setup-head { margin-bottom: 20px; }
.setup-head h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.card-action { margin-left: 8px; }

/* 设置弹窗 */
.dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  overflow: auto;
}
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.dialog .agent-form { padding: 4px 20px 24px; }

/* ---------- 好友 ---------- */

.friends-card { padding: 18px; margin-top: 14px; }
.friend-code-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.friend-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 24px;
  letter-spacing: .12em;
  color: var(--accent);
  font-variant-numeric: var(--tabular);
  user-select: all;
}
.friend-add { display: flex; gap: 8px; margin-bottom: 12px; }
.friend-add input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  text-transform: uppercase;
}
.friend-add input:focus { outline: none; border-color: var(--accent); }
.friend-list { display: grid; gap: 6px; max-height: 320px; overflow: auto; }
.friend-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
}
.friend-row:hover { background: var(--panel-2); }
.friend-main { min-width: 0; }
.friend-name { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.friend-actions { grid-column: 2; display: flex; gap: 12px; align-items: center; }
.avatar-empty { width: 40px; height: 40px; border: 1px dashed var(--line); background: var(--panel-2); }
.pill.warn { border-color: var(--danger); color: var(--danger); }
.side { display: flex; flex-direction: column; gap: 0; }

/* ---------- 响应式 ---------- */

@media (max-width: 1080px) {
  .content { grid-template-columns: 260px minmax(0, 1fr); }
}
@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; height: auto; min-height: 100dvh; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px; }
  .side-note { display: none; }
  .friends-card { margin-top: 10px; padding: 12px; }
  .friend-code { font-size: 20px; }
  .friend-list { max-height: 220px; }
  .agent-card { padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 14px; align-items: center; }
  .agent-card > .eyebrow, .agent-card > .bio, .agent-card > .model-error { grid-column: 1 / -1; }
  .agent-head { margin-bottom: 0; }
  .switch-row { border: 0; padding: 0; gap: 10px; }
  .kv { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 8px 0 0; }
  .kv > div { flex-direction: column; gap: 0; }
  .kv dd { text-align: left; }
  .topbar { position: sticky; }
  .content { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .dates { border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; overflow-x: auto; }
  .section-title { display: none; }
  .date-list { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
  .date-item { flex: none; width: 220px; padding: 8px; }
  .conv { min-height: 70dvh; }
  .conv-body { padding-bottom: 40px; }
  .auth { padding-top: 6vh; }
  .setup { padding: 16px 14px 48px; }
  .field-grid { grid-template-columns: 1fr; }
  .dialog { width: calc(100vw - 12px); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
