:root {
  --bg: #0b0d0c;
  --bg-elev: #121513;
  --bg-elev-2: #181c1a;
  --border: #23322a;
  --border-strong: #2f4638;
  --fg: #e9ece8;
  --fg-dim: #93a298;
  --fg-faint: #5f6e65;
  --accent: #d4a93a;
  --accent-dim: #8a7324;
  --danger: #c14141;
  --user-bg: #1a2620;
  --bot-bg: #151a17;
  --mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo,
    Consolas, monospace;
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background-image: radial-gradient(
      ellipse at top,
      rgba(212, 169, 58, 0.05),
      transparent 60%
    ),
    linear-gradient(180deg, #0b0d0c 0%, #090b0a 100%);
}

.sr {
  position: absolute;
  left: -9999px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 11, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sigil {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1a2620, #0e1411);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  font-size: 16px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(212, 169, 58, 0.08);
}

.brand-title {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
}

.brand-sub {
  font-size: 11px;
  color: var(--fg-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3a8a5e;
  box-shadow: 0 0 8px #3a8a5e88;
}

.status[data-state='thinking'] .dot {
  background: var(--accent);
  box-shadow: 0 0 8px #d4a93aaa;
  animation: pulse 1.2s ease-in-out infinite;
}

.status[data-state='error'] .dot {
  background: var(--danger);
  box-shadow: 0 0 8px #c1414188;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 28px 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadein 0.25s ease;
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg.user {
  align-items: flex-end;
}

.role {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-faint);
  padding: 0 4px;
}

.msg.user .role {
  color: var(--fg-dim);
}

.bubble {
  max-width: 86%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bot-bg);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset;
}

.msg.user .bubble {
  background: var(--user-bg);
  border-color: var(--border-strong);
}

.msg.bot .bubble {
  border-left: 2px solid var(--accent-dim);
}

.bubble p {
  margin: 0 0 0.6em;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble strong {
  color: var(--accent);
  font-weight: 600;
}

.bubble code {
  font-family: var(--mono);
  background: rgba(212, 169, 58, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}

.bubble pre {
  background: #0a0c0b;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
}

.bubble ul,
.bubble ol {
  padding-left: 1.2em;
  margin: 0.4em 0;
}

.bubble li {
  margin: 0.2em 0;
}

.bubble blockquote {
  border-left: 2px solid var(--accent-dim);
  padding-left: 10px;
  color: var(--fg-dim);
  margin: 0.4em 0;
}

.bubble a {
  color: var(--accent);
}

.bubble .small {
  font-size: 12px;
  color: var(--fg-dim);
}

.bubble .cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 14px 22px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 40%);
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

#input {
  width: 100%;
  resize: none;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  max-height: 200px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(212, 169, 58, 0.12);
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.counter {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-faint);
}

.send {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #d4a93a, #a68524);
  border: 1px solid #7a6019;
  color: #0c0a04;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}

.send:hover {
  filter: brightness(1.1);
}

.send:active {
  transform: translateY(1px);
}

.send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

.turnstile {
  margin-top: 10px;
  min-height: 0;
}

.foot {
  text-align: center;
  padding: 10px 22px 18px;
  color: var(--fg-faint);
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.06em;
}

.chat::-webkit-scrollbar {
  width: 10px;
}
.chat::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
.chat::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
  }
  .chat {
    padding: 18px 14px 8px;
  }
  .composer {
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  }
  .bubble {
    max-width: 92%;
  }
  .brand-sub {
    display: none;
  }
}
