:root {
  --bg: #F4EFE6;
  --ink: #2B2A28;
  --muted: #8A847A;
  --accent: #C98B8B;
  --accent-ink: #9E5F5F;
  --line: #E2DACD;
  --card: #FAF7F1;
  --late: #B4645A;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sky-h: 230px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 300 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overflow-x: hidden;
}
a { color: var(--accent-ink); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); }
a:hover { border-bottom-color: var(--accent-ink); }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#dawn { position: fixed; inset: 0 0 auto 0; width: 100%; height: 100dvh; z-index: 0; pointer-events: none; }
.view { position: relative; z-index: 1; }

/* ── login ─────────────────────────────────────────── */
#login { min-height: 100dvh; display: grid; grid-template-rows: 1fr auto; padding: 0 16px; }
.login-box { align-self: end; width: min(360px, 100%); margin: 0 auto; padding-bottom: 12vh; text-align: center; }
.brand-big { font: 400 clamp(44px, 9vw, 64px)/1 var(--serif); letter-spacing: .01em; margin: 0 0 12px; }
.lede { color: var(--muted); margin: 0 0 32px; }
#login-form { display: grid; gap: 14px; text-align: left; }
#login-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, textarea {
  font: inherit; color: var(--ink); background: color-mix(in srgb, var(--card) 85%, transparent);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; outline: none;
  transition: border-color .2s, background .2s;
}
input:focus, textarea:focus { border-color: var(--accent); background: var(--card); }
.primary {
  background: var(--ink); color: var(--bg); border: 0; border-radius: 999px; padding: 11px 20px;
  font-weight: 400; letter-spacing: .02em; transition: background .2s, transform .15s;
}
.primary:hover { background: #45423e; }
.primary:active { transform: scale(.98); }
.primary.wide { width: 100%; }
.form-err { color: var(--late); min-height: 1.4em; margin: 0; font-size: 14px; text-align: center; }
.legal { text-align: center; font-size: 12px; color: var(--muted); padding: 16px 0 calc(16px + env(safe-area-inset-bottom)); margin: 0; }
.legal a { color: var(--muted); border: 0; }

/* ── app bar ───────────────────────────────────────── */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { background: none; border: 0; font: 400 20px/1 var(--serif); padding: 6px 0; }
.quiet {
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--ink);
}
.quiet:hover { border-color: var(--accent); }

/* ── main column ───────────────────────────────────── */
.col { width: min(680px, 100%); margin: 0 auto; padding: 0 16px 140px; }
.sky-space { height: var(--sky-h); }
#goal-head { text-align: center; margin-bottom: 26px; }
#goal-title { font: 400 clamp(26px, 5.4vw, 36px)/1.2 var(--serif); margin: 0; text-wrap: balance; }
#goal-sub { color: var(--muted); font-size: 14px; margin: 8px 0 0; min-height: 1.4em; }

