/* Kergo — mobile-first, warm and calm. Big type, one obvious action per screen. */
:root {
  --bg: #f6efe4;        /* warm paper */
  --bg-2: #fff9f0;
  --white: #ffffff;
  --ink: #23211d;
  --ink-2: #5e5a52;
  --accent: #2f7d6d;    /* calm teal-green (the patch of grass, fixed) */
  --accent-ink: #ffffff;
  --mic: #7fa69b;       /* softer mic teal from the mockup */
  --danger: #b4452f;
  --ring: rgba(47,125,109,.25);
  --user: #e7f0ec;
  --blk-1: #eef4f1; --blk-2: #f3efe6; --blk-3: #edf1f5; --blk-4: #f5efe9;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#1d1b18; --bg-2:#27241f; --white:#2d2924; --ink:#f3ede3; --ink-2:#b9b2a6; --accent:#57b39f; --accent-ink:#10201c; --mic:#5b8f83; --ring:rgba(87,179,159,.3); --user:#2b3a35; --blk-1:#233430; --blk-2:#2e2a24; --blk-3:#262d33; --blk-4:#302a26; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 18px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
.screen { height: 100dvh; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.view[hidden] { display: none; }
.stack { margin: auto; width: min(100% - 2.5rem, 26rem); display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: calc(var(--safe-top) + 2rem) 0 calc(var(--safe-bottom) + 2rem); text-align: center; }
h1 { font-size: 2.2rem; margin: 0; letter-spacing: -.02em; }
.lead { font-size: 1.15rem; color: var(--ink-2); margin: 0; }
form { width: 100%; display: flex; flex-direction: column; gap: .75rem; }
input[type=text] {
  width: 100%; font-size: 1.25rem; /* ≥16px: stops iOS zoom-on-focus */
  padding: .9rem 1rem; border-radius: var(--radius); border: 2px solid #d9cfbf; background: var(--bg-2); color: var(--ink);
  text-align: center; letter-spacing: .06em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type=text]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
.btn { font: inherit; font-size: 1.15rem; font-weight: 600; padding: 1rem 1.25rem; border-radius: var(--radius); border: 0; cursor: pointer; min-height: 56px; }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .6; }
.msg { min-height: 1.5em; margin: 0; color: var(--danger); font-weight: 500; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Top bar */
.topbar { display: flex; align-items: center; gap: .5rem; padding: calc(var(--safe-top) + .5rem) .75rem .5rem; flex: none; }
.brand { font-weight: 700; font-size: 1.1rem; }
.spacer { flex: 1; }
.iconbtn { font: inherit; font-size: 1.4rem; background: transparent; border: 0; color: var(--ink); width: 44px; height: 44px; border-radius: 12px; cursor: pointer; }

/* Empty state */
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; padding: 1rem 1.5rem; text-align: center; }
.stage[hidden] { display: none; }
.greeting { font-size: 1.6rem; font-weight: 600; margin: 0; }
.hint { color: var(--ink-2); margin: 0; font-size: 1.1rem; }

/* Conversation */
.thread { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: .5rem 1rem 1rem; display: flex; flex-direction: column; gap: .75rem; scroll-behavior: smooth; }
.thread[hidden] { display: none; }
.bubble { max-width: 92%; border-radius: 20px; padding: .75rem 1rem; line-height: 1.5; overflow-wrap: anywhere; }
.bubble--user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.bubble--kergo { align-self: flex-start; background: var(--white); border-bottom-left-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.04); max-width: 100%; }
.bubble--kergo.thinking::after { content: "…"; display: inline-block; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.bubble--kergo p { margin: .35rem 0; }
.bubble--kergo p:first-child { margin-top: 0; } .bubble--kergo p:last-child { margin-bottom: 0; }
.bubble--kergo ul, .bubble--kergo ol { margin: .35rem 0; padding-left: 1.3rem; }
.bubble--kergo li { margin: .2rem 0; }
.bubble--kergo code { font: .92em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: .05rem .35rem; border-radius: 6px; }
.bubble--kergo pre { background: var(--bg); padding: .6rem .8rem; border-radius: 12px; overflow-x: auto; font-size: .9rem; }
.bubble--kergo pre code { background: none; padding: 0; }
/* Structured answers: each section is a soft color block */
.blk { border-radius: 14px; padding: .7rem .85rem; margin: .6rem 0; }
.blk:first-child { margin-top: 0; } .blk:last-child { margin-bottom: 0; }
.blk h3 { margin: 0 0 .35rem; font-size: 1.05rem; letter-spacing: -.01em; }
.blk-1 { background: var(--blk-1); } .blk-2 { background: var(--blk-2); } .blk-3 { background: var(--blk-3); } .blk-4 { background: var(--blk-4); }
.bubble--error { align-self: center; background: transparent; color: var(--danger); font-weight: 500; text-align: center; }

/* Dock: mic first, typing right below */
.dock { flex: none; display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: .75rem 1rem calc(var(--safe-bottom) + .9rem); }
.mic { width: 88px; height: 88px; border-radius: 50%; border: 0; background: var(--mic); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 24px var(--ring); cursor: pointer; transition: transform .15s; }
.mic:active { transform: scale(.96); }
.mic[data-state="listening"] { background: var(--accent); box-shadow: 0 0 0 10px var(--ring); }
.thread:not([hidden]) ~ .dock .mic { width: 64px; height: 64px; }
.thread:not([hidden]) ~ .dock .mic svg { width: 30px; height: 30px; }
.thread:not([hidden]) ~ .dock #type-label { display: none; }
.dock-note { margin: 0; color: var(--ink-2); font-size: 1.02rem; text-align: center; }
.ask { position: relative; width: min(100%, 34rem); display: block; }
.ask textarea {
  width: 100%; display: block; resize: none; font: inherit; font-size: 1.15rem; line-height: 1.4; color: var(--ink);
  background: var(--white); border: 0; border-radius: 28px; padding: 1rem 3.4rem 1rem 1.25rem; min-height: 60px; max-height: 9rem;
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
}
.ask textarea:focus { outline: none; box-shadow: 0 0 0 4px var(--ring); }
.send { position: absolute; right: .5rem; bottom: .5rem; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; }
.send[hidden] { display: none; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 20; }
.scrim[hidden] { display: none; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 22rem); background: var(--bg-2); z-index: 21; padding: calc(var(--safe-top) + .5rem) 1rem calc(var(--safe-bottom) + 1rem); display: flex; flex-direction: column; gap: .75rem; box-shadow: 6px 0 30px rgba(0,0,0,.12); animation: slide .2s ease-out; }
.drawer[hidden] { display: none; }
@keyframes slide { from { transform: translateX(-100%); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.convs { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.convs button { width: 100%; text-align: left; font: inherit; font-size: 1.02rem; background: transparent; border: 0; border-radius: 12px; padding: .7rem .75rem; color: var(--ink); cursor: pointer; display: flex; flex-direction: column; gap: .1rem; }
.convs button[aria-current="true"] { background: var(--user); }
.convs small { color: var(--ink-2); font-size: .85rem; }

/* Toast */
.toast { position: fixed; left: 50%; top: calc(var(--safe-top) + 3.6rem); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: 999px; font-size: 1rem; z-index: 30; max-width: 90vw; text-align: center; }
.toast[hidden] { display: none; }

/* Kergo avatar — placeholder mark (bald, glasses, small dog). Real animated character lands in Milestone 2. */
.avatar { width: 160px; height: 160px; border-radius: 50%; background: var(--bg-2) url('/icons/kergo.svg') center/78% no-repeat; box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.avatar--sm { width: 96px; height: 96px; }
.avatar[data-state="listening"] { box-shadow: 0 0 0 10px var(--ring); }
@media (min-width: 900px) { .thread, .dock { width: min(100%, 44rem); margin: 0 auto; } }

/* Dock tools row (photo, mute) — small, secondary to the mic */
.dock-tools { display: flex; gap: .75rem; align-items: center; justify-content: center; min-height: 0; }
.toolbtn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--bg-2); color: var(--ink-2); display: grid; place-items: center; font-size: 1.2rem; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.toolbtn[hidden] { display: none; }
.toolbtn[aria-pressed="true"] { background: var(--user); color: var(--accent); }

/* Two-tier: the longer answer (M4) */
.deep { align-self: stretch; border-radius: 16px; background: var(--bg-2); border: 1px dashed #d9cfbf; overflow: hidden; }
.deep.done { border-style: solid; border-color: transparent; background: var(--white); box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.deep-head { width: 100%; display: flex; align-items: center; gap: .6rem; font: inherit; font-size: 1rem; color: var(--ink-2); background: transparent; border: 0; padding: .75rem 1rem; text-align: left; cursor: pointer; }
.deep.done .deep-head { color: var(--accent); font-weight: 600; }
.deep-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.2s infinite; }
.deep.done .deep-dot, .deep.failed .deep-dot { animation: none; }
.deep.failed .deep-dot { background: var(--danger); }
.deep-body { padding: 0 1rem 1rem; line-height: 1.5; }
.deep-body[hidden] { display: none; }
.deep-body p { margin: .35rem 0; } .deep-body ul, .deep-body ol { margin: .35rem 0; padding-left: 1.3rem; }
.toast-btn { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; padding: 0; }

/* In conversation mode, keep the dock compact: mic + tools on one row, the field below */
.thread:not([hidden]) ~ .dock { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; gap: .6rem 1rem; padding-top: .5rem; }
.thread:not([hidden]) ~ .dock .ask { flex-basis: 100%; }
.thread:not([hidden]) ~ .dock .ask textarea { min-height: 54px; padding-top: .8rem; padding-bottom: .8rem; }

/* Settings (hidden behind one unobtrusive link in the drawer) */
.linkbtn { font: inherit; font-size: .95rem; color: var(--ink-2); background: transparent; border: 0; text-decoration: underline; cursor: pointer; align-self: flex-start; padding: .4rem 0; }
.settings { display: flex; flex-direction: column; gap: .6rem; padding-top: .25rem; border-top: 1px solid #e6dccb; }
.settings[hidden] { display: none; }
.settings .row { display: flex; justify-content: space-between; align-items: center; font-size: 1rem; padding: .3rem 0; }
.settings input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
.btn--soft { background: var(--user); color: var(--ink); font-size: 1rem; min-height: 48px; padding: .7rem 1rem; }
