:root {
  --text: #f8fbff;
  --muted: rgba(235, 244, 255, 0.78);
  --soft: rgba(255, 255, 255, 0.12);
  --soft-strong: rgba(255, 255, 255, 0.22);
  --accent: rgba(114, 233, 255, 0.22);
  --accent-border: rgba(114, 233, 255, 0.42);
  --danger: #ff9eb0;
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: "Avenir Next", "SF Pro Display", "Helvetica Neue", sans-serif;
}

.sophie-screen {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000;
  overflow: hidden;
}

.sophie-stage {
  position: absolute;
  inset: 0;
}

.sophie-video,
.sophie-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.sophie-fallback {
  z-index: 1;
}

.stage-gradient {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(circle at 50% 14%, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0) 42%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.14) 0%, rgba(0, 0, 0, 0.03) 22%, rgba(0, 0, 0, 0.05) 56%, rgba(0, 0, 0, 0.52) 100%);
}

.top-overlay,
.bottom-overlay {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 3;
  pointer-events: none;
}

.top-overlay {
  top: 0;
  padding-top: calc(env(safe-area-inset-top) + 0.4rem);
  padding-left: max(0.85rem, env(safe-area-inset-left));
  padding-right: max(0.85rem, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex-wrap: wrap;
  color: var(--muted);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.65);
}

.status-strip,
.voice-config {
  display: none !important;
}

.status-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.24rem;
  font-size: 0.82rem;
  min-width: 0;
}

.status-chip .label {
  opacity: 0.75;
}

.status-chip strong {
  color: var(--text);
  font-weight: 600;
  text-transform: capitalize;
}

.status-divider {
  opacity: 0.5;
}

.voice-config {
  pointer-events: auto;
}

.voice-config input {
  width: 74px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.16);
  color: var(--text);
  padding: 0.36rem 0.6rem;
  font-size: 0.82rem;
  backdrop-filter: blur(6px);
  text-align: center;
}

.voice-config input:focus {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 2px rgba(114, 233, 255, 0.14);
}

.bottom-overlay {
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-left: max(0.75rem, env(safe-area-inset-left));
  padding-right: max(0.75rem, env(safe-area-inset-right));
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
}

.warning {
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.75);
  pointer-events: auto;
}

.billing-banner {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  pointer-events: auto;
  color: var(--text);
  font-size: 0.82rem;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.75);
}

.billing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.billing-actions .btn {
  padding: 0.4rem 0.65rem;
  font-size: 0.78rem;
}

.payg-card {
  max-width: min(92vw, 380px);
}

.payg-copy {
  margin: 0.2rem 0 0;
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.92rem;
}

.payg-actions {
  display: flex;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.payg-actions .btn {
  flex: 1;
}

.chat-log {
  min-height: 120px;
  max-height: min(42vh, 340px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  padding: 0.15rem 0.12rem;
  pointer-events: auto;
  background: transparent;
  border: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-track {
  background: transparent;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.bubble {
  margin: 0;
  padding: 0.25rem 0.15rem;
  max-width: 88%;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: var(--text);
  text-shadow: 0 2px 10px var(--shadow), 0 0 2px rgba(0, 0, 0, 0.7);
  line-height: 1.28;
  font-size: 0.98rem;
}

.bubble p {
  margin: 0;
}

.bubble-user {
  align-self: flex-end;
  text-align: right;
}

.bubble-friend {
  align-self: flex-start;
}

.meta {
  display: none;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  pointer-events: auto;
  margin: 0;
}

.text-row,
.action-row {
  display: flex;
  gap: 0.45rem;
}

.action-row {
  justify-content: space-between;
}

#textInput {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(8px);
  color: var(--text);
  padding: 0.78rem 0.95rem;
  font-size: 0.98rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

#textInput::placeholder {
  color: rgba(248, 251, 255, 0.72);
}

#textInput:focus {
  outline: none;
  border-color: var(--accent-border);
  background: rgba(0, 0, 0, 0.12);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 0 0 2px rgba(114, 233, 255, 0.14);
}

.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
  padding: 0.72rem 0.95rem;
  font-size: 0.93rem;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.btn:hover {
  border-color: rgba(255, 255, 255, 0.32);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  border-color: var(--accent-border);
  background: var(--accent);
}

.btn-send {
  min-width: 64px;
}

.action-row .btn {
  flex: 1;
}

.hidden {
  display: none !important;
}

.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;
}

.expression-happy .sophie-video,
.expression-excited .sophie-video,
.expression-laughing .sophie-video {
  filter: saturate(1.06) brightness(1.02);
}

.expression-worried .sophie-video,
.expression-sad .sophie-video {
  filter: saturate(0.95);
}

.expression-thinking .sophie-video,
.expression-confused .sophie-video {
  filter: contrast(1.03);
}

.mode-listening .stage-gradient {
  background:
    radial-gradient(circle at 50% 85%, rgba(114, 233, 255, 0.12) 0%, rgba(114, 233, 255, 0) 42%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.12) 0%, rgba(0, 0, 0, 0.03) 20%, rgba(0, 0, 0, 0.06) 52%, rgba(0, 0, 0, 0.54) 100%);
}

