:root {
  --bg: #f6f4ee; --surface: #fffdf8; --surface-2: #efede5; --line: #e3dfd3;
  --text: #2c3630; --muted: #6c766f; --faint: #9aa29b;
  --sage: #6f8f77; --sage-deep: #4d6a56; --sage-soft: #dfe8dd; --sage-tint: #eef3ec;
  --lav: #e4e0f1; --peach: #f6e2d6; --sky: #dcebee; --sand: #f1ead9; --rose: #f3dcdc;
  --warn-bg: #fbeee4; --warn: #9a4f2a; --danger: #a84545;
  --shadow: 0 1px 2px rgba(44,54,48,.05), 0 8px 24px rgba(44,54,48,.06);
  --r: 18px; --r-sm: 12px;
  --serif: "New York", ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141815; --surface: #1c211d; --surface-2: #232a25; --line: #2e3630;
    --text: #e6ebe5; --muted: #a2aca4; --faint: #77817a;
    --sage: #93b29a; --sage-deep: #b5cfb9; --sage-soft: #2b3a2f; --sage-tint: #212b24;
    --lav: #2d2b3b; --peach: #3a2e27; --sky: #23333a; --sand: #2f2c24; --rose: #3a2828;
    --warn-bg: #3a2a20; --warn: #f0b48f; --danger: #e48f8f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141815; --surface: #1c211d; --surface-2: #232a25; --line: #2e3630;
  --text: #e6ebe5; --muted: #a2aca4; --faint: #77817a;
  --sage: #93b29a; --sage-deep: #b5cfb9; --sage-soft: #2b3a2f; --sage-tint: #212b24;
  --lav: #2d2b3b; --peach: #3a2e27; --sky: #23333a; --sand: #2f2c24; --rose: #3a2828;
  --warn-bg: #3a2a20; --warn: #f0b48f; --danger: #e48f8f;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.08rem; }
p { margin: 0 0 .8em; }
a { color: var(--sage-deep); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .tiny { font-size: .78rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 14px; }
.grow { flex: 1; min-width: 0; }

/* layout */
.app { min-height: 100dvh; display: flex; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(14px + env(safe-area-inset-top)) 0 10px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand img { width: 34px; height: 34px; border-radius: 10px; }
.brand span { font-family: var(--serif); font-size: 1.35rem; letter-spacing: .02em; }
.sos { font-size: .82rem; text-decoration: none; color: var(--warn); background: var(--warn-bg); padding: 6px 12px; border-radius: 999px; white-space: nowrap; }
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.navlink { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--faint); font-size: .7rem; padding: 6px 0; border-radius: 12px; }
.navlink svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.navlink.on { color: var(--sage-deep); }
.navlink.on svg { stroke-width: 2.1; }
@media (min-width: 900px) {
  .bottomnav { display: none; }
  .side { display: flex; flex-direction: column; gap: 4px; width: 232px; padding: 28px 16px; position: sticky; top: 0; height: 100dvh; border-right: 1px solid var(--line); background: var(--surface); }
  .side .brand { margin: 0 8px 22px; }
  .side .navlink { flex-direction: row; gap: 12px; font-size: .95rem; padding: 10px 12px; color: var(--muted); }
  .side .navlink.on { background: var(--sage-tint); }
  .side .sos { margin-top: auto; text-align: center; }
  .topbar .brand, .topbar .sos { display: none; }
  .main { padding: 18px 32px 60px; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.card.soft { background: var(--sage-tint); border-color: transparent; box-shadow: none; }
.card.tint-lav { background: var(--lav); border-color: transparent; box-shadow: none; }
.card.tint-peach { background: var(--peach); border-color: transparent; box-shadow: none; }
.card.tint-sky { background: var(--sky); border-color: transparent; box-shadow: none; }
.card.warn { background: var(--warn-bg); border-color: transparent; color: var(--text); }
.card h3 { margin-bottom: 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; background: var(--sage-deep); color: #fff; padding: 11px 18px; border-radius: 999px; cursor: pointer; text-decoration: none; font-weight: 500; min-height: 44px; }
:root[data-theme="dark"] .btn:not(.ghost):not(.line), .btn.primary-dark { color: #101410; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:not(.ghost):not(.line) { color: #101410; } }
.btn.ghost { background: transparent; color: var(--sage-deep); }
.btn.line { background: transparent; color: var(--text); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 10px; cursor: pointer; min-width: 40px; min-height: 40px; }
.iconbtn:hover { background: var(--surface-2); }
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], textarea, select {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; font-size: 16px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--sage); }
textarea { resize: vertical; line-height: 1.7; }
textarea.writer { min-height: 46vh; border: 0; background: transparent; padding: 4px 0; font-family: var(--serif); font-size: 1.12rem; }
input.title-in { border: 0; background: transparent; padding: 4px 0; font-family: var(--serif); font-size: 1.4rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: .9rem; }
.chip.on { background: var(--sage-soft); border-color: var(--sage); color: var(--sage-deep); }
.scale { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.scale button { min-width: 0; padding: 0; height: 40px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; cursor: pointer; font-weight: 500; font-size: .92rem; }
@media (min-width: 560px) { .scale { gap: 6px; } .scale button { height: 46px; } }
.scale button.on { background: var(--sage); border-color: var(--sage); color: #fff; }
.faces { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.faces button { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 10px 2px; cursor: pointer; font-size: .72rem; line-height: 1.2; min-width: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.faces button svg { width: 30px; height: 30px; }
.faces button.on { border-color: var(--sage); background: var(--sage-tint); color: var(--sage-deep); }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.item:hover { border-color: var(--sage); }
.item .meta { font-size: .8rem; color: var(--faint); display: flex; gap: 8px; flex-wrap: wrap; }
.item .t { font-family: var(--serif); font-size: 1.08rem; margin: 2px 0; }
.item .ex { color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tag { display: inline-block; font-size: .74rem; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.sage { background: var(--sage-soft); color: var(--sage-deep); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.hero { padding: 8px 0 4px; }
.hero h1 { font-size: 1.9rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action { display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: var(--r); text-decoration: none; color: var(--text); min-height: 96px; }
.action svg { width: 26px; height: 26px; stroke: var(--sage-deep); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.action b { font-weight: 500; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 26px 0 10px; }
.section-title h2 { margin: 0; font-size: 1.15rem; }
.section-title a { font-size: .88rem; text-decoration: none; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 999px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem; z-index: 50; max-width: calc(100% - 32px); }
.modal-bg { position: fixed; inset: 0; background: rgba(20,24,21,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 620px; max-height: 92dvh; overflow: auto; border-radius: 24px 24px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 24px; } }
.banner { background: var(--lav); border-radius: var(--r-sm); padding: 10px 14px; font-size: .88rem; margin-bottom: 12px; }

/* prose (AI output) */
.prose { font-size: 1rem; line-height: 1.75; }
.prose h2, .prose h3 { font-size: 1.08rem; margin: 1.1em 0 .4em; color: var(--sage-deep); }
.prose ul, .prose ol { padding-left: 1.2em; margin: 0 0 .8em; }
.prose li { margin: .2em 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.ai-label { font-size: .75rem; color: var(--faint); display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }
.msg { max-width: 88%; padding: 12px 16px; border-radius: 20px; white-space: normal; }
.msg.user { align-self: flex-end; background: var(--sage-soft); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.composer { position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); background: var(--bg); padding: 10px 0; display: flex; gap: 8px; align-items: flex-end; }
@media (min-width: 900px) { .composer { bottom: 0; } }
.composer textarea { min-height: 48px; max-height: 40vh; border-radius: 22px; padding: 12px 16px; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; } }
.modes { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 560px) { .modes { grid-template-columns: 1fr 1fr; } }
.mode { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 12px 14px; cursor: pointer; }
.mode.on { border-color: var(--sage); background: var(--sage-tint); }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--faint); font-size: 10px; font-family: var(--sans); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { stroke: var(--sage); stroke-width: 2.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.chart .area { fill: var(--sage-soft); opacity: .6; }
.chart .dot { fill: var(--surface); stroke: var(--sage-deep); stroke-width: 2; }
.chart .bar { fill: var(--sage); }
.bars { display: flex; flex-direction: column; gap: 8px; }
.barrow { display: grid; grid-template-columns: 110px 1fr 28px; gap: 10px; align-items: center; font-size: .88rem; }
.barrow .track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.barrow .fill { height: 100%; background: var(--sage); border-radius: 999px; }
.stat { display: flex; flex-direction: column; }
.stat b { font-family: var(--serif); font-size: 1.7rem; font-weight: 500; }
.stat span { font-size: .8rem; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; font-size: .85rem; }
.cal .h { color: var(--faint); font-size: .72rem; padding: 4px 0; }
.cal button { aspect-ratio: 1; border: 0; background: transparent; border-radius: 10px; cursor: pointer; position: relative; }
.cal button.has { background: var(--sage-soft); color: var(--sage-deep); font-weight: 600; }
.cal button.sel { outline: 2px solid var(--sage); }
.cal button.today { text-decoration: underline; }

/* auth */
.auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth .box { width: 100%; max-width: 400px; }
.auth .logo { width: 72px; height: 72px; border-radius: 20px; display: block; margin: 0 auto 14px; }
.auth h1 { text-align: center; font-size: 2.2rem; margin-bottom: 4px; letter-spacing: .04em; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 22px; }
.err { color: var(--danger); font-size: .9rem; min-height: 1.2em; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t td, table.t th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; user-select: all; word-break: break-all; }

.chips.collapsed > .chip:nth-child(n+9) { display: none; }
.more { border: 0; background: transparent; color: var(--sage-deep); cursor: pointer; padding: 6px 4px; font-size: .9rem; }
.iconbtn svg, .btn svg, .ai-label svg, .item .meta svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ai-label svg, .item .meta svg { width: 15px; height: 15px; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; }
input[type=checkbox] { accent-color: var(--sage-deep); width: 20px; height: 20px; flex: none; }
