:root {
  --bg: #f3f5f1; --surface: #ffffff; --ink: #17201c; --muted: #5b6a62; --line: #dbe2da;
  --accent: #1d6a4e; --accent-ink: #ffffff; --accent-soft: #e2efe7; --me: #1d6a4e; --me-ink: #ffffff;
  --gap: #fff0bf; --gap-ink: #5e4500; --danger: #a3392b; --focus: #2c8d67;
  --radius: 16px; --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412; --surface: #17201c; --ink: #e5ebe7; --muted: #98a69e; --line: #26312c;
    --accent: #5bbf92; --accent-ink: #0a1912; --accent-soft: #1c2d25; --me: #2b7658; --me-ink: #ffffff;
    --gap: #4a390b; --gap-ink: #ffe08a; --danger: #ff8b7b; --focus: #7dd3ac; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.noscript { padding: 24px; }

/* buttons */
.primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px;
  padding: 12px 18px; font-weight: 650; min-height: 48px; cursor: pointer;
}
.primary[disabled] { opacity: .6; cursor: default; }
.primary.wide { width: 100%; }
.as-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.secondary {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; min-height: 48px; cursor: pointer; color: var(--ink);
}
.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }
.icon-btn, .back {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; flex: none;
  color: var(--ink); background: none; border: 0; text-decoration: none; cursor: pointer;
}
.icon-btn:hover, .back:hover { background: var(--accent-soft); }

/* sign in */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 22px calc(24px + env(safe-area-inset-bottom));
}
.login-card { width: 100%; max-width: 420px; }
.login-mark { width: 64px; height: 64px; display: block; margin-bottom: 18px; }
.login h1 { font-size: 34px; line-height: 1.1; margin: 0 0 14px; letter-spacing: -.02em; }
.lede { font-size: 20px; font-weight: 650; margin: 0 0 8px; line-height: 1.35; }
.login p { margin: 0 0 8px; }
.login-form { margin-top: 26px; display: grid; gap: 12px; }
.login-form input {
  width: 100%; font-size: 18px; padding: 13px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); min-height: 50px;
}
.form-err { color: var(--danger); min-height: 1.5em; margin: 0; }
.fine { color: var(--muted); font-size: 14px; margin-top: 34px !important; }

/* home */
.home {
  max-width: 680px; margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}
