:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-alt: #ecece7;
  --ink: #181a18;
  --muted: #666b66;
  --line: #d9dbd5;
  --accent: #146c52;
  --accent-ink: #ffffff;
  --user: #e4f1eb;
  --commentary: #f1f1ed;
  --danger: #a33232;
  --shadow: 0 10px 35px rgba(18, 28, 22, .09);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161816;
  --surface: #202320;
  --surface-alt: #292d29;
  --ink: #f3f4f1;
  --muted: #aeb3ad;
  --line: #3a3f3a;
  --accent: #68c9a3;
  --accent-ink: #10241c;
  --user: #214538;
  --commentary: #292d29;
  --danger: #ff8c8c;
  --shadow: 0 10px 35px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
  letter-spacing: 0;
}
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: 0; }

.lock-view { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.lock-panel { width: min(100%, 430px); }
.brand-mark {
  display: grid; width: 48px; height: 48px; margin-bottom: 28px; place-items: center;
  border: 1px solid var(--ink); font-family: Georgia, serif; font-size: 26px;
}
.lock-panel h1 { margin: 0; max-width: 390px; font-family: Georgia, "Microsoft YaHei UI", serif; font-size: clamp(32px, 7vw, 46px); line-height: 1.08; font-weight: 500; }
.lock-copy { margin: 18px 0 30px; color: var(--muted); line-height: 1.7; }
.lock-panel label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 700; }
.password-row { display: grid; grid-template-columns: 1fr 68px; gap: 8px; }
input {
  width: 100%; min-width: 0; height: 46px; padding: 0 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 4px; outline: 0; background: var(--surface);
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.primary-button {
  width: 100%; height: 48px; margin-top: 12px; border: 0; border-radius: 4px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.primary-button:disabled { opacity: .55; cursor: wait; }
.icon-button {
  min-width: 44px; height: 44px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: 4px; background: var(--surface); color: var(--ink); font-size: 13px;
}
.status { min-height: 22px; margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.status.error { color: var(--danger); }

.viewer { height: 100%; }
.topbar {
  position: relative; z-index: 20; display: grid; grid-template-columns: 1fr auto auto;
  grid-template-areas: "title theme lock";
  align-items: center; gap: 8px; height: 64px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar-title { grid-area: title; min-width: 0; display: flex; flex-direction: column; font-weight: 700; }
.topbar-title small { overflow: hidden; color: var(--muted); font-size: 11px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.nav-button { grid-area: nav; display: none; }
#theme-button { grid-area: theme; }
#lock-button { grid-area: lock; }
.workspace { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); height: calc(100% - 64px); }
.sidebar { overflow: hidden; border-right: 1px solid var(--line); background: var(--surface); }
.search-wrap { padding: 14px 14px 8px; }
.search-wrap input { height: 42px; background: var(--bg); }
.list-summary { display: flex; justify-content: space-between; min-height: 30px; padding: 3px 16px 7px; color: var(--muted); font-size: 11px; }
.thread-list { height: calc(100% - 94px); overflow-y: auto; padding: 0 8px 16px; }
.thread-item {
  display: block; width: 100%; min-height: 72px; padding: 12px 10px; border: 0;
  border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--ink); text-align: left;
}
.thread-item:hover { background: var(--bg); }
.thread-item.active { background: var(--surface-alt); box-shadow: inset 3px 0 0 var(--accent); }
.thread-item strong { display: -webkit-box; overflow: hidden; margin-bottom: 7px; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.35; }
.thread-item span { color: var(--muted); font-size: 11px; }
.conversation { overflow-y: auto; padding: 42px max(24px, calc((100% - 820px) / 2)) 90px; scroll-behavior: smooth; }
.conversation-header { padding-bottom: 26px; border-bottom: 1px solid var(--line); }
.conversation-header h2 { overflow-wrap: anywhere; margin: 0 0 12px; font-family: Georgia, "Microsoft YaHei UI", serif; font-size: 32px; line-height: 1.2; font-weight: 500; }
.conversation-header > p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.messages { display: grid; gap: 18px; padding-top: 26px; }
.message { max-width: 92%; padding: 15px 17px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: 0 2px 10px rgba(20, 30, 24, .03); }
.message.user { justify-self: end; background: var(--user); border-color: transparent; }
.message.commentary { background: var(--commentary); }
.message-label { margin-bottom: 9px; color: var(--muted); font-size: 11px; font-weight: 700; }
.markdown { overflow-wrap: anywhere; line-height: 1.72; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol { margin: 0 0 12px; }
.markdown h1, .markdown h2, .markdown h3 { margin: 20px 0 10px; font-size: 18px; }
.markdown pre { overflow-x: auto; margin: 13px 0; padding: 14px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); }
.markdown code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }
.markdown blockquote { margin: 12px 0; padding-left: 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.empty-state { display: grid; min-height: 60vh; place-content: center; text-align: center; }
.empty-state h2 { margin: 0; font-family: Georgia, serif; font-size: 30px; font-weight: 500; }
.empty-state p:last-child { color: var(--muted); }
.scrim { display: none; }

@media (max-width: 760px) {
  .topbar { grid-template-columns: auto 1fr auto auto; grid-template-areas: "nav title theme lock"; padding: 8px 10px; }
  .nav-button { display: block; }
  .workspace { display: block; position: relative; }
  .sidebar {
    position: absolute; z-index: 15; inset: 0 auto 0 0; width: min(88vw, 360px);
    transform: translateX(-105%); transition: transform .18s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim { position: absolute; z-index: 14; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(0, 0, 0, .32); }
  .scrim.open { display: block; }
  .conversation { height: 100%; padding: 28px 16px 70px; }
  .conversation-header h2 { font-size: 26px; }
  .message { max-width: 96%; padding: 13px 14px; }
}

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