/* Twister Chat: the full-page chat. One stylesheet, no build step.
   Layers, back to front: .scene (forest photo, light shaft, motes, scrim) then .app (header, thread, composer).
   Reading comes first: text sits on a dark veil that thickens once a conversation starts.
   All ambient motion is transform/opacity only, stops when the tab is hidden (html.is-paused)
   and is removed under prefers-reduced-motion. */

/* ---------- fonts: Mona Sans (SIL OFL 1.1, see assets/fonts/LICENSE-MonaSans.txt) ---------- */
@font-face {
  font-family: 'Mona Sans';
  src: url(assets/fonts/mona-sans-latin-wdth-normal.woff2) format('woff2');
  font-weight: 200 900;
  font-stretch: 75% 125%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Mona Sans';
  src: url(assets/fonts/mona-sans-latin-wght-italic.woff2) format('woff2');
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- tokens ---------- */
:root {
  --page: #0a2019;              /* average colour of the forest photos: shown before they load */
  --ink: #e4ede7;               /* body text */
  --ink-2: #b8c9bf;             /* secondary text */
  --ink-3: #97aea1;             /* quiet text: hints, notes, counter */
  --ink-strong: #f3f8f4;        /* headings and bold inside answers */
  --accent: #3dbb12;            /* Twister green, sampled from the logo mark */
  --accent-ink: #06140e;        /* text and icons on the accent */
  --accent-soft: #8fe06c;       /* links, focus rings, markers on dark */
  --accent-hover: #4fd122;
  --err: #ff9b8a;
  --warn: #f0c46a;
  --line: rgba(184, 220, 196, .13);
  --line-strong: rgba(184, 220, 196, .24);
  --veil: rgba(5, 18, 13, .86);  /* the reading surface over the photo */
  --field: rgba(8, 24, 18, .95);
  --bubble: rgba(61, 187, 18, .13);
  --font: 'Mona Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  --col: 47rem;                 /* conversation column */
  --gutter: 2.75rem;            /* the leaf beside each answer */
  --pad: clamp(16px, 4vw, 28px);
  --r-sm: 10px;
  --r-md: 16px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io: cubic-bezier(.45, 0, .55, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: rgba(61, 187, 18, .42); color: #fff; }
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- the scene ---------- */
.scene { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; background: var(--page); }
.scene-photo {
  position: absolute; inset: -3%;
  background: var(--page) url(assets/bg/forest-wide-1600.jpg) center / cover no-repeat;
  background-image: image-set(url(assets/bg/forest-wide-1600.webp) type('image/webp'), url(assets/bg/forest-wide-1600.jpg) type('image/jpeg'));
  animation: drift 90s var(--ease-io) infinite alternate;
}
@media (orientation: landscape) and (min-width: 1601px), (orientation: landscape) and (min-width: 1000px) and (min-resolution: 1.5dppx) {
  .scene-photo {
    background-image: url(assets/bg/forest-wide-2560.jpg);
    background-image: image-set(url(assets/bg/forest-wide-2560.webp) type('image/webp'), url(assets/bg/forest-wide-2560.jpg) type('image/jpeg'));
  }
}
@media (orientation: portrait) {
  .scene-photo {
    background-position: center top;
    background-image: url(assets/bg/forest-tall-720.jpg);
    background-image: image-set(url(assets/bg/forest-tall-720.webp) type('image/webp'), url(assets/bg/forest-tall-720.jpg) type('image/jpeg'));
  }
}
@media (orientation: portrait) and (min-width: 481px), (orientation: portrait) and (min-resolution: 2dppx) {
  .scene-photo {
    background-image: url(assets/bg/forest-tall-1080.jpg);
    background-image: image-set(url(assets/bg/forest-tall-1080.webp) type('image/webp'), url(assets/bg/forest-tall-1080.jpg) type('image/jpeg'));
  }
}
@keyframes drift {
  from { transform: scale(1) translate3d(0, 0, 0); }
  to { transform: scale(1.045) translate3d(-.8%, -.5%, 0); }
}

/* A slow shimmer laid over the photo's own light shaft (top, right of centre). */
.scene-shaft {
  position: absolute; top: -20%; left: 52%; width: 26vw; height: 95%;
  background: linear-gradient(90deg, transparent, rgba(200, 240, 225, .075) 45%, rgba(200, 240, 225, .05) 60%, transparent);
  transform: rotate(24deg); transform-origin: top center;
  animation: shaft 17s var(--ease-io) infinite alternate;
  opacity: .5;
}
@keyframes shaft {
  from { opacity: .25; transform: rotate(24deg) translate3d(-2vw, 0, 0); }
  to { opacity: .9; transform: rotate(22deg) translate3d(1vw, 0, 0); }
}
@media (orientation: portrait) {
  .scene-shaft { left: 44%; width: 40vw; height: 60%; }
}

/* A few faint motes drifting up through the leaves at the edges, never across the reading column. */
.scene-motes i {
  position: absolute; bottom: -4%;
  width: 4px; height: 4px; border-radius: 50%;
  background: radial-gradient(circle, rgba(222, 246, 205, .9), rgba(222, 246, 205, 0) 70%);
  opacity: 0;
  animation: mote 34s linear infinite;
}
.scene-motes i:nth-child(1) { left: 6%;  animation-duration: 38s; animation-delay: -4s; }
.scene-motes i:nth-child(2) { left: 13%; animation-duration: 46s; animation-delay: -21s; width: 3px; height: 3px; }
.scene-motes i:nth-child(3) { left: 20%; animation-duration: 41s; animation-delay: -33s; }
.scene-motes i:nth-child(4) { left: 81%; animation-duration: 44s; animation-delay: -12s; width: 5px; height: 5px; }
.scene-motes i:nth-child(5) { left: 88%; animation-duration: 36s; animation-delay: -27s; width: 3px; height: 3px; }
.scene-motes i:nth-child(6) { left: 94%; animation-duration: 49s; animation-delay: -6s; }
.scene-motes i:nth-child(7) { left: 75%; animation-duration: 52s; animation-delay: -40s; width: 3px; height: 3px; }
@keyframes mote {
  0% { transform: translate3d(0, 0, 0); opacity: 0; }
  12% { opacity: .55; }
  50% { transform: translate3d(14px, -52vh, 0); }
  85% { opacity: .4; }
  100% { transform: translate3d(-10px, -104vh, 0); opacity: 0; }
}
@media (max-width: 599px) {
  .scene-motes i:nth-child(n+4) { display: none; }
  .scene-motes i:nth-child(1) { left: 4%; }
  .scene-motes i:nth-child(2) { left: 93%; }
  .scene-motes i:nth-child(3) { left: 86%; }
}

/* The scrim: top and bottom fades, a vignette, and the reading veil (stronger once there is a conversation). */
.scene-scrim {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(3, 11, 8, .72), rgba(3, 11, 8, 0) 18%, rgba(3, 11, 8, 0) 72%, rgba(3, 11, 8, .82)),
    radial-gradient(120% 90% at 50% 45%, transparent 40%, rgba(2, 9, 6, .55));
}
.scene-scrim::before {
  content: ''; position: absolute; inset: 0;
  --half: calc(var(--col) / 2 + 2.5rem);
  background: linear-gradient(90deg,
    transparent calc(50% - var(--half) - 7rem),
    var(--veil) calc(50% - var(--half)),
    var(--veil) calc(50% + var(--half)),
    transparent calc(50% + var(--half) + 7rem));
  opacity: .5;
  transition: opacity .9s var(--ease-out);
}
.has-chat .scene-scrim::before { opacity: 1; }
@media (max-width: 599px) {
  .scene-scrim::before { background: rgba(5, 18, 13, .8); opacity: .35; }
  .has-chat .scene-scrim::before { opacity: 1; }
}

/* ---------- the app frame ---------- */
.app {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1;
  height: 100vh; height: 100dvh; height: var(--app-h, 100dvh);
  display: flex; flex-direction: column;
}

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(var(--pad), env(safe-area-inset-right)) 8px max(var(--pad), env(safe-area-inset-left));
  min-height: 64px;
}
.brand { display: flex; align-items: center; gap: 14px; margin: 0; min-width: 0; overflow: hidden; }
.brand-logo { display: block; flex: none; height: 36px; width: auto; }
.brand-name {
  padding-left: 14px; border-left: 1px solid var(--line-strong);
  font-size: .9375rem; font-weight: 560; font-stretch: 125%; letter-spacing: .04em;
  line-height: 22px; color: var(--ink-2); text-transform: uppercase;
}

.btn-quiet {
  flex: none;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 14px 0 12px;
  background: rgba(6, 20, 14, .5); border: 1px solid var(--line-strong); border-radius: 999px;
  font-size: .9375rem; font-weight: 520; color: var(--ink);
  transition: background-color .2s, border-color .2s;
}
.btn-quiet:hover { background: rgba(20, 52, 38, .7); border-color: rgba(143, 224, 108, .45); }
.btn-quiet .icon { width: 18px; height: 18px; }

/* ---------- the thread ---------- */
.thread {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: rgba(184, 220, 196, .22) transparent;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 20px, #000 calc(100% - 12px), transparent);
  mask-image: linear-gradient(180deg, transparent, #000 20px, #000 calc(100% - 12px), transparent);
}
.thread:focus { outline: none; }
.thread::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb { background: rgba(184, 220, 196, .2); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
.column {
  max-width: calc(var(--col) + 2 * var(--pad));
  min-height: 100%;
  margin: 0 auto;
  padding: 24px max(var(--pad), env(safe-area-inset-right)) 32px max(var(--pad), env(safe-area-inset-left));
  display: flex; flex-direction: column;
}

/* ---------- the empty state ---------- */
.welcome { margin: auto 0; padding: 24px 0 8px; text-align: center; }
.welcome .leaf-hero { --leaf: 76px; margin-bottom: 18px; }
.welcome-title {
  margin: 0 auto; max-width: 18em;
  font-size: clamp(1.625rem, 1.15rem + 1.5vw, 2.25rem);
  font-weight: 620; font-stretch: 116%; line-height: 1.15; letter-spacing: -.012em;
  text-wrap: balance;
}
.welcome-lede {
  margin: 14px auto 0; max-width: 34rem;
  font-size: 1.0625rem; color: var(--ink-2); text-wrap: pretty;
}
.starters {
  list-style: none; margin: 32px auto 0; padding: 0; max-width: 40rem;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
  text-align: left;
}
.starter {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; height: 100%; min-height: 56px; padding: 12px 14px 12px 16px;
  background: rgba(5, 18, 13, .72); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  font-size: .96875rem; line-height: 1.4; text-align: left; color: var(--ink);
  transition: background-color .2s, border-color .2s;
}
.starter .icon { width: 18px; height: 18px; color: var(--accent-soft); opacity: .7; transition: transform .25s var(--ease-out), opacity .2s; }
.starter:hover { background: rgba(14, 40, 28, .85); border-color: rgba(143, 224, 108, .45); }
.starter:hover .icon { transform: translateX(3px); opacity: 1; }
.starter:active { background: rgba(20, 54, 37, .9); }

/* ---------- messages ---------- */
.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 30px; }
.msg { min-width: 0; }
.msg.is-new { animation: msg-in .36s var(--ease-out) both; }
@keyframes msg-in { from { opacity: 0; transform: translate3d(0, 10px, 0); } }

.msg-user {
  align-self: flex-end; max-width: min(85%, 36rem);
  padding: 10px 16px 11px;
  background: var(--bubble); border: 1px solid rgba(143, 224, 108, .18);
  border-radius: 20px 20px 6px 20px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 1.0625rem; line-height: 1.55;
}

.msg-bot {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  column-gap: 12px;
  align-items: start;
}
.msg-bot > * { grid-column: 2; }
.msg-bot > .msg-mark { grid-column: 1; grid-row: 1 / span 4; padding-top: 1px; }
.msg-mark .leaf { --leaf: 44px; }
.msg-mark .leaf-svg { scale: .82; transition: scale .7s var(--ease-out); }
:is(.is-searching, .is-thinking) > .msg-mark .leaf-svg { scale: 1; }
.is-streaming > .msg-mark .leaf-svg { scale: .64; }
.msg-status {
  margin: 0; min-height: 40px; display: flex; align-items: center;
  font-size: .9375rem; color: var(--ink-2);
}
.msg-bot:not(.is-searching):not(.is-thinking) .msg-status { display: none; }

/* Answers: rendered Markdown, set for reading. */
.prose {
  max-width: 68ch;
  font-size: 1.0625rem; line-height: 1.68;
  overflow-wrap: break-word;
}
.prose:empty { display: none; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose pre, .prose blockquote, .prose .table-wrap { margin: 0 0 .9em; }
.prose h3, .prose h4, .prose h5 {
  margin: 1.5em 0 .5em; line-height: 1.3; font-weight: 640; font-stretch: 108%; letter-spacing: .002em; color: var(--ink-strong);
  text-wrap: balance;
}
.prose h3 { font-size: 1.1875rem; }
.prose h4 { font-size: 1.0625rem; }
.prose h5 { font-size: 1rem; color: var(--ink-2); }
.prose strong { font-weight: 650; color: var(--ink-strong); }
.prose em { font-style: italic; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose ul { list-style-type: disc; }
.prose ul ul { list-style-type: circle; }
.prose ol { list-style-type: decimal; }
.prose li { padding-left: .2em; }
.prose li + li { margin-top: .4em; }
.prose li > ul, .prose li > ol, .prose li > p { margin: .4em 0 0; }
.prose ul > li::marker { color: var(--accent); }
.prose ol > li::marker { color: var(--accent-soft); font-weight: 650; font-variant-numeric: tabular-nums; }
.prose a {
  color: var(--accent-soft);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em;
  text-decoration-color: rgba(143, 224, 108, .5);
  overflow-wrap: anywhere;
  transition: text-decoration-color .15s;
}
.prose a:hover { text-decoration-color: currentColor; }
.prose code {
  font-family: var(--mono); font-size: .875em;
  background: rgba(184, 220, 196, .09); border: 1px solid var(--line); border-radius: 6px;
  padding: .08em .36em;
}
.prose pre {
  padding: 12px 16px; overflow-x: auto;
  background: rgba(2, 10, 7, .65); border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: .875rem; line-height: 1.6;
  scrollbar-width: thin; scrollbar-color: rgba(184, 220, 196, .22) transparent;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.prose code.nw { white-space: nowrap; }
.prose blockquote { padding: 0 0 0 1em; border-left: 2px solid var(--line-strong); color: var(--ink-2); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.prose .table-wrap {
  overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm);
  /* a soft green edge appears on whichever side has more columns to scroll to */
  background:
    linear-gradient(90deg, #06150f 40%, rgba(6, 21, 15, 0)) left / 36px 100% no-repeat local,
    linear-gradient(270deg, #06150f 40%, rgba(6, 21, 15, 0)) right / 36px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(143, 224, 108, .3), rgba(143, 224, 108, 0)) left / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(143, 224, 108, .3), rgba(143, 224, 108, 0)) right / 12px 100% no-repeat scroll,
    #06150f;
  scrollbar-width: thin; scrollbar-color: rgba(184, 220, 196, .22) transparent;
}
.prose table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: .9375rem; line-height: 1.5; font-variant-numeric: tabular-nums; }
.prose th, .prose td { max-width: 18rem; padding: 9px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.prose th { font-weight: 640; color: var(--ink-strong); background: rgba(184, 220, 196, .06); white-space: nowrap; }
.prose tr:last-child td { border-bottom: 0; }
.prose .al-c { text-align: center; }
.prose .al-r { text-align: right; }

/* The caret while an answer is being written. */
.is-streaming .prose > :is(p, h3, h4, h5):last-child::after,
.is-streaming .prose > :is(ul, ol):last-child > li:last-child::after {
  content: ''; display: inline-block; width: 2px; height: 1.05em; margin-left: 3px;
  vertical-align: -.16em; border-radius: 1px; background: var(--accent-soft);
  animation: caret 1.1s var(--ease-io) infinite;
}
@keyframes caret { 50% { opacity: .15; } }

/* Under each finished answer: copy, thumbs, a short note. */
.msg-actions { display: flex; align-items: center; gap: 2px; margin: 8px 0 0 -10px; min-height: 40px; }
.act {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  background: transparent; border: 0; border-radius: var(--r-sm);
  color: var(--ink-3);
  transition: background-color .15s, color .15s;
}
.act:hover { background: rgba(184, 220, 196, .08); color: var(--ink); }
.act .icon { width: 19px; height: 19px; }
.act[aria-pressed="true"] { color: var(--accent-soft); }
.act[aria-pressed="true"] .icon { fill: rgba(143, 224, 108, .22); }
.act.is-done { color: var(--accent-soft); }
.msg-note { margin: 0 0 0 8px; font-size: .875rem; color: var(--ink-3); }
.msg-note:empty { display: none; }

/* An answer that could not be given. */
.error-box {
  padding: 12px 16px 14px;
  background: rgba(40, 14, 10, .55); border: 1px solid rgba(255, 155, 138, .28); border-radius: var(--r-md);
  max-width: 34rem;
}
.is-auth .error-box, .is-busy .error-box { background: rgba(38, 30, 8, .55); border-color: rgba(240, 196, 106, .3); }
.error-title { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 640; font-size: 1rem; color: #fff3ef; }
.error-title .icon { width: 20px; height: 20px; color: var(--err); }
.is-auth .error-title .icon, .is-busy .error-title .icon { color: var(--warn); }
.is-auth .error-title, .is-busy .error-title { color: #fff6e3; }
.error-text { margin: 4px 0 12px 30px; color: var(--ink-2); font-size: .9375rem; }
.error-box .btn { margin-left: 30px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 18px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  font-weight: 620; font-size: .9375rem;
  transition: background-color .15s;
}
.btn:hover { background: var(--accent-hover); }
.btn .icon { width: 18px; height: 18px; }
.msg-cut { margin: 10px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--ink-2); font-size: .9375rem; }
.msg-cut .btn-quiet { min-height: 40px; }

/* ---------- the leaf: the assistant's mark and its thinking indicator ---------- */
.leaf {
  --leaf: 36px;
  position: relative; display: inline-grid; place-items: center; vertical-align: middle;
  width: var(--leaf); height: calc(var(--leaf) * .9);
}
.leaf-svg {
  position: relative; width: 100%; height: 100%; overflow: visible;
  transform-origin: 50% 69%;
  transition: transform .6s var(--ease-out), opacity .6s var(--ease-out);
}
.leaf-stem { fill: none; stroke: #2f8a1e; stroke-width: 2; stroke-linecap: round; }
.leaf-glow {
  position: absolute; inset: -45%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(120, 230, 80, .55), rgba(61, 187, 18, .2) 50%, rgba(61, 187, 18, 0));
  opacity: 0; transform: scale(.7);
  transition: opacity .6s var(--ease-out), transform .6s var(--ease-out);
}
.blade { transform-box: fill-box; transform-origin: 50% 100%; }
.b-c  { --d: 0;  --i: 0; }
.b-l1 { --d: -1; --i: 1; } .b-r1 { --d: 1; --i: 1; }
.b-l2 { --d: -1; --i: 2; } .b-r2 { --d: 1; --i: 2; }
.b-l3 { --d: -1; --i: 3; } .b-r3 { --d: 1; --i: 3; }

/* Searching and thinking: the leaf breathes. The fan opens from the centre outward, the glow swells with it. */
:is(.is-searching, .is-thinking) .leaf-svg { animation: leaf-breathe 2.8s var(--ease-io) infinite; }
:is(.is-searching, .is-thinking) .leaf-glow { animation: glow-breathe 2.8s var(--ease-io) infinite; }
:is(.is-searching, .is-thinking) .blade { animation: blade-open 2.8s var(--ease-io) infinite; animation-delay: calc(var(--i) * 120ms); }
:is(.is-searching, .is-thinking) .b-c { animation-name: blade-rise; }
.is-thinking .leaf-svg, .is-thinking .leaf-glow, .is-thinking .blade { animation-duration: 2.2s; }
@keyframes leaf-breathe { 0%, 100% { transform: scale(.92); } 50% { transform: scale(1.08); } }
@keyframes glow-breathe { 0%, 100% { opacity: .3; transform: scale(.72); } 50% { opacity: 1; transform: scale(1.06); } }
@keyframes blade-open { 0%, 100% { transform: rotate(calc(var(--d) * -5deg)); } 50% { transform: rotate(calc(var(--d) * 4deg)); } }
@keyframes blade-rise { 0%, 100% { transform: scale(.95, .93); } 50% { transform: scale(1, 1.03); } }

/* Writing: the leaf settles, smaller and calm, and its leaflets sway a little as the words arrive. */
.is-streaming .leaf-glow { opacity: .3; transform: scale(.8); }
.is-streaming .blade { animation: blade-sway 2.4s var(--ease-io) infinite; animation-delay: calc(var(--i) * -300ms); }
@keyframes blade-sway { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }

/* The greeting's leaf unfolds once when the page opens. */
.leaf-hero .leaf-glow { opacity: .55; transform: scale(1); }
.leaf-hero .blade { animation: blade-unfurl 1.1s var(--ease-out) both; animation-delay: calc(var(--i) * 80ms + 120ms); }
@keyframes blade-unfurl { from { transform: rotate(calc(var(--d) * -22deg)) scale(.6); } }

/* ---------- open chats: the tab strip under the header ---------- */
.tabs-row {
  display: flex; align-items: center; gap: 6px;
  width: 100%; max-width: calc(var(--col) + 2 * var(--pad)); margin: 0 auto;
  padding: 0 max(var(--pad), env(safe-area-inset-right)) 2px max(var(--pad), env(safe-area-inset-left));
}
.tabs {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 4px;
  margin-left: -10px; padding: 4px 22px 4px 10px;   /* room for focus rings; the edges fade */
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 10px, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 10px, #000 calc(100% - 22px), transparent);
}
.tabs::-webkit-scrollbar { display: none; }
.tablist { display: contents; }
.tab-item {
  flex: 0 0 auto; display: flex; align-items: center; max-width: 15rem;
  border: 1px solid transparent; border-radius: var(--r-sm);
  transition: background-color .15s, border-color .15s;
}
.tab-item:hover { background: rgba(184, 220, 196, .07); }
.tab-item.is-active { background: rgba(61, 187, 18, .13); border-color: rgba(143, 224, 108, .3); }
.tab {
  display: flex; align-items: center; gap: 8px; min-width: 0; height: 34px; padding: 0 2px 0 12px;
  background: none; border: 0; border-radius: var(--r-sm);
  font-size: .875rem; font-weight: 520; color: var(--ink-3);
}
.tab-item.is-active .tab, .tab:hover { color: var(--ink); }
.tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-dot { display: none; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-soft); }
.is-live .tab-dot { display: block; animation: tab-dot 1.4s var(--ease-io) infinite; }
@keyframes tab-dot { 50% { opacity: .3; transform: scale(.75); } }
.tab-close {
  display: grid; place-items: center; flex: none;
  width: 28px; height: 28px; margin: 0 3px 0 2px; padding: 0;
  background: none; border: 0; border-radius: 8px; color: var(--ink-3);
  opacity: 0; transition: opacity .15s, background-color .15s, color .15s;
}
.tab-item:hover .tab-close, .tab-item.is-active .tab-close, .tab-close:focus-visible { opacity: 1; }
.tab-close:hover { background: rgba(184, 220, 196, .12); color: var(--ink); }
.tab-close .icon { width: 15px; height: 15px; stroke-width: 2; }
.tab:focus-visible, .tab-close:focus-visible { outline-offset: 0; }
.tabs-row .new-chat { min-height: 36px; padding: 0 12px 0 10px; font-size: .875rem; }

.export[aria-disabled="true"] { opacity: .55; cursor: default; }
.export[aria-disabled="true"]:hover { background: rgba(6, 20, 14, .5); border-color: var(--line-strong); }

/* A short notice under the tabs: "Chat closed. Undo", the chat limit, storage trouble. */
.notice-layer { position: relative; height: 0; z-index: 5; }
.notice {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: calc(100vw - 2 * var(--pad));
  padding: 6px 6px 6px 16px; min-height: 44px;
  background: #0d2219; border: 1px solid var(--line-strong); border-radius: 22px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .8);
  font-size: .9375rem; color: var(--ink);
  animation: notice-in .22s var(--ease-out);
}
.notice:not(:has(.notice-action:not([hidden]))) { padding-right: 16px; }
.notice-text { margin: 0; line-height: 1.4; }
.notice-action {
  flex: none; min-height: 34px; padding: 0 14px;
  background: transparent; border: 1px solid rgba(143, 224, 108, .45); border-radius: 999px;
  font-weight: 620; font-size: .9375rem; color: var(--accent-soft);
}
.notice-action:hover { background: rgba(61, 187, 18, .14); }
@keyframes notice-in { from { opacity: 0; transform: translate(-50%, -6px); } }
.hint.is-wait { color: var(--ink-2); }

/* ---------- the composer ---------- */
.jump {
  position: absolute; bottom: calc(var(--dock-h, 120px) + 8px); z-index: 2;
  right: max(var(--pad), calc(50% - var(--col) / 2));   /* the column's right edge, clear of most text */
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  background: var(--field); border: 1px solid var(--line-strong); border-radius: 50%;
  color: var(--ink); box-shadow: 0 8px 20px -8px rgba(0, 0, 0, .7);
}
.jump:hover { border-color: rgba(143, 224, 108, .5); }

.dock {
  padding: 6px max(var(--pad), env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
}
.composer {
  max-width: var(--col); margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 6px 6px 6px 18px;
  background: var(--field);
  border: 1px solid var(--line-strong); border-radius: 24px;
  box-shadow: 0 16px 40px -18px rgba(0, 0, 0, .8);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within {
  border-color: rgba(143, 224, 108, .6);
  box-shadow: 0 0 0 3px rgba(61, 187, 18, .2), 0 16px 40px -18px rgba(0, 0, 0, .8);
}
.composer textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: 12.5rem;
  margin: 0; padding: 10px 0; border: 0; outline: 0; resize: none;
  background: transparent; color: var(--ink); caret-color: var(--accent-soft);
  font-size: 1rem; line-height: 1.5;
  scrollbar-width: thin; scrollbar-color: rgba(184, 220, 196, .22) transparent;
}
.composer textarea::placeholder { color: var(--ink-3); opacity: 1; }
.send {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid transparent; border-radius: 50%;
  transition: background-color .15s, color .15s, border-color .15s, opacity .15s;
}
.send:hover { background: var(--accent-hover); }
.send:disabled { background: rgba(184, 220, 196, .14); color: var(--ink-3); cursor: default; }
.send .icon { width: 20px; height: 20px; stroke-width: 2.2; }
.send .icon-stop { display: none; fill: currentColor; stroke: none; }
.is-busy .send { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.is-busy .send:hover { border-color: rgba(143, 224, 108, .6); background: rgba(184, 220, 196, .06); }
.is-busy .send .icon-send { display: none; }
.is-busy .send .icon-stop { display: block; }

.dock-meta {
  max-width: var(--col); margin: 6px auto 0; padding: 0 14px;
  display: flex; justify-content: center; align-items: baseline; gap: 12px;
  font-size: .8125rem; line-height: 1.4; color: var(--ink-3);
}
.hint, .counter { margin: 0; }
.hint { text-align: center; }
.hint.is-demo { color: var(--warn); }
.counter { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.counter.is-full { color: var(--warn); }
.dock-meta:has(.counter:not([hidden])) .hint { text-align: left; }

/* ---------- phones and small windows ---------- */
@media (max-width: 599px) {
  :root { --gutter: auto; }
  .export, .tabs-row .new-chat { width: 44px; padding: 0; justify-content: center; }
  .export .btn-label, .tabs-row .new-chat .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .tab-item { max-width: 11.5rem; }
  .bar { min-height: 56px; padding-top: max(10px, env(safe-area-inset-top)); }
  .brand { gap: 10px; }
  .brand-logo { height: 26px; }
  .brand-name { padding-left: 10px; font-size: .8125rem; }
  .column { padding-top: 12px; padding-bottom: 24px; }
  .welcome { margin: auto 0 0; padding-bottom: 0; }
  .welcome .leaf-hero { --leaf: 60px; margin-bottom: 12px; }
  .welcome-lede { font-size: 1rem; }
  .starters { grid-template-columns: 1fr; margin-top: 24px; gap: 8px; }
  .starter { min-height: 52px; }
  .messages { gap: 24px; }
  .msg-user, .prose { font-size: 1rem; }
  .prose pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  .msg-user { max-width: 88%; }
  /* the leaf sits on its own line above the answer, beside the status */
  .msg-bot { grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; }
  .msg-bot > * { grid-column: 1 / -1; }
  .msg-bot > .msg-mark { grid-column: 1; grid-row: 1; }
  .msg-bot > .msg-status { grid-column: 2; grid-row: 1; }
  .msg-mark .leaf { --leaf: 38px; }
  .msg-bot .prose, .msg-bot .msg-cut { margin-top: 6px; }
  .msg-error .msg-mark { display: none; }
  .dock-meta { padding: 0 8px; font-size: .75rem; }
}
@media (max-width: 379px) {
  .brand-logo { height: 24px; }
}
@media (pointer: coarse) {
  .tab { height: 44px; }
  .tab-close { width: 44px; height: 44px; margin: 0 0 0 -6px; opacity: .85; }
  .tab-item:not(.is-active) .tab-close { opacity: .6; }
  .tabs-row .new-chat { min-height: 44px; }
  .notice-action { min-height: 44px; }
  .act { width: 44px; height: 44px; }
  .msg-actions { min-height: 44px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .bar { min-height: 48px; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 4px; }
  .hint { display: none; }
  .welcome .leaf-hero { display: none; }
}

/* ---------- motion preferences and hidden tabs ---------- */
.is-paused .tab-dot, .is-paused .scene *, .is-paused .msg .leaf-svg, .is-paused .msg .leaf-glow, .is-paused .msg .blade { animation-play-state: paused !important; }
@media (prefers-reduced-motion: reduce) {
  .scene-photo, .scene-shaft, .scene-motes i, .leaf-svg, .leaf-glow, .blade, .msg.is-new, .tab-dot, .notice,
  .is-streaming .prose *::after { animation: none !important; }
  .scene-shaft, .scene-motes { display: none; }
  .leaf-svg, .leaf-glow, .scene-scrim::before, .starter .icon { transition: none !important; }
  /* a steady glow (no pulse) says "working"; the status text carries the meaning */
  :is(.is-searching, .is-thinking) .leaf-glow { opacity: .8; transform: none; }
}
@media (forced-colors: active) {
  .scene { display: none; }
  .composer, .starter, .btn-quiet, .error-box { border: 1px solid CanvasText; }
}

/* ---------- Export PDF: a company document on white paper ----------
   The person prints (Save as PDF). Only the print document is shown; nothing relies on background graphics. */
.print-doc { display: none; }
@media print {
  @page { margin: 18mm 18mm 20mm; }
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; }
  body > :not(.print-doc) { display: none !important; }
  .print-doc {
    display: block;
    --ink: #1b1f1d; --ink-2: #3d4541; --ink-3: #555d59; --ink-strong: #000;
    --accent: #2e8a10; --accent-soft: #1f620a; --line: #c4c8c6; --line-strong: #8f9693;
    font-family: var(--font); font-size: 10.5pt; line-height: 1.5; color: var(--ink);
  }
  .pd-head { margin-bottom: 7mm; padding-bottom: 4.5mm; border-bottom: 1pt solid #3dbb12; }
  .pd-logo { display: block; width: 56mm; height: auto; margin-bottom: 5mm; }
  .pd-title { margin: 0; font-size: 16pt; line-height: 1.25; font-weight: 650; font-stretch: 105%; color: #000; }
  .pd-meta { margin: 1.5mm 0 0; font-size: 9pt; color: var(--ink-3); }
  .pd-empty { color: var(--ink-3); }
  .pd-q { margin: 7mm 0 3mm; padding: .4mm 0 .4mm 4mm; border-left: 2pt solid #3dbb12; break-inside: avoid; break-after: avoid; }
  .pd-label { margin: 0 0 1mm; font-size: 7.5pt; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #2e7a10; break-after: avoid; }
  .pd-qtext { margin: 0; font-size: 11pt; font-weight: 600; color: #000; white-space: pre-wrap; overflow-wrap: anywhere; }
  .pd-a { padding-left: calc(4mm + 2pt); }
  .pd-a .pd-label { color: var(--ink-3); }
  .pd-mark {
    display: inline-block; margin: 1mm 0 0 calc(4mm + 2pt); padding: .3mm 2mm;
    border: .75pt solid var(--line-strong); border-radius: 1.5mm;
    font-size: 8.5pt; font-weight: 650; color: var(--ink-2);
  }
  .pd-a .pd-mark { margin-left: 0; }
  .print-doc .prose { max-width: none; font-size: 10.5pt; line-height: 1.5; color: var(--ink); }
  .print-doc .prose p, .print-doc .prose li { orphans: 3; widows: 3; }
  .print-doc .prose li { break-inside: avoid; }
  .print-doc .prose h3, .print-doc .prose h4, .print-doc .prose h5 { margin: 4.5mm 0 1.5mm; color: #000; break-after: avoid; }
  .print-doc .prose h3 { font-size: 12pt; }
  .print-doc .prose h4 { font-size: 11pt; }
  .print-doc .prose h5 { font-size: 10.5pt; }
  .print-doc .prose code { background: none; border: .5pt solid #b5bab8; color: #111; }
  .print-doc .prose pre { background: none; border: .75pt solid #9aa09d; border-radius: 1.5mm; padding: 2.5mm 3.5mm; font-size: 9pt; color: #111; white-space: pre-wrap; overflow-wrap: anywhere; break-inside: avoid; }
  .print-doc .prose pre code { border: 0; }
  .print-doc .prose blockquote { border-left-color: var(--line-strong); }
  .print-doc .prose .table-wrap { overflow: visible; background: none; border: 0; border-radius: 0; }
  .print-doc .prose table { width: 100%; min-width: 0; border-collapse: collapse; border: .75pt solid var(--line-strong); font-size: 9.5pt; }
  .print-doc .prose thead { display: table-header-group; }
  .print-doc .prose tr { break-inside: avoid; }
  .print-doc .prose th, .print-doc .prose td { max-width: none; padding: 1.4mm 2.5mm; border: .5pt solid #b0b5b3; color: #111; }
  .print-doc .prose th { background: none; white-space: normal; font-weight: 700; color: #000; }
  .print-doc .prose a { color: #1f5f0a; text-decoration: underline; text-decoration-color: currentColor; }
  .print-doc .prose a[data-href]::after { content: "(" attr(data-href) ")"; display: inline-block; margin-left: .3em; text-decoration: none; color: var(--ink-3); font-size: 9pt; overflow-wrap: anywhere; }
  .pd-foot { margin-top: 10mm; padding-top: 3mm; border-top: .75pt solid var(--line-strong); font-size: 8.5pt; color: var(--ink-3); break-inside: avoid; }
  .pd-foot p { margin: 0 0 1mm; }
}