/* steps */
#steps { list-style: none; padding: 0; margin: 0 0 34px; border-top: 1px solid var(--line); }
#steps:empty { display: none; }
.step { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start; padding: 12px 2px; border-bottom: 1px solid var(--line); animation: rise .5s ease both; }
.tick {
  width: 20px; height: 20px; margin-top: 2px; border-radius: 50%; border: 1px solid var(--muted); background: transparent; padding: 0;
  display: grid; place-items: center; transition: background .25s, border-color .25s;
}
.tick:hover { border-color: var(--accent-ink); }
.step.done .tick { background: var(--accent); border-color: var(--accent); }
.step.done .tick::after { content: ""; width: 8px; height: 4px; border: solid var(--bg); border-width: 0 0 1.5px 1.5px; transform: translateY(-1px) rotate(-45deg); }
.step-text { min-width: 0; overflow-wrap: anywhere; }
.step.done .step-text { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.step-when { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.step.late .step-when { color: var(--late); }
.step-tools { display: flex; gap: 2px; opacity: .55; transition: opacity .2s; }
.step:hover .step-tools, .step:focus-within .step-tools { opacity: 1; }
.icon-btn { background: none; border: 0; padding: 4px; color: var(--muted); border-radius: 6px; display: grid; place-items: center; }
.icon-btn:hover { color: var(--ink); background: var(--line); }
a.icon-btn { border: 0; }

/* thread */
#thread { display: grid; gap: 22px; }
.msg { animation: rise .45s ease both; }
.msg.user { justify-self: end; max-width: 85%; background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 4px 16px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.ai { max-width: 100%; overflow-wrap: anywhere; }
.msg.ai p { margin: 0 0 10px; }
.msg.ai p:last-child { margin-bottom: 0; }
.msg.ai ul, .msg.ai ol { margin: 0 0 10px; padding-left: 22px; }
.msg.ai li { margin: 3px 0; }
.msg.ai strong { font-weight: 500; }
.msg.ai h4 { font: 400 18px/1.3 var(--serif); margin: 12px 0 6px; }
.msg.ai .next { margin-top: 12px; padding-left: 12px; border-left: 2px solid var(--accent); }
.trace { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.trace .live { display: inline-block; }
.dots::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.msg.err { color: var(--late); font-size: 14px; }

/* cards */
.cards { display: grid; gap: 10px; margin-top: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.card-k { font-size: 12px; color: var(--muted); letter-spacing: .03em; margin: 0 0 6px; }
.draft-to { font-size: 14px; color: var(--muted); margin: 0 0 6px; overflow-wrap: anywhere; }
.draft-body { white-space: pre-wrap; margin: 0 0 10px; font-size: 15px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 14px; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 13px; color: var(--ink); }
.pill:hover { border-color: var(--accent); }
a.pill { border-bottom: 1px solid var(--line); }
.pill.go { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.place { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.place:first-of-type { border-top: 0; padding-top: 0; }
.place b { font-weight: 500; display: block; }
.place .meta { color: var(--muted); display: block; }
.place .links { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.wx { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; text-align: center; font-size: 12px; }
.wx b { display: block; font-weight: 400; color: var(--muted); }
.wx span { display: block; }
.sources { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; margin-top: 10px; }
.sources a { color: var(--muted); }

/* composer */
#composer {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 4;
  width: min(680px, 100%); padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: end;
  background: linear-gradient(to top, var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
}
#input { flex: 1; resize: none; max-height: 40vh; border-radius: 22px; padding: 12px 16px; line-height: 1.4; box-shadow: 0 1px 0 var(--line); }
#send { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); display: grid; place-items: center; transition: opacity .2s, transform .15s; }
#send:disabled { opacity: .35; cursor: default; }
#send:not(:disabled):active { transform: scale(.94); }

/* drawer */
#scrim { position: fixed; inset: 0; z-index: 8; background: rgba(43, 42, 40, .18); animation: fade .25s ease; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 9; width: min(340px, 88vw); overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--line); padding: calc(18px + env(safe-area-inset-top)) 18px 0;
  display: flex; flex-direction: column; gap: 22px;
  transform: translateX(105%); transition: transform .35s cubic-bezier(.2, .8, .2, 1);
}
#drawer.open { transform: none; }
#drawer h3 { font: 400 13px/1 var(--sans); color: var(--muted); letter-spacing: .04em; margin: 0 0 8px; }
#goal-list, #facts { list-style: none; margin: 0; padding: 0; }
#goal-list li button {
  width: 100%; text-align: left; background: none; border: 0; border-radius: 10px; padding: 9px 10px;
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
}
#goal-list li button:hover { background: var(--card); }
#goal-list li button.on { background: var(--card); box-shadow: inset 2px 0 0 var(--accent); }
#goal-list .g-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#goal-list .g-n { font-size: 12px; color: var(--muted); }
#goal-list li.gdone .g-t { color: var(--muted); }
#facts li { display: flex; justify-content: space-between; gap: 8px; align-items: start; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.row-btn { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 2px; font-size: 15px; color: var(--ink); }
a.row-btn { border-bottom: 1px solid var(--line); }
.row-btn:hover { color: var(--accent-ink); }
.row-btn.danger { color: var(--late); }
.drawer-foot { margin-top: auto; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } }

@media (max-width: 520px) {
  :root { --sky-h: 190px; }
  body { font-size: 15.5px; }
  .step-tools { opacity: 1; }
}

/* ── first-visit intro ─────────────────────────────── */
#intro { position: fixed; inset: 0; z-index: 20; display: grid; place-items: end center; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(244,239,230,.96) 45%, rgba(244,239,230,.55)); animation: fade .35s ease; }
.intro-card { position: relative; width: min(440px, 100%); margin-bottom: 6vh; background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  padding: 30px 26px 22px; text-align: center; box-shadow: 0 18px 50px -24px rgba(43,42,40,.25); }
.intro-skip { position: absolute; top: 12px; right: 12px; font-size: 13px; padding: 4px 10px; }
.intro-glyph { height: 56px; display: grid; place-items: center; color: var(--accent-ink); margin-bottom: 10px; }
.intro-glyph svg { animation: rise .5s ease both; }
#intro h2 { font: 400 26px/1.2 var(--serif); margin: 0 0 10px; }
#intro p { margin: 0 auto; max-width: 34ch; color: #55514b; min-height: 4.7em; animation: rise .45s ease both; }
.intro-dots { display: flex; justify-content: center; gap: 7px; margin: 18px 0 18px; }
.intro-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--line); transition: background .3s, transform .3s; }
.intro-dots span.on { background: var(--accent); transform: scale(1.35); }
.intro-nav { display: flex; justify-content: space-between; gap: 10px; }
.intro-nav .primary { flex: 1; }
.intro-nav .pill[disabled] { visibility: hidden; }
