:root {
  --sky-top: #4a90d9;
  --sky-mid: #7ab8e6;
  --sky-bottom: #cfeaff;
  --ink: #1c2b3a;
  --ink-soft: #4a5d70;
  --glass: rgba(255, 255, 255, 0.55);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --bubble-user: rgba(255, 255, 255, 0.9);
  --bubble-bot: rgba(255, 255, 255, 0.96);
  --accent: #2f7fd1;
  --accent-glow: #6db8ff;
  --shadow: 0 12px 40px rgba(28, 43, 58, 0.18);
  --radius: 22px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The `hidden` attribute must always win over component display rules. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 45%, var(--sky-bottom) 100%);
  background-attachment: fixed;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

.sun {
  position: absolute;
  top: -120px; right: -120px;
  width: 360px; height: 360px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,247,214,0.9) 0%, rgba(255,238,170,0.35) 40%, transparent 70%);
  filter: blur(4px);
}

.cloud {
  position: absolute;
  background: #fff;
  border-radius: 100px;
  opacity: 0.85;
  filter: blur(2px);
  animation: drift linear infinite;
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; background: #fff; border-radius: 50%;
}
.cloud::before { width: 55%; height: 160%; top: -55%; left: 12%; }
.cloud::after  { width: 45%; height: 140%; top: -42%; right: 14%; }

.cloud-1 { width: 180px; height: 56px; top: 12%; left: -240px; animation-duration: 65s; }
.cloud-2 { width: 120px; height: 40px; top: 26%; left: -200px; animation-duration: 85s; animation-delay: -20s; opacity: 0.7; }
.cloud-3 { width: 240px; height: 70px; top: 48%; left: -320px; animation-duration: 100s; animation-delay: -50s; opacity: 0.6; }
.cloud-4 { width: 140px; height: 46px; top: 67%; left: -220px; animation-duration: 75s; animation-delay: -10s; opacity: 0.5; }

@keyframes drift {
  from { transform: translateX(0); }
  to   { transform: translateX(calc(100vw + 360px)); }
}

@media (prefers-reduced-motion: reduce) {
  .cloud { animation: none; display: none; }
}

/* ---------- Layout ---------- */
.app {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: clamp(16px, 4vw, 32px) clamp(14px, 4vw, 28px) 0;
}

.masthead { text-align: center; padding: 12px 0 18px; }

.logo {
  font-family: "Fraunces", serif;
  font-weight: 900;
  font-size: clamp(2.6rem, 9vw, 4rem);
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 4px 24px rgba(28, 60, 100, 0.35);
  line-height: 1;
}
.tagline {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.95);
  font-size: clamp(0.95rem, 2.6vw, 1.1rem);
  text-shadow: 0 2px 10px rgba(28, 60, 100, 0.25);
}
.tagline strong { font-weight: 600; }

/* ---------- Chat ---------- */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 2px 20px;
  overflow-y: auto;
}

.msg { display: flex; gap: 10px; align-items: flex-end; animation: rise 0.4s ease both; }
.msg.user { flex-direction: row-reverse; }

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

.avatar {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.2rem;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
}
.msg.user .avatar { background: var(--accent); }

.bubble {
  max-width: 80%;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--bubble-bot);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  line-height: 1.55;
  font-size: 0.98rem;
}
.msg.bot .bubble { border-bottom-left-radius: 6px; }
.msg.user .bubble { background: var(--bubble-user); border-bottom-right-radius: 6px; }

.bubble img.shot {
  display: block;
  max-width: 240px;
  width: 100%;
  border-radius: 14px;
  margin: 0;
}

/* Rich markdown inside bot bubbles */
.bubble h2 {
  font-family: "Fraunces", serif;
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--accent);
}
.bubble p { margin: 8px 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { color: var(--ink); }
.bubble ul, .bubble ol { margin: 8px 0 8px 18px; }
.bubble a { color: var(--accent); }

/* Confidence meter */
.confidence {
  margin: 12px 0 6px;
}
.confidence-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.8rem; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 5px;
}
.confidence-label b { font-size: 1.05rem; color: var(--accent); }
.confidence-track {
  height: 10px; border-radius: 999px;
  background: rgba(47, 127, 209, 0.12);
  overflow: hidden;
}
.confidence-fill {
  height: 100%; width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-glow), var(--accent));
  box-shadow: 0 0 12px rgba(109, 184, 255, 0.7);
  transition: width 1.1s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Typing indicator */
.typing { display: flex; gap: 5px; padding: 4px 2px; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: bob 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bob {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ---------- Composer ---------- */
.composer { position: sticky; bottom: 0; padding: 6px 0 14px; }

.dropzone { transition: transform 0.2s; }
.dropzone.drag { transform: scale(1.02); }

.upload-btn {
  width: 100%;
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px;
  border: 2px dashed rgba(255, 255, 255, 0.8);
  border-radius: var(--radius);
  background: var(--glass);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  cursor: pointer;
  color: var(--ink);
  text-align: left;
  transition: background 0.2s, border-color 0.2s;
}
.upload-btn:hover { background: var(--glass-strong); border-color: #fff; }
.dropzone.drag .upload-btn { background: var(--glass-strong); border-color: #fff; }
.upload-icon { font-size: 1.8rem; }
.upload-text { display: flex; flex-direction: column; }
.upload-text strong { font-size: 1.02rem; }
.upload-text small { color: var(--ink-soft); }

.ask {
  display: flex; gap: 8px; align-items: center;
  padding: 8px;
  background: var(--glass-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.ask input[type="text"] {
  flex: 1;
  border: none; background: transparent;
  font: inherit; font-size: 1rem;
  padding: 10px 12px;
  color: var(--ink);
  outline: none;
}
.ask button {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border: none; border-radius: 14px;
  background: var(--accent);
  color: #fff; font-size: 1.1rem;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.15s, background 0.2s;
}
.ask button:hover { transform: scale(1.06); }
.ask button:disabled { opacity: 0.5; cursor: default; transform: none; }
.ask button.ghost { background: rgba(47, 127, 209, 0.12); color: var(--accent); }

.footer {
  text-align: center;
  padding: 8px 0 16px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 6px rgba(28, 60, 100, 0.25);
}

/* Suggestion chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  border: 1px solid rgba(47, 127, 209, 0.3);
  background: rgba(255, 255, 255, 0.7);
  color: var(--accent);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit; font-size: 0.85rem; font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, transform 0.15s;
}
.chip:hover { background: #fff; transform: translateY(-1px); }
