/* ==========================================================================
   Explain Like I'm 10 — style.css
   A warm, calm, kids-safe visual language:
   soft pastels, rounded shapes, gentle motion, generous padding.
   ========================================================================== */

/* ----------------------------- Design tokens ----------------------------- */
:root {
  --cream: #fff9ef;
  --cream-deep: #fdf1dd;
  --paper: #ffffff;
  --ink: #23324b;
  --ink-soft: #5e6e89;
  --ink-faint: #64748b;

  --mint: #d9f6e7;
  --mint-deep: #b7ecd2;
  --lavender: #e9ddff;
  --lavender-deep: #d8c6ff;
  --sky: #a3d5ff;
  --sky-soft: #e3f3ff;
  --sun: #ffd166;
  --coral: #ff9d94;
  --grass: #7ed3a2;

  --accent: #7b61ff;
  --accent-2: #38bdf8;
  --accent-soft: #f0ebff;

  --line: #ece4d6;
  --line-strong: #ded3c1;

  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;

  --shadow-soft: 0 10px 30px rgba(84, 103, 143, 0.1);
  --shadow-card: 0 18px 50px rgba(84, 103, 143, 0.14);
  --shadow-pop: 0 24px 60px rgba(53, 68, 105, 0.22);

  --font: 'Nunito', 'Quicksand', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;

  --topbar-h: auto;
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--cream);
  background-image:
    radial-gradient(1200px 700px at 8% -10%, rgba(233, 221, 255, 0.85), transparent 60%),
    radial-gradient(900px 620px at 100% 0%, rgba(227, 243, 255, 0.9), transparent 62%),
    radial-gradient(1000px 700px at 85% 108%, rgba(217, 246, 231, 0.9), transparent 60%),
    linear-gradient(180deg, #fffdf7 0%, #fff8ec 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
}

button:disabled {
  cursor: not-allowed;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 3px solid rgba(123, 97, 255, 0.55);
  outline-offset: 3px;
  border-radius: 8px;
}

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
  z-index: 60;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 1rem;
}

/* --------------------------- Decorative sky ----------------------------- */
.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(12px);
  opacity: 0.55;
  animation: float-slow 18s ease-in-out infinite;
}

