:root {
  --bg1: #14112b;
  --bg2: #2b1d4f;
  --card: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f6f4ff;
  --muted: rgba(246, 244, 255, 0.65);
  --accent: #ff7ab6;
  --accent2: #7a8cff;
  --ok: #3ddc97;
  --warn: #ffc857;
  --bad: #ff5d73;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg1) 70%) fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

main {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.screen {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.screen[hidden] { display: none; }

.card {
  width: 100%;
  padding: 28px 22px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  text-align: center;
}

h1 { margin: 8px 0 4px; font-size: 1.6rem; }
.muted { color: var(--muted); margin: 0; }
.hint { text-align: center; font-size: 0.95rem; }

.wave {
  font-size: 3.5rem;
  display: inline-block;
  transform-origin: 70% 70%;
  animation: wave 2.4s ease-in-out infinite;
}
@keyframes wave {
  0%, 60%, 100% { transform: rotate(0); }
  10%, 30% { transform: rotate(16deg); }
  20%, 40% { transform: rotate(-8deg); }
}

form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }

input {
  font: inherit;
  font-size: 1.2rem;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
input:focus { outline: 2px solid var(--accent2); outline-offset: 1px; }

button { font: inherit; cursor: pointer; touch-action: manipulation; }

.primary {
  font-size: 1.15rem;
  font-weight: 600;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.primary:disabled { opacity: 0.6; }

.link {
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  padding: 8px;
}

.error { color: var(--bad); margin: 12px 0 0; }

#react-screen { justify-content: flex-start; }

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1.1rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }
.status[data-state="live"] .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status[data-state="offline"] .dot { background: var(--bad); }

.grid {
  width: 100%;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-content: center;
  gap: 14px;
  padding: 8px 0;
}

.reaction {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: clamp(2.6rem, 13vw, 3.6rem);
  line-height: 1;
  transition: transform 120ms ease, background 120ms ease;
}
.reaction img { width: 60%; height: 60%; object-fit: contain; }
.reaction:active, .reaction.pressed { transform: scale(0.9); background: rgba(255, 255, 255, 0.18); }
.reaction.shake { animation: shake 360ms ease; }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.toast {
  position: fixed;
  left: 50%;
  top: max(14px, env(safe-area-inset-top));
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid var(--border);
  z-index: 40;
  max-width: calc(100vw - 24px);
  text-align: center;
}

/* ---------- Ask / raised hand ---------- */

.ask-area { width: 100%; margin-top: auto; }

.ask-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 200, 87, 0.45);
  background: linear-gradient(135deg, rgba(255, 200, 87, 0.22), rgba(255, 122, 182, 0.18));
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: transform 120ms ease;
}
.ask-button:active { transform: scale(0.97); }
.ask-button[hidden] { display: none; }
.ask-emoji { font-size: 2.2rem; line-height: 1; }

.hand-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid rgba(255, 200, 87, 0.45);
  text-align: center;
  animation: rise 320ms ease-out;
}
.hand-panel[hidden] { display: none; }
.hand-panel[data-state="active"] {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px var(--ok), 0 0 28px rgba(61, 220, 151, 0.25);
}
.hand-title { margin: 0; font-size: 1.25rem; font-weight: 700; }
.hand-detail { font-size: 0.95rem; }
.hand-panel[data-state="waiting"] .hand-title::before {
  content: "🖐🏽";
  display: inline-block;
  margin-right: 8px;
  animation: wave 2.4s ease-in-out infinite;
  transform-origin: 70% 70%;
}

.secondary {
  font-size: 1.05rem;
  font-weight: 600;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

.speak-button {
  width: 100%;
  min-height: 112px;
  border-radius: 22px;
  border: 0;
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, #2bb673, #1e8f9c);
  touch-action: none;
  -webkit-touch-callout: none;
  transition: transform 100ms ease, box-shadow 100ms ease, filter 100ms ease;
}
.speak-button[hidden] { display: none; }
.speak-button[data-state="connecting"] { filter: grayscale(0.8) brightness(0.8); }
.speak-button[data-state="talking"] {
  transform: scale(0.97);
  background: linear-gradient(135deg, #ff5d73, #ff7ab6);
  box-shadow: 0 0 0 4px rgba(255, 93, 115, 0.35), 0 0 36px rgba(255, 93, 115, 0.55);
  animation: pulse 1.1s ease-in-out infinite;
}
.speak-button[data-state="blocked"],
.speak-button[data-state="failed"],
.speak-button[data-state="unsupported"] { background: rgba(255, 93, 115, 0.25); font-size: 1.05rem; }
@keyframes pulse {
  50% { box-shadow: 0 0 0 10px rgba(255, 93, 115, 0.15), 0 0 48px rgba(255, 93, 115, 0.7); }
}
@keyframes rise {
  from { transform: translateY(16px); opacity: 0; }
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 6, 20, 0.6);
  backdrop-filter: blur(4px);
  animation: fade 200ms ease-out;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 26px 22px max(22px, env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: linear-gradient(180deg, #2f2257, #1b1638);
  border: 1px solid var(--border);
  border-bottom: 0;
  text-align: center;
  animation: sheet-up 300ms cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.sheet h2 { margin: 0; font-size: 1.5rem; }
.sheet-emoji { font-size: 3.4rem; line-height: 1; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.floater {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  will-change: transform, opacity;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}
.floater img { width: 100%; height: 100%; object-fit: contain; }
