:root {
  --base: #0C0C0C;
  --surface: #141414;
  --surface-2: #1a1a1a;
  --border: #262626;
  --border-strong: #333;
  --text: #FAFAFA;
  --text-muted: #A1A1AA;
  --text-dim: #71717A;
  --accent: #F59E0B;
  --accent-text: #FBBF24;
  --accent-soft: rgba(245, 158, 11, 0.12);
  --success: #22C55E;
  --error: #EF4444;

  --f-display: 'Satoshi', 'DM Sans', system-ui, -apple-system, sans-serif;
  --f-body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--base); }
body {
  font-family: var(--f-body);
  color: var(--text);
  background: var(--base);
  font-size: 16px;
  line-height: 1.55;
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
}

.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;
}

.grain {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  opacity: 0.03; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--base) 78%, transparent);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: 1040px; margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand__mark {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border);
  font-family: var(--f-mono); font-weight: 700; color: var(--accent-text);
  font-size: 14px; line-height: 1;
}
.brand__name { font-family: var(--f-mono); font-size: 13px; letter-spacing: 0.02em; color: var(--text-muted); }
.topbar__links { display: inline-flex; align-items: center; gap: 10px; font-family: var(--f-mono); font-size: 12px; color: var(--text-muted); }
.topbar__links a { color: var(--text-muted); text-decoration: none; transition: color 150ms; }
.topbar__links a:hover { color: var(--accent-text); }
.dot { width: 3px; height: 3px; background: var(--border-strong); border-radius: 50%; }

.iconbtn {
  appearance: none; cursor: pointer;
  display: inline-grid; place-items: center;
  width: 28px; height: 28px;
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; border-radius: var(--radius-md);
  padding: 0;
  transition: color 150ms, background 150ms, border-color 150ms;
}
.iconbtn:hover { color: var(--accent-text); background: var(--surface); border-color: var(--border); }
.iconbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Page layout */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 48px 24px 80px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 40px;
}

/* Hero */
.hero { display: grid; gap: 20px; }
.hero__meta { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tag {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 9px; border-radius: 9999px;
  background: var(--accent-soft); border: 1px solid rgba(245,158,11,0.35);
  color: var(--accent-text);
  font-family: var(--f-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
}
.tag__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(245,158,11,.55); animation: pulse 2s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,.55); }
  50% { box-shadow: 0 0 0 6px rgba(245,158,11,0); }
}
.mono { font-family: var(--f-mono); font-size: 12px; color: var(--text-dim); letter-spacing: 0.01em; }

.hero__title {
  font-family: var(--f-display);
  font-weight: 900;
  font-size: clamp(40px, 6.4vw, 72px);
  line-height: 0.98;
  letter-spacing: -0.025em;
  margin: 0;
}
.accent { color: var(--accent-text); }
.hero__sub {
  color: var(--text-muted);
  font-size: 17px; line-height: 1.6; max-width: 62ch;
  margin: 0;
}
.hero__sub a { color: var(--accent-text); text-decoration: none; border-bottom: 1px solid rgba(251,191,36,.3); }
.hero__sub a:hover { border-bottom-color: var(--accent-text); }

.hero__prompts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  appearance: none; border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 9px 13px;
  font-family: var(--f-body); font-size: 13px; font-weight: 500;
  border-radius: 9999px;
  cursor: pointer;
  transition: color 150ms, border-color 150ms, background 150ms, transform 150ms var(--ease-out);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); transform: translateY(-1px); }
.chip:active { transform: translateY(0); }

/* Chat panel */
.chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto auto;
  min-height: 520px;
}

.chat__log {
  padding: 24px;
  display: grid;
  gap: 22px;
  max-height: 62vh;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.chat__log::-webkit-scrollbar { width: 10px; }
.chat__log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--surface); }
.chat__log::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

