/* ─────────────────────────────────────────────────────────────
   Ask Quackals — Quick Quack Car Wash
   Brand: Quackamole Green primary, Yellow + Orange secondary,
          DM Sans body, Fredoka headlines (Bloomer analog),
          Caveat for Quackals' handwritten asides.
   ───────────────────────────────────────────────────────────── */

:root {
  /* Brand palette (per QQ guidelines 2024) */
  --quackamole: #00AD21;     /* primary */
  --duckweed: #00843D;       /* secondary green */
  --firequacker: #FF5A00;    /* secondary orange */
  --rubber-ducky: #FFC400;   /* secondary yellow */
  --bird-bath: #1000A6;      /* tertiary blue */
  --birds-eye: #00C6FF;
  --blackbird: #000000;
  --egg-white: #FFFFFF;

  /* Soft / supporting */
  --paper: #FFFEF6;          /* warm egg white */
  --paper-soft: #FFF7DA;     /* very pale yellow */
  --ink: #0E0E0E;
  --ink-soft: #2c2c2c;
  --ink-mute: #6b6b6b;
  --ink-faint: #c2c2c2;

  --display: "Fredoka", "Helvetica Neue", sans-serif;
  --body: "DM Sans", "Helvetica Neue", sans-serif;
  --hand: "Caveat", "Comic Sans MS", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 80% 60% at 70% 0%, rgba(255, 196, 0, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 0% 100%, rgba(0, 173, 33, 0.10) 0%, transparent 70%),
    var(--paper);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Brand bubbles (decorative) ─────────────────────────── */
/* Per brand guide: bubbles scale to ~25% of frame and bleed off 1-2 sides. */

.bubbles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bubble {
  position: absolute;
  border-radius: 50%;
  filter: blur(0.5px);
}

.bubble--green-1 {
  width: 520px; height: 520px;
  background: var(--quackamole);
  top: -180px; right: -180px;
  opacity: 0.12;
}
.bubble--yellow-1 {
  width: 380px; height: 380px;
  background: var(--rubber-ducky);
  bottom: -140px; left: -120px;
  opacity: 0.22;
}
.bubble--orange-1 {
  width: 220px; height: 220px;
  background: var(--firequacker);
  top: 38%; right: -100px;
  opacity: 0.10;
}
.bubble--green-2 {
  width: 140px; height: 140px;
  background: var(--quackamole);
  top: 60%; left: 4%;
  opacity: 0.08;
}
.bubble--yellow-2 {
  width: 90px; height: 90px;
  background: var(--rubber-ducky);
  top: 14%; left: 38%;
  opacity: 0.18;
}

/* ─── Stage layout ───────────────────────────────────────── */

.stage {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 0 auto;
  padding: 36px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100vh;
}

/* ─── Hero ───────────────────────────────────────────────── */

.hero {
  background: var(--quackamole);
  color: var(--egg-white);
  border-radius: 32px;
  padding: 28px 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 12px 40px -12px rgba(0, 173, 33, 0.4);
}

.hero::before {
  /* yellow bubble accent inside hero */
  content: "";
  position: absolute;
  width: 280px; height: 280px;
  border-radius: 50%;
  background: var(--rubber-ducky);
  opacity: 0.18;
  top: -120px; right: 30%;
  pointer-events: none;
}

.hero__brand {
  display: flex;
  align-items: center;
  gap: 18px;
  z-index: 1;
}

.hero__avatar {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--egg-white);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
}
.hero__avatar svg,
.hero__avatar img {
  width: 64px; height: 64px;
  border-radius: 50%;
  object-fit: cover;
}

.hero__text { line-height: 1; }

.hero__eyebrow {
  display: block;
  font-family: var(--display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--rubber-ducky);
  margin-bottom: 8px;
}

.hero__name {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(40px, 6vw, 56px);
  line-height: 0.95;
  margin: 0;
  letter-spacing: -0.01em;
}

.hero__role {
  font-family: var(--body);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
  margin: 10px 0 0;
}

.hero__quote {
  font-family: var(--hand);
  font-weight: 500;
  font-size: 22px;
  margin: 4px 0 0;
  color: var(--paper-soft);
  font-style: italic;
}

