:root {
  --bg: #000000;
  --bg-elevated: #0a0c10;
  --bg-soft: #10141c;
  --ink: #eef3ff;
  --ink-soft: #9aa8c2;
  --muted: #6b7a96;
  --line: rgba(120, 160, 220, 0.16);
  --blue: #2f8cff;
  --blue-bright: #5cadff;
  --blue-deep: #1466d8;
  --blue-glow: rgba(47, 140, 255, 0.35);
  --danger: #ff6b6b;
  --success: #3dd68c;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --font-display: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "Plus Jakarta Sans", "Avenir Next", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 70% 50% at 80% 0%, rgba(47, 140, 255, 0.16), transparent 55%),
    radial-gradient(ellipse 50% 40% at 10% 80%, rgba(20, 102, 216, 0.12), transparent 60%),
    var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--blue-bright);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: #9dcbff;
}

button,
input,
select,
textarea {
  font: inherit;
}

.site-nav {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 72rem;
  margin-inline: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.brand:hover {
  color: var(--blue-bright);
}

.brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  object-fit: contain;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 0 14px var(--blue-glow));
}

.brand-text {
  display: none;
}

@media (min-width: 520px) {
  .brand-text {
    display: inline;
  }
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.92rem;
}

.nav-links a:hover {
  color: var(--ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.72rem 1.25rem;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue-bright), var(--blue-deep));
  color: #fff;
  box-shadow: 0 8px 28px var(--blue-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #7abbff, var(--blue));
  color: #fff;
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn-secondary:hover {
  border-color: rgba(92, 173, 255, 0.45);
  color: var(--ink);
  background: rgba(47, 140, 255, 0.08);
}

.btn-compact {
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
}

.hero {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hero-visual {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.hero-glow {
  position: absolute;
  width: 42rem;
  height: 42rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(47, 140, 255, 0.28), transparent 68%);
  filter: blur(8px);
  top: -12%;
  right: -8%;
  animation: drift 16s ease-in-out infinite alternate;
}

.hero-glow.secondary {
  width: 28rem;
  height: 28rem;
  top: auto;
  bottom: -10%;
  left: -10%;
  right: auto;
  background: radial-gradient(circle, rgba(20, 102, 216, 0.22), transparent 70%);
  animation-delay: -4s;
}

.hero-ring {
  position: absolute;
  inset: 18% 8% auto auto;
  width: min(48vw, 28rem);
  height: min(48vw, 28rem);
  border-radius: 50%;
  border: 1px solid rgba(92, 173, 255, 0.18);
  box-shadow: inset 0 0 60px rgba(47, 140, 255, 0.08);
  animation: pulse-ring 5s ease-in-out infinite;
}

.hero-veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.15) 0%, rgba(0, 0, 0, 0.55) 58%, var(--bg) 100%);
}

.hero-copy {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-width: 72rem;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4.5rem;
}

.hero-logo {
  width: min(14rem, 52vw);
  height: auto;
  margin: 0 0 1.35rem;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 10px 28px rgba(47, 140, 255, 0.4));
  animation: rise 700ms ease both;
}

.hero-headline {
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.15;
  margin: 0 0 0.9rem;
  max-width: 16ch;
  animation: rise 700ms ease 80ms both;
}

.hero-lede {
  margin: 0 0 1.6rem;
  max-width: 34rem;
  color: var(--ink-soft);
  font-size: 1.05rem;
  animation: rise 700ms ease 140ms both;
}

.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  animation: rise 700ms ease 200ms both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(-3%, 2%, 0) scale(1.06);
  }
}

@keyframes pulse-ring {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(1);
  }
  50% {
    opacity: 0.75;
    transform: scale(1.03);
  }
}

.section {
  max-width: 72rem;
  margin: 0 auto;
  padding: 3.5rem 1.5rem;
}

.section h2 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.03em;
  margin: 0 0 0.65rem;
}

.section > p {
  margin: 0 0 1.75rem;
  color: var(--ink-soft);
  max-width: 40rem;
}

.feature-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .feature-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.feature {
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.feature h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0 0 0.45rem;
  letter-spacing: -0.02em;
}

.feature p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.96rem;
}

.api-panel {
  margin-top: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: #d5e2f7;
  padding: 1.1rem 1.2rem;
  overflow-x: auto;
  box-shadow: var(--shadow);
}

.api-panel pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
}

.api-panel .comment {
  color: #6f809c;
}

.api-panel .key {
  color: var(--blue-bright);
}

.site-footer {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  justify-content: space-between;
  border-top: 1px solid var(--line);
}

.site-footer a {
  color: var(--ink-soft);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--blue-bright);
}

/* —— Chat app shell —— */
.chat-app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(ellipse 70% 40% at 100% 0%, rgba(47, 140, 255, 0.14), transparent 55%),
    radial-gradient(ellipse 50% 35% at 0% 100%, rgba(20, 102, 216, 0.1), transparent 50%),
    var(--bg);
}

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

.chat-top-left,
.chat-top-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.chat-top select,
.chat-top input,
.composer textarea,
.settings-panel input,
.admin-shell input {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--ink);
  padding: 0.55rem 0.7rem;
}