.blob--one {
  width: 320px;
  height: 320px;
  top: -90px;
  left: -70px;
  background: radial-gradient(circle at 35% 35%, #f3e8ff, #e2d2ff);
}

.blob--two {
  width: 260px;
  height: 260px;
  top: 18%;
  right: -90px;
  background: radial-gradient(circle at 40% 40%, #e8f7ff, #c7e9ff);
  animation-delay: -4s;
}

.blob--three {
  width: 300px;
  height: 300px;
  bottom: -110px;
  left: 12%;
  background: radial-gradient(circle at 40% 40%, #e6fff1, #c3f0d8);
  animation-delay: -8s;
}

.blob--four {
  width: 180px;
  height: 180px;
  bottom: 12%;
  right: 16%;
  background: radial-gradient(circle at 40% 40%, #fff6df, #ffe9b8);
  animation-delay: -12s;
}

.sparkle {
  position: absolute;
  color: #c9b8ff;
  font-size: 22px;
  opacity: 0.7;
  animation: twinkle 5s ease-in-out infinite;
}

.sparkle--one {
  top: 16%;
  left: 7%;
}
.sparkle--two {
  top: 34%;
  right: 8%;
  color: #9fd9ff;
  animation-delay: -1.8s;
}
.sparkle--three {
  bottom: 22%;
  left: 20%;
  color: #ffd88f;
  animation-delay: -3.2s;
}

/* ------------------------------ App shell ------------------------------- */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: 100vh;
  height: 100dvh;
  max-width: 1060px;
  margin: 0 auto;
  padding: clamp(0.6rem, 2vw, 1.1rem) clamp(0.6rem, 2.2vw, 1.25rem) 0.5rem;
}

/* -------------------------------- Top bar -------------------------------- */
.topbar {
  flex: 0 0 auto;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.75rem 0.6rem 0.9rem;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.brand-mascot {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding-top: 0.35rem;
  transform-origin: 50% 90%;
}

.brand-copy {
  min-width: 0;
}

.brand-title {
  font-size: clamp(1.02rem, 2.3vw, 1.38rem);
  font-weight: 900;
  letter-spacing: -0.015em;
  line-height: 1.15;
  white-space: nowrap;
}

.brand-accent {
  background: linear-gradient(100deg, var(--accent) 10%, var(--accent-2) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-tagline {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-top: 0.1rem;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Trust badge + tooltip */
.trust {
  position: relative;
}

.trust-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.7rem;
  border-radius: 999px;
  background: linear-gradient(140deg, #eafff3, #d5f7e6);
  border: 1px solid #b8ecd2;
  color: #186b45;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
  transition: transform 0.18s var(--ease-soft), box-shadow 0.18s ease;
}

.trust-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(56, 160, 112, 0.18);
}

.trust-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2fbf7b;
  box-shadow: 0 0 0 0 rgba(47, 191, 123, 0.55);
  animation: live-pulse 2.6s ease-out infinite;
}

.trust-shield {
  font-size: 0.9rem;
}

.trust-tip[hidden] {
  display: none;
}

.trust-tip {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  left: auto;
  z-index: 9999;
  width: min(260px, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.45;
  box-shadow: var(--shadow-pop);
  animation: tip-in 0.18s var(--ease-soft);
  /* Tooltip only: it must never sit between the child's finger and the chat. */
  pointer-events: none;
}

.trust-tip::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 28px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--ink);
  transform: rotate(45deg);
}

/* Language switch */
.lang-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: #f4efe4;
  border: 1px solid var(--line);
}

.lang-btn {
  padding: 0.32rem 0.68rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink-soft);
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.lang-btn:hover {
  color: var(--ink);
}

.lang-btn.is-active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 2px 7px rgba(84, 103, 143, 0.16);
}

/* Small round icon buttons */
.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 1.05rem;
  line-height: 1;
  transition: transform 0.18s var(--ease-soft), background 0.18s ease, box-shadow 0.18s ease;
}

.icon-btn:hover {
  transform: translateY(-2px) rotate(-3deg);
  background: var(--accent-soft);
  box-shadow: 0 6px 16px rgba(123, 97, 255, 0.16);
}

.icon-btn:active {
  transform: translateY(0) scale(0.95);
}

.icon-btn.is-muted {
  opacity: 0.62;
  background: #f6f2ea;
}

.avatar-btn {
  background: linear-gradient(150deg, #fff4dd, #ffe6ee);
  border-color: #f4dcc6;
}

/* ------------------------------- Chat card ------------------------------- */
.chat-card {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.8rem 0.6rem 1.1rem;
  border-bottom: 1px dashed var(--line);
  background: linear-gradient(180deg, rgba(255, 253, 247, 0.95), rgba(255, 255, 255, 0.7));
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--ink-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--grass);
  box-shadow: 0 0 0 4px rgba(126, 211, 162, 0.22);
}

.chat-actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.soft-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line);
  transition: transform 0.16s var(--ease-soft), border-color 0.16s ease, color 0.16s ease,
    background 0.16s ease;
}

.soft-btn:hover {
  transform: translateY(-1px);
  color: var(--accent);
  border-color: #dcd0ff;
  background: #faf7ff;
}

.chat-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  background-image: radial-gradient(rgba(146, 162, 191, 0.12) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: center top;
}

.chat-body::-webkit-scrollbar {
  width: 10px;
}

.chat-body::-webkit-scrollbar-thumb {
  background: #e2dacb;
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: #cfc4af;
  background-clip: content-box;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: clamp(0.9rem, 2.6vw, 1.4rem);
  min-height: 100%;
}

/* ------------------------------- Messages -------------------------------- */
.msg {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  animation: msg-in 0.32s var(--ease-soft) both;
}

/* History is rendered without a staggered entrance. */
.msg.is-instant {
  animation: none;
}

.msg--user {
  flex-direction: row-reverse;
}

.msg-stack {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: min(80%, 640px);
  min-width: 0;
}

.msg--user .msg-stack {
  align-items: flex-end;
}

.bubble {
  position: relative;
  padding: 0.8rem 1rem;
  border-radius: 1.35rem;
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  direction: auto;
  box-shadow: 0 4px 14px rgba(84, 103, 143, 0.07);
}

