:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5b6270;
  --line: #dde1e7;
  --accent: #1f5eff;
  --accent-ink: #ffffff;
  --danger: #c62828;
  --ok: #1e8e3e;
  --warn: #b26a00;
  --focus: #1f5eff55;

  /* The call screen: a deep ink tinted from the accent, the same in light and dark. */
  --call-bg: #0b1120;
  --call-bg-lift: #16244a;
  --call-text: #f2f5fb;
  --call-muted: #a9b6d3;
  --call-soft: rgb(255 255 255 / 0.12);
  --call-soft-hover: rgb(255 255 255 / 0.2);
  --call-ring: #6f97ff;
  --call-end: #e5484d;
  --call-end-hover: #f2555a;
  --call-alert: #ffb4a8;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --text: #e9ecf1;
    --muted: #a2a9b6;
    --line: #2a2f39;
    --accent: #5b8cff;
    --accent-ink: #0b0d12;
    --danger: #ff6b6b;
    --ok: #4cc46e;
    --warn: #f0a33a;
    --focus: #5b8cff66;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  caret-color: var(--accent);
}

::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

a { color: var(--accent); text-underline-offset: 0.18em; }

.sprite { display: none; }

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-lg { width: 28px; height: 28px; }

/* --- the form page ---------------------------------------------------------------------------- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 0;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  color: var(--text);
  text-decoration: none;
}

.tag {
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 24px 0 8px;
  text-wrap: balance;
}

.lead { color: var(--muted); margin: 0 0 12px; max-width: 65ch; }

.facts {
  margin: 0 0 20px;
  padding-left: 1.2em;
  color: var(--muted);
  font-size: 0.95rem;
}

.facts li { margin: 2px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}

.field { display: flex; flex-direction: column; margin-bottom: 14px; min-width: 0; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media (max-width: 560px) {
  .row { grid-template-columns: 1fr; gap: 0; }
}

label { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }

input[type="text"], input[type="tel"], textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}

input:focus-visible, button:focus-visible, a:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

input[aria-invalid="true"] { border-color: var(--danger); }

.hint, .small { color: var(--muted); font-size: 0.85rem; }

.small { margin: 10px 0 0; }

.req { color: var(--danger); font-weight: 700; }

.consents { border: 0; margin: 6px 0 8px; padding: 0; }

.check {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: start;
  font-weight: 400;
  font-size: 0.92rem;
  margin-bottom: 10px;
  cursor: pointer;
}

.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }

button {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  padding: 12px 18px;
  border: 1px solid transparent;
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: progress; }

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
  font-size: 1.05rem;
  min-height: 52px;
  transition: filter 160ms var(--ease-out);
}

.primary:hover:not(:disabled) { filter: brightness(1.08); }

.ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: transparent;
  color: var(--accent);
  border-color: currentColor;
  font-size: 0.95rem;
}

.ghost[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0 12px;
  font-size: 0.95rem;
}

.foot {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 32px;
  color: var(--muted);
  font-size: 0.85rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- the call screen -------------------------------------------------------------------------- */

body.in-call { overflow: hidden; background: var(--call-bg); }

.call {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--call-text);
  background:
    radial-gradient(120% 70% at 50% 0%, var(--call-bg-lift) 0%, transparent 70%),
    var(--call-bg);
  padding:
    max(16px, env(safe-area-inset-top)) 20px
    max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  animation: call-in 420ms var(--ease-out) both;
}

.call ::selection { background: rgb(111 151 255 / 0.4); }

.call a { color: var(--call-ring); }

@keyframes call-in {
  from { opacity: 0.4; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.call-top {
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--call-muted);
}

.call-brand { font-weight: 700; color: var(--call-text); letter-spacing: 0.01em; }

.call-who {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  max-width: 420px;
  padding: 24px 0;
}

.avatar {
  --level: 0;
  position: relative;
  width: 132px;
  height: 132px;
  margin-bottom: 28px;
}

.face {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #1f5eff;
  color: #ffffff;
  font-size: 3.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  box-shadow: 0 18px 40px -12px rgb(31 94 255 / 0.55);
}

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--call-ring);
  opacity: 0;
  transition: transform 140ms linear, opacity 220ms var(--ease-out);
}

/* Ringing: the rings breathe slowly while the call is being connected. */
.call[data-state="connecting"] .ring-1 { animation: breathe 2.4s var(--ease-out) infinite; }
.call[data-state="connecting"] .ring-2 { animation: breathe 2.4s var(--ease-out) 1.2s infinite; }

@keyframes breathe {
  0% { transform: scale(1); opacity: 0.55; }
  100% { transform: scale(1.55); opacity: 0; }
}

/* Robert speaking: the rings follow the loudness of his voice (--level, 0-1, set by app.js). */
.avatar.speaking .ring-1 {
  opacity: calc(0.35 + var(--level) * 0.6);
  transform: scale(calc(1.08 + var(--level) * 0.22));
}

.avatar.speaking .ring-2 {
  opacity: calc(0.15 + var(--level) * 0.4);
  transform: scale(calc(1.18 + var(--level) * 0.42));
}

