:root {
  --primary: #16181d;
  --primary-hover: #2a2e36;
  --accent: #4f6df5;
  --success: #17804b;
  --warning: #9c6412;
  --danger: #bd2c2c;
  --info: #315cce;
  --neutral-0: #ffffff;
  --neutral-25: #fbfbfc;
  --neutral-50: #f7f7f8;
  --neutral-100: #efeff1;
  --neutral-200: #dedfe3;
  --neutral-400: #9699a2;
  --neutral-600: #62656e;
  --neutral-800: #292c33;
  --neutral-950: #111318;
  --surface: var(--neutral-0);
  --surface-subtle: var(--neutral-50);
  --text: var(--neutral-950);
  --muted: var(--neutral-600);
  --border: var(--neutral-200);
  --focus: rgba(79, 109, 245, .28);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-sm: 0 1px 2px rgba(17, 19, 24, .04);
  --shadow-md: 0 14px 40px rgba(17, 19, 24, .08);
  --font: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
html[data-theme="dark"] .answer-card { background: rgba(21,23,28,.94); }
html[data-theme="dark"] .composer-wrap {
  background: linear-gradient(to bottom, rgba(18,20,25,0), rgba(18,20,25,.94) 20%, #121419 48%);
}
html[data-theme="dark"] .hero-badge { background: rgba(29, 32, 38, .78); }

html[data-theme="dark"] .brand-mark {
  background: #f3f4f6;
  color: #111318;
}

.brand-copy { display: grid; line-height: 1.05; }
.brand-name { font-size: 15px; }
.brand-powered {
  margin-top: 4px;
  color: #79c7ff;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .01em;
}

html[data-theme="dark"] .topbar {
  background: rgba(18, 20, 25, .88);
  border-bottom-color: rgba(48, 52, 61, .8);
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swal2-popup {
  font-family: var(--font) !important;
  border-radius: 20px !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-md) !important;
}

.swal2-title { font-size: 22px !important; letter-spacing: -.02em; }
.swal2-html-container { color: var(--muted) !important; font-size: 13px !important; line-height: 1.65 !important; }
.swal2-confirm, .swal2-cancel { border-radius: 11px !important; font-weight: 600 !important; }

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 50% -20%, rgba(142, 162, 255, .10), transparent 34rem),
    var(--surface);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

html[data-theme="dark"] {
  color-scheme: dark;
  --primary: #f3f4f6;
  --primary-hover: #ffffff;
  --accent: #8ea2ff;
  --success: #5fd39a;
  --warning: #efb85d;
  --danger: #ff8585;
  --info: #9eb0ff;
  --neutral-0: #15171c;
  --neutral-25: #181a20;
  --neutral-50: #1d2026;
  --neutral-100: #252830;
  --neutral-200: #333741;
  --neutral-400: #8d929d;
  --neutral-600: #a9aeb8;
  --neutral-800: #e1e4e9;
  --neutral-950: #f7f8fa;
  --surface: #121419;
  --surface-subtle: #1b1e24;
  --text: #f4f5f7;
  --muted: #a7acb6;
  --border: #30343d;
  --focus: rgba(142, 162, 255, .34);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .24);
  --shadow-md: 0 16px 46px rgba(0, 0, 0, .34);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -20%, rgba(79, 109, 245, .07), transparent 34rem),
    var(--surface);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 68px;
  padding: 0 clamp(18px, 4vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(222,223,227,.7);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -.02em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}
.ghost-button:hover { background: var(--surface-subtle); color: var(--text); border-color: var(--border); }
.ghost-button:focus-visible, .ask-button:focus-visible, .composer:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.ghost-button svg { width: 17px; }
.icon-button { width: 40px; padding: 0; justify-content: center; }

.app-shell {
  width: min(860px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(34px, 8vh, 88px) 0 54px;
}

.hero {
  text-align: center;
  padding: clamp(30px, 8vh, 80px) 0 28px;
  transition: all .2s ease;
}

.hero.compact { padding: 4px 0 18px; }
.hero.compact h1, .hero.compact p, .hero.compact .hero-badge { display: none; }

.hero-badge {
  width: max-content;
  margin: 0 auto 16px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.72);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(40px, 8vw, 68px);
  line-height: 1.03;
  letter-spacing: -.055em;
  font-weight: 700;
}

.hero p {
  margin: 18px auto 0;
  max-width: 590px;
  color: var(--muted);
  font-size: clamp(15px, 2vw, 18px);
  line-height: 1.65;
}

.composer-wrap {
  position: sticky;
  bottom: 0;
  padding: 12px 0 4px;
  z-index: 15;
  background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,.94) 20%, #fff 48%);
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 12px;
  min-height: 62px;
  padding: 10px 10px 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  transition: border-color .16s ease, box-shadow .16s ease;
}

.search-icon { width: 20px; height: 20px; margin-bottom: 10px; color: var(--neutral-400); }

.composer textarea {
  width: 100%;
  max-height: 180px;
  min-height: 40px;
  padding: 8px 0 6px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}
.composer textarea::placeholder { color: var(--neutral-400); }

.ask-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  transition: background .16s ease, transform .16s ease;
}
.ask-button:hover { background: var(--primary-hover); transform: translateY(-1px); }
.ask-button svg { width: 19px; }