.msg--assistant .bubble {
  background: linear-gradient(160deg, #eafff5 0%, #d5f5e5 100%);
  border: 1px solid #c3eeda;
  border-bottom-left-radius: 0.4rem;
  color: #17453a;
}

.msg--user .bubble {
  background: linear-gradient(160deg, #f1e9ff 0%, #e0d3ff 100%);
  border: 1px solid #d8c8ff;
  border-bottom-right-radius: 0.4rem;
  color: #33265c;
}

.msg--safe .bubble {
  background: linear-gradient(160deg, #fff8e3, #fff0c9);
  border-color: #ffe3a3;
  color: #6a4c12;
}

.msg--offline .bubble {
  background: linear-gradient(160deg, #eef7ff, #e0efff);
  border-color: #cae4fb;
  color: #1f4a6e;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  padding: 0 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink-faint);
}

.msg--user .msg-meta {
  justify-content: flex-end;
}

.msg-author {
  font-weight: 800;
  color: var(--ink-soft);
}

.msg-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.msg-badge {
  padding: 0.08rem 0.42rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.64rem;
  font-weight: 800;
  color: var(--ink-faint);
}

.msg-badge--safe {
  color: #2c6b53;
  background: #effaf3;
  border-color: #bfe8cf;
}

/* Developer-only provenance badge (?debug=1). Subtle by design. */
.msg-source {
  display: inline-block;
  max-width: min(360px, 72vw);
  overflow: hidden;
  padding: 0.06rem 0.38rem;
  border-radius: 999px;
  border: 1px dashed #c3d2e6;
  background: #eef3fa;
  color: #4a5a72;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  pointer-events: none;
}

/* Debug: a real AI answer — green, with the model that produced it. */
.msg-source[data-source='ai'] {
  border-style: solid;
  border-color: #bfe8cf;
  background: #effaf3;
  color: #186b45;
}

/* Debug: a safety redirect — amber, not an error. */
.msg-source[data-source='guard'] {
  border-color: #f2ddb0;
  background: #fff8e8;
  color: #8a5a00;
}

/* Debug: any failure/fallback — red. */
.msg-source[data-source='error'] {
  border-color: #f4b4ad;
  background: #fef3f2;
  color: #b42318;
}

.listen-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  color: #2c6b53;
  background: #fff;
  border: 1px solid #cdeeda;
  transition: background 0.16s ease, transform 0.16s var(--ease-soft), color 0.16s ease;
}

.listen-btn:hover {
  background: #f2fff9;
  transform: translateY(-1px);
}

.listen-btn.is-speaking {
  background: #effff7;
  color: #1b7a56;
  border-color: #9fe4c2;
}

/* User avatar chip */
.user-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(150deg, #fff3dd, #ffe3ea);
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(84, 103, 143, 0.14);
  font-size: 1.1rem;
  line-height: 1;
}

/* ------------------------ Professor Pixel (CSS art) ---------------------- */
.pixel {
  --pixel-size: 72px;
  position: relative;
  flex: 0 0 auto;
  width: 1em;
  height: 1.2em;
  font-size: var(--pixel-size);
  transform-origin: 50% 92%;
}

.pixel__antenna {
  position: absolute;
  top: 0;
  left: 50%;
  width: 0.045em;
  height: 0.16em;
  border-radius: 99px;
  background: #8ec2ea;
  transform: translateX(-50%);
}

.pixel__bulb {
  position: absolute;
  top: -0.11em;
  left: 50%;
  width: 0.13em;
  height: 0.13em;
  border-radius: 50%;
  transform: translateX(-50%);
  background: radial-gradient(circle at 34% 30%, #fffde3 0%, #ffe07a 52%, #f6b93b 100%);
  box-shadow: 0 0 0.14em rgba(255, 209, 102, 0.95), 0 0 0.28em rgba(255, 209, 102, 0.55);
  animation: bulb-pulse 2.4s ease-in-out infinite;
}

.pixel__head {
  position: absolute;
  inset: 0.2em 0 0 0;
  border-radius: 0.27em;
  background: linear-gradient(158deg, #c9e8ff 0%, #a3d5ff 46%, #7fbdec 100%);
  box-shadow:
    inset 0 -0.07em 0 rgba(64, 127, 181, 0.22),
    inset 0 0.05em 0.06em rgba(255, 255, 255, 0.8),
    0 0.08em 0.18em rgba(70, 121, 168, 0.24);
  animation: pixel-breathe 6s ease-in-out infinite;
}

/* Little ears / side buttons add character without copyrighted artwork */
.pixel__head::before,
.pixel__head::after {
  content: '';
  position: absolute;
  top: 0.42em;
  width: 0.08em;
  height: 0.22em;
  border-radius: 0.04em;
  background: #8bc8f2;
  box-shadow: inset 0 0 0 0.015em rgba(56, 111, 156, 0.25);
}

.pixel__head::before {
  left: -0.07em;
}

.pixel__head::after {
  right: -0.07em;
}

.pixel__eye {
  position: absolute;
  top: 0.36em;
  width: 0.155em;
  height: 0.175em;
  border-radius: 50%;
  background: #1c2434;
  transform-origin: 50% 50%;
  animation: pixel-blink 4s infinite;
}

.pixel__eye--left {
  left: 0.19em;
}

.pixel__eye--right {
  right: 0.19em;
}

.pixel__spark {
  position: absolute;
  top: 0.028em;
  left: 0.035em;
  width: 0.052em;
  height: 0.052em;
  border-radius: 50%;
  background: #fff;
}

.pixel__spark--small {
  top: 0.095em;
  left: 0.09em;
  width: 0.025em;
  height: 0.025em;
  opacity: 0.85;
}

.pixel__mouth {
  position: absolute;
  bottom: 0.2em;
  left: 50%;
  width: 0.3em;
  height: 0.145em;
  transform: translateX(-50%);
  border-bottom: 0.045em solid #1c2434;
  border-radius: 0 0 0.3em 0.3em;
}

.pixel__cheek {
  position: absolute;
  bottom: 0.28em;
  width: 0.1em;
  height: 0.065em;
  border-radius: 50%;
  background: rgba(255, 138, 128, 0.5);
  filter: blur(0.005em);
}

.pixel__cheek--left {
  left: 0.1em;
}

.pixel__cheek--right {
  right: 0.1em;
}

.pixel--sm {
  --pixel-size: 38px;
}

.pixel--md {
  --pixel-size: 56px;
}

.pixel--lg {
  --pixel-size: clamp(74px, 12vw, 104px);
}

.pixel.is-waving {
  animation: pixel-wave 2.4s var(--ease-soft) 1 both;
}

.pixel.is-happy .pixel__eye {
  animation: pixel-blink 4s infinite, pixel-happy 2.6s ease-in-out 1;
}

/* Speech bubble above the hero mascot */
.hero-mascot {
  display: flex;
  justify-content: center;
}

/* ------------------------------ Empty state ------------------------------ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  width: 100%;
  max-width: 720px;
  margin: auto;
  padding: clamp(0.5rem, 2vw, 1rem) 0 0.4rem;
  animation: fade-up 0.5s var(--ease-soft) both;
}

.hero-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  flex-wrap: wrap;
}

.speech {
  position: relative;
  max-width: 350px;
  padding: 0.8rem 1rem;
  border-radius: 1.25rem;
  background: #fff;
  border: 2px solid #e9ddff;
  box-shadow: var(--shadow-soft);
  text-align: left;
}

.speech::after {
  content: '';
  position: absolute;
  left: -8px;
  bottom: 18px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-left: 2px solid #e9ddff;
  border-bottom: 2px solid #e9ddff;
  transform: rotate(45deg);
  border-radius: 0 0 0 3px;
}

.speech__title {
  font-size: 1rem;
  font-weight: 900;
  color: #33265c;
  margin-bottom: 0.15rem;
}

.speech__body {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.55;
}

.empty-heading {
  margin-top: 0.25rem;
  font-size: 0.92rem;
  font-weight: 900;
  color: var(--ink);
  text-align: center;
}

.empty-sub {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-faint);
  text-align: center;
  margin-top: -0.45rem;
}

.chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 0.5rem;
  width: 100%;
}

.chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.62rem 0.8rem;
  border-radius: var(--radius-md);
  background: #fff;
  border: 1.5px solid var(--line);
  text-align: left;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink-soft);
  box-shadow: 0 3px 10px rgba(84, 103, 143, 0.06);
  transition: transform 0.18s var(--ease-soft), border-color 0.18s ease, box-shadow 0.18s ease,
    color 0.18s ease;
}

.chip:hover {
  transform: translateY(-2px);
  color: var(--ink);
  border-color: #cfc0ff;
  box-shadow: 0 10px 22px rgba(123, 97, 255, 0.14);
}

.chip:active {
  transform: translateY(0) scale(0.985);
}

.chip__emoji {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: linear-gradient(150deg, #f7f1ff, #eaf7ff);
  font-size: 1rem;
}

.chip__text {
  min-width: 0;
}

/* ------------------------------- Typing ---------------------------------- */
.msg--typing .bubble {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.8rem 0.95rem;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5fbf95;
  animation: typing-bounce 1.3s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

/* ------------------------------- Composer -------------------------------- */
.composer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.7rem clamp(0.7rem, 2vw, 1.1rem) 0.8rem;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #fffdf8, #fff8ec);
}

.mode-bar {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 1px;
}

.mode-bar::-webkit-scrollbar {
  display: none;
}

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.42rem 0.85rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink-soft);
  background: #fff;
  border: 1.5px solid var(--line);
  white-space: nowrap;
  transition: transform 0.18s var(--ease-soft), background 0.18s ease, color 0.18s ease,
    border-color 0.18s ease, box-shadow 0.18s ease;
}

.mode-btn:hover {
  transform: translateY(-1px);
  border-color: #d7ccf9;
  color: var(--ink);
}

.mode-btn.is-active {
  background: linear-gradient(130deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px rgba(105, 108, 255, 0.28);
}

.mode-hint {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-faint);
  padding-left: 0.2rem;
  min-height: 1.1em;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.45rem 0.45rem 0.95rem;
  border-radius: 1.4rem;
  background: #fff;
  border: 2px solid var(--line);
  box-shadow: 0 4px 16px rgba(84, 103, 143, 0.06);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-row:focus-within {
  border-color: #c9b8ff;
  box-shadow: 0 0 0 4px rgba(123, 97, 255, 0.12);
}

#userInput {
  flex: 1 1 auto;
  min-width: 0;
  height: auto;
  max-height: 132px;
  padding: 0.45rem 0 0.45rem;
  border: 0;
  background: transparent;
  resize: none;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.5;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

#userInput::placeholder {
  color: #b4bccb;
  font-weight: 700;
}

/* The composer is text-only: make sure no browser ever paints spinner arrows
   over the child's question. */
#userInput::-webkit-outer-spin-button,
#userInput::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

#userInput[type='number'],
input[type='number'] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.send-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 18px rgba(105, 108, 255, 0.32);
  transition: transform 0.18s var(--ease-soft), box-shadow 0.18s ease, filter 0.18s ease;
}

.send-btn svg {
  transform: translateX(-1px);
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.04);
  filter: saturate(1.1);
  box-shadow: 0 12px 24px rgba(105, 108, 255, 0.4);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.send-btn:disabled {
  filter: grayscale(0.4) opacity(0.65);
  box-shadow: none;
}

.input-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink-faint);
}