.chat-top select {
  max-width: min(42vw, 18rem);
  min-width: 8rem;
}

.model-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.thread {
  max-width: 48rem;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.15rem 1.5rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.thread-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 24rem;
  animation: rise 600ms ease both;
}

.thread-empty img {
  width: 4.75rem;
  height: auto;
  margin: 0 auto 1rem;
  display: block;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 0 22px var(--blue-glow));
}

.thread-empty strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--ink);
  margin-bottom: 0.35rem;
}

.msg {
  max-width: min(100%, 38rem);
  padding: 0.85rem 1rem;
  border-radius: 16px;
  word-break: break-word;
  animation: rise 280ms ease both;
}

.msg .plain-body {
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.assistant {
  align-self: flex-start;
  background: rgba(16, 20, 28, 0.9);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  max-width: min(100%, 42rem);
}

.msg.error {
  align-self: stretch;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.28);
  color: var(--danger);
}

.msg .role {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 0.3rem;
}

.md-body {
  font-size: 0.98rem;
  line-height: 1.65;
  color: var(--ink);
}

.md-body > *:first-child {
  margin-top: 0;
}

.md-body > *:last-child {
  margin-bottom: 0;
}

.md-body p,
.md-body ul,
.md-body ol,
.md-body pre,
.md-body blockquote,
.md-body table {
  margin: 0.65rem 0;
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 1rem 0 0.45rem;
}

.md-body h1 { font-size: 1.35rem; }
.md-body h2 { font-size: 1.2rem; }
.md-body h3 { font-size: 1.08rem; }

.md-body ul,
.md-body ol {
  padding-left: 1.25rem;
}

.md-body li + li {
  margin-top: 0.25rem;
}

.md-body a {
  color: var(--blue-bright);
}

.md-body code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: rgba(47, 140, 255, 0.12);
  border: 1px solid rgba(92, 173, 255, 0.18);
  border-radius: 6px;
  padding: 0.1em 0.35em;
}

.md-body pre {
  overflow-x: auto;
  background: #07090e;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}

.md-body pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: 0.82rem;
  color: #d7e4f8;
}

.md-body blockquote {
  margin-left: 0;
  padding: 0.15rem 0 0.15rem 0.9rem;
  border-left: 3px solid var(--blue);
  color: var(--ink-soft);
}

.md-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  overflow-x: auto;
  display: block;
}

.md-body th,
.md-body td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  text-align: left;
}

.md-body th {
  background: rgba(47, 140, 255, 0.1);
}

.md-body.is-streaming::after {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 1.05em;
  margin-left: 0.12em;
  vertical-align: text-bottom;
  background: var(--blue-bright);
  border-radius: 2px;
  animation: blink-caret 1s steps(1) infinite;
}

.thinking {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  min-height: 1.2rem;
  padding: 0.15rem 0;
}

.thinking span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--blue-bright);
  opacity: 0.35;
  animation: think-bounce 1.2s ease-in-out infinite;
}

.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink-caret {
  0%,
  45% { opacity: 1; }
  50%,
  100% { opacity: 0; }
}

@keyframes think-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  40% {
    transform: translateY(-0.28rem);
    opacity: 1;
  }
}

.composer-wrap {
  border-top: 1px solid var(--line);
  background: rgba(8, 10, 14, 0.92);
  backdrop-filter: blur(12px);
  padding: 0.85rem 1.15rem 1.15rem;
}

.composer {
  max-width: 48rem;
  margin: 0 auto;
  display: grid;
  gap: 0.65rem;
}

.composer textarea {
  width: 100%;
  min-height: 3.4rem;
  resize: vertical;
  max-height: 10rem;
}

.composer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.composer-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-panel {
  display: none;
  max-width: 48rem;
  margin: 0 auto 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 20, 28, 0.92);
}

.settings-panel.open {
  display: grid;
  gap: 0.55rem;
  animation: rise 220ms ease both;
}

.settings-panel label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.settings-panel input {
  width: 100%;
}

.admin-shell {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.5rem 1.15rem 3rem;
}

.admin-shell h1 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
  margin: 0 0 0.35rem;
}

.admin-shell .meta {
  color: var(--muted);
  margin: 0 0 1.25rem;
}

.admin-shell label {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.admin-shell table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1.25rem;
}

.admin-shell th,
.admin-shell td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.25rem;
  font-size: 0.92rem;
}

.new-key {
  background: rgba(47, 140, 255, 0.12);
  border: 1px solid rgba(92, 173, 255, 0.3);
  padding: 0.85rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.admin-gate,
.admin-panel {
  animation: rise 280ms ease both;
}

.admin-gate {
  max-width: 22rem;
  margin: 3rem auto 0;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 20, 28, 0.9);
  box-shadow: var(--shadow);
}

.admin-gate .brand-mark,
.admin-panel .brand-mark {
  width: 3.6rem;
  height: auto;
  margin-bottom: 1rem;
}

.admin-gate h1 {
  font-size: 1.35rem;
  margin-bottom: 0.35rem;
}

.admin-gate .error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
  min-height: 1.2em;
}

.admin-gate .btn {
  width: 100%;
  margin-top: 0.35rem;
}

.hidden {
  display: none !important;
}