.mode-speaking .sophie-video {
  transform: scale(1.01);
}

@media (max-width: 520px) {
  .status-strip {
    gap: 0.28rem;
    font-size: 0.76rem;
  }

  .voice-config input {
    width: 66px;
    padding: 0.34rem 0.5rem;
  }

  .chat-log {
    max-height: min(39vh, 280px);
  }

  .bubble {
    font-size: 0.95rem;
    max-width: 92%;
  }

  #textInput,
  .btn {
    font-size: 0.9rem;
  }
}

.auth-area {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
}

#loginBtn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  opacity: 0.7;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
  transition: opacity 120ms ease;
}

#loginBtn:hover {
  opacity: 1;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
}

.user-info #userEmail {
  opacity: 0.7;
}

#logoutBtn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  opacity: 0.7;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
  transition: opacity 120ms ease;
}

#logoutBtn:hover {
  opacity: 1;
}

#manageSubscriptionBtn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  opacity: 0.7;
  cursor: pointer;
  padding: 0.1rem 0.4rem 0.2rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
  transition: opacity 120ms ease;
}

#manageSubscriptionBtn:hover {
  opacity: 1;
}

.demo-timer {
  pointer-events: none;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.8;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
  padding: 0.2rem 0.4rem;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
}

.auth-card {
  position: relative;
  width: 92%;
  max-width: 380px;
  background: rgba(20, 22, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 1.1rem;
  padding: 2rem 1.6rem 1.6rem;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.auth-card h2 {
  margin: 0 0 1.2rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.auth-card input {
  width: 100%;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  padding: 0.72rem 0.95rem;
  font-size: 0.95rem;
  backdrop-filter: blur(6px);
}

.auth-card input::placeholder {
  color: rgba(248, 251, 255, 0.5);
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 2px rgba(114, 233, 255, 0.14);
}

.auth-card .btn {
  width: 100%;
  border-color: var(--accent-border);
  background: var(--accent);
  margin-top: 0.3rem;
}

.auth-toggle {
  margin: 0.9rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.auth-toggle a {
  color: var(--text);
  text-decoration: underline;
  cursor: pointer;
}

.auth-error {
  margin: 0;
  font-size: 0.82rem;
  color: var(--danger);
  text-align: center;
}

.auth-close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  opacity: 0.7;
  transition: opacity 120ms ease;
}

.auth-close:hover {
  opacity: 1;
}

@media (max-width: 520px) {
  .auth-card {
    padding: 1.5rem 1.2rem 1.2rem;
  }

  #loginBtn,
  #logoutBtn,
  .user-info {
    font-size: 0.66rem;
  }

  .demo-timer {
    font-size: 0.66rem;
  }
}

@media (min-aspect-ratio: 9/16) {
  .sophie-video,
  .sophie-fallback {
    object-fit: contain;
    object-position: center center;
  }

  .stage-gradient {
    background: linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.12) 0%,
      rgba(0, 0, 0, 0.03) 20%,
      rgba(0, 0, 0, 0.05) 56%,
      rgba(0, 0, 0, 0.52) 100%
    );
  }
}
