@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("./assets/fonts/archivo-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f5f7fa;
  --line: rgba(15, 23, 42, 0.1);
  --text: #0f172a;
  --muted: #5b6474;
  --accent: #0e7490;
  --call: #1faa59;
  --call-dark: #178a48;
  --hangup: #e5484d;
  --hangup-dark: #c93a3f;
  --warn: #d99a06;
  --danger: #b42323;
  /* Soft grey that spreads out from behind the avatar and fades to white. */
  --glow-core: #e3e7ec;
  --glow-mid: #eff2f5;
  --header-h: 64px;
  --font: "Archivo", "Helvetica Neue", Arial, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button { color: inherit; font: inherit; }
h1, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* One screen, no page scroll. Desktop: avatar + call button left, intro or questions right. */
.app {
  display: grid;
  height: 100vh;
  height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 28px 24px;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 460px);
  grid-template-rows: var(--header-h) minmax(0, 1fr) auto;
  grid-template-areas:
    "header header"
    "stage panel"
    "dock panel";
  column-gap: 48px;
}

.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
}

.identity { display: flex; align-items: center; gap: 14px; min-width: 0; }
.identity > div { display: grid; gap: 1px; min-width: 0; }
.identity strong { font-size: 17px; font-weight: 750; letter-spacing: .02em; white-space: nowrap; }
.identity span { color: var(--muted); font-size: 12px; white-space: nowrap; }
/* multiply lets the logo's white JPG ground disappear into whatever sits behind it. */
.brand-logo { display: block; flex: none; width: auto; height: 34px; mix-blend-mode: multiply; }
.brand-divider { flex: none; width: 1px; height: 28px; background: var(--line); }

.call-status {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(31,170,89,.28);
  border-radius: 999px;
  color: var(--call-dark);
  background: rgba(31,170,89,.07);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}