.char-count.is-near-limit {
  color: #d97706;
}

.char-count.is-over-limit {
  color: #dc2626;
}

.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  white-space: nowrap;
}

/* -------------------------------- Footer --------------------------------- */
.site-footer {
  flex: 0 0 auto;
  text-align: center;
  padding: 0.15rem 0.5rem 0.35rem;
  color: #64748b;
}

.footer-line {
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.55;
  letter-spacing: 0.005em;
}

.footer-line--safety {
  color: #5f7d6f;
  font-weight: 800;
}

/* -------------------------------- Modal ---------------------------------- */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(35, 50, 75, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease both;
}

.modal-card {
  position: relative;
  width: min(440px, 100%);
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 1.1rem 1.2rem 1.25rem;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, #fffdf8, #fff8ef);
  border: 1px solid #fff;
  box-shadow: var(--shadow-pop);
  text-align: center;
  animation: modal-in 0.32s var(--ease-soft) both;
}

.modal-mascot {
  display: flex;
  justify-content: center;
  margin-bottom: 0.15rem;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--ink);
}

.modal-subtitle {
  margin-top: 0.2rem;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0.9rem 0 1rem;
}

.avatar-option {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  background: #fff;
  border: 2px solid var(--line);
  font-size: 1.6rem;
  line-height: 1;
  transition: transform 0.16s var(--ease-soft), border-color 0.16s ease, background 0.16s ease,
    box-shadow 0.16s ease;
}