.home-top { display: flex; gap: 14px; align-items: center; margin: 8px 4px 20px; }
.home-mark { width: 46px; height: 46px; flex: none; }
.home h1 { font-size: 28px; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 15px; line-height: 1.35; }
.organs { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.organ-card {
  display: flex; align-items: center; gap: 14px; padding: 13px 14px; min-height: 74px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.organ-card:active { transform: scale(.99); }
.organ-emoji {
  font-size: 28px; width: 48px; height: 48px; display: grid; place-items: center;
  background: var(--accent-soft); border-radius: 13px; flex: none;
}
.organ-meta { display: grid; min-width: 0; flex: 1; }
.organ-name { font-weight: 650; font-size: 17px; }
.organ-role {
  color: var(--muted); font-size: 14.5px; line-height: 1.4; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.chev { color: var(--muted); font-size: 26px; line-height: 1; }
.grow-label { margin: 16px 6px 8px; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .07em; }
.home-foot { margin: 28px 6px 0; color: var(--muted); font-size: 14px; }
.home-foot p { margin: 0 0 8px; }
.links { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner { background: var(--gap); color: var(--gap-ink); padding: 12px 14px; border-radius: 12px; margin: 0 0 14px; }

/* chat */
.chat {
  height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr); width: 100%; max-width: 820px; margin: 0 auto;
}
.chat > * { min-width: 0; }
.chat-top {
  display: flex; align-items: center; gap: 6px; background: var(--bg);
  padding: calc(6px + env(safe-area-inset-top)) 6px 6px; border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.who-emoji { font-size: 26px; }
.who-text { min-width: 0; }
.who-name { font-weight: 650; line-height: 1.2; }
.who-role { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msgs {
  min-height: 0; overflow-y: auto; padding: 16px 12px 10px; display: flex; flex-direction: column; gap: 12px;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.msg { display: flex; flex-direction: column; }
.msg.me { align-items: flex-end; }
.msg.organ { align-items: flex-start; }
.bubble { max-width: min(94%, 700px); padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; }
.me .bubble { background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; max-width: 86%; }
.me-text { white-space: pre-wrap; }
.organ .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.bubble p { margin: 0 0 .65em; }
.bubble > :last-child { margin-bottom: 0; }
.bubble h2, .bubble h3, .bubble h4, .bubble h5 { margin: .9em 0 .35em; line-height: 1.3; }
.bubble h2 { font-size: 18px; } .bubble h3 { font-size: 17px; } .bubble h4, .bubble h5 { font-size: 16px; }
.bubble > h2:first-child, .bubble > h3:first-child, .bubble > h4:first-child { margin-top: .2em; }
.bubble ul, .bubble ol { margin: .3em 0 .7em; padding-left: 1.35em; }
.bubble li { margin: .15em 0; }
.bubble li.sub { margin-left: 1.2em; }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: .9em 0; }
.bubble pre { background: var(--bg); padding: 10px 12px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.bubble blockquote { margin: .4em 0 .7em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.table-wrap { overflow-x: auto; margin: .4em 0 .7em; }
.bubble table { border-collapse: collapse; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
mark.gap { background: var(--gap); color: var(--gap-ink); border-radius: 5px; padding: 0 4px; }
.actions { display: flex; gap: 8px; margin: 6px 4px 0; flex-wrap: wrap; }
.chip-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px;
  padding: 6px 14px; font-size: 14px; min-height: 38px; cursor: pointer;
}
.note { color: var(--muted); font-size: 14px; margin-top: .7em !important; }
.note.err { color: var(--danger); }
.phase { color: var(--muted); font-size: 14px; margin-top: .4em !important; }
.typing { display: flex; align-items: center; gap: 5px; min-height: 26px; color: var(--muted); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
.typing em { margin-left: 8px; font-size: 14px; font-style: normal; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.sources { margin-top: .9em; border-top: 1px solid var(--line); padding-top: .6em; font-size: 14px; }
.sources-label { color: var(--muted); font-weight: 650; margin: 0 0 .2em !important; }
.sources ol { margin: 0; padding-left: 1.3em; }
.att-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.att {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: rgba(255, 255, 255, .16); border-radius: 10px; padding: 4px 9px 4px 4px; font-size: 13px;
}
.att img, .chip img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; flex: none; }
.att .pdf, .chip .pdf {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; flex: none;
  background: rgba(127, 127, 127, .22); font-weight: 750; font-size: 11px; letter-spacing: .04em;
}
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

/* empty chat */
.empty { display: grid; gap: 12px; }
.examples { display: grid; gap: 8px; }
.examples-label { margin: 6px 4px 0; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .07em; }
.example {
  text-align: left; background: var(--accent-soft); color: var(--ink); border: 1px solid transparent;
  border-radius: 14px; padding: 10px 14px; cursor: pointer; font-size: 15px; line-height: 1.4;
}
.example:hover { border-color: var(--line); }

/* composer */
.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.composer .row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; resize: none; font-size: 16px; line-height: 1.4; padding: 11px 14px; border-radius: 22px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); min-height: 44px; max-height: 200px;
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.busy .send-btn { background: var(--ink); color: var(--bg); }
.hidden-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px 8px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 240px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; font-size: 13px;
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: none; width: 34px; height: 34px; font-size: 20px; cursor: pointer; color: var(--muted); flex: none; }

/* Mother's proposals */
.proposal { margin-top: .8em; border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--bg); display: grid; gap: 10px; }
.proposal-head { display: flex; gap: 12px; align-items: center; }
.proposal-emoji { font-size: 28px; width: 50px; height: 50px; display: grid; place-items: center; background: var(--accent-soft); border-radius: 13px; flex: none; }
.proposal-name { font-weight: 700; font-size: 17px; }
.proposal-role { color: var(--muted); font-size: 14px; line-height: 1.4; }
.proposal-soul summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.soul-text { white-space: pre-wrap; font-size: 14px; color: var(--muted); margin-top: 6px; }
.proposal-status { margin: 0 !important; font-size: 14px; color: var(--muted); }
.proposal-status:empty { display: none; }
.shaping { color: var(--muted); font-size: 14px; }

/* sheets */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .38); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet {
  width: 100%; max-width: 520px; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 8px calc(12px + env(safe-area-inset-bottom)); display: grid; gap: 2px; max-height: 80vh; overflow-y: auto;
}
.sheet-title { margin: 10px 12px 6px; color: var(--muted); font-size: 14px; }
.sheet-item { text-align: left; background: none; border: 0; padding: 13px 12px; border-radius: 12px; font-size: 16px; cursor: pointer; color: var(--ink); min-height: 48px; }
.sheet-item:hover { background: var(--bg); }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { color: var(--muted); text-align: center; }

/* about */
.page { max-width: 680px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom)); }
.page-top { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.page-top h1 { font-size: 22px; margin: 0; }
.prose { padding: 0 6px; }
.prose h2 { font-size: 17px; margin: 1.4em 0 .3em; }
.prose p { margin: 0 0 .8em; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%) translateY(16px); opacity: 0; pointer-events: none; transition: .2s;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* print one answer */
@media print {
  body.print-one * { visibility: hidden !important; }
  body.print-one .printing, body.print-one .printing * { visibility: visible !important; }
  body.print-one .printing { position: absolute; left: 0; top: 0; width: 100%; }
  body.print-one .chat { height: auto; display: block; }
  body.print-one .msgs { overflow: visible; }
  .printing .bubble { border: 0 !important; box-shadow: none !important; max-width: 100% !important; padding: 0 !important; background: none !important; color: #000 !important; }
  .printing .actions, .printing .proposal, .printing .note { display: none !important; }
  mark.gap { background: #eee !important; color: #000 !important; }
  #toast { display: none; }
}

/* voice */
.mic-btn.recording { background: var(--danger); color: #fff; }
.mic-btn.recording:hover { background: var(--danger); }
.voice-bar { display: none; align-items: center; gap: 8px; padding: 0 6px 8px; color: var(--muted); font-size: 14px; }
.voice-bar.on { display: flex; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; animation: blink 1.2s infinite both; }
