:root {
  --bg: #FBF8F3; --bg-elev: #F2EEE6; --bg-sunken: #EEEADF;
  --bubble: #ECDFCC; --text: #3A3530; --text-2: #776B5D;
  --text-3: #AB9F8E; --text-4: #C8BEAE; --border: #DFD8C9;
  --border-soft: #E8E1D3; --accent: #A77852; --accent-soft: #EDDFC8;
  --online: #6EB287; --warn: #C68A4A; --danger: #B95C4C;
  --scrim: rgba(0,0,0,.32); --overlay: rgba(0,0,0,.40);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Helvetica Neue", sans-serif;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
[data-theme="dark"] {
  --bg: #2A2421; --bg-elev: #332B26; --bg-sunken: #312A25;
  --bubble: #42362E; --text: #F0EAE0; --text-2: #B8AC9C;
  --text-3: #8C8073; --text-4: #6B6157; --border: #42362E;
  --border-soft: #3A312B; --accent: #D9AF7E; --accent-soft: #544237;
  --online: #90C8A4; --warn: #D9A36A; --danger: #D5826F;
  --scrim: rgba(0,0,0,.32); --overlay: rgba(0,0,0,.40);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-family: var(--font); font-weight: 400; -webkit-font-smoothing: antialiased; text-wrap: pretty; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
.app-shell { width: min(100%, 520px); min-height: 100dvh; margin: 0 auto; position: relative; background: var(--bg); }
.page { min-height: 100dvh; padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom)); }
.page.subpage { padding-bottom: 28px; }
.topbar { height: 54px; display: flex; align-items: center; padding: 0 18px; position: sticky; top: 0; z-index: 8; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(14px); }
.topbar-title { flex: 1; text-align: center; font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: 1.5px; }
.topbar-title.left { text-align: left; font-size: 24px; line-height: 32px; letter-spacing: 1px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--text-2); border-radius: 50%; }
.icon-btn svg, .tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.online { display: inline-block; width: 7px; height: 7px; margin-left: 7px; border-radius: 50%; background: var(--online); }
.content { padding: 0 24px; }
.tabbar { position: fixed; z-index: 10; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 520px); height: calc(84px + env(safe-area-inset-bottom)); padding: 10px 24px calc(30px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bg); border-top: 1px solid var(--border-soft); }
.tab { min-width: 56px; color: var(--text-3); display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10.5px; letter-spacing: .5px; }
.tab.active { color: var(--accent); }
.greeting { padding-top: 38px; font-size: 22px; line-height: 33px; font-weight: 500; letter-spacing: .2px; }
.days-wrap { margin-top: 56px; text-align: center; }
.days { font: 400 56px/1 var(--serif); letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.days-label { margin-top: 10px; color: var(--text-3); font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }
.home-stack { margin-top: 70px; display: grid; gap: 18px; }
.card { padding: 16px; background: var(--bg-elev); border-radius: 16px; }
.card-label, .group-label { color: var(--text-3); font-size: 11px; line-height: 14px; font-weight: 500; letter-spacing: 2px; text-transform: uppercase; }
.card-title { margin-top: 8px; font-size: 14.5px; line-height: 22px; letter-spacing: .3px; }
.card-copy { margin-top: 5px; color: var(--text-2); font-size: 13px; line-height: 20px; }
.anniversary { display: flex; align-items: center; gap: 14px; }
.anniversary-number { font: 400 24px/1 var(--serif); color: var(--accent); min-width: 28px; text-align: center; }
.context-bar { height: 2px; background: var(--border-soft); position: sticky; top: 54px; z-index: 9; }
.context-fill { height: 100%; background: color-mix(in srgb, var(--text-3) 50%, transparent); transition: width .2s; }
.context-fill.warn { background: color-mix(in srgb, var(--warn) 85%, transparent); }
.context-fill.full { background: var(--warn); animation: breathe 8s infinite; }
@keyframes breathe { 50% { opacity: .85; } }
.chat-page { height: 100dvh; padding-bottom: 0; display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; max-width: 260px; text-align: center; color: var(--text-3); font-size: 13px; line-height: 1.7; }
.message { max-width: 86%; display: flex; flex-direction: column; gap: 4px; animation: rise .2s ease-out; }
.message.user { align-self: flex-end; max-width: 78%; align-items: flex-end; }
.bubble { font-size: 15px; line-height: 24px; letter-spacing: .2px; white-space: pre-wrap; word-break: break-word; }
.user .bubble { padding: 11px 15px; background: var(--bubble); border-radius: 18px 6px 18px 18px; }
.assistant .bubble { padding: 2px 0; }
.message-time { color: var(--text-3); font-size: 10.5px; line-height: 14px; letter-spacing: .5px; font-variant-numeric: tabular-nums; }
.thought-summary { color: var(--text-3); font-size: 12px; line-height: 16px; display: flex; align-items: center; gap: 5px; padding: 4px 0; }
.thought-body { border-left: 1px solid var(--border); margin-left: 4px; padding-left: 8px; color: var(--text-2); font-size: 12.5px; line-height: 19px; white-space: pre-wrap; }
.tool-tag { font: 400 10.5px/1.5 var(--mono); background: var(--bg-elev); padding: 1px 6px; border-radius: 4px; color: var(--text-2); }
.composer { border-top: 1px solid var(--border-soft); padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer-row { display: flex; align-items: flex-end; gap: 2px; }
.composer textarea { flex: 1; min-height: 32px; max-height: 112px; resize: none; overflow-y: auto; padding: 6px 14px; margin: 0 4px; border: 0; outline: 0; border-radius: 16px; background: var(--bg-sunken); font-size: 14.5px; line-height: 20px; }
.composer textarea::placeholder { color: var(--text-3); }
.composer .small-btn { width: 32px; height: 32px; color: var(--text-2); display: grid; place-items: center; font-size: 22px; }
.send-btn { color: var(--accent) !important; }
.send-btn:disabled { opacity: .35; }
.memory-tabs { display: flex; padding: 0 24px 14px; gap: 20px; }
.memory-tab { font-size: 13.5px; color: var(--text-3); padding-bottom: 7px; }
.memory-tab.active { color: var(--text); border-bottom: 1px solid var(--accent); }
.searchbox { width: 100%; height: 44px; border: 0; outline: 0; border-radius: 14px; padding: 0 16px; background: var(--bg-sunken); color: var(--text); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0; scrollbar-width: none; }
.chip { flex: none; min-height: 36px; padding: 7px 14px; border-radius: 999px; background: var(--bg-sunken); color: var(--text-2); font-size: 13.5px; letter-spacing: .5px; }
.chip.active { background: var(--text); color: var(--bg); }
.section-title { margin: 22px 0 8px; color: var(--text-3); font-size: 10.5px; letter-spacing: 2.5px; text-transform: uppercase; }
.bucket { position: relative; padding: 14px 0 14px 8px; border-bottom: 1px solid var(--border-soft); }
.bucket::before { content: ""; position: absolute; left: 0; top: 18px; bottom: 18px; width: 2px; border-radius: 1px; background: var(--accent); opacity: .55; }
.bucket-title { font-size: 14.5px; line-height: 22px; }
.mood-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-left: 6px; background: #D8A170; }
.bucket-meta { margin-top: 6px; color: var(--text-3); font-size: 11px; }
.tag { display: inline-block; margin: 6px 4px 0 0; padding: 1px 7px; border-radius: 3px; background: var(--bg-elev); color: var(--text-3); font-size: 10.5px; }
.trend { height: 106px; margin: 8px 0 22px; }
.archive { padding: 14px 0 14px 18px; border-left: 1px solid var(--border); position: relative; }
.archive::before { content: ""; position: absolute; left: -3px; top: 20px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.archive-title { font-size: 14.5px; }
.archive-copy { margin-top: 5px; color: var(--text-2); font-size: 13px; line-height: 20px; }
.settings-group { margin-top: 18px; }
.settings-group .group-label { padding: 0 28px 8px; }
.setting-row { min-height: 50px; padding: 14px 24px; display: flex; align-items: center; border-top: 1px solid var(--border-soft); }
.setting-row:last-child { border-bottom: 1px solid var(--border-soft); }
.setting-label { font-size: 14.5px; letter-spacing: .3px; }
.setting-value { margin-left: auto; color: var(--text-3); font-size: 13px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { margin-left: 8px; color: var(--text-3); }
.segmented { margin-left: auto; display: flex; padding: 3px; border-radius: 10px; background: var(--bg-sunken); }
.segmented button { min-width: 48px; padding: 8px 9px; border-radius: 8px; color: var(--text-2); font-size: 13px; }
.segmented button.active { background: var(--bg); }
.field { padding: 14px 24px 6px; }
.field label { display: block; color: var(--text-3); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; }
.field input, .field textarea, .field select { width: 100%; border: 0; border-bottom: 1px solid var(--border); outline: 0; padding: 10px 0; background: transparent; font: 13px/20px var(--mono); }
.field textarea { min-height: 150px; resize: vertical; font-family: var(--font); }
.primary { width: calc(100% - 48px); height: 48px; margin: 24px; border-radius: 24px; background: var(--text); color: var(--bg); }
.dashed { width: calc(100% - 44px); height: 46px; margin: 24px 22px 0; border: 1px dashed var(--border); border-radius: 14px; color: var(--text-2); }
.drawer-scrim, .overlay-scrim { position: fixed; inset: 0; z-index: 30; background: var(--scrim); }
.drawer { position: fixed; z-index: 31; inset: 0 auto 0 0; width: min(296px, 75vw); padding-top: calc(54px + env(safe-area-inset-top)); background: var(--bg-elev); box-shadow: 0 0 40px rgba(0,0,0,.12); animation: drawer-in .24s cubic-bezier(.2,.8,.2,1); }
.drawer-new { height: 44px; margin: 14px 18px 18px; width: calc(100% - 36px); border: 1px dashed var(--border); border-radius: 14px; }
.conversation-item { padding: 12px 22px; }
.conversation-item.active { background: var(--bg-sunken); }
.conversation-title { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-meta { margin-top: 3px; color: var(--text-3); font-size: 10.5px; }
.sheet { position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; max-width: 520px; margin: auto; padding-bottom: 30px; background: var(--bg-elev); border-radius: 24px 24px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.18); animation: sheet-in .28s cubic-bezier(.2,.8,.2,1); }
.grab { width: 38px; height: 4px; margin: 10px auto 4px; border-radius: 2px; background: var(--border); }
.sheet-title { padding: 14px 24px; color: var(--text-3); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; }
.sheet-row { min-height: 48px; padding: 14px 24px; border-top: 1px solid var(--border-soft); display: flex; align-items: center; gap: 12px; }
.danger { color: var(--danger); }
.token-modal { position: fixed; z-index: 60; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--overlay); }
.token-card { width: min(100%, 380px); padding: 24px; border-radius: 16px; background: var(--bg-elev); box-shadow: 0 8px 30px rgba(0,0,0,.22); }
.token-card h1 { margin: 0; font-size: 24px; font-weight: 500; letter-spacing: 1px; }
.token-card p { color: var(--text-2); font-size: 13px; line-height: 20px; }
.token-card input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 12px; outline: 0; background: var(--bg-sunken); font-family: var(--mono); font-size: 12px; }
.toast { position: fixed; z-index: 70; left: 50%; bottom: 110px; transform: translateX(-50%); padding: 10px 16px; border-radius: 14px; background: var(--text); color: var(--bg); font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.18); }
.spinner-text { padding: 48px 24px; text-align: center; color: var(--text-3); font-size: 13px; }
@keyframes rise { from { transform: translateY(7px); opacity: 0; } }
@keyframes drawer-in { from { transform: translateX(-100%); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
