:root {
  --bg: #0b0c10;
  --text: #f1eee7;
  --muted: #8e93a0;
  --warm: #f2b56b;
  --warm-2: #ffd9a3;
  --cool: #8fd3c7;
  --deep: #a4622b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: radial-gradient(1200px 800px at 50% 60%, #12141b 0%, var(--bg) 60%); color: var(--text); font: 16px/1.5 "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif; overflow: hidden; }
button { font: inherit; }

.stage { position: relative; height: 100%; display: grid; place-items: center; grid-template-rows: 1fr auto 1fr; }

/* The orb is Serena. Everything else is quiet. */
.orb {
  grid-row: 2;
  width: min(34vmin, 260px); height: min(34vmin, 260px);
  border-radius: 50%; border: none; cursor: pointer; position: relative; z-index: 2;
  background: radial-gradient(circle at 38% 34%, var(--warm-2) 0%, var(--warm) 38%, var(--deep) 100%);
  box-shadow: 0 0 60px rgba(242, 181, 107, 0.28), inset 0 -20px 60px rgba(0, 0, 0, 0.25);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.35s, filter 0.5s;
  transform: scale(var(--pulse, 1));
}
.orb:focus-visible { outline: 2px solid var(--cool); outline-offset: 8px; }
.halo {
  position: absolute; left: 50%; top: 50%; width: min(34vmin, 260px); height: min(34vmin, 260px);
  margin: calc(min(34vmin, 260px) / -2); border-radius: 50%; pointer-events: none; z-index: 1;
  box-shadow: 0 0 0 0 rgba(143, 211, 199, 0);
  transition: box-shadow 0.4s, transform 0.4s, opacity 0.4s; opacity: 0.9;
}
.stage.listening .orb { background: radial-gradient(circle at 38% 34%, #e6fff8 0%, var(--cool) 40%, #2f7f72 100%); box-shadow: 0 0 80px rgba(143, 211, 199, 0.45); }
.stage.listening .halo { box-shadow: 0 0 0 22px rgba(143, 211, 199, 0.12), 0 0 0 48px rgba(143, 211, 199, 0.06); animation: ring 2.2s ease-in-out infinite; }
.stage.thinking .orb { animation: think 1.6s ease-in-out infinite; filter: saturate(0.85); }
.stage.speaking .orb { box-shadow: 0 0 calc(50px + var(--amp, 0) * 90px) rgba(242, 181, 107, calc(0.3 + var(--amp, 0) * 0.5)); }
.stage.speaking .halo { box-shadow: 0 0 0 calc(10px + var(--amp, 0) * 40px) rgba(242, 181, 107, 0.10); }
@keyframes ring { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes think { 0%, 100% { transform: scale(1); } 50% { transform: scale(0.95) rotate(2deg); } }

.state { grid-row: 3; align-self: start; margin-top: 4vmin; color: var(--muted); font-size: 14px; letter-spacing: 0.4px; min-height: 20px; transition: opacity 0.4s; }

/* Subtitles: Serena's words fade in as she speaks them and fade out when she's done. */
.subtitle {
  position: absolute; left: 50%; transform: translateX(-50%); width: min(78vw, 820px); text-align: center;
  opacity: 0; transition: opacity 0.6s ease; pointer-events: none; text-wrap: balance;
}
.subtitle.show { opacity: 1; }
.subtitle.serena { bottom: 16vh; font-size: clamp(18px, 2.6vmin, 28px); line-height: 1.45; color: var(--text); text-shadow: 0 2px 24px rgba(0, 0, 0, 0.6); }
.subtitle.you { top: 14vh; font-size: clamp(14px, 2vmin, 20px); color: var(--muted); font-style: italic; }

.corner { position: absolute; display: flex; gap: 10px; align-items: center; z-index: 3; }
.top-left { top: 18px; left: 20px; }
.top-right { top: 18px; right: 20px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.04); color: var(--muted); border: 1px solid rgba(255, 255, 255, 0.07); }
.chip.ok { color: var(--cool); border-color: rgba(143, 211, 199, 0.35); }
.chip.warn { color: var(--warm); border-color: rgba(242, 181, 107, 0.35); }
.chip.bad { color: #d97b7b; border-color: rgba(217, 123, 123, 0.35); }
.toggle { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; cursor: pointer; }
.ghost-btn { background: transparent; color: var(--muted); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.ghost-btn:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.2); }

.typeform { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); width: min(60vw, 520px); opacity: 0.35; transition: opacity 0.3s; z-index: 3; }
.typeform:hover, .typeform:focus-within { opacity: 1; }
.typeform input { width: 100%; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.08); color: var(--text); padding: 10px 14px; border-radius: 999px; text-align: center; }

.drawer { position: absolute; top: 0; right: 0; height: 100%; width: min(440px, 92vw); background: rgba(14, 16, 22, 0.96); border-left: 1px solid rgba(255, 255, 255, 0.08); z-index: 5; display: flex; flex-direction: column; backdrop-filter: blur(8px); }
.drawer header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.drawer h2 { margin: 0; font-size: 16px; font-weight: 600; }
.history-list { overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.history-list .h { padding: 8px 12px; border-radius: 12px; max-width: 92%; white-space: pre-wrap; }
.history-list .h.user { align-self: flex-end; background: #1e2a37; }
.history-list .h.assistant { align-self: flex-start; background: #2a2431; }
.history-list .h.proactive { align-self: flex-start; background: #1f2a2a; border: 1px dashed rgba(143, 211, 199, 0.4); }
.history-list .h.system { align-self: center; color: var(--muted); font-size: 12px; }
.history-list .h .t { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

dialog { background: #14161d; color: var(--text); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 18px; width: min(680px, 92vw); padding: 0; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.settings { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.settings h2 { margin: 0; }
.settings h3 { margin: 6px 0 4px; font-size: 14px; color: var(--warm); }
.settings section { border-top: 1px solid rgba(255, 255, 255, 0.06); padding-top: 10px; }
.settings button { background: var(--warm); color: #221a10; border: none; padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.settings button.ghost { background: transparent; color: var(--text); border: 1px solid rgba(255, 255, 255, 0.12); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0; }
.dump { max-height: 220px; overflow: auto; font-size: 12px; background: #0b0c10; padding: 10px; border-radius: 8px; white-space: pre-wrap; }
select { background: #0b0c10; color: var(--text); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; padding: 6px 8px; }
[hidden] { display: none !important; }

/* Wallpaper mode (?wallpaper=1): Serena as a live desktop background on a 5120×2160 display.
   Nothing but her: a larger orb, a soft aurora behind it, big subtitles, no controls. */
body.wallpaper { background: radial-gradient(1600px 1000px at 50% 58%, #141722 0%, #0b0c10 55%, #07080b 100%); }
body.wallpaper .corner, body.wallpaper .typeform { display: none; }
body.wallpaper .orb { width: min(30vmin, 620px); height: min(30vmin, 620px); box-shadow: 0 0 140px rgba(242, 181, 107, 0.32), 0 0 400px rgba(242, 181, 107, 0.12), inset 0 -40px 120px rgba(0, 0, 0, 0.25); animation: drift 14s ease-in-out infinite; }
body.wallpaper .halo { width: min(30vmin, 620px); height: min(30vmin, 620px); margin: calc(min(30vmin, 620px) / -2); }
body.wallpaper .stage.speaking .orb { box-shadow: 0 0 calc(120px + var(--amp, 0) * 220px) rgba(242, 181, 107, calc(0.3 + var(--amp, 0) * 0.45)), 0 0 400px rgba(242, 181, 107, 0.12); }
body.wallpaper .state { font-size: clamp(16px, 1.1vmin, 26px); letter-spacing: 0.8px; opacity: 0.75; margin-top: 3vmin; }
body.wallpaper .subtitle.serena { bottom: 12vh; font-size: clamp(22px, 2.2vmin, 44px); width: min(60vw, 1400px); }
body.wallpaper .subtitle.you { top: 12vh; font-size: clamp(16px, 1.4vmin, 28px); }
body.wallpaper::before { content: ""; position: fixed; inset: -20%; pointer-events: none; z-index: 0;
  background: radial-gradient(60% 40% at 30% 40%, rgba(143, 211, 199, 0.07), transparent 70%), radial-gradient(50% 45% at 72% 62%, rgba(242, 181, 107, 0.08), transparent 70%), radial-gradient(40% 35% at 50% 85%, rgba(120, 90, 200, 0.06), transparent 70%);
  animation: aurora 40s ease-in-out infinite alternate; }
@keyframes aurora { 0% { transform: translate3d(-2%, -1%, 0) scale(1); } 100% { transform: translate3d(2%, 2%, 0) scale(1.06); } }
@keyframes drift { 0%, 100% { transform: translateY(0) scale(var(--pulse, 1)); } 50% { transform: translateY(-1.2vmin) scale(var(--pulse, 1)); } }
body.wallpaper .stage.listening .orb, body.wallpaper .stage.thinking .orb, body.wallpaper .stage.speaking .orb { animation: none; }
