/* JARVIS face.
   Sized for an 800x480 5" panel but fluid, so it fills a desktop monitor too.
   Per-state colour + geometry live here; face.js only swaps data-state. */

:root {
  --bg-0: #05070c;
  --bg-1: #0b1220;
  --accent: #38d8ff;
  --accent-deep: #0a6c8f;
  --ink: #cfe9f5;
  --muted: #5b7386;
  --speed: 420ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-0);
  overflow: hidden;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* Pointer stays visible on a desk; hidden only in kiosk fullscreen. */
}

.stage {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vh, 40px);
  background:
    radial-gradient(120% 90% at 50% 38%, var(--bg-1) 0%, var(--bg-0) 62%);
  transition: background var(--speed) ease;
}

/* Faint CRT texture — sells "device" rather than "web page". */
.scanlines {
  position: absolute; inset: 0; pointer-events: none; opacity: .35;
  background: repeating-linear-gradient(
    to bottom, rgba(255,255,255,.025) 0 1px, transparent 1px 3px);
}

.head {
  width: min(78vw, 62vh * 1.55);
  filter: drop-shadow(0 0 42px color-mix(in srgb, var(--accent) 26%, transparent));
  animation: breathe 6s ease-in-out infinite;
  transition: filter var(--speed) ease;
}

.face { width: 100%; height: auto; display: block; overflow: visible; }

/* Gentle idle drift so he never looks frozen. */
@keyframes breathe {
  0%, 100% { transform: translateY(0)      scale(1);     }
  50%      { transform: translateY(-0.9%)  scale(1.006); }
}

