/* Digital Twin — page shell
   Dark, minimal, calm. System font stack, no build step. */

:root {
  --bg: #0a0b0d;
  --bg-raised: #131417;
  --bg-inset: #0e0f12;
  --border: #23252b;
  --border-soft: #1a1c21;
  --text: #eceef1;
  --text-dim: #9a9fa8;
  --text-faint: #63676f;
  --accent: #6ee7c8;
  --accent-dim: #2f5a4f;
  --focus: #8fb8ff;

  --state-idle: #63676f;
  --state-connecting: #e2b93b;
  --state-listening: #6ee7c8;
  --state-speaking: #8fb8ff;
  --state-reconnecting: #e2b93b;
  --state-ended: #e5697a;

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 20px 40px -24px rgba(0, 0, 0, 0.6);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

/* This page is dark-only by design (a late-night avatar call reads best on
   near-black), so colors are fixed rather than branched on prefers-color-scheme. */

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.badge {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--bg);
  background: var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
}

/* Stage */

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 70vh;
  margin: 0 auto;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

#avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--bg-inset);
  display: block;
}

.tap-sound {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 11, 13, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  padding: 14px 24px;
  border-radius: 999px;
  cursor: pointer;
}

.tap-sound[hidden] {
  display: none;
}

.status-pill {
  position: absolute;
  left: 12px;
  top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: rgba(10, 11, 13, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--state-idle);
  flex: none;
}

.status-pill[data-state="idle"] .status-dot {
  background: var(--state-idle);
}
.status-pill[data-state="connecting"] .status-dot,
.status-pill[data-state="reconnecting"] .status-dot {
  background: var(--state-connecting);
  animation: pulse 1.1s ease-in-out infinite;
}
.status-pill[data-state="listening"] .status-dot {
  background: var(--state-listening);
}
.status-pill[data-state="speaking"] .status-dot {
  background: var(--state-speaking);
  animation: pulse 0.9s ease-in-out infinite;
}
.status-pill[data-state="ended"] .status-dot {
  background: var(--state-ended);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

@media (prefers-reduced-motion: reduce) {
  .status-pill .status-dot {
    animation: none !important;
  }
}

.hint {
  font-size: 13px;
  line-height: 1.5;
  color: var(--state-ended);
  background: rgba(229, 105, 122, 0.08);
  border: 1px solid rgba(229, 105, 122, 0.25);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

/* Captions */

.captions {
  list-style: none;
  margin: 0;
  padding: 4px 2px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--text-dim);
}

.captions li {
  display: flex;
  gap: 6px;
}

.captions li:last-child {
  color: var(--text);
}

.captions .who {
  flex: none;
  font-weight: 600;
  color: var(--text-faint);
}

.captions li:last-child .who {
  color: var(--accent);
}

/* Controls */

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--border-soft);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  border-radius: var(--radius-md);
  padding: 12px 18px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:hover {
  border-color: #34363d;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  flex: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: #052019;
}

.btn-primary:hover {
  background: #7fedd2;
  border-color: #7fedd2;
}

.btn-primary[aria-pressed="true"] {
  background: var(--bg-raised);
  border-color: var(--state-ended);
  color: var(--state-ended);
}

.btn-primary[aria-pressed="true"]:hover {
  background: rgba(229, 105, 122, 0.1);
}

.btn-icon {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon[aria-pressed="true"] {
  color: var(--state-ended);
  border-color: var(--state-ended);
}

.icon {
  width: 20px;
  height: 20px;
}

.meter {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.meter-bar {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transform-origin: left;
  transition: width 90ms linear;
}

.text-form {
  display: flex;
  gap: 8px;
}

.text-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.text-form input::placeholder {
  color: var(--text-faint);
}

.text-form input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -1px;
  border-color: var(--focus);
}

.btn-secondary {
  flex: none;
  background: var(--bg-raised);
}

/* Small phones */
@media (max-width: 375px) {
  .page {
    padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
    gap: 12px;
  }
  .btn {
    padding: 11px 14px;
    font-size: 14px;
  }
  .video-frame {
    border-radius: var(--radius-md);
  }
}

/* Phones: full-screen avatar with a floating control bar. Captions, the
   text form and the mute toggle are hidden; the "AI twin" badge stays as
   the disclosure. */
@media (max-width: 640px) {
  .page {
    max-width: none;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0;
    gap: 0;
  }

  .video-frame {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    z-index: 0;
  }

  .topbar {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    padding: 0;
    z-index: 2;
  }

  .brand {
    display: none;
  }

  .status-pill {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    left: 12px;
    z-index: 2;
  }

  .captions,
  .text-form,
  #muteToggle {
    display: none;
  }

  .hint {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(96px + env(safe-area-inset-bottom));
    z-index: 2;
    background: rgba(20, 10, 12, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .controls {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 2;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    background: rgba(10, 11, 13, 0.6);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.7);
  }

  .controls-row {
    gap: 12px;
  }

  .btn-primary {
    flex: none;
    min-width: 120px;
    padding: 13px 22px;
    border-radius: 999px;
  }

  .btn-primary[aria-pressed="true"] {
    background: rgba(10, 11, 13, 0.7);
  }
}
