:root {
  /* brand ramp — the ONLY per-demo block (plus --head-font). Everything below is shared. */
  /* Hsin-Chuen Lin: celadon. The classic Chinese/Taiwanese ceramic glaze green, which is the
     right register for a Taiwan-born potter with an MFA and forty years in clay, and reads
     calm and craft rather than techy. Ground is unglazed-porcelain warm off-white so the
     whole page reads as clay and glaze. Heading font Spectral (a warm serif) for the same
     reason: this is a maker with a long tradition behind him, not a gadget channel. */
  --accent: #3E7A6E;
  --accent-dark: #2C5A51;
  --accent-soft: #E3F0EC;
  --accent-line: #C3DBD3;
  --bg: #F8F6F1;
  --bg-blur: rgba(248,246,241,.82);
  --bg-tint: rgba(62,122,110,.06);
  --surface: #ffffff;
  --ink: #1F2724;
  --muted: #63706B;
  --line: #E6E2D8;
  --head-font: "Spectral", Georgia, serif;

  --radius: 20px;
  --shadow-sm: 0 1px 2px rgba(20,40,50,.06);
  --shadow: 0 1px 2px rgba(20,40,50,.05), 0 10px 30px rgba(20,40,50,.07);
  --shadow-lg: 0 6px 16px rgba(20,40,50,.08), 0 22px 50px rgba(20,40,50,.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 460px at 50% -200px, var(--bg-tint) 0%, rgba(255,255,255,0) 72%);
}

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 14px 20px;
  background: var(--bg-blur);
  -webkit-backdrop-filter: saturate(1.3) blur(12px);
  backdrop-filter: saturate(1.3) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-line), transparent);
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.paw {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  font-size: 23px;
  background: linear-gradient(150deg, var(--accent-soft), #fff);
  border: 1px solid var(--accent-line);
  border-radius: 14px;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.85);
}
.brand-text { min-width: 0; }
.brand-text h1 {
  font-family: var(--head-font);
  font-weight: 700; font-size: 1.3rem; margin: 0; letter-spacing: -.02em; line-height: 1.12;
}
.tagline { margin: 3px 0 0; font-size: .82rem; color: var(--muted); max-width: 46ch; line-height: 1.4; }
.demo-badge {
  flex: none; align-self: center;
  font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  padding: 5px 11px; border-radius: 999px;
}

/* ---- thread ---- */
.thread {
  flex: 1; min-width: 0; overflow-y: auto;
  padding: 26px 20px 10px;
  display: flex; flex-direction: column; gap: 22px;
  scroll-behavior: smooth;
}
.thread > * { min-width: 0; max-width: 100%; }
.welcome-card, .suggestions, .bubble { max-width: 100%; }

.welcome { margin: auto 0; }
.welcome-card {
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 58%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
}
.intro { margin: 0 0 20px; font-size: 1.1rem; line-height: 1.5; color: var(--ink); }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  font: inherit; font-size: .9rem; text-align: left; max-width: 100%;
  color: var(--accent-dark); background: var(--surface);
  border: 1px solid var(--accent-line); border-radius: 14px;
  padding: 10px 14px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.chip:hover {
  background: var(--accent-soft); border-color: var(--accent);
  transform: translateY(-1px); box-shadow: var(--shadow);
}

/* ---- messages ---- */
.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }
.bubble {
  max-width: 88%;
  padding: 14px 17px; border-radius: 18px;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble {
  background: linear-gradient(160deg, var(--accent), var(--accent-dark));
  color: #fff; border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.msg.assistant .bubble {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}
.bubble :first-child { margin-top: 0; } .bubble :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .6em; }
.bubble ul, .bubble ol { margin: .3em 0 .6em; padding-left: 1.25em; }
.bubble li { margin: .2em 0; }
.bubble strong { font-weight: 600; }
.bubble a { color: var(--accent-dark); font-weight: 500; text-underline-offset: 2px; }

.who { font-size: .72rem; color: var(--muted); margin: 0 5px 6px; font-weight: 600; }

/* typing dots */
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  opacity: .4; animation: blink 1.3s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.25} 40%{opacity:1} }

/* ---- citations ---- */
.cites { margin-top: 14px; width: 100%; }
.cites-label {
  font-size: .72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin: 0 2px 10px;
  display: flex; align-items: center; gap: 6px;
}
.cite-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 11px;
}
.cite {
  display: flex; flex-direction: column; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .16s ease, border-color .16s ease;
}
.cite:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--accent-line); }
.cite-thumb { position: relative; aspect-ratio: 16/9; background: var(--accent-soft); }
.cite-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cite-play { position: absolute; inset: 0; display: grid; place-items: center; }
.cite-play span {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(15,25,30,.55); color: #fff; display: grid; place-items: center;
  font-size: 14px; padding-left: 3px;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  transition: transform .12s ease, background .16s ease;
}
.cite:hover .cite-play span { transform: scale(1.08); background: var(--accent); }
.cite-title {
  font-size: .8rem; font-weight: 600; line-height: 1.3;
  padding: 10px 11px 7px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.cite-jump {
  display: inline-flex; align-self: flex-start; align-items: center; gap: 4px;
  margin: 0 11px 11px; padding: 3px 9px;
  font-size: .7rem; font-weight: 700; color: var(--accent-dark);
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  border-radius: 999px;
}

/* ---- composer ---- */
.composer {
  position: sticky; bottom: 0;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, rgba(255,255,255,0));
}
.composer-form {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; padding: 6px 6px 6px 18px;
  box-shadow: var(--shadow);
}
.composer-form:focus-within { border-color: var(--accent); box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft); }
.composer-input {
  flex: 1; border: none; outline: none; background: transparent;
  font: inherit; color: var(--ink); padding: 9px 0;
  display: block; resize: none; overflow-y: auto; max-height: 140px; line-height: 1.4;
}
.composer-input::placeholder { color: var(--muted); }
.send-btn {
  flex: none; width: 42px; height: 42px; border: none; border-radius: 50%;
  background: linear-gradient(160deg, var(--accent), var(--accent-dark)); color: #fff; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
  transition: filter .15s ease, transform .08s ease;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { background: #b9c7cc; cursor: default; filter: none; }
.disclaimer { text-align: center; color: var(--muted); font-size: .72rem; margin: 10px 4px 0; line-height: 1.4; }

@media (max-width: 560px) {
  .brand-text h1 { font-size: 1.16rem; }
  .tagline { display: none; }
  .bubble { max-width: 92%; }
  .welcome-card { padding: 22px 20px; }
}
