:root {
  color-scheme: light;
  --forest: #132c25;
  --forest-2: #20483b;
  --moss: #567567;
  --mist: #e9efeb;
  --cream: #f7f5ef;
  --paper: #fffefa;
  --ink: #17211d;
  --muted: #728079;
  --line: #dfe5df;
  --amber: #e6a85c;
  --red: #a3493d;
  --shadow: 0 18px 60px rgba(19, 44, 37, .13);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--cream); color: var(--ink); }
body { min-height: 100dvh; overscroll-behavior: none; }
button, textarea, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.app-shell {
  width: min(760px, 100%);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto auto;
  background: var(--cream);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 18px 13px;
  border-bottom: 1px solid rgba(19, 44, 37, .08);
  background: rgba(247, 245, 239, .9);
  backdrop-filter: blur(18px);
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 41px; height: 41px; display: grid; place-items: center; border-radius: 13px; background: var(--forest); box-shadow: 0 7px 18px rgba(19,44,37,.16); }
.brand-mark svg { width: 31px; height: 31px; fill: none; stroke: #f7f5ef; stroke-width: 1.45; stroke-linecap: round; stroke-linejoin: round; }
.brand p, .kicker { margin: 0 0 3px; color: var(--moss); font-size: 9px; line-height: 1; font-weight: 750; letter-spacing: .17em; }
.brand h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 20px; line-height: 1.1; font-weight: 500; white-space: nowrap; }
.icon-button, .close-button { width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--forest); cursor: pointer; }
.icon-button:active, .close-button:active { background: var(--mist); transform: scale(.96); }
.icon-button svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }

.connection-bar { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 27px; padding: 5px 16px; background: var(--mist); color: var(--moss); font-size: 11px; font-weight: 650; transition: .2s ease; }
.connection-bar.offline { background: #f5e8e3; color: var(--red); }
.pulse { width: 6px; height: 6px; border-radius: 50%; background: #4b8a70; box-shadow: 0 0 0 3px rgba(75,138,112,.13); }
.offline .pulse { background: var(--red); box-shadow: none; }

.install-banner { position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 11px; margin: 11px 14px 0; padding: 11px 37px 11px 11px; border: 1px solid #d9dfd9; border-radius: 16px; background: var(--paper); box-shadow: 0 8px 30px rgba(19,44,37,.06); }
.install-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--mist); color: var(--forest); font-size: 17px; }
.install-banner strong, .install-banner span { display: block; }
.install-banner strong { font-size: 12px; }
.install-banner span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.install-banner > button:not(.dismiss) { border: 0; border-radius: 9px; padding: 8px 10px; background: var(--forest); color: white; font-size: 11px; font-weight: 700; }
.install-banner .dismiss { position: absolute; right: 8px; top: 3px; border: 0; background: none; color: #98a29d; font-size: 20px; }

.messages { overflow-y: auto; padding: 20px 15px 10px; scroll-behavior: smooth; overscroll-behavior: contain; }
.welcome { max-width: 500px; margin: clamp(22px, 7vh, 64px) auto 25px; text-align: center; animation: rise .45s ease both; }
.welcome-orbit { width: 71px; height: 71px; margin: 0 auto 19px; display: grid; place-items: center; border: 1px solid #ccd8d1; border-radius: 50%; color: var(--forest); position: relative; }
.welcome-orbit::before, .welcome-orbit::after { content: ""; position: absolute; border: 1px solid #dfe7e2; border-radius: 50%; }
.welcome-orbit::before { inset: 8px -13px; transform: rotate(36deg); }
.welcome-orbit::after { inset: -8px 7px; transform: rotate(-36deg); }
.welcome-orbit span { font-family: Georgia, serif; font-size: 18px; z-index: 1; }
.welcome h2 { margin: 0 0 9px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(28px, 8vw, 39px); font-weight: 500; letter-spacing: -.02em; }
.welcome p { max-width: 390px; margin: 0 auto; color: var(--muted); font-size: 14px; line-height: 1.55; }
.message { max-width: 88%; margin: 0 0 16px; animation: rise .24s ease both; }
.message.user { margin-left: auto; }
.message .meta { margin: 0 8px 5px; color: #89958f; font-size: 9px; font-weight: 750; letter-spacing: .13em; }
.message.user .meta { text-align: right; }
.bubble { padding: 13px 15px; border: 1px solid var(--line); border-radius: 5px 18px 18px 18px; background: var(--paper); box-shadow: 0 4px 18px rgba(19,44,37,.04); font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .bubble { border-color: var(--forest); border-radius: 18px 5px 18px 18px; background: var(--forest); color: white; box-shadow: 0 8px 25px rgba(19,44,37,.16); }
.bubble code { padding: 2px 5px; border-radius: 5px; background: var(--mist); color: var(--forest); font-size: .91em; }
.bubble strong { font-weight: 720; }
.typing .bubble { display: flex; gap: 4px; width: 53px; padding: 15px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--moss); animation: blink 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }.typing i:nth-child(3) { animation-delay: .3s; }

.quick-actions { display: flex; gap: 7px; overflow-x: auto; padding: 6px 14px 11px; scrollbar-width: none; }
.quick-actions::-webkit-scrollbar { display: none; }
.quick-actions button { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; border: 1px solid #d6ded8; border-radius: 999px; padding: 8px 11px; background: rgba(255,254,250,.75); color: var(--moss); font-size: 11px; font-weight: 650; cursor: pointer; }
.quick-actions button:active { background: var(--mist); transform: scale(.97); }
.quick-actions span { color: var(--forest); font-size: 14px; }

.composer { display: flex; align-items: flex-end; gap: 9px; margin: 0 13px; padding: 7px 7px 7px 15px; border: 1px solid #cbd5ce; border-radius: 21px; background: var(--paper); box-shadow: var(--shadow); }
.composer:focus-within { border-color: #789386; box-shadow: 0 18px 60px rgba(19,44,37,.17), 0 0 0 3px rgba(86,117,103,.1); }
textarea { flex: 1; max-height: 132px; resize: none; border: 0; outline: 0; padding: 9px 0; background: transparent; color: var(--ink); font-size: 16px; line-height: 1.35; }
textarea::placeholder { color: #98a39d; }
#send { flex: 0 0 auto; width: 43px; height: 43px; display: grid; place-items: center; border: 0; border-radius: 15px; background: var(--forest); color: white; cursor: pointer; transition: .15s ease; }
#send:disabled { opacity: .42; }
#send:not(:disabled):active { transform: scale(.93); }
#send svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.privacy-note { margin: 7px 0 max(8px, env(safe-area-inset-bottom)); text-align: center; color: #929d97; font-size: 9px; letter-spacing: .02em; }
.privacy-note span { color: var(--moss); }

dialog { border: 0; }
dialog::backdrop { background: rgba(10, 24, 20, .53); backdrop-filter: blur(4px); }
.sheet { width: min(540px, calc(100% - 18px)); max-height: min(91dvh, 740px); margin: auto auto 0; padding: 12px 22px max(25px, env(safe-area-inset-bottom)); border-radius: 27px 27px 0 0; background: var(--paper); color: var(--ink); box-shadow: 0 -15px 60px rgba(7,20,16,.25); animation: sheet-up .28s ease both; }
.sheet-handle { width: 36px; height: 4px; margin: 0 auto 24px; border-radius: 99px; background: #d4dbd6; }
.sheet h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 32px; line-height: 1.12; font-weight: 500; letter-spacing: -.02em; }
.sheet-copy { margin: 14px 0 25px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.auth-sheet { text-align: center; }
.auth-mark { width: 57px; height: 57px; display: grid; place-items: center; margin: 0 auto 18px; border-radius: 18px; background: var(--forest); color: white; font-family: Georgia, serif; box-shadow: 0 12px 30px rgba(19,44,37,.2); }
.auth-sheet form { text-align: left; }
.auth-sheet label { display: block; margin: 0 0 7px; color: var(--moss); font-size: 11px; font-weight: 700; }
.password-field { display: flex; border: 1px solid #ccd5cf; border-radius: 14px; overflow: hidden; background: white; }
.password-field:focus-within { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(86,117,103,.11); }
.password-field input { min-width: 0; flex: 1; border: 0; outline: 0; padding: 14px; background: transparent; font-size: 16px; }
.password-field button { border: 0; padding: 0 14px; background: transparent; color: var(--moss); font-size: 11px; font-weight: 700; }
.form-error { min-height: 18px; margin: 7px 2px 3px; color: var(--red); font-size: 11px; }
.primary-button { width: 100%; border: 0; border-radius: 14px; padding: 14px 17px; background: var(--forest); color: white; font-size: 13px; font-weight: 750; cursor: pointer; }
.primary-button:active { transform: scale(.985); }
.sheet-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.close-button { background: var(--mist); font-size: 25px; font-weight: 300; }
.setting-card { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 11px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting-icon { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 12px; background: var(--mist); color: var(--forest); font-size: 17px; }
.setting-copy strong, .setting-copy span { display: block; }
.setting-copy strong { margin-bottom: 3px; font-size: 13px; }
.setting-copy span { color: var(--muted); font-size: 10px; line-height: 1.35; }
.secondary-button { min-width: 59px; border: 1px solid #ccd6cf; border-radius: 10px; padding: 8px 10px; background: transparent; color: var(--forest); font-size: 10px; font-weight: 750; cursor: pointer; }
.secondary-button.enabled { border-color: var(--forest); background: var(--forest); color: white; }
.brain-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 22px 0; }
.brain-stats div { min-width: 0; padding: 13px 7px; border-radius: 13px; background: var(--mist); text-align: center; }
.brain-stats strong, .brain-stats span { display: block; }
.brain-stats strong { color: var(--forest); font-family: Georgia, serif; font-size: 20px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.brain-stats span { margin-top: 4px; color: var(--muted); font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.text-button { width: 100%; border: 0; border-top: 1px solid var(--line); padding: 13px; background: transparent; color: var(--moss); font-size: 12px; cursor: pointer; }
.text-button.danger { color: var(--red); }
.version { margin: 16px 0 0; text-align: center; color: #a1aaa5; font-size: 9px; }
.compact-sheet ol { margin: 20px 0 24px; padding-left: 22px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.compact-sheet li { margin-bottom: 9px; padding-left: 4px; }
.compact-sheet strong { color: var(--ink); }

@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 70%, 100% { opacity: .3; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-2px); } }
@keyframes sheet-up { from { opacity: 0; transform: translateY(35px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 761px) {
  body { background: #e3e9e4; }
  .app-shell { margin: 0 auto; box-shadow: 0 0 70px rgba(19,44,37,.12); }
  .sheet { margin-bottom: 4vh; border-radius: 27px; padding-bottom: 28px; }
}
@media (max-height: 670px) { .welcome { margin-top: 16px; } .welcome-orbit { width: 58px; height: 58px; margin-bottom: 12px; } .welcome h2 { font-size: 27px; } .welcome p { font-size: 12px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; } }