.call-name {
  margin: 0;
  font-size: 2rem;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.call-firm {
  margin: 4px 0 0;
  font-size: 1.05rem;
  color: var(--call-muted);
  text-wrap: balance;
}

.call-status {
  margin: 18px 0 0;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  color: var(--call-text);
  min-height: 1.6em;
}

.call-prep {
  margin: 4px 0 0;
  font-size: 0.95rem;
  color: var(--call-muted);
  min-height: 1.4em;
  transition: opacity 0.35s ease;
}

.call-prep.fading { opacity: 0; }

.dictate-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.opt { font-weight: 400; color: var(--muted, #666); font-size: 0.9em; }

.call-hint {
  margin: 6px 0 0;
  font-size: 0.92rem;
  color: var(--call-muted);
  max-width: 34ch;
}

.call-alert {
  margin: 16px 0 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgb(229 72 77 / 0.16);
  color: var(--call-alert);
  font-size: 0.95rem;
  max-width: 38ch;
}

.call-alert .sound-button {
  min-height: 48px;
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  background: #1f5eff;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.call-controls {
  display: flex;
  gap: 56px;
  justify-content: center;
  padding: 8px 0 18px;
}

.control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.control-label { font-size: 0.85rem; color: var(--call-muted); }

.round {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  color: var(--call-text);
  transition: background-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.round:active:not(:disabled) { transform: scale(0.94); }

.round:focus-visible { outline: 3px solid var(--call-ring); outline-offset: 3px; }

.round-soft { background: var(--call-soft); }

.round-soft:hover:not(:disabled) { background: var(--call-soft-hover); }

.round-soft[aria-pressed="true"] { background: var(--call-text); color: var(--call-bg); }

.round-soft .on-muted { display: none; }

.round-soft[aria-pressed="true"] .on-unmuted { display: none; }

.round-soft[aria-pressed="true"] .on-muted { display: block; }

.round-end { background: var(--call-end); color: #ffffff; }

.round-end:hover:not(:disabled) { background: var(--call-end-hover); }

.hang { transform: rotate(135deg); fill: currentColor; stroke: none; }

.call-foot {
  margin: 0;
  font-size: 0.78rem;
  color: var(--call-muted);
  text-align: center;
}

/* --- the end screen --------------------------------------------------------------------------- */

.end-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: 28px 0 12px;
}

.end-title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.end-time {
  margin: 4px 0 0;
  font-size: 1.15rem;
  color: var(--call-muted);
  font-variant-numeric: tabular-nums;
}

.end-reason {
  margin: 14px 0 0;
  color: var(--call-muted);
  max-width: 36ch;
}

.rate {
  width: 100%;
  margin-top: 36px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
}

.rate-scale { border: 0; margin: 0 0 20px; padding: 0; min-width: 0; }

.rate-q {
  padding: 0;
  margin: 0 0 14px;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  width: 100%;
}

.rate-options { display: flex; justify-content: space-between; gap: 8px; }

.rate-options label { margin: 0; flex: 1; display: flex; justify-content: center; }

.rate-options input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.rate-options span {
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 56px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--call-soft);
  font-size: 1.15rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.rate-options label:hover span { background: var(--call-soft-hover); }

.rate-options input:checked + span { background: var(--call-text); color: var(--call-bg); transform: scale(1.06); }

.rate-options input:focus-visible + span { outline: 3px solid var(--call-ring); outline-offset: 3px; }

.rate-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--call-muted);
}

.rate-comment-label { font-size: 0.95rem; margin-bottom: 6px; }

.opt { font-weight: 400; color: var(--call-muted); }

.rate textarea {
  border-color: rgb(255 255 255 / 0.16);
  background: rgb(255 255 255 / 0.05);
  color: var(--call-text);
  resize: vertical;
  min-height: 84px;
  caret-color: var(--call-ring);
}

.rate textarea:focus-visible { outline: 3px solid rgb(111 151 255 / 0.5); outline-offset: 2px; }

.rate .call-alert { align-self: center; }

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 1rem;
  transition: background-color 160ms var(--ease-out), filter 160ms var(--ease-out);
}

.pill:focus-visible { outline: 3px solid var(--call-ring); outline-offset: 3px; }

.pill-light { margin-top: 16px; background: var(--call-text); color: var(--call-bg); }

.pill-light:hover:not(:disabled) { filter: brightness(0.94); }

.pill-ghost { background: var(--call-soft); color: var(--call-text); }

.pill-ghost:hover:not(:disabled) { background: var(--call-soft-hover); }

.rate-thanks { margin-top: 36px; font-size: 1.05rem; color: var(--call-text); }

.end-actions { padding: 8px 0 12px; }

@media (min-height: 760px) {
  .avatar { width: 148px; height: 148px; }
  .call-controls { padding-bottom: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .call { animation: none; }
  .call[data-state="connecting"] .ring-1,
  .call[data-state="connecting"] .ring-2 { animation: none; opacity: 0.4; transform: scale(1.12); }
  .avatar.speaking .ring-1 { transform: scale(1.12); opacity: 0.7; }
  .avatar.speaking .ring-2 { opacity: 0; }
  .ring, .round, .rate-options span { transition: none; }
  .call-prep { transition: none; }
  .call-prep.fading { opacity: 1; }
}

[hidden] { display: none !important; }