.avatar-option:hover {
  transform: translateY(-2px) scale(1.03);
  border-color: #cdbcff;
}

.avatar-option.is-selected {
  border-color: var(--accent);
  background: linear-gradient(150deg, #f6f0ff, #eaf6ff);
  box-shadow: 0 0 0 4px rgba(123, 97, 255, 0.14);
}

.primary-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(130deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px rgba(105, 108, 255, 0.3);
  transition: transform 0.18s var(--ease-soft), box-shadow 0.18s ease;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 26px rgba(105, 108, 255, 0.38);
}

.primary-btn:active {
  transform: scale(0.985);
}

/* -------------------------------- Toast ---------------------------------- */
.toast[hidden] {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.1rem, env(safe-area-inset-bottom));
  z-index: 90;
  max-width: min(92vw, 420px);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  transform: translateX(-50%);
  background: rgba(35, 50, 75, 0.95);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow-pop);
  animation: toast-in 0.28s var(--ease-soft) both;
}

/* ------------------------- Export staging area --------------------------- */
.export-stage {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 760px;
  pointer-events: none;
  z-index: -1;
}

.export-card {
  padding: 34px;
  background: #fffaf0;
  font-family: var(--font);
  color: #23324b;
}

.export-card * {
  animation: none !important;
}