.hero__tag {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(20px, 2.6vw, 30px);
  line-height: 0.92;
  letter-spacing: -0.02em;
  color: var(--egg-white);
  z-index: 1;
  text-transform: lowercase;
}
.hero__tag span:nth-child(2) {
  color: var(--rubber-ducky);
}
.hero__tag span:last-child {
  color: var(--firequacker);
  text-decoration: underline;
  text-decoration-thickness: 4px;
  text-underline-offset: 4px;
}

/* ─── Thread shell ───────────────────────────────────────── */

.thread-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--egg-white);
  border-radius: 28px;
  padding: 8px;
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.18),
              0 2px 8px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.05);
  overflow: hidden;
  min-height: 600px;
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 28px 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.thread::-webkit-scrollbar { width: 8px; }
.thread::-webkit-scrollbar-track { background: transparent; }
.thread::-webkit-scrollbar-thumb {
  background: var(--ink-faint);
  border-radius: 8px;
}
.thread::-webkit-scrollbar-thumb:hover { background: var(--ink-mute); }

/* ─── Entries ────────────────────────────────────────────── */

.entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: enter 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-width: 92%;
}

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

/* Quackals (assistant) entries */
.entry--quackals {
  align-self: flex-start;
}

.entry__avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--quackamole);
  display: grid;
  place-items: center;
  margin-top: 2px;
  overflow: hidden;
  box-shadow: 0 2px 0 rgba(0,0,0,0.06);
}

.entry__bubble {
  background: var(--paper-soft);
  border: 1.5px solid rgba(255, 196, 0, 0.35);
  border-radius: 4px 22px 22px 22px;
  padding: 16px 20px;
  font-family: var(--body);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  position: relative;
}

.entry__bubble p { margin: 0 0 10px; }
.entry__bubble p:last-child { margin-bottom: 0; }

.entry__bubble h3,
.entry__bubble h4,
.entry__bubble h5,
.entry__bubble h6 {
  font-family: var(--display);
  font-weight: 600;
  color: var(--duckweed);
  line-height: 1.2;
  margin: 14px 0 6px;
  letter-spacing: -0.005em;
}
.entry__bubble h3:first-child,
.entry__bubble h4:first-child,
.entry__bubble h5:first-child,
.entry__bubble h6:first-child { margin-top: 0; }
.entry__bubble h3 { font-size: 19px; }
.entry__bubble h4 { font-size: 16px; text-transform: none; }
.entry__bubble h5 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--quackamole); }
.entry__bubble h6 { font-size: 13px; color: var(--ink-mute); }

.entry__bubble strong { font-weight: 700; }
.entry__bubble em { font-style: italic; color: var(--duckweed); }

.entry__bubble code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  font-size: 0.88em;
  background: rgba(0, 173, 33, 0.10);
  color: var(--duckweed);
  padding: 1px 6px;
  border-radius: 4px;
}

.entry__bubble ul, .entry__bubble ol {
  margin: 8px 0 10px;
  padding-left: 22px;
}
.entry__bubble li { margin-bottom: 4px; }
.entry__bubble li::marker { color: var(--quackamole); font-weight: 700; }

/* User entries — right side, green block */
.entry--you {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.entry__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.entry--you .entry__avatar {
  background: var(--blackbird);
  color: var(--egg-white);
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
}

.entry--you .entry__bubble {
  background: var(--quackamole);
  color: var(--egg-white);
  border-color: var(--duckweed);
  border-radius: 22px 4px 22px 22px;
  font-weight: 500;
}

.entry--you .entry__bubble strong,
.entry--you .entry__bubble em { color: var(--rubber-ducky); }

/* Streaming cursor */
.entry--quackals.streaming .entry__bubble::after {
  content: "▍";
  display: inline-block;
  color: var(--firequacker);
  margin-left: 2px;
  animation: blink 0.9s steps(2, end) infinite;
}
@keyframes blink { to { opacity: 0; } }

/* Welcome — slightly larger feel */
.entry--welcome .entry__bubble {
  background: var(--paper-soft);
  border-color: rgba(255, 196, 0, 0.5);
}

/* ─── Oops bubble (error state) ──────────────────────────── */
/* Quackals had a hiccup. Stay in voice, stay on brand. */

.entry--oops .entry__avatar {
  background: var(--firequacker);
  position: relative;
}
.entry--oops .entry__avatar::after {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--rubber-ducky);
  top: -3px; right: -3px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}

