:root {
  --canvas: #0b0b0a;
  --canvas-deep: #070706;
  --surface: #11110f;
  --surface-2: #171714;
  --surface-3: #1c1b17;
  --text: #f1eee5;
  --text-soft: #b8b3a8;
  --text-dim: #77736b;
  --line: rgba(242, 237, 224, 0.09);
  --line-strong: rgba(242, 237, 224, 0.16);
  --accent: #e8b56d;
  --accent-soft: #cf9d5a;
  --accent-glow: rgba(232, 181, 109, 0.16);
  --success: #9fc69a;
  --danger: #d8937d;
  --focus: #f2c47e;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  --mx: 50vw;
  --my: 48vh;
  --header-h: 72px;
  --composer-h: 146px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--canvas);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { background: var(--canvas); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 50% -150px, rgba(226, 189, 127, 0.06), transparent 70%),
    linear-gradient(180deg, #0c0c0b 0%, var(--canvas-deep) 100%);
  color: var(--text);
}

button, textarea, input, select { font: inherit; }
button, select { color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

::selection { background: rgba(232, 181, 109, 0.25); color: #fff8e8; }

.field[hidden] { display: none; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.ambient__spotlight {
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(620px circle at var(--mx) var(--my), rgba(231, 183, 112, 0.125), rgba(174, 124, 64, 0.04) 34%, transparent 70%);
  opacity: 0.92;
  transition: opacity 280ms ease;
}

.ambient__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(248, 239, 217, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(248, 239, 217, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(420px circle at var(--mx) var(--my), #000 0%, rgba(0,0,0,.72) 35%, transparent 78%);
  opacity: 0.34;
}

.ambient__grain {
  position: absolute;
  inset: 0;
  opacity: 0.14;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.15'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
  animation: grainShift 7s steps(7) infinite;
}

.ambient__vignette {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 220px rgba(0, 0, 0, 0.62);
}

@keyframes grainShift {
  0%, 100% { transform: translate3d(0,0,0) scale(1.05); }
  20% { transform: translate3d(-1.5%, 1%,0) scale(1.05); }
  40% { transform: translate3d(1%, -1.5%,0) scale(1.05); }
  60% { transform: translate3d(1.4%, .5%,0) scale(1.05); }
  80% { transform: translate3d(-.8%, -1%,0) scale(1.05); }
}

.shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--header-h) minmax(0, 1fr) auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(18px, 4vw, 48px);
  border-bottom: 1px solid rgba(241, 236, 223, 0.055);
  background: linear-gradient(180deg, rgba(11,11,10,.88), rgba(11,11,10,.36));
  backdrop-filter: blur(18px) saturate(110%);
}

.brand {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  border-radius: 14px;
  padding: 7px 9px 7px 6px;
}

.brand__mark {
  position: relative;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(238, 224, 193, 0.18);
  border-radius: 50%;
  box-shadow: inset 0 0 22px rgba(232,181,109,.06);
}
.brand__mark::before,
.brand__mark::after,
.brand__mark span {
  content: "";
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 9px rgba(232,181,109,.72);
}
.brand__mark::before { transform: translate(-6px, 3px); }
.brand__mark::after { transform: translate(6px, -3px); }
.brand__mark span { width: 3px; height: 3px; }

.brand__copy { display: grid; line-height: 1; gap: 4px; }
.brand__copy strong { font-size: 13px; letter-spacing: .015em; font-weight: 650; }
.brand__copy small { font-size: 9px; color: var(--text-dim); letter-spacing: .14em; text-transform: uppercase; }

.topbar__actions { display: flex; align-items: center; gap: 11px; }
.runtime-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: .02em;
  white-space: nowrap;
}
.runtime-state i {
  width: 5px; height: 5px; border-radius: 50%;
  background: #77736b;
  box-shadow: 0 0 0 3px rgba(119,115,107,.08);
}
.runtime-state[data-state="connected"] i { background: var(--success); box-shadow: 0 0 0 3px rgba(159,198,154,.09), 0 0 12px rgba(159,198,154,.28); }
.runtime-state[data-state="busy"] i { background: var(--accent); box-shadow: 0 0 0 3px rgba(232,181,109,.08), 0 0 12px rgba(232,181,109,.26); }
.runtime-state[data-state="error"] i { background: var(--danger); box-shadow: 0 0 0 3px rgba(216,147,125,.08); }

.key-button,
.prompt-chip,
.secondary-button,
.primary-button,
.icon-button,
.field__icon,
.send-button {
  border: 0;
  cursor: pointer;
}

.key-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  color: #d8d2c5;
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(244,235,216,.1);
  border-radius: 999px;
  font-size: 11px;
  transition: border-color 180ms ease, background 180ms ease, color 180ms ease, transform 180ms ease;
}
.key-button svg { width: 14px; height: 14px; fill: currentColor; opacity: .78; }
.key-button:hover { border-color: rgba(232,181,109,.25); color: #f3e3c7; background: rgba(232,181,109,.055); transform: translateY(-1px); }

.chat {
  position: relative;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(232,181,109,.18) transparent;
}
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: rgba(232,181,109,.16); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }

.empty-state {
  width: min(820px, calc(100% - 40px));
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(72px, 13vh, 148px) 0 80px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  transition: opacity 260ms ease, transform 360ms cubic-bezier(.22,.76,.25,1);
}
.empty-state[hidden] { display: none; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  color: #a59f94;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.eyebrow span { width: 26px; height: 1px; background: linear-gradient(90deg, var(--accent), transparent); box-shadow: 0 0 12px rgba(232,181,109,.3); }

.empty-state h1 {
  margin: 0;
  max-width: 760px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(48px, 8vw, 96px);
  line-height: .92;
  font-weight: 400;
  letter-spacing: -.055em;
  text-wrap: balance;
  color: #f0ece2;
  text-shadow: 0 14px 54px rgba(0,0,0,.28);
}
.empty-state p {
  max-width: 620px;
  margin: 25px 0 0;
  color: var(--text-soft);
  font-size: clamp(14px, 1.6vw, 17px);
  line-height: 1.72;
  letter-spacing: -.01em;
}

.prompt-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 34px;
}
.prompt-chip {
  position: relative;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(240,231,211,.09);
  color: #9d988e;
  background: rgba(255,255,255,.025);
  font-size: 11px;
  text-align: left;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease, transform 180ms ease;
}
.prompt-chip:hover { color: #ebe4d7; border-color: rgba(232,181,109,.2); background: rgba(232,181,109,.04); transform: translateY(-1px); }

.thread {
  width: min(820px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 70px;
}
.thread:empty { display: none; }

.message {
  position: relative;
  margin: 0 0 30px;
  animation: messageIn 420ms cubic-bezier(.18,.78,.24,1) both;
}
.message[data-role="user"] {
  width: fit-content;
  max-width: min(78%, 620px);
  margin-left: auto;
  padding: 13px 16px;
  border: 1px solid rgba(238,229,209,.09);
  border-radius: 18px 18px 5px 18px;
  background: linear-gradient(135deg, rgba(255,255,255,.055), rgba(255,255,255,.028));
  box-shadow: 0 12px 40px rgba(0,0,0,.16);
}
.message[data-role="assistant"] {
  max-width: 760px;
  padding: 2px 0 2px 22px;
}
.message[data-role="assistant"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(232,181,109,.55) 20%, rgba(232,181,109,.2) 78%, transparent);
  box-shadow: 0 0 14px rgba(232,181,109,.18);
}
.message__meta {
  display: none;
  margin-bottom: 8px;
  color: var(--text-dim);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.message[data-role="assistant"] .message__meta { display: block; }
.message__body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.72;
  letter-spacing: -.005em;
  color: #e8e3d8;
}
.message[data-role="user"] .message__body { color: #ddd8ce; line-height: 1.55; }
.message__body strong { color: #fff4df; font-weight: 650; }
.message__body .confidence { color: var(--accent); font-variant-numeric: tabular-nums; }

.message__details {
  margin-top: 13px;
  color: var(--text-dim);
}
.message__details summary { width: fit-content; cursor: pointer; font-size: 10px; letter-spacing: .05em; text-transform: uppercase; user-select: none; }
.message__details pre {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.18);
  overflow: auto;
  color: #ada79b;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.message[data-loading="true"] .message__body { color: var(--text-dim); }
.thinking-line { display: inline-flex; align-items: center; gap: 5px; height: 20px; }
.thinking-line span { width: 12px; height: 1px; background: #9a7951; transform-origin: left; animation: thinkPulse 1.25s ease-in-out infinite; opacity: .35; }
.thinking-line span:nth-child(2) { animation-delay: 120ms; width: 18px; }
.thinking-line span:nth-child(3) { animation-delay: 240ms; width: 8px; }
@keyframes thinkPulse { 0%,100% { transform: scaleX(.45); opacity:.24; } 50% { transform: scaleX(1); opacity:.84; } }
@keyframes messageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.composer-wrap {
  position: relative;
  padding: 10px 20px 16px;
  background: linear-gradient(180deg, transparent, rgba(8,8,7,.78) 18%, rgba(8,8,7,.96) 70%);
}
.composer {
  position: relative;
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 13px 13px 10px 16px;
  border: 1px solid rgba(242,232,211,.12);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(28,27,23,.92), rgba(17,17,15,.94));
  box-shadow: 0 18px 60px rgba(0,0,0,.34), inset 0 1px 0 rgba(255,255,255,.025);
  backdrop-filter: blur(20px) saturate(116%);
  overflow: hidden;
}
.composer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: radial-gradient(380px circle at var(--rx, 50%) var(--ry, 0%), rgba(232,181,109,.085), transparent 68%);
  opacity: .8;
}
.composer:focus-within { border-color: rgba(232,181,109,.22); box-shadow: 0 18px 64px rgba(0,0,0,.38), 0 0 0 1px rgba(232,181,109,.035), inset 0 1px 0 rgba(255,255,255,.03); }

.composer textarea {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  max-height: 180px;
  min-height: 32px;
  resize: none;
  overflow-y: auto;
  padding: 4px 4px 7px 0;
  border: 0;
  outline: 0;
  color: #eee9df;
  background: transparent;
  font-size: 14px;
  line-height: 1.55;
}
.composer textarea::placeholder { color: #6e6a62; }
.composer__footer { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 34px; }
.composer__hint { color: #66625c; font-size: 9px; letter-spacing: .025em; }
.send-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  color: #211a12;
  background: #e3b16d;
  box-shadow: 0 7px 24px rgba(232,181,109,.14);
  transition: transform 180ms ease, background 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}
.send-button svg { width: 18px; height: 18px; fill: currentColor; }
.send-button:hover:not(:disabled) { transform: translateY(-1px); background: #efc17d; box-shadow: 0 9px 28px rgba(232,181,109,.22); }
.send-button:disabled { opacity: .22; cursor: default; box-shadow: none; }
.privacy-note { width: min(820px, 100%); margin: 8px auto 0; text-align: center; color: #57534d; font-size: 9px; line-height: 1.45; }

.reactive { --rx: 50%; --ry: 50%; }
.reactive::before {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: 0;
  pointer-events: none;
  border-radius: inherit;
  opacity: 0;
  background: radial-gradient(180px circle at var(--rx) var(--ry), rgba(240,194,126,.11), transparent 68%);
  transition: opacity 180ms ease;
}
.reactive:hover::before { opacity: 1; }
.reactive > * { position: relative; z-index: 1; }

.key-dialog {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}
.key-dialog::backdrop { background: rgba(2,2,2,.64); backdrop-filter: blur(9px); }
.key-dialog[open] { display: grid; place-items: center; padding: 22px; }
.key-panel {
  position: relative;
  width: min(480px, 100%);
  overflow: hidden;
  padding: 24px;
  border-radius: 24px;
  border: 1px solid rgba(239,228,205,.12);
  background: linear-gradient(180deg, rgba(25,24,21,.985), rgba(13,13,11,.985));
  box-shadow: var(--shadow);
  animation: panelIn 280ms cubic-bezier(.18,.76,.28,1) both;
}
.key-panel::after { content:""; position:absolute; inset:0; pointer-events:none; background: radial-gradient(340px circle at var(--rx) var(--ry), rgba(232,181,109,.08), transparent 68%); }
@keyframes panelIn { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
.key-panel__head { position:relative; z-index:1; display:flex; align-items:flex-start; justify-content:space-between; gap:16px; }
.panel-kicker { color: #857f74; font-size: 9px; text-transform: uppercase; letter-spacing: .13em; }
.key-panel h2 { margin: 6px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: 30px; font-weight: 400; letter-spacing: -.035em; }
.icon-button { width: 34px; height: 34px; display:grid; place-items:center; border-radius:50%; color:#8a857b; background:rgba(255,255,255,.03); border:1px solid rgba(255,255,255,.06); }
.icon-button:hover { color: #efe8dc; background:rgba(255,255,255,.05); }
.icon-button svg { width:16px; height:16px; fill:none; stroke:currentColor; stroke-width:1.7; }
.key-panel__intro { position:relative; z-index:1; margin: 18px 0 20px; color:var(--text-soft); font-size:12px; line-height:1.65; }
.field { position:relative; z-index:1; display:grid; gap:8px; margin-top:14px; color:#8f897f; font-size:10px; letter-spacing:.04em; }
.field__control { display:flex; align-items:center; gap:8px; padding-right:8px; border:1px solid rgba(240,230,210,.1); border-radius:13px; background:rgba(255,255,255,.025); }
.field input,
.field select { width:100%; min-height:43px; border:1px solid rgba(240,230,210,.1); border-radius:13px; padding:0 12px; outline:0; background:rgba(255,255,255,.025); color:#e9e3d7; font-size:12px; }
.field__control input { border:0; background:transparent; }
.field input:focus,
.field select:focus,
.field__control:focus-within { border-color:rgba(232,181,109,.25); }
.field__icon { width:28px; height:28px; display:grid; place-items:center; border-radius:8px; background:transparent; color:#777168; }
.field__icon:hover { color:#d9d1c4; background:rgba(255,255,255,.04); }
.field__icon svg { width:16px; height:16px; fill:none; stroke:currentColor; stroke-width:1.6; }
.consent-row { position:relative; z-index:1; display:grid; grid-template-columns:16px 1fr; gap:9px; align-items:start; margin-top:18px; color:#858077; font-size:10px; line-height:1.5; }
.consent-row input { margin:1px 0 0; accent-color:#c89450; }
.key-panel__status { position:relative; z-index:1; min-height:18px; margin-top:11px; color:var(--text-dim); font-size:10px; }
.key-panel__status[data-state="error"] { color:#d89a86; }
.key-panel__status[data-state="warning"] { color:#d6b178; }
.key-panel__status[data-state="success"] { color:#a4c8a0; }
.key-panel__actions { position:relative; z-index:1; display:flex; justify-content:flex-end; gap:8px; margin-top:5px; }
.secondary-button,
.primary-button { min-height:40px; padding:0 15px; border-radius:12px; font-size:11px; }
.secondary-button { color:#aca69b; background:transparent; border:1px solid rgba(240,230,210,.09); }
.secondary-button:hover { background:rgba(255,255,255,.03); color:#e5dfd3; }
.primary-button { position:relative; overflow:hidden; color:#251d13; background:#e4b36e; font-weight:700; }
.primary-button:hover { background:#efc17f; }

@media (max-width: 640px) {
  :root { --header-h: 64px; }
  .topbar { padding: 0 14px; }
  .runtime-state { display: none; }
  .key-button span { display: none; }
  .key-button { width: 36px; padding:0; justify-content:center; }
  .empty-state { width: calc(100% - 30px); padding-top: 48px; }
  .empty-state h1 { font-size: clamp(46px, 16vw, 72px); }
  .empty-state p { font-size: 13px; }
  .prompt-rail { flex-direction: column; align-items:stretch; width:100%; }
  .prompt-chip { width:100%; border-radius:13px; padding:11px 12px; }
  .thread { width: calc(100% - 30px); padding-top: 24px; }
  .message[data-role="user"] { max-width: 88%; }
  .composer-wrap { padding: 8px 10px 12px; }
  .composer { border-radius:18px; }
  .composer__hint { display:none; }
  .composer__footer { justify-content:flex-end; }
  .privacy-note { padding:0 10px; font-size:8px; }
  .key-dialog[open] { padding: 10px; align-items:end; }
  .key-panel { border-radius:24px 24px 14px 14px; padding:20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .ambient__grain { animation: none; }
  .ambient__spotlight, .ambient__grid { opacity: .24; }
}

@media (prefers-contrast: more) {
  :root { --text-soft:#d6d1c6; --text-dim:#aaa49a; --line:rgba(255,255,255,.22); --line-strong:rgba(255,255,255,.32); }
  .key-button, .prompt-chip, .composer, .key-panel { border-color: var(--line-strong); }
}