html[data-theme="dark"] .ask-button {
  background: #f3f4f6;
  color: #111318;
}
html[data-theme="dark"] .ask-button:hover { background: #ffffff; }

.ask-button.stop-mode {
  background: #d64545;
  color: #ffffff;
}
.ask-button.stop-mode:hover { background: #c53636; }
html[data-theme="dark"] .ask-button.stop-mode {
  background: #ff6b6b;
  color: #16181d;
}
html[data-theme="dark"] .ask-button.stop-mode:hover { background: #ff7e7e; }

.stopped-card {
  color: var(--muted);
  font-size: 13px;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 9px 0;
  color: var(--neutral-400);
  font-size: 10.5px;
  line-height: 1.5;
}

.conversation { display: grid; gap: 28px; }

.turn { display: grid; gap: 14px; }

.user-query {
  margin: 0;
  font-size: clamp(22px, 4vw, 30px);
  line-height: 1.28;
  letter-spacing: -.03em;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.answer-card {
  padding: clamp(20px, 3vw, 28px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow-sm);
}

.answer-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 17px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.markdown { font-size: 15px; line-height: 1.76; overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1.45em 0 .55em; line-height: 1.25; letter-spacing: -.02em; }
.markdown h1 { font-size: 24px; }
.markdown h2 { font-size: 20px; }
.markdown h3 { font-size: 17px; }
.markdown p, .markdown ul, .markdown ol, .markdown pre, .markdown blockquote { margin: .8em 0; }
.markdown ul, .markdown ol { padding-left: 1.3rem; }
.markdown li + li { margin-top: .4em; }
.markdown a { color: var(--info); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.markdown img { display: block; width: 100%; max-height: 440px; object-fit: cover; margin: 18px 0; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface-subtle); }
.markdown code { padding: .15em .35em; border-radius: 6px; background: var(--neutral-100); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .9em; }
.markdown pre { overflow: auto; padding: 16px; border-radius: 14px; background: var(--neutral-950); color: #f5f5f6; }
.markdown pre code { padding: 0; background: transparent; color: inherit; }
.markdown blockquote { margin-left: 0; padding-left: 16px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown table { width: 100%; display: block; overflow-x: auto; border-collapse: collapse; }
.markdown th, .markdown td { padding: 9px 11px; border: 1px solid var(--border); text-align: left; vertical-align: top; }

.sources { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.sources-title { margin: 0 0 12px; font-size: 13px; font-weight: 700; }
.source-list { display: grid; gap: 8px; }
.source-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.source-item:hover { transform: translateY(-1px); border-color: #c7c9cf; background: var(--surface-subtle); }
.source-main { min-width: 0; }
.source-name { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-snippet { display: -webkit-box; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.5; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.source-host { display: block; margin-top: 6px; color: var(--neutral-400); font-size: 10px; }
.source-thumb { width: 58px; height: 58px; border-radius: 10px; object-fit: cover; background: var(--neutral-100); }

.followups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.followup {
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--neutral-0);
  color: var(--neutral-800);
  font-size: 12px;
  cursor: pointer;
}
.followup:hover { background: var(--surface-subtle); }

.error-card { border-color: rgba(189,44,44,.25); background: #fffafa; color: #802222; }
html[data-theme="dark"] .error-card { border-color: rgba(255,133,133,.28); background: #24191b; color: #ffb0b0; }
.error-card p { margin: 0; line-height: 1.6; }

.loading-card { overflow: hidden; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
.skeleton { height: 12px; width: 75%; margin-top: 12px; border-radius: 999px; background: linear-gradient(90deg, #ececef 25%, #f6f6f7 37%, #ececef 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; }
.skeleton.wide { width: 96%; }
.skeleton.short { width: 52%; }

@keyframes pulse { to { opacity: .28; transform: scale(.8); } }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

@media (max-width: 600px) {
  .topbar { height: 60px; padding: 0 14px; }
  .app-shell { width: min(100% - 20px, 860px); padding-top: 18px; }
  .hero { padding: 42px 4px 20px; }
  .hero h1 { font-size: 42px; }
  .composer { border-radius: 18px; padding-left: 14px; }
  .search-icon { display: none; }
  .composer { grid-template-columns: 1fr auto; }
  .composer-meta { display: block; text-align: center; }
  .composer-meta span:last-child { display: none; }
  .clear-label { display: none; }
  .ghost-button { width: 40px; padding: 0; justify-content: center; }
  .brand-powered { display: none; }
  .answer-card { border-radius: 18px; }
  .source-thumb { width: 52px; height: 52px; }
}

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

.share-popup {
  border-radius: 20px !important;
  background: var(--surface) !important;
  color: var(--text) !important;
}

.share-modal-content { text-align: left; }
.share-modal-help {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.share-url-field {
  width: 100%;
  min-height: 88px;
  resize: none;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: var(--surface-subtle);
  color: var(--text);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  word-break: break-all;
}
.share-url-field:focus { box-shadow: 0 0 0 3px var(--focus); }
.share-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 15px;
}
.share-modal-actions .swal2-styled { margin: 0 !important; }
.share-copy-button {
  background: var(--primary) !important;
  color: var(--surface) !important;
}
.share-close-button {
  background: var(--surface-subtle) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
}


.share-banner {
  position: fixed; left: 50%; bottom: 18px; z-index: 40;
  width: min(720px, calc(100% - 28px)); transform: translateX(-50%);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow-md);
}
.share-banner[hidden] { display: none; }
.share-banner strong { display: block; font-size: 13px; }
.share-banner span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.primary-text-button {
  flex: 0 0 auto; min-height: 38px; padding: 0 14px; border: 0; border-radius: 11px;
  background: var(--primary); color: white; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
html[data-theme="dark"] .primary-text-button { color: #111318; }
.share-toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 12px);
  opacity: 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-md); font-size: 12px;
  transition: opacity .18s ease, transform .18s ease;
}
.share-toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 600px) {
  .brand-powered { font-size: 8px; }
  .share-banner { align-items: stretch; flex-direction: column; bottom: 10px; }
  .primary-text-button { width: 100%; }
}