.entry--oops .entry__bubble {
  background:
    linear-gradient(180deg, rgba(255, 90, 0, 0.06) 0%, rgba(255, 196, 0, 0.04) 100%),
    var(--paper-soft);
  border: 1.5px dashed var(--firequacker);
  border-radius: 4px 22px 22px 22px;
}

.entry--oops .oops__title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  color: var(--firequacker);
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.entry--oops .oops__body {
  margin: 0 0 10px;
  color: var(--ink-soft);
}

.entry--oops .oops__aside {
  font-family: var(--hand);
  font-size: 19px;
  line-height: 1.2;
  color: var(--duckweed);
  margin: 10px 0 4px;
  padding-left: 12px;
  border-left: 2px solid rgba(0, 173, 33, 0.35);
}

.entry--oops .oops__details {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1.5px dashed rgba(255, 90, 0, 0.25);
  font-size: 13px;
  color: var(--ink-mute);
}

.entry--oops .oops__details summary {
  cursor: pointer;
  font-family: var(--body);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--firequacker);
  list-style: none;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.entry--oops .oops__details summary::-webkit-details-marker { display: none; }
.entry--oops .oops__details summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--firequacker);
  color: var(--egg-white);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}
.entry--oops .oops__details[open] summary::before { content: "−"; }

.entry--oops .oops__details pre {
  margin: 10px 0 0;
  padding: 10px 12px;
  background: rgba(14, 14, 14, 0.04);
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}

/* ─── Suggestions ────────────────────────────────────────── */

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1.5px dashed rgba(0, 173, 33, 0.25);
}

.suggest {
  background: var(--egg-white);
  border: 1.5px solid var(--quackamole);
  color: var(--quackamole);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--body);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.suggest:hover {
  background: var(--quackamole);
  color: var(--egg-white);
  transform: translateY(-1px);
}
.suggest:active { transform: translateY(0); }

/* Typing indicator (used during initial think) */
.typing {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.typing span {
  width: 8px;
  height: 8px;
  background: var(--quackamole);
  border-radius: 50%;
  animation: typing 1.1s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; background: var(--rubber-ducky); }
.typing span:nth-child(3) { animation-delay: 0.3s; background: var(--firequacker); }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ─── Composer ───────────────────────────────────────────── */

.composer {
  padding: 16px 20px 18px;
  background: var(--egg-white);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

.composer__shell {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--paper);
  border: 2px solid var(--ink-faint);
  border-radius: 18px;
  padding: 10px 10px 10px 18px;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.composer__shell:focus-within {
  border-color: var(--quackamole);
  box-shadow: 0 0 0 4px rgba(0, 173, 33, 0.14);
}

.composer__input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: var(--body);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--ink);
  outline: none;
  padding: 8px 0;
  max-height: 200px;
  overflow-y: auto;
}

.composer__input::placeholder {
  color: var(--ink-mute);
}

.composer__send {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--quackamole);
  color: var(--egg-white);
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  transition: background 0.18s, transform 0.08s, box-shadow 0.18s;
  box-shadow: 0 3px 0 var(--duckweed);
}

.composer__send:hover {
  background: var(--firequacker);
  box-shadow: 0 3px 0 #c14400;
}

.composer__send:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--duckweed);
}

.composer__send:disabled {
  background: var(--ink-faint);
  box-shadow: 0 3px 0 var(--ink-mute);
  cursor: not-allowed;
}

/* Stop-mode swap: while streaming, the send button becomes a stop button.
   We swap the visible label/icon via the .is-streaming flag on .composer. */
.composer__send .stop-label,
.composer__send .stop-icon { display: none; }

