/* WorkFactory brand system (Logo/Logo.md, Brand v1.0)
   Deep Blue #1E3A8A → Sky Blue #0EA5E9 (gradient 135°) · Agent Orange #F97316
   (accent — always the most saturated element) · Ink Black #0F172A
   Type: Cormorant Garamond 600 (wordmark) · Inter (UI) */
:root {
  --wf-deep-blue: #1E3A8A;
  --wf-sky-blue: #0EA5E9;
  --wf-orange: #F97316;
  --wf-ink: #0F172A;
  --wf-gradient: linear-gradient(135deg, #1E3A8A, #0EA5E9);
  --wf-surface: #F8FAFC;
  --wf-card: #FFFFFF;
  --wf-line: #E2E8F0;
  --wf-muted: #64748B;
}

* { box-sizing: border-box; margin: 0; }
body {
  font-family: "Inter", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  background: var(--wf-surface);
  color: var(--wf-ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid var(--wf-line);
  background: var(--wf-card);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { height: 36px; }
.wordmark {
  font-family: "Cormorant Garamond", serif;
  font-weight: 600;
  font-size: 28px;
  letter-spacing: 0.02em;
  background: var(--wf-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.wordmark .ai-hub { color: var(--wf-orange); -webkit-text-fill-color: var(--wf-orange); }
.badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--wf-deep-blue);
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
  padding: 4px 12px;
  border-radius: 999px;
}
body[data-state="listening"] .badge,
body[data-state="speaking"] .badge { color: var(--wf-orange); background: #FFF7ED; border-color: #FFEDD5; }
.header-actions { display: flex; gap: 12px; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 24px;
  padding: 24px 28px 28px;
}

.stage {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(160deg, #0F172A, #1E3A8A 130%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.stage video { width: 100%; height: 100%; object-fit: cover; }
/* Hard exclusivity: while the avatar video is visible, nothing else in the
   stage may render — even if a script state ever goes stale. */
.stage video:not([hidden]) ~ .placeholder,
.stage video:not([hidden]) ~ .voice-orb { display: none; }
/* And the orb can never appear before a session starts. */
body[data-state="tapToStart"] .voice-orb { display: none; }
.placeholder { color: #94A3B8; font-size: 15px; padding: 24px; text-align: center; }

/* Voice-only conversation status — animated orb driven by body[data-state] */
.voice-orb { display: flex; flex-direction: column; align-items: center; gap: 20px; color: #CBD5E1; }
.orb {
  width: 130px; height: 130px; border-radius: 50%;
  background: var(--wf-gradient);
  display: flex; align-items: center; justify-content: center; gap: 7px;
  animation: orb-breathe 3.2s ease-in-out infinite;
  box-shadow: 0 10px 48px rgba(14, 165, 233, 0.45);
  transition: background 0.3s;
}
.orb span { width: 9px; height: 18px; border-radius: 5px; background: rgba(255,255,255,0.92); }
body[data-state="listening"] .orb {
  background: radial-gradient(circle at 35% 30%, #FDBA74, var(--wf-orange));
  box-shadow: 0 10px 48px rgba(249, 115, 22, 0.5);
  animation: orb-listen 1s ease-in-out infinite;
}
body[data-state="thinking"] .orb { animation: orb-breathe 0.9s ease-in-out infinite; }
body[data-state="speaking"] .orb span:nth-child(1) { animation: orb-bar 0.45s ease-in-out infinite; }
body[data-state="speaking"] .orb span:nth-child(2) { animation: orb-bar 0.45s ease-in-out 0.15s infinite; }
body[data-state="speaking"] .orb span:nth-child(3) { animation: orb-bar 0.45s ease-in-out 0.3s infinite; }
@keyframes orb-breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes orb-listen { 0%,100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(249,115,22,0.45); } 50% { transform: scale(1.1); box-shadow: 0 0 0 26px rgba(249,115,22,0); } }
@keyframes orb-bar { 0%,100% { height: 14px; } 50% { height: 46px; } }

.subtitle-bar {
  position: absolute;
  left: 16px; right: 16px; bottom: 16px;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 999px;
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  color: var(--wf-ink);
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.25);
}
.latency { font-size: 12px; color: var(--wf-muted); font-variant-numeric: tabular-nums; }
body[data-state="listening"] .subtitle-bar { outline: 2px solid var(--wf-orange); }

.panel {
  background: var(--wf-card);
  border-radius: 20px;
  border: 1px solid var(--wf-line);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden; /* lets the transcript own the scroll */
}

/* Live transcript — visitor (right, blue) and assistant (left, slate) bubbles */
.transcript {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px;
}
.bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.bubble.user {
  align-self: flex-end;
  background: var(--wf-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--wf-surface);
  border: 1px solid var(--wf-line);
  color: var(--wf-ink);
  border-bottom-left-radius: 4px;
}
.panel h1 {
  font-family: "Cormorant Garamond", serif;
  font-weight: 600;
  font-size: 30px;
  line-height: 1.15;
  color: var(--wf-ink);
}
.panel p { color: var(--wf-deep-blue); }
.panel h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--wf-muted); }

.chips { display: flex; flex-direction: column; gap: 10px; }
.chip {
  text-align: left;
  background: var(--wf-surface);
  border: 1px solid var(--wf-line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--wf-ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.chip:hover { background: #EFF6FF; border-color: var(--wf-sky-blue); }

button { font: inherit; cursor: pointer; border: none; border-radius: 12px; }
.primary {
  background: var(--wf-gradient);
  color: #fff;
  font-weight: 600;
  padding: 16px;
  font-size: 18px;
}
.danger {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: #DC2626;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 999px;
}
.danger:hover { background: #FEE2E2; border-color: #FCA5A5; }

/* Session mode: Live Avatar vs Live Voice — segmented control */
.mode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--wf-surface);
  border: 1px solid var(--wf-line);
  border-radius: 12px;
  padding: 4px;
}
.mode-picker button {
  background: transparent;
  color: var(--wf-muted);
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  border-radius: 9px;
}
.mode-picker button[aria-pressed="true"] {
  background: var(--wf-card);
  color: var(--wf-deep-blue);
  border: 1px solid var(--wf-line);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  font-weight: 600;
}
.mode-picker button:disabled { opacity: 0.45; cursor: default; }

.lang-picker { display: flex; gap: 6px; }
.lang-picker button {
  background: transparent;
  border: 1px solid var(--wf-line);
  color: var(--wf-deep-blue);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
}
.lang-picker button[aria-pressed="true"] { background: var(--wf-gradient); color: #fff; border-color: transparent; }
.lang-picker button:disabled { opacity: 0.45; cursor: default; }

/* Push-to-talk = the key action → Agent Orange (the most saturated element) */
.ptt {
  margin-top: auto;
  background: var(--wf-orange);
  color: #fff;
  font-weight: 600;
  padding: 22px;
  font-size: 20px;
  border-radius: 16px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 6px 20px rgba(249, 115, 22, 0.35);
}
body[data-state="listening"] .ptt { background: #C2410C; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}
