:root {
  --bg: #0b0b0c;
  --surface: #141416;
  --surface-2: #1b1b1e;
  --line: #26262a;
  --text: #ececee;
  --mute: #8b8b93;
  --lime: #B3FD1D;
  --ink: #040404;
  --bot: #B3FD1D;
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
.hidden { display: none !important; }

/* ---------- layout: one centred column, full height ---------- */
.app { height: 100dvh; display: flex; justify-content: center; position: relative; }
.chat {
  width: 100%; max-width: 760px; height: 100%;
  display: flex; flex-direction: column; min-height: 0;
  border-inline: 1px solid var(--line);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  padding-top: max(12px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 40px; height: 40px; flex: none; border-radius: 12px; background: var(--ink); border: 1px solid var(--line); display: grid; place-items: center; }
.logo svg { width: 34px; height: 34px; overflow: visible; }
.brand-text { min-width: 0; line-height: 1.25; }
.brand-text b { display: block; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.brand-text small { display: block; color: var(--mute); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; align-items: center; gap: 8px; flex: none; }
.icon {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  color: var(--mute); border: 1px solid var(--line); transition: color .15s, background .15s, border-color .15s;
}
.icon:hover { color: var(--text); background: var(--surface-2); }
#speak.on { color: var(--ink); background: var(--lime); border-color: var(--lime); }
#speak .waves { opacity: .3; transition: opacity .15s; }
#speak.on .waves { opacity: 1; }
#speak[hidden], .mic[hidden] { display: none; }

select.lang {
  appearance: none; -webkit-appearance: none; cursor: pointer; font: 500 13px var(--font);
  color: var(--text); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b8b93' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line); border-radius: 10px; height: 36px; padding: 0 28px 0 12px; max-width: 130px;
}
select.lang:hover { background-color: var(--surface-2); }
select.lang option { background: var(--surface); color: var(--text); }

/* ---------- messages ---------- */
.msgs {
  flex: 1; min-height: 0; overflow-y: auto; padding: 24px 20px 12px;
  display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.m {
  max-width: min(85%, 560px); padding: 11px 15px; border-radius: var(--radius); line-height: 1.5;
  overflow-wrap: anywhere; animation: rise .2s ease-out both;
}
.m.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 4px; }
.m.me { align-self: flex-end; background: var(--lime); color: var(--ink); border-top-right-radius: 4px; font-weight: 500; }
.m.nodata { background: transparent; border-style: dashed; color: var(--mute); }
.m small { display: block; margin-top: 8px; font-size: 12px; color: var(--mute); }
.m small.dym, .m small.note, .m small.also { font-size: 12.5px; }
.m small.note, .m small.also { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); line-height: 1.4; }
.m small.dym { margin: 0 0 8px; }
.m small.also b { color: var(--text); font-weight: 600; }
.m small a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.m small a:hover { color: var(--lime); }
.m small.conf { display: flex; align-items: center; gap: 7px; }
.m small.conf i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c); }
.m small.conf.high { --c: #3ecf6e; }
.m small.conf.medium { --c: #e8a317; }
.m small.conf.low { --c: #e5484d; }
small.gk { color: #e8a317; }
.srcs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.srcs span { max-width: 100%; overflow-wrap: anywhere; font-size: 12px; color: var(--mute); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.srcs b { color: var(--lime); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chips button, .quick button {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; text-align: start;
  color: var(--text); background: transparent; border: 1px solid var(--line); transition: border-color .15s, background .15s;
}
.chips button:hover, .quick button:hover { border-color: var(--mute); background: var(--surface-2); }
.chips.follow button, .chips.rel button, .chips.again button { color: var(--mute); }

.typing { display: inline-flex; gap: 4px; padding: 5px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--mute); animation: dot 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

/* ---------- composer ---------- */
.dock { padding: 8px 20px max(16px, env(safe-area-inset-bottom)); }
.status { margin: 0 4px 8px; font-size: 12.5px; color: var(--mute); }
.status[hidden] { display: none; }
.quick { display: flex; gap: 8px; margin-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button { flex: none; }
.composer {
  position: relative; display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; transition: border-color .15s;
}
.composer:focus-within { border-color: var(--mute); }
.composer input { flex: 1; min-width: 0; border: 0; background: none; font: 400 16px var(--font); color: var(--text); outline: none; }
.composer input::placeholder { color: var(--mute); }
.composer button { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.composer .mic { color: var(--mute); }
.composer .mic:hover { color: var(--text); background: var(--surface-2); }
.composer .mic.on { color: var(--ink); background: #ff7a7a; animation: listen 1s ease-in-out infinite; }
.composer .send { background: var(--lime); color: var(--ink); transition: filter .15s; }
.composer .send:hover { filter: brightness(1.08); }
.suggest {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 5; list-style: none; margin: 0; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 16px 32px -12px rgba(0,0,0,.7);
  max-height: 240px; overflow-y: auto;
}
.suggest[hidden] { display: none; }
.suggest li { padding: 9px 12px; border-radius: 9px; cursor: pointer; }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--surface-2); }

/* ---------- brain sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 10; display: flex; justify-content: flex-end; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.6); animation: fade .2s both; }
.sheet {
  position: relative; width: min(420px, 100%); height: 100%; overflow-y: auto; padding: 24px 20px 28px;
  background: var(--bg); border-inline-start: 1px solid var(--line); animation: slide .25s ease-out both;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.sheet .close { position: absolute; top: 16px; inset-inline-end: 16px; font-size: 13px; }
.label { margin: 4px 0 16px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--mute); font-weight: 600; }
.donut-row { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.donut { position: relative; width: 180px; height: 180px; flex: none; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut circle { fill: none; stroke-width: 18; transition: stroke-dasharray .8s ease-out; }
.donut .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut .center small { font-size: 11.5px; color: var(--mute); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.donut .center b { font-size: 32px; font-weight: 650; letter-spacing: -.03em; line-height: 1.1; }
.legend { list-style: none; padding: 0; width: 100%; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.legend .nm { flex: 1; }
.legend .ct { color: var(--mute); font-size: 13px; }
.gap { margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); display: flex; gap: 14px; align-items: center; font-size: 13.5px; line-height: 1.4; color: var(--mute); }
.gap b { font-size: 28px; font-weight: 650; letter-spacing: -.03em; color: var(--lime); }

.credits { margin-top: 14px; padding: 12px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 13.5px; }
.credits summary { cursor: pointer; font-weight: 600; }
.credits .nc { margin: 10px 0 4px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--mute); line-height: 1.4; }
.credits ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.credits li { display: flex; justify-content: space-between; gap: 10px; color: var(--mute); }
.credits li em { font-style: normal; font-weight: 600; color: var(--text); white-space: nowrap; }
.credits .fine { margin: 10px 0 0; color: var(--mute); font-size: 12px; opacity: .8; }
.sitelinks { margin: 16px 4px 0; font-size: 13px; color: var(--mute); text-align: center; }
.sitelinks a, .linkbtn { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.teach { margin: 12px 4px 0; display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; font-size: 12.5px; color: var(--mute); }
.teach select { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font: inherit; max-width: 100%; }

/* ---------- robot (the logo) ---------- */
.robot { overflow: visible; }
.robot .whole { animation: bob 3.2s ease-in-out infinite; transform-origin: 32px 46px; }
.robot .eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.robot .look { transition: transform .12s ease-out; }
.robot .open { display: none; transform-box: fill-box; transform-origin: center; }
.robot .smile { display: none; }
.robot.talk .open { display: block; animation: yap .26s ease-in-out infinite alternate; }
.robot.happy .smile, .robot.wave .smile, .robot.love .smile { display: block; }
.robot.sad .smile { display: block; transform-box: fill-box; transform-origin: center; transform: scaleY(-1); }
.robot.sad .eye { animation: none; transform: scaleY(.6) translateY(2px); }
.robot.sad .whole { animation: sulk 2.4s ease-in-out infinite; }
.robot.think .look { animation: scan 1.1s ease-in-out infinite; }
.robot.wave .whole { animation: tilt .9s ease-in-out 2; }
.robot.happy .whole { animation: hop .5s ease-in-out 2; }
.robot.love .eye { animation: none; transform: scaleY(.7); }

@keyframes bob { 50% { transform: translateY(-1.500px); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.08); } }
@keyframes yap { from { transform: scaleY(.35); } to { transform: scaleY(1); } }
@keyframes sulk { 50% { transform: translateY(1px) rotate(-1.500deg); } }
@keyframes scan { 0%, 100% { transform: translate(-2px, -1px); } 50% { transform: translate(2px, -1px); } }
@keyframes tilt { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-7deg); } }
@keyframes hop { 50% { transform: translateY(-4px); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes dot { 40% { transform: translateY(-3px); background: var(--lime); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(100%); } }
@keyframes listen { 50% { box-shadow: 0 0 0 6px rgba(255,122,122,.25); } }

/* ---------- desktop: roomier ---------- */
@media (min-width: 900px) {
  .topbar { padding: 16px 28px; }
  .msgs { padding: 32px 28px 16px; gap: 14px; }
  .dock { padding: 8px 28px 24px; }
  .m { font-size: 15.5px; }
}

/* ---------- phones ---------- */
@media (max-width: 600px) {
  body { font-size: 15px; }
  .chat { border-inline: 0; }
  .topbar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .brand { gap: 10px; }
  .logo { width: 36px; height: 36px; border-radius: 10px; }
  .logo svg { width: 30px; height: 30px; }
  .brand-text small { display: none; }
  .tools { gap: 6px; }
  select.lang { max-width: 104px; padding: 0 24px 0 10px; }
  .msgs { padding: 16px 14px 8px; gap: 10px; }
  .m { max-width: 90%; }
  .dock { padding: 6px 14px max(12px, env(safe-area-inset-bottom)); }
  .sheet { width: 100%; border-inline-start: 0; }
}
@media (max-height: 480px) { .quick { display: none; } .topbar { padding-block: 6px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; scroll-behavior: auto !important; }
}

/* ---------- other scripts and right-to-left ---------- */
html[dir="rtl"] body { font-family: 'Noto Sans Arabic', var(--font); }
html[lang="hi"] body { font-family: var(--font), 'Noto Sans Devanagari', sans-serif; }
html[lang="zh"] body { font-family: var(--font), 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif; }
html[dir="rtl"] select.lang { background-position: left 10px center; padding: 0 12px 0 28px; }
html[dir="rtl"] .m.bot { border-top-left-radius: var(--radius); border-top-right-radius: 4px; }
html[dir="rtl"] .m.me { border-top-right-radius: var(--radius); border-top-left-radius: 4px; }
html[dir="rtl"] .composer { padding: 6px 16px 6px 6px; }
html[dir="rtl"] .composer .send svg { transform: scaleX(-1); }
html[dir="rtl"] .suggest li, html[dir="rtl"] .credits li { text-align: right; }
html[dir="rtl"] .sheet { animation-name: slide-rtl; }
@keyframes slide-rtl { from { transform: translateX(-100%); } }
html[dir="rtl"] .sheet-wrap { justify-content: flex-start; }
