/* Chad's LLM — public chat page. One column that works from small phones to
   wide desktops, light and dark themes, and safe areas of notched screens. */

:root {
  --bg: #f6f6fb;
  --bg-glow-1: rgba(99, 102, 241, .16);
  --bg-glow-2: rgba(168, 85, 247, .12);
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --border: rgba(15, 23, 42, .08);
  --border-strong: rgba(15, 23, 42, .14);
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(79, 70, 229, .10);
  --ring: rgba(79, 70, 229, .28);
  --warn: #b45309;
  --warn-bg: #fff7e6;
  --warn-border: #fde3b0;
  --bad: #b91c1c;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .12);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d14;
    --bg-glow-1: rgba(99, 102, 241, .22);
    --bg-glow-2: rgba(168, 85, 247, .14);
    --surface: #131622;
    --surface-2: #1a1e2d;
    --border: rgba(255, 255, 255, .07);
    --border-strong: rgba(255, 255, 255, .14);
    --text: #e8eaf2;
    --text-2: #c3c8d6;
    --muted: #8a93a8;
    --accent: #818cf8;
    --accent-2: #a78bfa;
    --accent-soft: rgba(129, 140, 248, .14);
    --ring: rgba(129, 140, 248, .35);
    --warn: #fbbf24;
    --warn-bg: rgba(251, 191, 36, .08);
    --warn-border: rgba(251, 191, 36, .22);
    --bad: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.55 var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 520px at 12% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(800px 480px at 105% 0%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}

/* Header */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 0 12px;
  flex: none;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.mark { width: 36px; height: 36px; flex: none; filter: drop-shadow(0 4px 10px rgba(79, 70, 229, .35)); }
.mark path, .hero-mark path, .avatar path { fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; }
.mark circle, .hero-mark circle, .avatar circle { fill: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text b { font-size: 16.5px; letter-spacing: -.01em; white-space: nowrap; }
.brand-text span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.model-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.model-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); flex: none; }
.model-chip.off .dot { background: var(--muted); box-shadow: none; }
.model-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-chip .params { margin-left: -3px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .15s ease;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn:active { transform: scale(.96); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[hidden] { display: none; }

/* Conversation */
.thread {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 2px 24px;
}
.welcome { text-align: center; padding: clamp(24px, 9vh, 90px) 4px 8px; animation: rise .5s ease both; }
.hero-mark { width: 76px; height: 76px; margin: 0 auto 20px; position: relative; }
.hero-mark::after { content: ""; position: absolute; inset: -18px; border-radius: 50%; background: radial-gradient(circle, rgba(124, 58, 237, .32), transparent 65%); z-index: -1; }
.hero-mark svg { width: 76px; height: 76px; filter: drop-shadow(0 10px 24px rgba(79, 70, 229, .35)); }
.welcome h1 { font-size: clamp(26px, 5vw, 34px); letter-spacing: -.03em; margin: 0 0 8px; line-height: 1.15; }
.lead { color: var(--muted); margin: 0 auto 22px; max-width: 460px; font-size: 16.5px; }
.notice {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  max-width: 560px; margin: 0 auto 26px;
  padding: 13px 16px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 14px;
  color: var(--text-2);
  font-size: 14.5px; line-height: 1.5;
}
.notice svg { width: 20px; height: 20px; flex: none; margin-top: 1px; fill: none; stroke: var(--warn); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.notice b { color: var(--warn); }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 560px; margin: 0 auto; }
.chip {
  text-align: left;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  font-size: 14.5px; color: var(--text-2);
  transition: transform .12s ease, border-color .15s ease, box-shadow .15s ease;
}
.chip:hover { border-color: var(--ring); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.chip:active { transform: scale(.98); }

.msg { display: flex; gap: 12px; margin: 18px 0; animation: rise .28s ease both; }
.msg.user { justify-content: flex-end; }
.bubble-user {
  max-width: min(78%, 620px);
  padding: 11px 16px;
  border-radius: 20px 20px 6px 20px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  box-shadow: 0 6px 18px rgba(79, 70, 229, .28);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.avatar { width: 32px; height: 32px; flex: none; margin-top: 2px; }
.avatar svg { width: 32px; height: 32px; }
.reply { min-width: 0; flex: 1; }
.reply-card {
  display: inline-block; max-width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px 20px 20px 20px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.reply-card p { margin: 0 0 .65em; }
.reply-card p:last-child, .reply-card ul:last-child, .reply-card ol:last-child, .reply-card pre:last-child { margin-bottom: 0; }
.reply-card ul, .reply-card ol { margin: 0 0 .65em; padding-left: 1.3em; }
.reply-card h1, .reply-card h2, .reply-card h3 { font-size: 1.05em; margin: .3em 0 .5em; }
.reply-card code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
.reply-card pre { background: var(--surface-2); padding: 12px 14px; border-radius: 12px; overflow-x: auto; margin: 0 0 .65em; }
.reply-card pre code { background: none; padding: 0; }
.reply-card blockquote { margin: 0 0 .65em; padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.reply-card a { color: var(--accent); }
.reply-card.error { border-color: rgba(185, 28, 28, .3); color: var(--bad); }
.caret > :last-child::after, .caret:empty::after { content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 3px; vertical-align: -.15em; border-radius: 2px; background: var(--accent); animation: blink 1s steps(2) infinite; }
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
.thinking { display: inline-flex; align-items: center; gap: 10px; }
.thinking-text { color: var(--muted); font-size: 14px; }
.thought { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.thought summary { cursor: pointer; width: fit-content; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 500; list-style: none; }
.thought summary::-webkit-details-marker { display: none; }
.thought summary::before { content: "▸"; display: inline-block; margin-right: 6px; transition: transform .15s; }
.thought[open] summary::before { transform: rotate(90deg); }
.thought-text { margin: 6px 0 2px; padding: 8px 12px; border-left: 3px solid var(--accent-soft); color: var(--text-2); line-height: 1.5; white-space: pre-wrap; }
.meta { margin-top: 7px; font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.meta .tag { padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Composer */
.dock { flex: none; padding: 8px 0 max(12px, env(safe-area-inset-bottom)); }
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 8px 8px 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring), var(--shadow-lg); }
.composer textarea {
  flex: 1; min-width: 0;
  border: 0; outline: 0; resize: none;
  background: transparent;
  padding: 9px 0;
  max-height: 180px;
  font-size: 16px; line-height: 1.45;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #8b5cf6);
  color: #fff;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
  transition: transform .12s ease, opacity .15s ease;
}
.send:active { transform: scale(.94); }
.send:disabled { opacity: .45; cursor: default; box-shadow: none; }
.send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.busy .i-send { display: none; }
.send.busy .i-stop { display: block; }
.fineprint { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); text-align: center; }
.warn-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); flex: none; }
.count { font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 460px);
  padding: 11px 16px;
  background: var(--text); color: var(--bg);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  font-size: 14px; text-align: center;
  z-index: 10;
}
.toast[hidden] { display: none; }

:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 10px; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { to { opacity: 0; } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .45; } 40% { transform: translateY(-5px); opacity: 1; } }

/* Phones */
@media (max-width: 560px) {
  .brand-text span { display: none; }
  .model-chip { padding: 6px 10px; font-size: 12.5px; max-width: 48vw; }
  .model-chip .params { display: none; }
  .suggestions { grid-template-columns: 1fr; }
  .bubble-user { max-width: 86%; }
  .avatar, .avatar svg { width: 28px; height: 28px; }
  .msg { gap: 9px; }
}
/* Tablets and up: a little more breathing room */
@media (min-width: 768px) {
  .thread { padding-top: 16px; }
  .reply-card, .bubble-user { font-size: 16.5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Rating an answer */
.rate { display: inline-flex; gap: 2px; margin-left: 2px; }
.thumb {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.thumb:hover { background: var(--surface-2); color: var(--text-2); }
.thumb:active { transform: scale(.92); }
.thumb svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.thumb.on { color: var(--accent); background: var(--accent-soft); }
.thumb.on svg { fill: currentColor; fill-opacity: .18; }
@media (pointer: coarse) { .thumb { width: 38px; height: 38px; } }

/* The encyclopedia article an answer was looked up in */
.source {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12.5px; font-weight: 600; text-decoration: none;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.source svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.source span { overflow: hidden; text-overflow: ellipsis; }
.source:hover { text-decoration: underline; }

/* How the model's answer was checked */
.tool-badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.check-ok { background: rgba(16, 185, 129, .12); color: #059669; }
.check-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-border); }
.check-none { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) { .check-ok { background: rgba(52, 211, 153, .14); color: #34d399; } }