.export-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 2px dashed #e6dcc9;
  margin-bottom: 22px;
}

.export-brand-title {
  font-size: 22px;
  font-weight: 900;
}

.export-brand-sub {
  font-size: 12px;
  font-weight: 700;
  color: #7b8798;
}

.export-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.export-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 82%;
}

.export-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.export-msg--assistant {
  align-self: flex-start;
}

.export-who {
  font-size: 11px;
  font-weight: 800;
  color: #7b8798;
  padding: 0 6px;
}

.export-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.export-msg--assistant .export-bubble {
  background: #d9f6e7;
  border: 1px solid #c3eeda;
  color: #17453a;
  border-bottom-left-radius: 6px;
}

.export-msg--user .export-bubble {
  background: #e9ddff;
  border: 1px solid #d8c8ff;
  color: #33265c;
  border-bottom-right-radius: 6px;
}

.export-meta {
  font-size: 10px;
  font-weight: 700;
  color: #98a2b3;
  padding: 0 6px;
}

.export-foot {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 2px dashed #e6dcc9;
  font-size: 11px;
  font-weight: 700;
  color: #7b8798;
  text-align: center;
  line-height: 1.6;
}

/* -------------------------------- Animations ----------------------------- */
@keyframes float-slow {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(12px, -18px, 0) scale(1.04);
  }
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.25;
    transform: scale(0.9) rotate(0deg);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.1) rotate(12deg);
  }
}

@keyframes live-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(47, 191, 123, 0.55);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(47, 191, 123, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(47, 191, 123, 0);
  }
}

@keyframes bulb-pulse {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0.1em rgba(255, 209, 102, 0.8), 0 0 0.22em rgba(255, 209, 102, 0.4);
  }
  50% {
    opacity: 0.86;
    box-shadow: 0 0 0.18em rgba(255, 209, 102, 1), 0 0 0.36em rgba(255, 209, 102, 0.62);
  }
}

@keyframes pixel-blink {
  0%,
  90%,
  96%,
  100% {
    transform: scaleY(1);
  }
  92%,
  94% {
    transform: scaleY(0.1);
  }
}

@keyframes pixel-breathe {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-0.012em);
  }
}

@keyframes pixel-happy {
  0%,
  100% {
    transform: scaleY(1);
  }
  30% {
    transform: scaleY(0.55) translateY(0.01em);
  }
  60% {
    transform: scaleY(1);
  }
}

