/* driz.cam — palette lifted from the avatar: sky, skin, hair, cream tee, sunglasses brown. */
:root {
  --sky-1: #4aadf3;
  --sky-2: #9ad6ff;
  --sky-3: #d8efff;
  --ink: #3b2a22;          /* sunglasses / outline brown */
  --ink-soft: #6b5247;
  --cream: #fbf5ea;        /* the tee */
  --cream-2: #f1e7d6;
  --peach: #ffe1cc;        /* his bubbles */
  --skin: #e9a982;
  --hair: #a65d34;
  --accent: #e07a3a;
  --ok: #3ec27a;
  --warn: #f2b134;
  --bad: #e5533d;
  --radius: 26px;
  --pad: clamp(14px, 2.4vw, 28px);
  --font-display: "Fredoka", "Nunito", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 55%, var(--sky-3) 100%);
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- sky bands (the white swooshes behind the pfp) ---------- */
.sky { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.band {
  position: absolute;
  border-radius: 50%;
  border: 0 solid rgba(255, 255, 255, .34);
  filter: blur(1px);
  animation: drift 26s ease-in-out infinite alternate;
}
.b1 { width: 170vw; height: 110vh; left: -30vw; top: -58vh; border-width: 42px; transform: rotate(-9deg); }
.b2 { width: 190vw; height: 120vh; left: -40vw; top: -40vh; border-width: 22px; opacity: .8; animation-delay: -8s; transform: rotate(-9deg); }
.b3 { width: 150vw; height: 100vh; left: 10vw; top: 55vh; border-width: 34px; opacity: .55; animation-delay: -16s; transform: rotate(-6deg); }
@keyframes drift { from { translate: 0 0; } to { translate: 2vw -1.5vh; } }
@media (prefers-reduced-motion: reduce) { .band { animation: none; } }

/* ---------- header ---------- */
.top {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--pad) * .7) var(--pad);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--ink); display: grid; place-items: center;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .18);
  transition: transform .15s ease;
}
.brand:hover .brand-mark { transform: rotate(-6deg) scale(1.04); }
.brand-mark img { image-rendering: auto; display: block; }
.brand-word {
  font-family: var(--font-display); font-weight: 700; font-size: 1.55rem; letter-spacing: .01em;
  text-shadow: 0 3px 0 rgba(59, 42, 34, .55);
}
.brand-word .dot { color: var(--accent); }
.top-right { display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 800; font-size: .85rem; letter-spacing: .01em;
  color: var(--ink); background: var(--cream);
  border: 2.5px solid var(--ink); border-radius: 999px;
  padding: 7px 14px 7px 11px; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s ease, box-shadow .08s ease;
}
.pill:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.pill:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.pill svg { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pill svg .spk { fill: var(--ink); }
.pill[aria-pressed="false"] .wave { opacity: .25; }

.voice-status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .78rem; font-weight: 800; color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, .25);
  padding: 6px 10px; border-radius: 999px; background: rgba(59, 42, 34, .28); backdrop-filter: blur(6px);
}
.voice-status i { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px rgba(255, 255, 255, .25); }
.voice-status[data-state="ok"] i { background: var(--ok); }
.voice-status[data-state="bad"] i { background: var(--bad); }
.voice-status b { font-weight: 800; }

/* ---------- stage ---------- */
.stage {
  position: relative; z-index: 1;
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(320px, 1fr);
  gap: var(--pad);
  padding: 0 var(--pad) var(--pad);
  max-width: 1280px; width: 100%; margin: 0 auto;
}