.msg { display: grid; gap: 6px; max-width: 92%; }
.msg__who {
  font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-dim);
}
.msg__body {
  padding: 14px 16px; border-radius: var(--radius-lg);
  line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
  font-size: 15.5px;
}
.msg--user { justify-self: end; text-align: right; }
.msg--user .msg__who { color: var(--accent-text); }
.msg--user .msg__body {
  background: var(--accent-soft);
  border: 1px solid rgba(245,158,11,0.25);
  color: var(--text);
  text-align: left;
}
.msg--assistant .msg__body {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.msg--intro .msg__body { background: transparent; border-color: transparent; padding-left: 0; padding-right: 0; color: var(--text-muted); }

.msg__body .cursor {
  display: inline-block; width: 8px; height: 1.1em;
  vertical-align: -2px; background: var(--accent);
  margin-left: 2px; animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Composer */
.composer {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 14px 14px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer textarea {
  appearance: none; resize: none;
  background: var(--base); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: var(--f-body);
  font-size: 15px; line-height: 1.5;
  max-height: 240px;
  min-height: 44px;
  transition: border-color 150ms;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245,158,11,.12);
}
.send {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #0a0a0a;
  border: 1px solid var(--accent);
  padding: 0 16px; min-height: 44px;
  border-radius: var(--radius-md);
  font-family: var(--f-mono); font-weight: 500; font-size: 13px;
  letter-spacing: 0.02em;
  transition: background 150ms, transform 150ms var(--ease-out);
}
.send:hover:not(:disabled) { background: #FBBF24; }
.send:active:not(:disabled) { transform: scale(0.98); }
.send:disabled { opacity: 0.5; cursor: not-allowed; }

.composer__hint {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 4px 16px 14px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11px;
}
kbd {
  font-family: var(--f-mono); font-size: 10.5px;
  padding: 1px 5px; border-radius: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted);
}
.status { color: var(--text-dim); }
.status.active { color: var(--accent-text); }
.status.error  { color: var(--error); }

/* Footer */
.foot {
  display: flex; flex-wrap: wrap; gap: 8px;
  color: var(--text-dim);
  font-size: 11.5px;
  justify-content: center;
  text-align: center;
}
.foot__sep { opacity: 0.4; }

@media (max-width: 640px) {
  .page { padding: 28px 16px 56px; gap: 28px; }
  .topbar__inner { padding: 12px 16px; }
  .hero__title { font-size: clamp(36px, 10vw, 52px); }
  .hero__sub { font-size: 15.5px; }
  .chat__log { padding: 18px; max-height: 56vh; }
  .msg { max-width: 96%; }
  .send__label { display: none; }
  .send { padding: 0 14px; }
  .modal__panel { padding: 20px 18px; }
}

/* Settings modal */
.modal {
  padding: 0; border: none; background: transparent;
  max-width: 520px; width: calc(100% - 32px);
  color: var(--text);
}
.modal::backdrop { background: rgba(0,0,0,0.65); backdrop-filter: blur(6px); }
.modal[open] { animation: modalIn 180ms var(--ease-out); }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal__panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 22px 18px;
  display: grid; gap: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal__head { display: flex; align-items: center; justify-content: space-between; }
.modal__title {
  font-family: var(--f-display); font-weight: 700;
  font-size: 22px; letter-spacing: -0.015em; margin: 0;
}
.modal__lede { margin: -4px 0 2px; color: var(--text-muted); font-size: 13.5px; line-height: 1.55; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.field { display: grid; gap: 6px; }
.field--status { padding-top: 2px; border-top: 1px dashed var(--border); margin-top: 4px; padding-top: 10px; min-height: 18px; }
.field__label {
  font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-dim);
}
.field__hint { color: var(--text-dim); font-size: 11px; margin: 0; }
.field__hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; border: 1px solid var(--border); }
.field input[type="text"],
.field input[type="url"],
.field input[type="password"] {
  appearance: none;
  background: var(--base); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--f-mono); font-size: 13px;
  width: 100%;
  transition: border-color 150ms;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245,158,11,.12);
}
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
}
.segmented label {
  display: grid; place-items: center;
  padding: 8px 10px;
  border-radius: calc(var(--radius-md) - 2px);
  font-family: var(--f-mono); font-size: 12px; color: var(--text-muted);
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.segmented label:has(input:checked) { background: var(--surface-2); color: var(--accent-text); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.ghostbtn {
  appearance: none; cursor: pointer;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 9px 14px; min-height: 38px;
  border-radius: var(--radius-md);
  font-family: var(--f-mono); font-size: 12px;
  transition: color 150ms, border-color 150ms, background 150ms;
}
.ghostbtn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.send--sm { min-height: 38px; padding: 0 14px; font-size: 12px; }

[data-only="custom"] { display: none; }
.modal[data-provider="custom"] [data-only="custom"] { display: grid; }

/* Mic / voice-mode buttons */
.mic {
  appearance: none; cursor: pointer;
  display: inline-grid; place-items: center;
  width: 44px; min-height: 44px;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  transition: color 150ms, background 150ms, border-color 150ms, transform 150ms var(--ease-out);
}
.mic:hover:not(:disabled) { color: var(--accent-text); border-color: var(--border-strong); }
.mic:disabled { opacity: 0.4; cursor: not-allowed; }
.mic.is-listening {
  color: #0a0a0a; background: var(--accent); border-color: var(--accent);
  animation: mic-pulse 1.3s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,.55); }
  50%     { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
}

#voiceMode.is-on { color: var(--accent-text); background: var(--accent-soft); border-color: rgba(245,158,11,0.35); }

/* Per-message speaker button */
.msg__speak {
  justify-self: end;
  margin-top: 2px;
  width: 26px; height: 26px;
  color: var(--text-dim);
}
.msg--user .msg__speak { display: none; }

/* Voice settings block */
.field--voice { display: grid; gap: 10px; }
.voice-grid {
  display: grid; grid-template-columns: 1fr;
  gap: 10px;
}
.voice-grid select {
  appearance: none;
  background: var(--base); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px 12px; font-family: var(--f-mono); font-size: 12px;
}
.voice-grid select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245,158,11,.12); }
.voice-slider {
  display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 10px;
  font-family: var(--f-mono); font-size: 11px; color: var(--text-dim);
}
.voice-slider input[type="range"] { width: 100%; accent-color: var(--accent); }
.checkbox {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--f-mono); font-size: 12px; color: var(--text-muted);
  cursor: pointer;
}
.checkbox input { accent-color: var(--accent); }

@media (max-width: 640px) {
  .composer { grid-template-columns: 1fr auto auto; }
  .mic { width: 40px; min-height: 40px; }
}
