:root {
  --forest: #173b31;
  --forest-deep: #0e2922;
  --moss: #637b5e;
  --sage: #a9b9a3;
  --lime: #d9e8a2;
  --paper: #f3f0e7;
  --paper-light: #fbfaf6;
  --stone: #d8d3c6;
  --ink: #18221e;
  --muted: #69716c;
  --line: rgba(23, 59, 49, 0.16);
  --shadow: 0 24px 70px rgba(19, 45, 37, 0.14);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #dcd8cd;
  font-family: "Manrope", sans-serif;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.grid-field {
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(23, 59, 49, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 59, 49, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 82% 12%, rgba(217, 232, 162, 0.5), transparent 28rem),
    linear-gradient(140deg, #d2cec3, #ede9df 48%, #d8d4ca);
  background-size: 2.5rem 2.5rem, 2.5rem 2.5rem, auto, auto;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr);
  width: min(96vw, 104rem);
  height: min(94dvh, 64rem);
  margin: 3dvh auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 1.25rem;
  background: var(--paper-light);
  box-shadow: var(--shadow);
  transition: grid-template-columns 300ms cubic-bezier(.2,.8,.2,1);
}
.app.rail-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
.app.rail-collapsed .rail { visibility: hidden; opacity: 0; transform: translateX(-1rem); }

.rail {
  z-index: 3;
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  color: #f5f3eb;
  background:
    linear-gradient(145deg, rgba(255,255,255,.035), transparent 28%),
    var(--forest-deep);
  transition: opacity 220ms ease, transform 300ms ease, visibility 300ms;
}
.identity { display: flex; align-items: center; gap: 1rem; padding: 2.2rem 1.7rem 1.65rem; }
.monogram {
  display: grid;
  width: 3.4rem;
  height: 3.4rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(217, 232, 162, .65);
  border-radius: 50%;
  color: var(--lime);
  font-family: "Newsreader", serif;
  font-size: 1.18rem;
  letter-spacing: .05em;
}
.kicker { margin: 0 0 .35rem; color: var(--moss); font-size: .65rem; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.identity .kicker { color: rgba(217, 232, 162, .62); }
.identity h1 { margin: 0; font-family: "Newsreader", serif; font-size: 1.75rem; font-weight: 500; }

.new-thread {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 0 1.4rem 1.7rem;
  padding: .85rem 1rem;
  border: 1px solid rgba(217, 232, 162, .28);
  border-radius: .65rem;
  color: #f7f5ee;
  background: rgba(217, 232, 162, .08);
  text-align: left;
  transition: border-color 160ms, background 160ms, transform 160ms;
}
.new-thread:hover { border-color: rgba(217, 232, 162, .65); background: rgba(217, 232, 162, .13); transform: translateY(-1px); }
.new-thread span { color: var(--lime); font-size: 1.25rem; }

.history { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.history-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 1.55rem .8rem; color: rgba(245,243,235,.45); font-size: .66rem; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
.icon-button { width: 2rem; height: 2rem; border: 0; border-radius: 50%; color: inherit; background: transparent; }
.rail-close { display: none; }
.thread-list { margin: 0; padding: 0 .65rem; overflow: auto; list-style: none; scrollbar-width: thin; }
.thread { position: relative; display: flex; border-radius: .55rem; }
.thread.active { background: rgba(217, 232, 162, .11); }
.thread-open { min-width: 0; flex: 1; padding: .8rem .9rem; overflow: hidden; border: 0; color: rgba(245,243,235,.72); background: transparent; text-align: left; }
.thread.active .thread-open { color: #fff; }
.thread-title { display: block; overflow: hidden; font-size: .78rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.thread-date { display: block; margin-top: .25rem; color: rgba(245,243,235,.34); font-size: .61rem; }
.thread-delete { width: 2rem; border: 0; color: rgba(245,243,235,.25); background: transparent; opacity: 0; }
.thread:hover .thread-delete, .thread-delete:focus { opacity: 1; }
.empty-history { padding: .8rem 1.55rem; color: rgba(245,243,235,.35); font-size: .72rem; line-height: 1.7; }
.rail-foot { display: flex; align-items: center; gap: .55rem; margin: 1rem 1.5rem 1.4rem; color: rgba(245,243,235,.38); font-size: .65rem; }
.live-dot { width: .45rem; height: .45rem; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 .25rem rgba(217,232,162,.08); }

.workspace { display: grid; min-width: 0; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; background: var(--paper-light); }
.topbar { display: flex; align-items: center; gap: 1rem; min-height: 4.4rem; padding: .8rem 1.5rem; border-bottom: 1px solid var(--line); }
.rail-toggle, .about-button { border: 0; border-radius: 999px; color: var(--forest); background: transparent; font-size: .72rem; font-weight: 700; }
.rail-toggle { display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem; }
.rail-toggle:hover, .about-button:hover { background: rgba(23,59,49,.07); }
.presence { display: flex; align-items: center; gap: .7rem; margin-right: auto; color: var(--muted); font-size: .68rem; letter-spacing: .04em; }
.presence-line { display: block; width: 2.5rem; height: 1px; background: var(--moss); }
.about-button { padding: .65rem .85rem; }

.conversation { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; padding: clamp(1.2rem, 3vw, 3rem) clamp(1rem, 5vw, 5.5rem); }
.opening { width: min(54rem, 100%); margin: auto; animation: rise 650ms both; }
.opening-mark { display: flex; width: 4.5rem; height: 4.5rem; margin-bottom: 2rem; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--forest); border-radius: 50%; color: var(--forest); font-size: .64rem; font-weight: 800; line-height: 1.25; }
.opening-mark span:last-child { color: var(--moss); font-size: .57rem; }
.opening h2 { max-width: 49rem; margin: 0; font-family: "Newsreader", serif; font-size: clamp(3rem, 7vw, 6.7rem); font-weight: 350; letter-spacing: -.045em; line-height: .88; }
.opening h2 em { color: var(--moss); font-weight: 300; }
.opening-copy { max-width: 42rem; margin: 1.7rem 0 2.3rem; color: var(--muted); font-size: clamp(.9rem, 1.2vw, 1.05rem); line-height: 1.8; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }
.suggestions button { position: relative; display: grid; gap: .35rem; padding: 1.2rem 1.1rem; border: 0; border-right: 1px solid var(--line); background: transparent; text-align: left; transition: background 160ms, transform 160ms; }
.suggestions button:last-child { border-right: 0; }
.suggestions button:hover { background: rgba(99,123,94,.08); transform: translateY(-2px); }
.suggestions span { color: var(--moss); font-family: "Newsreader", serif; font-size: .75rem; }
.suggestions strong { font-family: "Newsreader", serif; font-size: 1rem; font-weight: 550; }
.suggestions small { color: var(--muted); font-size: .65rem; line-height: 1.45; }

.message { display: grid; width: min(52rem, 100%); margin: 0 auto 1.7rem; animation: rise 350ms both; }
.message.user { justify-items: end; }
.message.assistant { justify-items: start; }
.message-label { margin: 0 0 .4rem; color: var(--muted); font-size: .62rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.bubble { min-width: 0; max-width: min(90%, 46rem); padding: 1rem 1.15rem; border-radius: 1rem; font-size: .88rem; line-height: 1.75; white-space: pre-wrap; }
.user .bubble { color: #f8f7f1; background: var(--forest); border-bottom-right-radius: .25rem; }
.assistant .bubble { padding: 1.25rem 1.4rem; border: 1px solid var(--line); background: #fff; border-bottom-left-radius: .25rem; box-shadow: 0 8px 30px rgba(23,59,49,.055); }
.thinking .bubble { color: var(--muted); }
.thinking-dots { display: inline-flex; gap: .3rem; }
.thinking-dots i { width: .35rem; height: .35rem; border-radius: 50%; background: var(--moss); animation: pulse 1.2s infinite; }
.thinking-dots i:nth-child(2) { animation-delay: .15s; }
.thinking-dots i:nth-child(3) { animation-delay: .3s; }
.message-actions { display: flex; gap: .35rem; margin-top: .45rem; }
.message-action { padding: .25rem .5rem; border: 0; border-radius: .4rem; color: var(--muted); background: transparent; font-size: .62rem; }
.message-action:hover { color: var(--forest); background: rgba(23,59,49,.06); }

.prose { white-space: normal; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose li { line-height: 1.82; }
.prose h2, .prose h3, .prose h4 { margin: 1.2em 0 .45em; color: var(--forest); font-family: "Newsreader", serif; font-weight: 550; line-height: 1.2; }
.prose h2 { font-size: 1.45rem; }
.prose h3 { font-size: 1.18rem; }
.prose ul, .prose ol { padding-left: 1.35rem; }
.prose blockquote { margin: 1rem 0; padding: .2rem 1rem; border-left: 3px solid var(--moss); color: var(--muted); }
.prose code { padding: .12rem .35rem; border-radius: .25rem; background: #eeece4; font-size: .82em; }
.prose pre { max-width: 100%; overflow: auto; padding: .9rem; border-radius: .55rem; color: #eef5ef; background: var(--forest-deep); }
.prose pre code { padding: 0; background: transparent; }
.prose a { color: #34664f; text-underline-offset: .18em; }
.table-scroll { max-width: 100%; overflow-x: auto; }
.prose table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.prose th, .prose td { padding: .55rem .65rem; border: 1px solid var(--line); text-align: left; }
.prose th { background: rgba(99,123,94,.08); }

.composer-zone { padding: .7rem clamp(1rem, 4vw, 4rem) 1rem; background: linear-gradient(transparent, var(--paper-light) 25%); }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; width: min(55rem, 100%); margin: auto; padding: .35rem .4rem .35rem 1.15rem; border: 1px solid rgba(23,59,49,.24); border-radius: 1rem; background: #fff; box-shadow: 0 10px 35px rgba(23,59,49,.09); transition: border-color 160ms, box-shadow 160ms; }
.composer:focus-within { border-color: var(--moss); box-shadow: 0 12px 40px rgba(23,59,49,.13); }
.composer textarea { max-height: 11rem; resize: none; overflow-y: auto; border: 0; outline: 0; background: transparent; line-height: 1.65; }
.composer textarea::placeholder { color: #979d98; }
.send { display: grid; width: 2.65rem; height: 2.65rem; place-items: center; border: 0; border-radius: .72rem; color: #fff; background: var(--forest); transition: transform 160ms, background 160ms; }
.send:hover:not(:disabled) { transform: translateY(-1px); background: #245545; }
.send:disabled { cursor: wait; opacity: .45; }
.send svg { width: 1.15rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.composer-meta { display: flex; width: min(55rem, 100%); margin: .4rem auto 0; justify-content: space-between; color: #8b918c; font-size: .59rem; }
.composer-meta p { margin: 0; }
.legal-note a, .about a { color: var(--forest); text-underline-offset: .16em; }

.about { width: min(34rem, calc(100vw - 2rem)); padding: 2.2rem; border: 1px solid var(--line); border-radius: 1rem; color: var(--ink); background: var(--paper-light); box-shadow: var(--shadow); }
.about::backdrop { background: rgba(10,29,24,.57); backdrop-filter: blur(5px); }
.about h2 { margin: .3rem 0 1rem; font-family: "Newsreader", serif; font-size: 2rem; font-weight: 450; }
.about p:not(.kicker) { color: var(--muted); font-size: .82rem; line-height: 1.8; }
.about-close { position: absolute; top: 1rem; right: 1rem; width: 2rem; border: 0; background: transparent; font-size: 1.3rem; }
.about.required .about-close { display: none; }
.about-terms { padding-top: .75rem; border-top: 1px solid var(--line); }
.dialog-action { margin-top: .8rem; padding: .72rem 1rem; border: 0; border-radius: .55rem; color: white; background: var(--forest); }
.scrim { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.legal-page { min-height: 100%; overflow: auto; background: #dcd8cd; }
.legal-page .grid-field { position: fixed; }
.legal-sheet { position: relative; width: min(54rem, calc(100% - 2rem)); margin: 2rem auto; padding: clamp(1.5rem, 5vw, 4.5rem); border: 1px solid rgba(255,255,255,.72); border-radius: 1.1rem; background: var(--paper-light); box-shadow: var(--shadow); }
.legal-header { margin-bottom: 3rem; padding-bottom: 2.3rem; border-bottom: 1px solid var(--line); }
.legal-header .monogram { margin: 2.2rem 0 1.6rem; color: var(--forest); border-color: var(--moss); }
.legal-header h1 { margin: .35rem 0 .8rem; font-family: "Newsreader", serif; font-size: clamp(2.6rem, 7vw, 5.2rem); font-weight: 350; letter-spacing: -.04em; line-height: .93; }
.legal-header > p:last-child { color: var(--muted); font-size: .72rem; }
.legal-back { color: var(--forest); font-size: .72rem; font-weight: 700; text-decoration: none; }
.legal-sheet section { display: grid; grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr); gap: 1.5rem; padding: 1.4rem 0; border-bottom: 1px solid var(--line); }
.legal-sheet section h2 { margin: 0; color: var(--forest); font-family: "Newsreader", serif; font-size: 1.2rem; font-weight: 550; }
.legal-sheet section p { grid-column: 2; margin: 0 0 .75rem; color: var(--muted); font-size: .81rem; line-height: 1.78; }
.legal-footer { padding-top: 2rem; color: var(--muted); font-size: .7rem; line-height: 1.7; }
.legal-footer a { color: var(--forest); font-weight: 700; }

@keyframes rise { from { opacity: 0; transform: translateY(.65rem); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-.2rem); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }

@media (max-width: 860px) {
  .app { width: 100%; height: 100dvh; margin: 0; grid-template-columns: minmax(0,1fr); border: 0; border-radius: 0; }
  .app.rail-collapsed { grid-template-columns: minmax(0,1fr); }
  .rail { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(20rem, 86vw); visibility: hidden; opacity: 0; transform: translateX(-100%); }
  .app.rail-open .rail { visibility: visible; opacity: 1; transform: translateX(0); }
  .rail-close { display: block; }
  .scrim { position: fixed; z-index: 19; display: block; inset: 0; border: 0; background: rgba(10,29,24,.48); backdrop-filter: blur(3px); }
  .topbar { min-height: 3.9rem; padding: .65rem .8rem; }
  .presence-line { width: 1rem; }
  .about-button { font-size: .65rem; }
  .conversation { padding: 1.4rem 1rem; }
  .opening h2 { font-size: clamp(3rem, 15vw, 4.5rem); }
  .suggestions { grid-template-columns: 1fr; }
  .suggestions button { border-right: 0; border-bottom: 1px solid var(--line); }
  .suggestions button:last-child { border-bottom: 0; }
  .bubble { max-width: 94%; }
  .composer-zone { padding: .6rem .75rem .8rem; }
}

@media (max-width: 520px) {
  .rail-toggle { width: 2.6rem; overflow: hidden; font-size: 0; white-space: nowrap; }
  .rail-toggle span { flex: 0 0 auto; font-size: 1rem; }
  .presence { display: none; }
  .about-button { margin-left: auto; }
  .opening-mark { width: 3.7rem; height: 3.7rem; margin-bottom: 1.4rem; }
  .opening h2 { font-size: 3.25rem; }
  .opening-copy { margin: 1.2rem 0 1.5rem; }
  .composer-meta p { display: none; }
  .composer-meta { justify-content: flex-end; }
  .legal-note { max-width: 15rem; text-align: right; }
}

@media (max-width: 680px) {
  .legal-sheet { width: 100%; margin: 0; border: 0; border-radius: 0; }
  .legal-sheet section { grid-template-columns: 1fr; gap: .65rem; }
  .legal-sheet section p { grid-column: 1; }
}