.avatar-wrap { position: relative; min-height: 0; display: flex; flex-direction: column; }
#avatar { width: 100%; height: 100%; flex: 1; min-height: 0; display: block; touch-action: none; }
.nameplate {
  position: absolute; left: 50%; bottom: 8px; translate: -50% 0;
  display: inline-flex; align-items: baseline; gap: 10px;
  background: var(--ink); color: var(--cream);
  padding: 8px 16px 9px; border-radius: 999px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .18);
  font-family: var(--font-display);
}
.nameplate .name { font-weight: 700; font-size: 1.1rem; }
.nameplate .state { font-family: var(--font-body); font-size: .75rem; font-weight: 800; color: #d8b9a6; text-transform: lowercase; }
.nameplate .state::before { content: "· "; }
.nameplate[data-state="talking"] .state { color: #ffb37a; }
.nameplate[data-state="thinking"] .state { color: #9ad6ff; }

/* ---------- chat card ---------- */
.chat {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--cream);
  border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: 8px 8px 0 var(--ink);
  overflow: hidden;
}
.chat-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 18px 8px;
  display: flex; flex-direction: column; gap: 6px;
  scroll-behavior: smooth;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, .8), transparent 60%),
    var(--cream);
}
.msg { display: flex; gap: 10px; align-items: flex-end; max-width: 88%; animation: pop .22s cubic-bezier(.2, .9, .3, 1.3) both; }
.msg.them { align-self: flex-start; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg + .msg.same { margin-top: -2px; }
.msg .who {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 10px;
  background: var(--ink); display: grid; place-items: center;
  visibility: hidden;
}
.msg .who img { width: 18px; height: 18px; }
.msg.them.first .who { visibility: visible; }
.msg .bubble {
  padding: 10px 14px; border-radius: 18px;
  font-size: .98rem; line-height: 1.35; font-weight: 600;
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.them .bubble { background: var(--peach); color: var(--ink); border-bottom-left-radius: 6px; border: 2px solid rgba(59, 42, 34, .12); }
.msg.me .bubble { background: var(--ink); color: var(--cream); border-bottom-right-radius: 6px; }
.msg.sys .bubble { background: transparent; color: var(--ink-soft); font-size: .8rem; font-style: italic; text-align: center; }
.msg.sys { align-self: center; max-width: 100%; }
.msg.err .bubble { background: #ffe0da; color: #8a2a1c; border: 2px solid #f2b3a8; }
@keyframes pop { from { opacity: 0; translate: 0 6px; scale: .96; } to { opacity: 1; translate: 0 0; scale: 1; } }

.typing .bubble { display: inline-flex; gap: 5px; padding: 12px 14px; }
.typing .bubble i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); opacity: .5; animation: blink 1.1s infinite ease-in-out; }
.typing .bubble i:nth-child(2) { animation-delay: .15s; }
.typing .bubble i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-4px); opacity: .9; } }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px; border-top: 3px solid var(--ink); background: var(--cream-2);
}
.composer textarea {
  flex: 1; resize: none; font: inherit; font-weight: 600; font-size: 1rem; line-height: 1.35;
  color: var(--ink); background: #fff;
  border: 2.5px solid var(--ink); border-radius: 16px;
  padding: 11px 14px; min-height: 46px; max-height: 160px;
  outline: none;
}
.composer textarea:focus { box-shadow: 0 0 0 3px rgba(74, 173, 243, .45); }
.composer textarea::placeholder { color: #a08a7d; font-weight: 600; }
.send {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 16px;
  border: 2.5px solid var(--ink); background: var(--accent); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
}
.send svg { fill: currentColor; }
.send:hover { filter: brightness(1.06); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.send:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.send:disabled { filter: saturate(.3) brightness(1.1); cursor: progress; transform: none; box-shadow: 3px 3px 0 var(--ink); }
.send.wide { width: auto; padding: 0 18px; font: inherit; font-weight: 800; }

/* ---------- access code dialog ---------- */
.code-dialog {
  border: 3px solid var(--ink); border-radius: var(--radius); background: var(--cream); color: var(--ink);
  padding: 26px 28px; width: min(92vw, 380px); box-shadow: 8px 8px 0 var(--ink);
}
.code-dialog::backdrop { background: rgba(59, 42, 34, .45); backdrop-filter: blur(3px); }
.code-dialog h2 { margin: 0 0 6px; font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; }
.code-dialog p { margin: 0 0 14px; color: var(--ink-soft); font-size: .9rem; }
.code-dialog input {
  width: 100%; font: inherit; font-weight: 700; font-size: 1rem; padding: 11px 14px;
  border: 2.5px solid var(--ink); border-radius: 14px; background: #fff; color: var(--ink); outline: none;
}
.code-dialog .row { display: flex; justify-content: flex-end; margin-top: 12px; }
.code-dialog .err { color: var(--bad); margin: 10px 0 0; font-weight: 800; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(260px, 38dvh) minmax(380px, 1fr); }
  .chat { box-shadow: 5px 5px 0 var(--ink); }
  .brand-word { font-size: 1.3rem; }
  .voice-status b { display: none; }
  .pill span { display: none; }
  .pill { padding: 8px 10px; }
}
@media (max-width: 420px) {
  :root { --radius: 20px; }
  .msg { max-width: 94%; }
}
