:root {
  color-scheme: dark;
  --bg: #101713;
  --surface: #17211b;
  --surface-2: #1d2922;
  --surface-3: #24332a;
  --text: #f2f5ef;
  --muted: #a7b3a9;
  --faint: #738177;
  --accent: #d7f36a;
  --accent-ink: #17210d;
  --line: rgba(228, 239, 224, 0.1);
  --danger: #ffb1a7;
  --radius: 24px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; }

body {
  min-width: 300px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -18%, rgba(90, 133, 86, 0.2), transparent 48%),
    var(--bg);
  color: var(--text);
}

button, textarea, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 760px);
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-inline: 1px solid rgba(255, 255, 255, 0.035);
  background: rgba(16, 23, 19, 0.78);
}

.topbar {
  flex: 0 0 auto;
  min-height: 76px;
  padding: max(12px, env(safe-area-inset-top)) 18px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 25, 20, 0.94);
}

.brand, .top-actions { display: flex; align-items: center; }
.brand { min-width: 0; gap: 12px; }
.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--accent);
  border-radius: 16px;
  background: linear-gradient(145deg, #334537, #202e25);
  box-shadow: inset 0 1px rgba(255,255,255,.11), 0 7px 22px rgba(0,0,0,.17);
}
.brand-mark svg { width: 30px; height: 30px; }
.brand-copy { min-width: 0; }
.brand-copy h1 { margin: 0 0 3px; font-size: 17px; font-weight: 650; letter-spacing: -.02em; }
.service-status { display: block; color: var(--muted); font-size: 12px; line-height: 1.2; }
.service-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 6px 1px 0;
  border-radius: 50%;
  background: #89968b;
}
.service-status[data-state="ready"]::before { background: #a8d75b; box-shadow: 0 0 9px rgba(168,215,91,.5); }
.service-status[data-state="error"]::before { background: #e99589; }
.top-actions { gap: 9px; }

.icon-button, .tool-button {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-2);
  cursor: pointer;
  transition: transform .14s ease, background .14s ease, border-color .14s ease;
}
.icon-button:active, .tool-button:active { transform: scale(.96); }
.icon-button svg, .tool-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.conversation {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #465649 transparent;
}

.welcome {
  width: min(100% - 36px, 530px);
  margin: clamp(36px, 9vh, 90px) auto 48px;
  text-align: center;
  animation: appear .35s ease both;
}
.welcome-orbit {
  width: 76px;
  height: 76px;
  margin: 0 auto 23px;
  display: grid;
  place-items: center;
  color: var(--accent);
  border: 1px solid rgba(215, 243, 106, .24);
  border-radius: 26px;
  background: radial-gradient(circle at 34% 27%, #40563c, #1d2a20 68%);
  box-shadow: 0 15px 40px rgba(0,0,0,.24), inset 0 1px rgba(255,255,255,.09);
  transform: rotate(-5deg);
}
.welcome-orbit span { font-size: 38px; line-height: 1; transform: rotate(5deg); }
.eyebrow { margin: 0; color: #b4c78b; font-size: 10px; font-weight: 750; letter-spacing: .2em; }
.welcome h2 { margin: 14px 0 12px; font-size: clamp(30px, 8vw, 42px); line-height: 1.1; font-weight: 620; letter-spacing: -.045em; }
.welcome h2 span { color: #a9b9a8; }
.welcome-copy { max-width: 340px; margin: 0 auto; color: var(--muted); font-size: 15px; line-height: 1.55; }
.memory-hint { margin: 14px auto 0; color: #b4c78b; font-size: 12px; line-height: 1.45; }
.message-list {
  width: min(100% - 28px, 650px);
  margin: 0 auto;
  padding: 24px 0 36px;
  display: flex;
  flex-direction: column;
  gap: 19px;
}
.message { display: flex; flex-direction: column; gap: 6px; animation: appear .2s ease both; }
.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message-label { padding: 0 7px; color: var(--faint); font-size: 11px; font-weight: 650; letter-spacing: .02em; }
.bubble {
  max-width: min(88%, 570px);
  padding: 13px 16px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 19px 19px 19px 6px;
  background: var(--surface-2);
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.user .bubble {
  color: var(--accent-ink);
  border-color: transparent;
  border-radius: 19px 19px 6px 19px;
  background: var(--accent);
  font-weight: 520;
}
.message.error .bubble { color: #ffd2cb; border-color: rgba(255,177,167,.22); background: rgba(83,44,39,.58); }
.message-sources { max-width: min(88%, 570px); padding: 2px 7px; color: var(--muted); font-size: 12px; }
.message-sources ul { display: flex; flex-wrap: wrap; gap: 5px 14px; margin: 5px 0 0; padding-left: 17px; }
.message-sources a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.message-tools { min-height: 30px; display: flex; gap: 6px; }
.message-tool {
  min-width: 38px;
  min-height: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 0;
  border-radius: 11px;
  background: transparent;
  cursor: pointer;
}
.message-tool:hover { color: var(--accent); background: rgba(255,255,255,.05); }
.message-tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.typing-bubble { min-width: 72px; display: flex; align-items: center; gap: 5px; }
.typing-bubble i { width: 6px; height: 6px; border-radius: 50%; background: #b7c2b6; animation: pulse 1s infinite ease-in-out; }
.typing-bubble i:nth-child(2) { animation-delay: .12s; }
.typing-bubble i:nth-child(3) { animation-delay: .24s; }

.composer-wrap {
  flex: 0 0 auto;
  padding: 0 14px max(11px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(16,23,19,0), rgba(16,23,19,.96) 19%);
}
.voice-status { min-height: 22px; padding: 0 5px 5px; color: var(--accent); font-size: 12px; text-align: center; }
.voice-console {
  width: min(100%, 680px);
  margin: 0 auto;
  display: flex;
  justify-content: center;
}
.tool-button { width: 48px; height: 48px; border: 0; color: #bfccb9; background: transparent; }
.voice-button { width: 100%; min-height: 70px; padding: 0 18px; display: flex; flex: 0 1 420px; align-items: center; justify-content: center; gap: 12px; color: var(--accent-ink); border-radius: 22px; background: var(--accent); box-shadow: 0 5px 18px rgba(215,243,106,.16); font-size: 16px; font-weight: 720; }
.voice-button svg { width: 27px; height: 27px; flex: 0 0 auto; }
.voice-button.conversation-active { color: var(--text); border: 1px solid rgba(215,243,106,.32); background: #26392b; box-shadow: 0 5px 22px rgba(0,0,0,.18); }
.tool-button:hover { color: var(--accent); background: rgba(255,255,255,.05); }
.voice-button:hover { color: var(--accent-ink); background: #e2f78a; }
.voice-button.conversation-active:hover { color: var(--text); background: #304734; }
.tool-button[disabled] { opacity: .35; cursor: not-allowed; }
.tool-button.recording { color: var(--text); background: #e16d61; animation: ring 1.3s infinite; }
.composer-note { margin: 8px auto 0; color: #76837a; font-size: 10px; line-height: 1.35; text-align: center; }

.access-dialog { width: min(420px, calc(100% - 32px)); padding: 0; color: var(--text); border: 1px solid rgba(238,248,234,.14); border-radius: 27px; background: #19241d; box-shadow: 0 25px 100px rgba(0,0,0,.6); }
.access-dialog::backdrop { background: rgba(3,8,5,.72); backdrop-filter: blur(7px); }
.access-card { padding: 26px; display: flex; flex-direction: column; align-items: stretch; }
.memory-dialog { max-height: calc(100dvh - 36px); }
.memory-card { max-height: calc(100dvh - 36px); overflow-y: auto; }
.memory-note { margin-bottom: 10px !important; }
.memory-empty { margin: 4px 0 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.memory-list { max-height: min(38vh, 300px); margin: 0 0 12px; padding: 0; overflow-y: auto; list-style: none; }
.memory-list li { margin: 7px 0; padding: 12px 14px; color: var(--text); border: 1px solid var(--line); border-radius: 14px; background: #101713; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.access-icon { width: 48px; height: 48px; margin-bottom: 18px; display: grid; place-items: center; color: var(--accent); border: 1px solid rgba(215,243,106,.2); border-radius: 16px; background: var(--surface-3); font-size: 28px; }
.access-card h2 { margin: 8px 0; font-size: 25px; letter-spacing: -.03em; }
.access-card p:not(.eyebrow):not(.access-error) { margin: 0 0 19px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.access-card label { margin-bottom: 7px; color: #d8e0d5; font-size: 12px; }
.access-card input { min-height: 50px; padding: 0 13px; color: var(--text); border: 1px solid var(--line); border-radius: 14px; outline: 0; background: #101713; }
.access-card input:focus { border-color: rgba(215,243,106,.55); }
.access-error { min-height: 19px; margin: 5px 0; color: var(--danger); font-size: 12px; }
.primary-button { min-height: 50px; margin-top: 6px; color: var(--accent-ink); border: 0; border-radius: 15px; background: var(--accent); font-weight: 750; cursor: pointer; }
.secondary-button { min-height: 48px; margin: 2px 0 8px; color: var(--text); border: 1px solid rgba(255,177,167,.28); border-radius: 15px; background: rgba(255,177,167,.07); font-weight: 650; cursor: pointer; }
.secondary-button:disabled { opacity: .45; cursor: default; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes pulse { 0%, 60%, 100% { opacity: .4; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes appear { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes ring { 50% { box-shadow: 0 0 0 8px rgba(215,243,106,.09); } }

@media (min-width: 700px) {
  .app-shell { border-inline-color: rgba(255,255,255,.055); box-shadow: 0 0 70px rgba(0,0,0,.2); }
  .topbar { padding-inline: 24px; }
  .composer-wrap { padding-inline: 22px; }
  .welcome { margin-top: clamp(55px, 12vh, 115px); }
  .message-list { padding-top: 35px; }
}

@media (max-height: 650px) {
  .topbar { min-height: 65px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; }
  .welcome { margin-top: 24px; }
  .welcome-orbit { width: 57px; height: 57px; margin-bottom: 13px; border-radius: 20px; }
  .welcome-orbit span { font-size: 30px; }
  .welcome h2 { margin: 9px 0; font-size: 30px; }
  .composer-wrap { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .composer-note { margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