@keyframes pixel-wave {
  0% {
    transform: rotate(0deg);
  }
  15% {
    transform: rotate(-7deg);
  }
  30% {
    transform: rotate(6deg);
  }
  45% {
    transform: rotate(-5deg);
  }
  60% {
    transform: rotate(4deg);
  }
  75% {
    transform: rotate(-2deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes tip-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ------------------------------- Responsive ------------------------------ */
@media (max-width: 720px) {
  .topbar-inner {
    padding: 0.55rem 0.6rem;
    border-radius: 24px;
    gap: 0.5rem;
  }

  .brand-mascot .pixel {
    --pixel-size: 38px;
  }

  .brand-tagline {
    display: none;
  }

  .topbar-actions {
    gap: 0.3rem;
  }

  .trust-label {
    display: none;
  }

  .trust-badge {
    padding: 0.42rem 0.55rem;
  }

  .trust-tip {
    right: -0.25rem;
    width: min(240px, calc(100vw - 1.25rem));
    max-width: calc(100vw - 1.25rem);
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 0.98rem;
  }

  .lang-btn {
    padding: 0.28rem 0.55rem;
    font-size: 0.75rem;
  }

  .chat-card {
    border-radius: 24px;
  }

  .chat-head {
    padding: 0.5rem 0.6rem 0.5rem 0.85rem;
    gap: 0.4rem;
  }

  .chat-status {
    font-size: 0.7rem;
  }

  .chat-status span:last-child {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .soft-btn {
    padding: 0.36rem 0.55rem;
    font-size: 0.7rem;
  }

  .soft-btn span:last-child {
    display: none;
  }

  .messages {
    gap: 0.75rem;
    padding: 0.8rem 0.65rem;
  }

  .msg {
    gap: 0.4rem;
  }

  .msg-stack {
    max-width: 84%;
  }

  .bubble {
    font-size: 0.9rem;
    padding: 0.7rem 0.85rem;
  }

  .user-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.95rem;
  }

  .pixel--sm {
    --pixel-size: 32px;
  }

  .speech {
    max-width: 260px;
    padding: 0.65rem 0.8rem;
  }

  .speech__title {
    font-size: 0.9rem;
  }

  .speech__body {
    font-size: 0.76rem;
  }

  .chips {
    gap: 0.4rem;
  }

  .chip {
    font-size: 0.75rem;
    padding: 0.5rem 0.6rem;
    gap: 0.4rem;
  }

  .chip__emoji {
    width: 26px;
    height: 26px;
    font-size: 0.85rem;
  }

  .mode-btn {
    font-size: 0.74rem;
    padding: 0.36rem 0.68rem;
  }

  .mode-hint {
    font-size: 0.68rem;
  }

  .mode-label--full {
    display: none;
  }

  .input-row {
    padding: 0.35rem 0.35rem 0.35rem 0.8rem;
  }

  #userInput {
    font-size: 0.9rem;
  }

  .send-btn {
    width: 42px;
    height: 42px;
  }

  .input-meta {
    font-size: 0.64rem;
  }

  .footer-line {
    font-size: 0.66rem;
  }
}

@media (max-width: 420px) {
  .brand-title {
    font-size: 1rem;
  }

  .brand-mascot .pixel {
    --pixel-size: 34px;
  }

  .lang-btn {
    padding: 0.26rem 0.45rem;
  }

  .chips {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .chip {
    font-size: 0.7rem;
    padding: 0.45rem 0.5rem;
  }

  .empty {
    gap: 0.55rem;
  }

  .hero-row {
    gap: 0.4rem;
  }

  .pixel--lg {
    --pixel-size: 66px;
  }

  .speech {
    max-width: 215px;
  }
}

@media (max-height: 620px) {
  .brand-tagline {
    display: none;
  }

  .empty {
    padding-top: 0.2rem;
  }

  .speech {
    display: none;
  }

  .empty-sub {
    display: none;
  }

  .mode-hint {
    display: none;
  }
}

/* Respect the child's / parent's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .pixel__eye,
  .pixel__head,
  .pixel__bulb,
  .blob,
  .sparkle {
    animation: none !important;
  }
}

/* Reduce heavy blur on lower-powered devices */
@media (max-width: 480px) {
  .blob {
    filter: blur(22px);
    opacity: 0.45;
  }

  .chat-body {
    background-size: 28px 28px;
  }
}
