:root {
  --bg: #f5fafa;
  --surface: #ffffff;
  --ink: #12262b;
  --ink-soft: #56707a;
  --ink-faint: #8aa0a8;
  --line: #e2edee;
  --teal: #0f9d9a;
  --teal-deep: #0b7f7d;
  --teal-soft: #e3f5f4;
  --blue: #2f86d6;
  --blue-soft: #e6f1fc;
  --red: #e0524d;
  --red-deep: #c8403b;
  --red-soft: #fdeceb;
  --amber: #b97a12;
  --amber-soft: #fdf4e1;
  --shadow: 0 1px 2px rgba(18, 38, 43, .04), 0 12px 40px rgba(15, 100, 110, .09);
  --radius: 24px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic",
          "Noto Sans JP", Meiryo, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 85% -10%, rgba(47, 134, 214, .10), transparent 60%),
    radial-gradient(800px 460px at 0% 0%, rgba(15, 157, 154, .11), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

/* ---------- header / footer ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px max(20px, env(safe-area-inset-left)) 0;
  padding-right: max(20px, env(safe-area-inset-right));
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 32px; height: 32px; color: var(--teal); }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.brand-kana { font-size: 11px; color: var(--ink-faint); letter-spacing: .14em; margin-top: 4px; }
.tagline {
  font-size: 12px; color: var(--teal-deep); background: var(--teal-soft);
  padding: 5px 12px; border-radius: 999px; letter-spacing: .08em; white-space: nowrap;
}
.site-footer {
  display: flex; justify-content: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 20px max(18px, env(safe-area-inset-bottom));
  font-size: 12px; color: var(--ink-faint);
}

/* ---------- card ---------- */
.stage { flex: 1; display: grid; place-items: center; padding: 20px 16px; }
.call-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.notice {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--amber-soft); color: #6f4a08;
  border: 1px solid #f3deb0; border-radius: 14px;
  padding: 11px 14px; font-size: 13px;
}
.notice code, .alert code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; background: rgba(0, 0, 0, .06); padding: 1px 5px; border-radius: 5px;
}

/* ---------- agent ---------- */
.agent { display: flex; flex-direction: column; align-items: center; text-align: center; }
.avatar-wrap { position: relative; width: 104px; height: 104px; display: grid; place-items: center; }
.avatar { width: 96px; height: 96px; border-radius: 50%; overflow: hidden; position: relative; z-index: 1;
  box-shadow: 0 6px 18px rgba(15, 130, 140, .25); }
.avatar svg { display: block; width: 100%; height: 100%; }
/* ring scale/opacity are driven by the real AI audio level (see app.js) */
.avatar-ring {
  position: absolute; inset: -10px; border-radius: 50%;
  background: radial-gradient(circle, rgba(15, 157, 154, .34), rgba(47, 134, 214, .12) 62%, transparent 72%);
  transform: scale(var(--level-scale, 1));
  opacity: var(--level-opacity, 0);
  will-change: transform, opacity;
}
.agent-name { margin: 14px 0 0; font-size: 22px; font-weight: 700; letter-spacing: .06em; }
.agent-role { margin: 0; font-size: 13px; color: var(--ink-soft); letter-spacing: .06em; }