.call-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--call); }
.call-time { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.call-time[hidden] { display: none; }
[data-state="connecting"] .call-status { border-color: rgba(217,154,6,.35); color: #8a6100; background: rgba(217,154,6,.08); }
[data-state="connecting"] .call-status i { background: var(--warn); }
[data-state="live"] .call-status i { animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* Square stage sized to whichever of width or height runs out first.
   Desktop: a gentle grey glow behind the avatar that fades out before the area's edges. */
.stage-wrap {
  grid-area: stage;
  display: grid;
  place-items: center;
  min-height: 0;
  padding-top: 20px;
  background: radial-gradient(closest-side at 50% 55%, var(--glow-core) 0%, var(--glow-mid) 45%, rgba(255,255,255,0) 100%);
  container-type: size;
}

.stage {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1 / 1;
  overflow: hidden;
}
.stage-preview, .stage-video, .stage-canvas, .stage-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
/* The 16:9 stream is center-cropped into the square: only empty sides are cut, the person stays whole. */
.stage-preview, .stage-video, .stage-canvas { object-fit: cover; object-position: center bottom; }
/* The raw video keeps decoding while hidden; the keyed canvas is what visitors see. */
.stage-video, .stage-canvas { visibility: hidden; }
.stage.is-live .stage-canvas { visibility: visible; }
.stage.is-live .stage-preview { visibility: hidden; }

.stage-overlay { z-index: 5; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 16px; color: var(--text); background: rgba(255,255,255,.6); font-size: 15px; text-align: center; }
.stage-overlay i { width: 36px; height: 36px; border: 2px solid rgba(15,23,42,.12); border-top-color: var(--call); border-radius: 50%; animation: spin 700ms linear infinite; }
.stage-overlay[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Call button: round, green, flat with a soft lift; turns red to hang up. */
.call-dock { grid-area: dock; display: grid; justify-items: center; gap: 6px; padding-top: 16px; }

.call-button {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #ffffff;
  background: var(--call);
  box-shadow: 0 6px 16px rgba(31,170,89,.3);
  cursor: pointer;
  transition: background-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}
.call-button:hover { background: var(--call-dark); }
.call-button:active { transform: scale(.95); }
.call-button:disabled { cursor: progress; }
.call-button svg { width: 30px; height: 30px; transition: transform 200ms ease; }
[data-state="connecting"] .call-button { animation: ring 1.2s ease-out infinite; }
@keyframes ring { from { box-shadow: 0 0 0 0 rgba(31,170,89,.45); } to { box-shadow: 0 0 0 18px rgba(31,170,89,0); } }
[data-state="live"] .call-button { background: var(--hangup); box-shadow: 0 6px 16px rgba(229,72,77,.3); }
[data-state="live"] .call-button:hover { background: var(--hangup-dark); }
[data-state="live"] .call-button svg { transform: rotate(135deg); }

.call-label { font-size: 14px; font-weight: 700; }
.call-note { min-height: 1.4em; color: var(--muted); font-size: 12.5px; line-height: 1.4; text-align: center; }
.call-note.is-error { color: var(--danger); }

/* Right panel (desktop) */
.panel { grid-area: panel; display: flex; flex-direction: column; gap: 22px; min-height: 0; padding-top: 32px; }

.greeting { display: none; }

.intro { display: grid; gap: 10px; }
/* During a call the intro steps aside so the questions get the room. */
[data-state="live"] .intro { display: none; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 750; letter-spacing: .12em; }
h1 { font-size: clamp(24px, 2.2vw, 30px); line-height: 1.35; letter-spacing: .01em; }
.intro-text { color: var(--muted); font-size: 15px; line-height: 1.65; }

.questions { display: grid; align-content: start; gap: 12px; min-height: 0; overflow-y: auto; }
.questions[hidden] { display: none; }
.questions-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-label { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .04em; }

.refresh {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  padding: 6px 13px 6px 10px;
  border: 1px solid rgba(14,116,144,.3);
  border-radius: 999px;
  color: var(--accent);
  background: var(--bg);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 150ms ease;
}
.refresh:hover { background: #eef6f8; }
.refresh svg { width: 16px; height: 16px; transition: transform 300ms ease; }
.refresh:active svg { transform: rotate(-180deg); }

.question-list { display: grid; gap: 8px; }
.question {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 15px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease;
}
.question::after { content: "›"; flex: none; color: var(--muted); font-size: 20px; line-height: 1; }
.question:hover { border-color: var(--accent); color: var(--accent); }
.question.is-asked { border-color: transparent; color: var(--muted); background: var(--surface); }
.question.is-asked::after { content: "已問"; font-size: 12px; }

/* Short desktop windows: let the page scroll rather than crush the avatar. */
@media (min-width: 761px) and (max-height: 620px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .stage-wrap { height: 460px; }
}

/* Phone: one screen — header, avatar, greeting or questions, call button at the bottom. */
@media (max-width: 760px) {
  :root { --header-h: 54px; }

  /* The whole screen carries the grey glow, centred on the avatar and fading to white at the edges. */
  body {
    background:
      radial-gradient(farthest-side at 50% 44%, var(--glow-core) 0%, var(--glow-mid) 42%, #ffffff 100%) no-repeat,
      #ffffff;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--header-h) minmax(0, 1fr) auto auto;
    grid-template-areas: "header" "stage" "panel" "dock";
    padding: 0 16px calc(14px + env(safe-area-inset-bottom));
    column-gap: 0;
  }

  .identity { gap: 10px; }
  .identity span { display: none; }
  .identity strong { font-size: 15px; }
  .brand-logo { height: 26px; }
  .brand-divider { height: 20px; }
  .call-status { padding: 5px 10px; font-size: 12px; background: rgba(255,255,255,.7); }

  /* Seat the avatar right above the greeting; spare height collects under the header. */
  .stage-wrap { padding-top: 10px; place-items: end center; background: none; }

  .panel { gap: 10px; padding-top: 10px; }
  .intro { display: none; }
  .greeting { display: grid; gap: 4px; text-align: center; }
  .greeting strong { font-size: 17px; }
  .greeting span { color: var(--muted); font-size: 13.5px; }
  [data-state="live"] .greeting { display: none; }

  .questions { gap: 8px; margin-inline: -16px; overflow: visible; }
  .questions-head { padding-inline: 16px; }
  .section-label { font-size: 12.5px; font-weight: 600; letter-spacing: 0; }
  .refresh { padding: 5px 11px 5px 8px; font-size: 12.5px; }
  .refresh svg { width: 14px; height: 14px; }

  .question-list {
    display: flex;
    gap: 8px;
    padding: 2px 16px;
    overflow-x: auto;
    scroll-padding-inline: 16px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }
  .question-list::-webkit-scrollbar { display: none; }
  .question { flex: none; width: auto; padding: 8px 13px; border-radius: 999px; font-size: 13.5px; white-space: nowrap; scroll-snap-align: start; }
  .question::after, .question.is-asked::after { content: none; }
  .question.is-asked { border-color: var(--line); background: rgba(255,255,255,.55); }

  .call-dock { gap: 4px; padding-top: 12px; }
  .call-button { width: 68px; height: 68px; }
}

@media (max-width: 380px) {
  .brand-divider { display: none; }
  .identity strong { font-size: 14px; }
}

@media (max-width: 760px) and (max-height: 620px) {
  .call-button { width: 58px; height: 58px; }
  .call-button svg { width: 26px; height: 26px; }
  .call-note { display: none; }
  .greeting span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ?debug staging panel: presets + reply timings, kept out of the way in a corner. */
.debug-panel {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: 50;
  display: grid;
  gap: 6px;
  width: min(340px, calc(100vw - 16px));
  max-height: 45vh;
  padding: 10px 12px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.95);
  box-shadow: 0 6px 24px rgba(15,23,42,.12);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.debug-panel label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.debug-panel select { font: inherit; }
.debug-panel ol { margin: 4px 0 0; padding-left: 18px; color: var(--muted); }
