:root {
  --bg: #f4f1e8;
  --bg-2: #ebe7dc;
  --paper: #fffdf7;
  --paper-soft: #faf7ef;
  --ink: #1e2a23;
  --ink-soft: #3d4b42;
  --muted: #6f7c73;
  --line: #ddd8c9;
  --line-strong: #c9c2b0;
  --accent: #2f6b4f;
  --accent-2: #487e61;
  --accent-soft: #e4efe7;
  --accent-ink: #1f4a37;
  --gold: #a8752f;
  --danger: #9b3d36;
  --danger-soft: #f8e8e6;
  --shadow: 0 10px 30px rgba(39, 48, 42, .08);
  --shadow-soft: 0 2px 10px rgba(39, 48, 42, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --sans: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", "Noto Serif SC", Georgia, serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #131a16;
  --bg-2: #0f1512;
  --paper: #1b241e;
  --paper-soft: #202b24;
  --ink: #e8eee9;
  --ink-soft: #c4cec6;
  --muted: #93a197;
  --line: #334139;
  --line-strong: #45564a;
  --accent: #7dc29d;
  --accent-2: #9ad5b5;
  --accent-soft: #22382d;
  --accent-ink: #d8f0e2;
  --gold: #d8ab63;
  --danger: #e08e86;
  --danger-soft: #3a2422;
  --shadow: 0 10px 30px rgba(0, 0, 0, .3);
  --shadow-soft: 0 2px 10px rgba(0, 0, 0, .2);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1000px 600px at 8% -8%, color-mix(in srgb, var(--accent-soft) 70%, transparent), transparent 62%),
    radial-gradient(900px 500px at 100% 0%, color-mix(in srgb, var(--gold) 12%, transparent), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 20px clamp(14px, 3vw, 34px) 28px;
}
.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
h1 { font-family: var(--serif); font-size: clamp(25px, 3.4vw, 34px); line-height: 1.08; font-weight: 650; }
h2 { font-family: var(--serif); font-size: 20px; line-height: 1.2; font-weight: 620; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 4px 0 14px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 46px; height: 46px; border-radius: 50%;
  color: var(--accent-ink);
  background: linear-gradient(145deg, var(--accent-soft), color-mix(in srgb, var(--gold) 18%, var(--paper)));
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), var(--shadow-soft);
}
.brand-mark svg { width: 25px; height: 25px; fill: var(--accent); }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--paper);
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge[data-state="ready"] { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); background: var(--accent-soft); }
.badge[data-state="ready"]::before { background: var(--accent); }
.badge[data-state="error"] { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: var(--danger-soft); }
.badge[data-state="error"]::before { background: var(--danger); }
.badge[data-state="pending"] { color: var(--gold); }

.ghost, .primary {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--paper);
  color: var(--ink-soft); font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.ghost:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.primary {
  border-color: var(--accent); background: var(--accent); color: #fff;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 28%, transparent);
}
.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.ghost:active, .primary:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button:disabled { opacity: .48; cursor: not-allowed; transform: none; }

.intro {
  margin: 0 0 18px;
  max-width: 780px;
  color: var(--ink-soft);
  font-size: 14px;
}
.intro strong { color: var(--accent-ink); font-weight: 650; }

.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
  margin-bottom: 16px;
}
.stats article {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  box-shadow: var(--shadow-soft);
}
.stats span { display: block; color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .06em; }
.stats strong { display: block; margin-top: 2px; font-family: var(--serif); font-size: 21px; font-weight: 600; line-height: 1.2; }
.stats small { display: block; color: var(--muted); font-size: 11px; }

.searchbar {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px 7px 14px; margin-bottom: 16px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--paper); box-shadow: var(--shadow-soft);
}
.search-icon { color: var(--accent); font-size: 20px; line-height: 1; transform: rotate(-15deg); }
.searchbar input {
  flex: 1 1 auto; min-width: 0; height: 38px; border: 0; outline: 0; background: transparent;
  font-size: 14.5px;
}
.searchbar input::placeholder { color: var(--muted); }
.searchbar .primary, .searchbar .ghost { min-height: 36px; padding: 0 16px; }

.board {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 16px;
  align-items: start;
}
.list-pane, .detail-pane {
  min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.list-pane { padding: 14px; }
.pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 2px 2px 10px; }
.pane-head h2 { font-size: 18px; }
.memory-list { display: grid; gap: 8px; max-height: 56vh; overflow: auto; padding: 2px; scrollbar-width: thin; }
.memory-item {
  display: block; width: 100%; text-align: left;
  padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--paper-soft);
  cursor: pointer; transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.memory-item:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); }
