/* ═══════════════════════════════════════════════════════════
   Sam SLIM — Voice PWA styles
   Mobile-first (Android Chrome), high-contrast, big tap targets.
   The talk button has 3 states driven by [data-state]:
     idle      -> YELLOW  ("Tap to talk to Sam")
     live      -> GREEN   (listening / connected)
     speaking  -> PULSING (animated rings; Sam is talking)
   ═══════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;
  --bg: #0e1116;
  --bg-soft: #161b22;
  --ink: #f3f6f9;
  --muted: #9aa6b2;
  --line: #2a3340;

  --idle: #f5c518;        /* yellow  */
  --idle-ink: #1a1400;
  --live: #25c46a;        /* green   */
  --live-ink: #05230f;
  --speaking: #3aa0ff;    /* blue pulse while Sam speaks */
  --danger: #ff5b5b;
  --accent: #3aa0ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% -10%, #1b2330 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#remoteAudio { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ── Layout ─────────────────────────────────────────────── */
.stage {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: 0.2px; }
.brand-name { font-size: 18px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--idle);
  box-shadow: 0 0 12px var(--idle);
}
body[data-mode="premium"] .brand-dot { background: var(--accent); box-shadow: 0 0 12px var(--accent); }

.spend-meter {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
}

/* ── Talk zone ──────────────────────────────────────────── */
.talk-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
}

.talk-button {
  position: relative;
  width: min(72vw, 280px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: var(--idle-ink);
  background: var(--idle);
  font: inherit;
  font-weight: 800;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, transform 0.08s ease, box-shadow 0.25s ease;
  box-shadow: 0 14px 40px -12px rgba(245, 197, 24, 0.55);
  touch-action: manipulation;
  user-select: none;
}
.talk-button:active { transform: scale(0.97); }

.talk-label {
  position: relative;
  z-index: 2;
  padding: 0 18px;
  font-size: clamp(17px, 5vw, 22px);
  line-height: 1.25;
  letter-spacing: 0.2px;
}

/* Rings used by the pulsing "speaking" state. */
.talk-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid currentColor;
  opacity: 0;
  pointer-events: none;
}

/* IDLE = yellow (default values above). */
.talk-button[data-state="idle"] {
  background: var(--idle);
  color: var(--idle-ink);
  box-shadow: 0 14px 40px -12px rgba(245, 197, 24, 0.55);
}

/* LIVE = green, steady glow. */
.talk-button[data-state="live"] {
  background: var(--live);
  color: var(--live-ink);
  box-shadow: 0 0 0 6px rgba(37, 196, 106, 0.18), 0 14px 44px -10px rgba(37, 196, 106, 0.6);
}

/* SPEAKING = blue with animated expanding rings. */
.talk-button[data-state="speaking"] {
  background: var(--speaking);
  color: #04203f;
  box-shadow: 0 0 0 6px rgba(58, 160, 255, 0.18), 0 14px 44px -10px rgba(58, 160, 255, 0.6);
}
.talk-button[data-state="speaking"] .talk-ring {
  color: var(--speaking);
  animation: pulse-ring 1.8s ease-out infinite;
}
.talk-button[data-state="speaking"] .talk-ring--2 { animation-delay: 0.9s; }

/* CONNECTING (premium handshake) = dimmed yellow, subtle breathing. */
.talk-button[data-state="connecting"] {
  background: var(--idle);
  color: var(--idle-ink);
  opacity: 0.85;
  animation: breathe 1.4s ease-in-out infinite;
}

@keyframes pulse-ring {
  0%   { opacity: 0.55; transform: scale(1); }
  100% { opacity: 0;    transform: scale(1.5); }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.03); }
}
@media (prefers-reduced-motion: reduce) {
  .talk-button[data-state="speaking"] .talk-ring,
  .talk-button[data-state="connecting"] { animation: none; }
  .talk-button[data-state="speaking"] .talk-ring { opacity: 0.4; }
}

.status {
  margin: 0;
  min-height: 22px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="live"] { color: var(--live); }

.speech-note {
  margin: 0;
  max-width: 36ch;
  color: var(--idle);
  font-size: 14px;
  line-height: 1.4;
}

/* ── Controls (mode toggle) ─────────────────────────────── */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.mode-toggle {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  cursor: pointer;
}
.mode-pill {
  padding: 9px 22px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  transition: background 0.18s ease, color 0.18s ease;
}
body[data-mode="lite"] .mode-pill[data-mode="lite"] { background: var(--idle); color: var(--idle-ink); }
body[data-mode="premium"] .mode-pill[data-mode="premium"] { background: var(--accent); color: #04203f; }

.mode-hint { margin: 0; color: var(--muted); font-size: 13px; min-height: 16px; }

/* The Lite/Premium toggle is the OWNER's switch (sam face only). The family
   demo is always Premium, so hide the whole control there. */
body[data-face="family"] .controls { display: none; }

/* ── Scene editor ───────────────────────────────────────── */
/* The editor overlay uses display:grid, which would otherwise beat the UA
   [hidden] rule and leave the popover permanently visible. Restore hiding. */
.scene-editor[hidden] { display: none; }
.scene-fab {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 28px -10px rgba(0, 0, 0, 0.7);
}

.scene-editor {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(5, 8, 12, 0.7);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: end center;
  padding: 0;
}
.scene-editor__card {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 20px 20px max(24px, env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}
.scene-editor__head { display: flex; align-items: center; justify-content: space-between; }
.scene-editor__head h2 { margin: 0; font-size: 20px; }

.field { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  padding: 11px 12px;
  resize: vertical;
}
.field input:focus,
.field textarea:focus { outline: 2px solid rgba(58, 160, 255, 0.4); border-color: var(--accent); }

.scene-editor__actions { display: flex; gap: 10px; margin-top: 4px; }
.primary-btn, .danger-btn, .ghost-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  padding: 12px 18px;
  cursor: pointer;
}
.primary-btn { background: var(--accent); border-color: var(--accent); color: #04203f; flex: 1; }
.danger-btn { background: transparent; color: var(--danger); border-color: rgba(255, 91, 91, 0.5); }
.ghost-btn { background: transparent; color: var(--muted); }

.scene-status { margin: 0; min-height: 18px; font-size: 13px; color: var(--muted); }
.scene-status[data-kind="ok"] { color: var(--live); }
.scene-status[data-kind="error"] { color: var(--danger); }

@media (min-width: 600px) {
  .scene-editor { place-items: center; }
  .scene-editor__card { border-radius: 18px; }
}
