:root {
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --text: #2a2723;
  --muted: #8a837a;
  --faint: #b9b2a7;
  --line: #e7e1d7;
  --accent: #4f5d78;
  --accent-text: #fffdf9;
  --mirror: #eceff4;
  --mirror-line: #d9dee8;
  --mine: #e9e4da;
  --danger: #b0503f;
  --shadow: 0 1px 2px rgba(60, 50, 40, .06), 0 4px 16px rgba(60, 50, 40, .05);
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --tabbar: 56px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --surface: #201f1c;
    --text: #ebe6dd;
    --muted: #958e83;
    --faint: #5d5850;
    --line: #2f2d29;
    --accent: #a3b2d0;
    --accent-text: #171614;
    --mirror: #1d2129;
    --mirror-line: #2b3240;
    --mine: #2b2925;
    --danger: #e08a78;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
[hidden] { display: none !important; }

/* ---------- page frame ---------- */

#view {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--top) + 12px) 16px calc(var(--tabbar) + var(--bottom) + 24px);
}
.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 14px;
}
.page-head h1 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: .02em; }
.page-head .sub { color: var(--muted); font-size: 14px; }

#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px calc(var(--bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
  z-index: 10;
}
#tabbar a {
  flex: 0 1 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 0;
  font-size: 11px;
  color: var(--muted);
}
#tabbar a.active { color: var(--text); font-weight: 600; }
.tab-icon svg {
  display: block;
  width: 23px; height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
body.typing #tabbar { display: none; }

/* ---------- buttons ---------- */

.btn {
  border: 0;
  border-radius: 999px;
  padding: 9px 18px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 15px;
}
.btn:disabled { opacity: .35; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.block { display: block; width: 100%; padding: 12px; }
.link {
  border: 0; background: none; padding: 4px 0;
  color: var(--accent); font-size: 14px;
}

/* ---------- composer ---------- */

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 12px 10px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}
.composer textarea {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 40vh;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 17px;
  line-height: 1.6;
}
.composer textarea::placeholder { color: var(--faint); }
.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  min-height: 36px;
}
.composer-foot .hint { color: var(--faint); font-size: 13px; }
.outbox { margin: 4px 2px 0; color: var(--muted); font-size: 13px; }
.outbox .note-row { opacity: .6; }

/* ---------- days & notes ---------- */

.day { margin-top: 26px; }
.day-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 2px 6px;
}
.day-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.day-head .date { color: var(--muted); font-size: 13px; }

.note-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
}
.note-row:last-child { border-bottom: 0; }
.note-row:active { background: color-mix(in srgb, var(--line) 50%, transparent); }
.note-time {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}
.note-text { font-size: 16.5px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty-day { color: var(--faint); font-size: 14px; padding: 6px 2px; }

/* ---------- the mirror (daily reflection) ---------- */

.mirror {
  margin-top: 10px;
  background: var(--mirror);
  border: 1px solid var(--mirror-line);
  border-radius: 16px;
  padding: 16px 16px 12px;
}
.mirror-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .12em;
  margin-bottom: 8px;
}
.mirror-label::before {
  content: "";
  width: 9px; height: 12px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
}
.mirror-body {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.85;
  white-space: pre-wrap;
}
.questions { margin-top: 14px; }
.questions-label { color: var(--muted); font-size: 12px; letter-spacing: .12em; margin-bottom: 6px; }
.question {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  border: 0;
  border-top: 1px solid var(--mirror-line);
  background: none;
  padding: 11px 0;
  font-size: 15.5px;
  line-height: 1.6;
}
.question::after { content: "›"; margin-left: auto; color: var(--muted); font-size: 20px; line-height: 1.2; }
.mirror-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12.5px;
}
.mirror-pending {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px dashed var(--mirror-line);
  border-radius: 14px;
  color: var(--muted);
  font-size: 14px;
}
.thinking { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.load-more { display: block; margin: 28px auto 0; }

/* ---------- conversations list ---------- */

.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-item {
  display: block;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.chat-item .title { font-weight: 600; font-size: 16px; line-height: 1.5; }
.chat-item .last {
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-item .meta { color: var(--faint); font-size: 12px; margin-top: 4px; }
.empty {
  color: var(--muted);
  text-align: center;
  padding: 48px 24px;
  font-size: 15px;
  line-height: 1.8;
}

/* ---------- a conversation ---------- */

.chat {
  position: fixed;
  left: 0; right: 0; top: 0;
  height: var(--vvh, 100dvh);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--top) + 6px) 8px 8px;
  border-bottom: 1px solid var(--line);
}
.chat-head .title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.icon-btn {
  border: 0;
  background: none;
  width: 40px; height: 40px;
  font-size: 24px;
  line-height: 1;
  color: var(--accent);
  flex: none;
}
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.chat-inner { max-width: 640px; margin: 0 auto; padding: 16px 16px 8px; }
.seed {
  border-left: 3px solid var(--mirror-line);
  padding: 4px 0 4px 12px;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  white-space: pre-wrap;
}
.msg { margin: 0 0 16px; display: flex; }
.msg .bubble { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.75; }
.msg.assistant .bubble { font-family: var(--serif); font-size: 16.5px; max-width: 100%; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--mine);
  border-radius: 18px 18px 4px 18px;
  padding: 9px 14px;
  max-width: 85%;
  font-size: 16px;
}
.msg-error {
  color: var(--danger);
  font-size: 14px;
  margin: -6px 0 16px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.chat-compose {
  border-top: 1px solid var(--line);
  padding: 8px 12px calc(var(--bottom) + 8px);
  background: var(--bg);
}
.chat-compose form {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-compose textarea {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  padding: 9px 14px;
  font-size: 16px;
  line-height: 1.5;
  max-height: 30vh;
  resize: none;
  outline: 0;
}
.chat-compose .btn { padding: 9px 16px; }

/* ---------- settings ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 4px 16px;
  margin-bottom: 16px;
}
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.row:last-child { border-bottom: 0; }
.row .value { color: var(--muted); text-align: right; overflow-wrap: anywhere; }
.card p { font-size: 14.5px; color: var(--muted); margin: 12px 0; }
.section-label { color: var(--muted); font-size: 13px; margin: 0 4px 8px; }
.model-settings { padding: 16px; }
.model-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.model-preset { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 8px; text-align: left; cursor: pointer; }
.model-preset strong { display: block; margin-bottom: 5px; }
.model-preset span { display: block; color: var(--muted); font-size: 12px; line-height: 1.5; }
.model-preset.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.model-details summary { cursor: pointer; font-size: 14px; padding: 8px 0; }
.model-row { align-items: center; }
.model-row select { min-width: 0; max-width: 60%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 16px; }
.model-status { min-height: 22px; }

/* ---------- login ---------- */

.login {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 340px;
  margin: 0 auto;
}
.login h1 { font-size: 34px; margin: 0 0 4px; font-weight: 650; }
.login p { color: var(--muted); margin: 0 0 28px; }
.login input {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 17px;
  margin-bottom: 12px;
  outline: 0;
}
.login .error { color: var(--danger); font-size: 14px; min-height: 22px; margin-top: 8px; }

/* ---------- sheet & toast ---------- */

#sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 15, .35);
  z-index: 20;
}
#sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(var(--bottom) + 16px);
  z-index: 21;
  max-height: 85vh;
  overflow-y: auto;
}
.sheet-quote {
  color: var(--muted);
  font-size: 14px;
  padding: 10px 4px 12px;
  border-bottom: 1px solid var(--line);
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sheet-action {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 15px 4px;
  text-align: left;
  font-size: 17px;
  border-bottom: 1px solid var(--line);
}
.sheet-action:last-child { border-bottom: 0; }
.sheet-action.danger { color: var(--danger); }
.sheet-action.muted { color: var(--muted); }
.sheet-edit textarea {
  width: 100%;
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg);
  font-size: 17px;
  line-height: 1.6;
  resize: vertical;
  margin: 8px 0 12px;
  outline: 0;
}
.sheet-buttons { display: flex; gap: 10px; justify-content: flex-end; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar) + var(--bottom) + 16px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 30;
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  .thinking { animation: none; }
}