.memory-item[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.item-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.item-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; font-size: 14.5px; color: var(--ink); }
.item-date { flex: 0 0 auto; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.item-excerpt { margin-top: 4px; color: var(--ink-soft); font-size: 12.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-excerpt mark, .detail-body mark { background: color-mix(in srgb, var(--gold) 32%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.item-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font-size: 10.5px; font-weight: 650; }
.item-path { margin-left: auto; max-width: 65%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-family: var(--mono); font-size: 10.5px; }
.item-hits { color: var(--gold); font-size: 10.5px; font-weight: 650; }

.detail-pane { padding: 16px; position: sticky; top: 16px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-head h2 { font-size: 22px; overflow-wrap: anywhere; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin: 10px 0 12px; color: var(--muted); font-size: 11.5px; }
.detail-meta code { font-family: var(--mono); font-size: 10.5px; color: var(--ink-soft); }
.detail-body { max-height: 48vh; overflow: auto; padding: 2px 4px 2px 2px; scrollbar-width: thin; }
.detail-placeholder {
  display: grid; place-items: center; align-content: center; gap: 6px;
  min-height: 220px; padding: 20px; border: 1px dashed var(--line-strong); border-radius: var(--radius);
  color: var(--muted); background: color-mix(in srgb, var(--paper) 55%, transparent);
  text-align: center;
}
.detail-placeholder span { font-size: 26px; color: var(--accent); }
.detail-placeholder p { margin: 0; font-size: 13px; }

.markdown { color: var(--ink-soft); font-size: 13.5px; }
.markdown > *:first-child { margin-top: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { font-family: var(--serif); color: var(--ink); margin: 14px 0 6px; }
.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 18px; }
.markdown h3 { font-size: 16px; }
.markdown p { margin: 8px 0; }
.markdown ul, .markdown ol { margin: 8px 0; padding-left: 20px; }
.markdown li { margin: 2px 0; }
.markdown blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; color: var(--ink-soft); }
.markdown pre { margin: 9px 0; padding: 10px 12px; overflow: auto; border-radius: 8px; background: color-mix(in srgb, var(--ink) 6%, var(--paper)); border: 1px solid var(--line); }
.markdown code { font-family: var(--mono); font-size: 12px; }
.markdown :not(pre) > code { padding: 1px 5px; border-radius: 4px; background: color-mix(in srgb, var(--ink) 6%, var(--paper)); }
.markdown a { color: var(--accent); text-underline-offset: 2px; }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.markdown .md-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12.5px; }
.markdown .md-table th, .markdown .md-table td { border: 1px solid var(--line); padding: 5px 7px; text-align: left; vertical-align: top; }
.markdown .md-table th { background: var(--paper-soft); font-weight: 650; }

.raw { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 600; }
.raw pre { margin: 8px 0 0; max-height: 30vh; overflow: auto; padding: 10px; border-radius: 8px; background: color-mix(in srgb, var(--ink) 5%, var(--paper)); border: 1px solid var(--line); font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; overflow-wrap: anywhere; }

.empty {
  display: grid; justify-items: center; gap: 4px; padding: 26px 16px 22px; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--paper-soft);
}
.empty-mark { color: var(--accent); font-size: 26px; }
.empty h3 { margin: 2px 0 0; }
.empty p { margin: 2px 0 8px; color: var(--muted); font-size: 12.5px; max-width: 430px; }
.empty pre {
  width: 100%; max-width: 560px; margin: 0; padding: 10px; text-align: left; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
  color: var(--ink-soft); font-family: var(--mono); font-size: 11px; line-height: 1.5;
}
.inline-error { margin: 10px 2px 2px; color: var(--danger); font-size: 12.5px; }

.api-card {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px;
  margin-top: 16px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 86%, transparent); box-shadow: var(--shadow-soft);
}
.api-copy h2 { font-size: 19px; margin-bottom: 6px; }
.api-copy p { margin: 0; color: var(--muted); font-size: 12.5px; }
.api-copy code { font-family: var(--mono); font-size: 11px; color: var(--accent-ink); }
.api-fields { display: grid; gap: 8px; align-content: start; }
.api-row { display: flex; align-items: center; gap: 8px; }
.api-row label { flex: 0 0 58px; color: var(--muted); font-size: 11px; font-weight: 650; }
.api-row input { flex: 1 1 auto; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font-family: var(--mono); font-size: 11px; }
.api-row button { min-height: 34px; padding: 0 12px; }
.hint { margin: 0; color: var(--muted); font-size: 11.5px; }
#api-key-row[hidden] { display: none; }

.login-state {
  margin: 14px 0; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper); box-shadow: var(--shadow); text-align: left;
}
.login-state h2 { margin: 2px 0 8px; }
.login-state p { margin: 0 0 10px; color: var(--ink-soft); font-size: 13.5px; max-width: 720px; }
.login-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 10px; }

.footer {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 22px 0 4px; color: var(--muted); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
}
.footer i { width: 20px; height: 1px; background: var(--line-strong); }

/* 手机 / 嵌入卡片：单列；详情跟着列表走，不强行粘住。 */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board { grid-template-columns: minmax(0, 1fr); }
  .detail-pane { position: static; }
  .memory-list { max-height: none; }
  .detail-body { max-height: none; }
  .api-card { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .page { padding: 14px 12px 20px; }
  .topbar { align-items: flex-start; }
  .top-actions { width: 100%; justify-content: flex-start; }
  .brand-mark { width: 40px; height: 40px; }
  h1 { font-size: 25px; }
  .stats { gap: 8px; }
  .stats article { padding: 10px 11px; }
  .stats strong { font-size: 18px; }
  .searchbar { flex-wrap: wrap; padding: 10px; border-radius: 16px; }
  .search-icon { display: none; }
  .searchbar input { flex-basis: 100%; height: 36px; }
  .searchbar .primary { flex: 1 1 0; }
  .item-date { display: none; }
  .detail-head h2 { font-size: 20px; }
  .api-row { flex-wrap: wrap; }
  .api-row label { flex-basis: 100%; }
  .api-row input { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
