:root {
  --bg: #0f172a;
  --bg-alt: #1e293b;
  --fg: #f8fafc;
  --accent: #38bdf8;
  --warn: #facc15;
  --err: #f87171;
  --ok: #34d399;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* =========================
 * Participant page (sender)
 * ========================= */
body.page-sender {
  min-height: 100dvh;
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
  color: #0f172a;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.sender-header {
  text-align: center;
  padding: 16px 8px 8px;
}
.sender-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.sender-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: #475569;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 12px 0 16px;
  flex: 1;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  padding: 18px 12px;
  font-size: 18px;
  font-weight: 600;
  color: #0f172a;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  cursor: pointer;
  min-height: 96px;
}
.btn:active, .btn--pressed {
  transform: scale(0.96);
  background: #e0f2fe;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
.btn__emoji { font-size: 32px; line-height: 1; }
.btn__text { font-size: 15px; }

.sender-footer {
  text-align: center;
  padding: 8px;
  color: #64748b;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%) translateY(80px);
  background: #0f172a;
  color: #f8fafc;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: transform 220ms ease, opacity 220ms ease;
  pointer-events: none;
  z-index: 10;
}
.toast--visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast[data-kind="warn"] { background: #b45309; }
.toast[data-kind="error"] { background: #b91c1c; }

/* =========================
 * Screen page
 * ========================= */
body.page-screen {
  background: radial-gradient(ellipse at center, #1e293b 0%, #020617 100%);
  color: var(--fg);
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.comment {
  position: absolute;
  white-space: nowrap;
  font-size: clamp(28px, 4.2vw, 56px);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow:
    0 0 6px rgba(0,0,0,0.55),
    2px 2px 0 #0f172a,
    -2px 2px 0 #0f172a,
    2px -2px 0 #0f172a,
    -2px -2px 0 #0f172a;
  will-change: transform, opacity, filter;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
}
.comment__emoji { font-size: 1.1em; }

@keyframes flow {
  from { transform: translateX(100vw); }
  to   { transform: translateX(-110%); }
}

@keyframes rise {
  0%   { transform: translate(-50%, 20vh); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translate(-50%, -80vh); opacity: 0; }
}

body[data-mode="drift"] .comment {
  white-space: normal;
  max-width: 80vw;
  text-align: center;
  font-size: clamp(26px, 4.5vmin, 56px);
  text-shadow:
    0 0 18px rgba(0, 0, 0, 0.75),
    0 0 28px currentColor;
}

@keyframes drift {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.55);
    filter: blur(14px);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    filter: blur(0);
  }
  82% {
    opacity: 1;
    transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -40px))) scale(1.04);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -40px))) scale(1.12);
    filter: blur(10px);
  }
}

.screen-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 5;
}
.mode-toggle {
  appearance: none;
  border: 1px solid rgba(248, 250, 252, 0.2);
  background: rgba(15, 23, 42, 0.6);
  color: #f8fafc;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 120ms ease;
}
.mode-toggle:hover { background: rgba(15, 23, 42, 0.85); }

.ai-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 25vh;
  padding: 16px clamp(16px, 4vw, 48px) calc(20px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg,
    rgba(2, 6, 23, 0) 0%,
    rgba(2, 6, 23, 0.55) 40%,
    rgba(2, 6, 23, 0.85) 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(248, 250, 252, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  z-index: 3;
  transition: transform 420ms ease, opacity 420ms ease;
  pointer-events: none;
}
body[data-ai="off"] .ai-panel {
  transform: translateY(110%);
  opacity: 0;
}

.ai-panel__label {
  font-size: clamp(11px, 1.6vmin, 18px);
  letter-spacing: 0.14em;
  color: rgba(248, 250, 252, 0.65);
  text-transform: uppercase;
  font-weight: 600;
}

.ai-panel__text {
  font-size: clamp(22px, 3.6vmin, 42px);
  line-height: 1.5;
  color: #f8fafc;
  font-weight: 700;
  text-shadow: 0 0 18px rgba(0, 0, 0, 0.6);
  transition: opacity 240ms ease;
}
.ai-panel__text.is-thinking {
  opacity: 0.55;
}

.conn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #facc15;
  box-shadow: 0 0 8px currentColor;
}
.conn-dot[data-state="ok"] { background: #34d399; }
.conn-dot[data-state="wait"] { background: #facc15; }