/* ── Parts ──────────────────────────────────────────────────────────── */
.socket { fill: rgba(10, 30, 44, .55); stroke: color-mix(in srgb, var(--accent) 42%, transparent); stroke-width: 2.5; }
.pupil  { fill: url(#eyeCore); transition: transform 260ms cubic-bezier(.22,.9,.3,1), opacity var(--speed); }
.lid    { fill: var(--bg-0); transform-origin: center top; transform: scaleY(0); transition: transform 90ms ease; }
.brow   { fill: var(--accent); opacity: .82; transform-box: fill-box; transform-origin: center; transition: transform var(--speed) cubic-bezier(.22,.9,.3,1), opacity var(--speed); }

.mouth-line {
  fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round;
  opacity: .9; transition: d var(--speed) ease, opacity 200ms ease;
}
.mouth-bars { opacity: 0; transition: opacity 200ms ease; }
.mouth-bars rect { fill: var(--accent); transform-box: fill-box; transform-origin: center; }

.think-dots { opacity: 0; transition: opacity 220ms ease; }
.think-dots circle { fill: var(--accent); }

/* Blink is driven by a class from JS so timing can be random. */
.blinking .lid { transform: scaleY(1); }

/* ── Name plate ─────────────────────────────────────────────────────── */
.plate {
  display: flex; align-items: center; gap: 14px;
  font-size: clamp(11px, 1.6vh, 15px); letter-spacing: .32em; text-transform: uppercase;
}
.name   { color: var(--ink); font-weight: 600; }
.sep    { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.status { color: var(--accent); min-width: 8ch; }
.caption {
  color: var(--muted); letter-spacing: .06em; text-transform: none;
  max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.caption:empty { display: none; }

.link-warning {
  position: absolute; bottom: 10px; right: 14px;
  font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: #d98a3a;
}

:fullscreen, :fullscreen * { cursor: none; }
:fullscreen .chat-bar, :fullscreen .chat-bar * { cursor: text; }

/* ══ STATES ══════════════════════════════════════════════════════════ */

/* idle — calm, slow breath. (base styles) */

/* listening — brighter, alert brows, mouth a small attentive line */
.stage[data-state="listening"] { --accent: #4ff0c0; --accent-deep: #0c7a63; }
[data-state="listening"] .brow-l { transform: translateY(-5px); }
[data-state="listening"] .brow-r { transform: translateY(-5px); }
[data-state="listening"] .head   { animation-duration: 3.2s; }
[data-state="listening"] .mouth-line { d: path("M172 200 Q200 200 228 200"); }

/* thinking — eyes drift up, dots pulse */
.stage[data-state="thinking"] { --accent: #8f9dff; --accent-deep: #3b3f9e; }
[data-state="thinking"] .pupil { transform: translate(6px, -8px); }
[data-state="thinking"] .brow-l { transform: translateY(-3px) rotate(-7deg); }
[data-state="thinking"] .think-dots { opacity: 1; }
[data-state="thinking"] .think-dots circle { animation: dot 1.25s ease-in-out infinite; }
[data-state="thinking"] .think-dots circle:nth-child(2) { animation-delay: .16s; }
[data-state="thinking"] .think-dots circle:nth-child(3) { animation-delay: .32s; }
@keyframes dot { 0%,100% { opacity:.25; transform: translateY(0);} 50% { opacity:1; transform: translateY(-4px);} }

/* speaking — line hides, waveform bars run */
.stage[data-state="speaking"] .mouth-line { opacity: 0; }
.stage[data-state="speaking"] .mouth-bars { opacity: 1; }
[data-state="speaking"] .mouth-bars rect { animation: talk 620ms ease-in-out infinite; }
[data-state="speaking"] .mouth-bars rect:nth-child(1) { animation-delay: 0ms;   }
[data-state="speaking"] .mouth-bars rect:nth-child(2) { animation-delay: 80ms;  }
[data-state="speaking"] .mouth-bars rect:nth-child(3) { animation-delay: 160ms; }
[data-state="speaking"] .mouth-bars rect:nth-child(4) { animation-delay: 120ms; }
[data-state="speaking"] .mouth-bars rect:nth-child(5) { animation-delay: 40ms;  }
[data-state="speaking"] .mouth-bars rect:nth-child(6) { animation-delay: 200ms; }
@keyframes talk { 0%,100% { transform: scaleY(.45);} 50% { transform: scaleY(2.4);} }

/* happy — warm, brows lift, mouth curves up */
.stage[data-state="happy"] { --accent: #6ff08a; --accent-deep: #157a3a; }
[data-state="happy"] .brow-l { transform: translateY(-9px) rotate(-9deg); }
[data-state="happy"] .brow-r { transform: translateY(-9px) rotate(9deg); }
[data-state="happy"] .mouth-line { d: path("M150 194 Q200 226 250 194"); }
[data-state="happy"] .head { animation-duration: 4s; }

/* confused — one brow up, head tilts, mouth wavers */
.stage[data-state="confused"] { --accent: #ffcf5c; --accent-deep: #8a6410; }
[data-state="confused"] .brow-l { transform: translateY(-11px) rotate(-15deg); }
[data-state="confused"] .brow-r { transform: translateY(3px) rotate(5deg); }
[data-state="confused"] .mouth-line { d: path("M158 204 Q180 190 200 202 Q222 214 244 198"); }
[data-state="confused"] .head { transform: rotate(-3.5deg); animation-duration: 5s; }

/* annoyed — brows down and inward, flat mouth, red cast */
.stage[data-state="annoyed"] { --accent: #ff6b6b; --accent-deep: #8c1f26; }
[data-state="annoyed"] .brow-l { transform: translateY(12px) rotate(13deg); }
[data-state="annoyed"] .brow-r { transform: translateY(12px) rotate(-13deg); }
[data-state="annoyed"] .pupil  { transform: scale(.86); }
[data-state="annoyed"] .mouth-line { d: path("M162 206 Q200 198 238 206"); }

/* sleeping — dim, lids closed, slow deep breath */
.stage[data-state="sleeping"] { --accent: #43607a; --accent-deep: #16232e; }
[data-state="sleeping"] .lid { transform: scaleY(1); }
[data-state="sleeping"] .brow-l,
[data-state="sleeping"] .brow-r { transform: translateY(6px); opacity: .35; }
[data-state="sleeping"] .mouth-line { d: path("M176 202 Q200 202 224 202"); opacity: .45; }
[data-state="sleeping"] .head { animation-duration: 9s; filter: drop-shadow(0 0 18px rgba(67,96,122,.35)); }
[data-state="sleeping"] .status { opacity: .6; }

/* ── 5" 800x480 panel ───────────────────────────────────────────────── */
@media (max-height: 520px) {
  .stage { gap: 10px; }
  .head  { width: min(84vw, 58vh * 1.55); }
  .plate { font-size: 11px; letter-spacing: .26em; }
}

@media (prefers-reduced-motion: reduce) {
  .head, .mouth-bars rect, .think-dots circle { animation: none !important; }
}

/* ══ Phase 2: reply text + temporary chat input ══════════════════════ */
/* Both stay out of the way — the face is still the experience. */

.chat-reply {
  max-width: min(80ch, 86vw);
  text-align: center;
  font-size: clamp(14px, 2.1vh, 18px);
  line-height: 1.55;
  color: var(--ink);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 320ms ease, transform 320ms ease;
  pointer-events: none;
  min-height: 0;
}
.chat-reply.visible { opacity: 1; transform: translateY(0); }
.chat-reply[data-kind="error"] { color: #e79a5c; }

.chat-bar {
  position: absolute;
  bottom: 18px; left: 50%; transform: translateX(-50%);
  width: min(560px, 82vw);
  opacity: 0;
  transition: opacity 260ms ease;
  cursor: text;
}
.chat-bar.open, .chat-bar:hover { opacity: 1; }

.chat-bar input {
  width: 100%;
  padding: 11px 16px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  background: rgba(6, 12, 20, .78);
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 220ms ease, box-shadow 220ms ease;
}
.chat-bar input::placeholder { color: var(--muted); }
.chat-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.chat-bar input:disabled { opacity: .5; }

/* On the 5" panel the bar would crowd the face; keep it tighter. */
@media (max-height: 520px) {
  .chat-bar { bottom: 10px; width: min(440px, 88vw); }
  .chat-bar input { padding: 8px 14px; font-size: 13px; }
  .chat-reply { font-size: 14px; }
}
