*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --border: #eeeeee;
  --text: #1a1a1a;
  --text-dim: #888888;
  --text-muted: #cccccc;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --bubble-user: #ebebeb;
  --wave1: #FF6B9E;
  --wave2: #C850C0;
  --wave3: #4158D0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── App shell with pastel gradient ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 100% 45% at 0% 108%,   rgba(255, 182, 215, 0.28) 0%, transparent 60%),
    radial-gradient(ellipse 100% 45% at 50% 108%,  rgba(200, 182, 255, 0.22) 0%, transparent 60%),
    radial-gradient(ellipse 100% 45% at 100% 108%, rgba(160, 230, 255, 0.22) 0%, transparent 60%),
    #ffffff;
}

/* ── Header ── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 14px;
  flex-shrink: 0;
}

.logo { height: 30px; width: auto; }

.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-dim);
  transition: color 0.3s;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

.status-connected { color: var(--green); }
.status-connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: dot-pulse 2s ease-in-out infinite;
}
.status-connecting { color: var(--amber); }
.status-connecting .status-dot {
  background: var(--amber);
  animation: dot-pulse 0.6s ease-in-out infinite;
}
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── History area — chat bubbles ── */
.history-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.history-area::-webkit-scrollbar { width: 0; }

.history-line {
  max-width: 80%;
  line-height: 1.55;
  word-break: break-word;
  animation: line-in 0.2s ease;
}
@keyframes line-in {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* User bubble — right aligned gray pill */
.history-user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-radius: 20px 20px 4px 20px;
  padding: 9px 15px;
  font-size: 14px;
  color: #555;
  max-width: 72%;
}

/* AI text — left aligned, plain */
.history-gemini {
  align-self: flex-start;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  padding: 2px 0;
  max-width: 90%;
}

/* System messages — very subtle center */
.history-system {
  align-self: center;
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  font-style: italic;
  padding: 2px 0;
}

/* ── Live area (current exchange + waveform) ── */
.live-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 28px 12px;
  flex-shrink: 0;
  min-height: 160px;
  justify-content: center;
  gap: 6px;
}

/* Live user question — no bubble, small muted label above AI answer */
.live-user {
  font-size: 12px;
  font-weight: 400;
  color: #aaa;
  text-align: center;
  letter-spacing: 0.01em;
  max-width: 88%;
  word-break: break-word;
  line-height: 1.45;
}
.live-user:empty { display: none; }

/* Live AI answer (streaming) */
.live-gemini {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.6;
  text-align: center;
  color: var(--text);
  max-width: 100%;
  word-break: break-word;
}

/* ── Gradient waveform ── */
.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 64px;
  flex-shrink: 0;
}

.waveform .bar {
  width: 5px;
  border-radius: 5px;
  background: linear-gradient(to top, var(--wave1), var(--wave2), var(--wave3));
  transform-origin: center;
}

.waveform .bar:nth-child(1) { height: 12px; }
.waveform .bar:nth-child(2) { height: 22px; }
.waveform .bar:nth-child(3) { height: 38px; }
.waveform .bar:nth-child(4) { height: 56px; }
.waveform .bar:nth-child(5) { height: 38px; }
.waveform .bar:nth-child(6) { height: 22px; }
.waveform .bar:nth-child(7) { height: 12px; }

/* Disconnected: invisible */
.waveform.disconnected .bar {
  transform: scaleY(0.08);
  opacity: 0;
  transition: transform 0.5s ease, opacity 0.5s ease;
}

/* Idle: soft breathe */
.waveform.idle .bar {
  animation: wave-idle 2.4s ease-in-out infinite;
  opacity: 0.55;
}
.waveform.idle .bar:nth-child(1) { animation-delay: 0.00s; }
.waveform.idle .bar:nth-child(2) { animation-delay: 0.18s; }
.waveform.idle .bar:nth-child(3) { animation-delay: 0.36s; }
.waveform.idle .bar:nth-child(4) { animation-delay: 0.54s; }
.waveform.idle .bar:nth-child(5) { animation-delay: 0.36s; }
.waveform.idle .bar:nth-child(6) { animation-delay: 0.18s; }
.waveform.idle .bar:nth-child(7) { animation-delay: 0.00s; }

@keyframes wave-idle {
  0%, 100% { transform: scaleY(0.18); }
  50%       { transform: scaleY(0.55); }
}

/* Active: full lively wave */
.waveform.active .bar {
  animation: wave-active 0.75s ease-in-out infinite;
  opacity: 1;
}
.waveform.active .bar:nth-child(1) { animation-delay: 0.00s; }
.waveform.active .bar:nth-child(2) { animation-delay: 0.10s; }
.waveform.active .bar:nth-child(3) { animation-delay: 0.20s; }
.waveform.active .bar:nth-child(4) { animation-delay: 0.30s; }
.waveform.active .bar:nth-child(5) { animation-delay: 0.20s; }
.waveform.active .bar:nth-child(6) { animation-delay: 0.10s; }
.waveform.active .bar:nth-child(7) { animation-delay: 0.00s; }