/* ---------- deep exploration ---------- */

.head-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 15px;
  padding: 8px 6px;
  flex: none;
}
.assistant-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  max-width: 100%;
}
.analysis-toggle {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 0 0;
}
.analysis {
  margin-top: 8px;
  padding: 10px 14px 12px;
  border-left: 2px solid var(--mirror-line);
  background: var(--mirror);
  border-radius: 0 12px 12px 0;
  font-size: 14px;
  line-height: 1.65;
  align-self: stretch;
}
.analysis ul { margin: 0; padding-left: 1.1em; }
.analysis li { margin: 2px 0; }
.analysis-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
  margin: 10px 0 2px;
}
.analysis-terms { color: var(--muted); font-size: 12.5px; }
.analysis-sub { display: block; color: var(--muted); font-size: 13px; }

.distill {
  margin: 4px 0 20px;
  padding: 14px 16px;
  border: 1px dashed var(--mirror-line);
  border-radius: 14px;
  background: var(--mirror);
  color: var(--muted);
  font-size: 14px;
}
.distill-label { color: var(--muted); font-size: 12px; letter-spacing: .12em; margin-bottom: 4px; }
.distill-body + .distill-label { margin-top: 14px; }
.distill-body, .take-away {
  color: var(--text);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.take-away { font-weight: 600; }
.closed-banner {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  margin: 0 0 16px;
}

.notes-sheet h3 { margin: 10px 4px 2px; font-size: 18px; }
.notes-label { color: var(--muted); font-size: 12.5px; letter-spacing: .08em; margin: 18px 4px 4px; }
.notes-question {
  margin: 0 4px;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.6;
}
.notes-text {
  margin: 0 4px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.notes-list { margin: 0; padding-left: 1.5em; font-size: 15px; line-height: 1.7; }
.notes-empty { color: var(--muted); font-size: 15px; line-height: 1.8; margin: 14px 4px; }
.notes-sheet .btn.block { margin-top: 22px; }

.chat-item.closed .title { color: var(--muted); font-weight: 500; }
.list-label { margin-top: 28px; }

/* ---------- clues ---------- */

.clues { margin-bottom: 8px; }
.clues-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 2px 10px;
}
.clues-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.clues-meta { flex: 1; color: var(--muted); font-size: 13px; }
.clue-cards { display: flex; flex-direction: column; gap: 10px; }
.clue-card {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--mirror-line);
  background: var(--mirror);
  border-radius: 14px;
  padding: 12px 14px 10px;
}
.clue-card:active { opacity: .8; }
.clue-title { font-weight: 650; font-size: 16px; line-height: 1.5; }
.clue-question {
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.65;
}
.clue-meta { margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.clues-empty {
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.8;
  padding: 12px 14px;
  border: 1px dashed var(--mirror-line);
  border-radius: 14px;
}
.empty.small { padding: 20px 12px; font-size: 14px; }

.clue-sheet h3 { margin: 10px 4px 6px; font-size: 19px; }
.clue-description {
  margin: 0 4px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
}
.clue-start { margin: 18px 0 6px; }
.clue-note { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.clue-note:last-of-type { border-bottom: 0; }
.clue-note-date { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.clue-note-text { font-size: 15.5px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.clue-sheet .btn.ghost.block { margin-top: 16px; }