.composer.is-streaming .composer__send {
  background: var(--firequacker);
  box-shadow: 0 3px 0 #c14400;
}
.composer.is-streaming .composer__send:hover {
  background: #ff7733;
}
.composer.is-streaming .composer__send .send-label,
.composer.is-streaming .composer__send .send-icon { display: none; }
.composer.is-streaming .composer__send .stop-label,
.composer.is-streaming .composer__send .stop-icon {
  display: inline-flex;
  align-items: center;
}

.composer__hint {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--body);
  font-size: 12px;
  color: var(--ink-mute);
  margin-top: 10px;
  padding: 0 4px;
}

kbd {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 11px;
  background: var(--paper);
  border: 1px solid var(--ink-faint);
  border-bottom-width: 2px;
  padding: 1px 5px;
  margin-right: 4px;
  color: var(--ink-soft);
  border-radius: 4px;
}

.reset-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--body);
  font-weight: 600;
  font-size: 12px;
  color: var(--firequacker);
  padding: 0;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.reset-btn:hover { color: #c14400; }

/* ─── Model picker ───────────────────────────────────────── */
.model-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-mute);
}
.model-pick select {
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  color: var(--duckweed);
  background: var(--paper);
  border: 1px solid var(--ink-faint);
  border-radius: 6px;
  padding: 2px 6px;
  cursor: pointer;
}
.model-pick select:focus {
  outline: none;
  border-color: var(--quackamole);
  box-shadow: 0 0 0 2px rgba(0, 173, 33, 0.18);
}

/* ─── Citations / footnotes ──────────────────────────────── */
sup.cite {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 0;
  margin-left: 1px;
}
sup.cite a {
  display: inline-block;
  min-width: 14px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--quackamole);
  color: var(--egg-white);
  text-decoration: none;
  font-weight: 700;
  font-family: var(--body);
  text-align: center;
  transition: background 0.15s;
}
sup.cite a:hover {
  background: var(--firequacker);
}
.entry--you sup.cite a {
  background: var(--rubber-ducky);
  color: var(--ink);
}

.citations {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1.5px dashed rgba(0, 173, 33, 0.25);
  font-size: 13px;
}
.citations summary {
  cursor: pointer;
  font-family: var(--body);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--duckweed);
  list-style: none;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.citations summary::-webkit-details-marker { display: none; }
.citations summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s;
  color: var(--quackamole);
}
.citations[open] summary::before { transform: rotate(90deg); }

.citations__list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.citations__list li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.4;
}
.citations__list .cite__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.citations__list .cite__quote {
  margin: 2px 0 0 26px;
  font-family: var(--body);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-mute);
  font-style: italic;
  border-left: 2px solid rgba(0, 173, 33, 0.25);
  padding: 2px 0 2px 8px;
}
.citations__list .cite__num {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--quackamole);
  color: var(--egg-white);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--body);
}
.citations__list a {
  color: var(--duckweed);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  font-weight: 600;
}
.citations__list a:hover { color: var(--firequacker); }
.citations__list .cite__page {
  color: var(--ink-mute);
  font-size: 12px;
}

/* ─── Stopped reply ──────────────────────────────────────── */
.entry--stopped .entry__bubble {
  border-style: dashed;
  border-color: var(--ink-faint);
  opacity: 0.92;
}
.entry--stopped .entry__bubble::after {
  content: "stopped";
  display: block;
  margin-top: 8px;
  font-family: var(--hand);
  font-size: 14px;
  color: var(--ink-mute);
}

/* ─── Responsive ─────────────────────────────────────────── */

@media (max-width: 720px) {
  .stage { padding: 16px 12px; gap: 16px; }
  .hero {
    flex-direction: column;
    align-items: flex-start;
    border-radius: 24px;
    padding: 22px 24px;
  }
  .hero__tag {
    flex-direction: row;
    gap: 8px;
    align-self: flex-start;
  }
  .hero__avatar { width: 56px; height: 56px; }
  .hero__avatar svg,
  .hero__avatar img { width: 48px; height: 48px; }
  .thread { padding: 18px 16px 12px; }
  .composer { padding: 12px 14px 14px; }
  .composer__send span { display: none; }
  .composer__send { padding: 12px; }
  .thread-shell { min-height: 500px; }
}