@keyframes wave-active {
  0%, 100% { transform: scaleY(0.28); }
  50%       { transform: scaleY(1); }
}

/* ── Text input bar ── */
.text-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(8px);
}

.text-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 16px;
  outline: none;
  font-family: inherit;
  -webkit-appearance: none;
}
.text-input::placeholder { color: var(--text-muted); }
.text-input:disabled { opacity: 0.4; }

.btn-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-send:disabled { opacity: 0.2; cursor: not-allowed; }
.btn-send:not(:disabled):active { transform: scale(0.93); }

/* ── Controls footer ── */
.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 12px 24px max(env(safe-area-inset-bottom), 20px);
  flex-shrink: 0;
}

/* ── PNG icon buttons ── */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.15s, opacity 0.2s;
  border-radius: 50%;
}
.btn-icon img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  pointer-events: none;
  border-radius: 50%;
}
.btn-icon:active { transform: scale(0.91); }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-icon:disabled:active { transform: none; }
/* Mute button — 3 states */
/* 1. Disabled: inherits .btn-icon:disabled opacity (0.3) — same as other buttons */
/* 2. Connected, not muted: normal — no extra styles needed */
/* 3. Manually muted: red icon + diagonal slash */
#muteBtn { position: relative; }
#muteBtn.muted img {
  filter: invert(21%) sepia(96%) saturate(2400%) hue-rotate(343deg) brightness(105%) contrast(96%);
}
#muteBtn.muted::after {
  content: '';
  position: absolute;
  width: 56%;
  height: 3.5px;
  background: #ef4444;
  border-radius: 99px;
  transform: rotate(-45deg);
  pointer-events: none;
}

/* Green reconnect circle */
.icon-start {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #22c55e;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Camera preview — normal (small floating) ── */
.camera-preview {
  position: absolute;
  bottom: 150px;
  right: 16px;
  width: 120px;
  height: 90px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  z-index: 10;
  background: #000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.camera-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Close button — default (small, on floating preview) */
.close-camera-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(0,0,0,0.5);
  border: none;
  cursor: pointer;
  padding: 3px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  width: 22px;
  height: 22px;
}
.close-camera-btn img {
  width: 14px;
  height: 14px;
  object-fit: contain;
  filter: invert(1);
}

/* ── Video mode — full screen camera ── */
.video-mode .camera-preview {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 0;
  border: none;
  z-index: 50;
}
.video-mode .camera-preview video {
  /* no mirror — show camera as-is */
}

/* Hide history & other chrome in video mode */
.video-mode .history-area,
.video-mode .header,
.video-mode .text-bar,
.video-mode .controls { display: none; }

/* Live transcription overlay — only current exchange shown on video */
.video-mode .live-area {
  position: fixed;
  top: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 51;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0) 100%);
  padding: 24px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.video-mode .waveform { display: none; }
.video-mode .live-user {
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  text-align: center;
  letter-spacing: 0.01em;
}
.video-mode .live-gemini {
  color: #ffffff;
  font-size: 1rem;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.video-mode .live-user:empty { display: none; }

/* Large close button in video mode */
.video-mode .close-camera-btn {
  position: fixed;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 52;
  width: 60px;
  height: 60px;
  background: rgba(200,200,200,0.85);
  backdrop-filter: blur(6px);
  border-radius: 50%;
  top: auto;
  right: auto;
}
.video-mode .close-camera-btn img {
  width: 22px;
  height: 22px;
  filter: none;
}

/* ── Desktop border ── */
@media (min-width: 480px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ── Landing screen overlay ── */
.landing-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 120% 60% at 10% 110%, rgba(255,182,215,0.45) 0%, transparent 60%),
    radial-gradient(ellipse 120% 60% at 90% 110%, rgba(160,230,255,0.35) 0%, transparent 60%),
    #f9f9f9;
  transition: opacity 0.4s ease;
}

.landing-card {
  background: #ffffff;
  border-radius: 24px;
  padding: 36px 28px 32px;
  width: min(88vw, 360px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.10);
}

.landing-logo {
  height: 48px;
  object-fit: contain;
  margin-bottom: 4px;
}

.landing-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

.landing-sub {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  margin-top: -4px;
}

.landing-input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  background: #fafafa;
  color: var(--text);
  transition: border-color 0.2s;
}

.landing-input:focus {
  border-color: #C850C0;
}

.landing-btn {
  margin-top: 6px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  cursor: pointer;
  background: linear-gradient(135deg, #FF6B9E 0%, #C850C0 50%, #4158D0 100%);
  transition: opacity 0.2s;
}

.landing-btn:active {
  opacity: 0.85;
}