/* ---------- status ---------- */
.status-row { display: flex; align-items: center; justify-content: center; gap: 12px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; letter-spacing: .04em;
  padding: 6px 14px; border-radius: 999px;
  background: #eef3f4; color: var(--ink-soft);
  transition: background-color .2s, color .2s;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.timer {
  font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600;
  color: var(--ink-faint); letter-spacing: .06em;
}

[data-state="connecting"] .status-pill { background: var(--amber-soft); color: var(--amber); }
[data-state="connecting"] .status-dot { animation: blink 1s ease-in-out infinite; }
[data-state="connected"] .status-pill { background: var(--teal-soft); color: var(--teal-deep); }
[data-state="ai_speaking"] .status-pill { background: var(--teal); color: #fff; }
[data-state="user_speaking"] .status-pill { background: var(--blue); color: #fff; }
[data-state="error"] .status-pill { background: var(--red-soft); color: var(--red-deep); }
[data-state="connected"] .timer,
[data-state="ai_speaking"] .timer,
[data-state="user_speaking"] .timer { color: var(--ink); }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- waves ---------- */
.waves { display: flex; flex-direction: column; gap: 10px; }
.wave {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfdfd;
  padding: 8px 12px 6px;
  transition: border-color .2s, background-color .2s;
}
.wave-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 600; letter-spacing: .1em; color: var(--ink-faint);
}
.wave canvas { display: block; width: 100%; height: 56px; }
.wave-user canvas { height: 40px; }
[data-state="ai_speaking"] .wave-ai { border-color: rgba(15, 157, 154, .45); background: #f4fbfb; }
[data-state="ai_speaking"] .wave-ai .wave-label { color: var(--teal-deep); }
[data-state="user_speaking"] .wave-user { border-color: rgba(47, 134, 214, .45); background: #f5f9fe; }
[data-state="user_speaking"] .wave-user .wave-label { color: var(--blue); }
.muted-tag {
  font-size: 10px; letter-spacing: .06em; color: var(--red-deep);
  background: var(--red-soft); padding: 1px 8px; border-radius: 999px;
}

/* ---------- alert ---------- */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--red-soft); color: #8f2b27;
  border: 1px solid #f6cfcc; border-radius: 14px;
  padding: 12px 14px; font-size: 13px;
}
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.alert strong { display: block; }
.alert.is-info { background: var(--blue-soft); color: #1d5a94; border-color: #cfe3f8; }

/* ---------- controls ---------- */
.controls { display: flex; justify-content: center; min-height: 56px; }
.btn {
  font: inherit; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border-radius: 999px; font-weight: 700; letter-spacing: .08em;
  transition: background-color .15s, transform .1s, box-shadow .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn svg { width: 22px; height: 22px; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:focus-visible { outline: 3px solid rgba(47, 134, 214, .45); outline-offset: 3px; }
.btn:disabled { cursor: not-allowed; opacity: .55; }

.btn-start {
  width: 100%; height: 56px; font-size: 16px; color: #fff;
  background: linear-gradient(135deg, #13aaa6, #0f8f9d);
  box-shadow: 0 8px 20px rgba(15, 157, 154, .28);
}
.btn-start:hover:not(:disabled) { background: linear-gradient(135deg, #0f9d9a, #0c8090); }

.in-call { display: none; width: 100%; gap: 12px; align-items: center; }
.btn-icon {
  flex: none; height: 56px; padding: 0 18px; font-size: 13px;
  background: #eef3f4; color: var(--ink);
}
.btn-icon:hover:not(:disabled) { background: #e3ebed; }
.btn-icon .ic-mic-off { display: none; }
.btn-icon[aria-pressed="true"] { background: var(--red-soft); color: var(--red-deep); }
.btn-icon[aria-pressed="true"] .ic-mic { display: none; }
.btn-icon[aria-pressed="true"] .ic-mic-off { display: block; }
.btn-end {
  flex: 1; height: 56px; font-size: 16px; color: #fff; background: var(--red);
  box-shadow: 0 8px 20px rgba(224, 82, 77, .24);
}
.btn-end:hover:not(:disabled) { background: var(--red-deep); }

/* swap buttons while a call is being set up or is live */
[data-state="connecting"] .btn-start,
[data-state="connected"] .btn-start,
[data-state="ai_speaking"] .btn-start,
[data-state="user_speaking"] .btn-start { display: none; }
[data-state="connecting"] .in-call,
[data-state="connected"] .in-call,
[data-state="ai_speaking"] .in-call,
[data-state="user_speaking"] .in-call { display: flex; }

.hint { margin: 0; text-align: center; font-size: 12px; color: var(--ink-faint); }

/* ---------- responsive ---------- */
@media (min-width: 720px) {
  .call-card { max-width: 480px; padding: 36px 36px 26px; gap: 22px; }
  .avatar-wrap { width: 124px; height: 124px; }
  .avatar { width: 112px; height: 112px; }
  .wave canvas { height: 64px; }
  .wave-user canvas { height: 44px; }
}
@media (max-width: 380px) {
  .call-card { padding: 22px 16px 18px; gap: 16px; border-radius: 20px; }
  .brand-kana { display: none; }
  .btn-caption { display: none; }
  .btn-icon { width: 56px; padding: 0; }
}
@media (max-height: 700px) {
  .stage { padding-top: 10px; padding-bottom: 6px; }
  .call-card { gap: 14px; padding-top: 20px; }
  .avatar-wrap { width: 84px; height: 84px; }
  .avatar { width: 76px; height: 76px; }
  .agent-name { margin-top: 8px; font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
