/* Feel Understood — Your Conversation Coach — App Styles */

:root {
  /* Light mode — happy, positive, approachable */
  --bg: #ffffff;
  --surface: #faf8f3;
  --surface-2: #ececec;
  --accent: #ffd21f;
  --accent-rgb: 255, 210, 31;
  --accent-dim: rgba(var(--accent-rgb), 0.18);
  --text: #1a1a1a;
  --text-dim: #6b6b6b;
  --red: #e74c3c;
  --red-rgb: 231, 76, 60;
  --green: #abd601;
  --green-rgb: 171, 214, 1;
  --on-accent: #1a1a1a;
  --accent-ink: #8a6f00;
  --red-ink: #b83228;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Doodle-style SVG icons (chat avatar) */
.doodle-icon {
  filter: brightness(0);
  opacity: 0.85;
}
.avatar .doodle-icon {
  filter: none;
  opacity: 0.85;
}

/* ===== NAME SCREEN ===== */
.quiz-container {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
}

/* Screen container & animations */
.quiz-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 24px 32px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.quiz-enter {
  animation: quizSlideIn 0.3s ease-out both;
}
@keyframes quizSlideIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* CTA button */
.quiz-cta {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  font-family: inherit;
}
.quiz-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(var(--accent-rgb), 0.3);
}
.quiz-cta:active { transform: scale(0.98); }
.quiz-cta-disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* Quiz titles */
.quiz-title {
  font-family: Arial, sans-serif;
  font-size: 26px;
  font-weight: 400;
  line-height: 1.25;
  margin-bottom: 8px;
  color: var(--text);
}

.quiz-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 28px;
}

/* Name input */
.quiz-name {
  justify-content: center;
}

.quiz-name-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.quiz-name-input {
  width: 100%;
  padding: 16px 20px;
  font-size: 20px;
  font-family: inherit;
  background: var(--surface);
  border: 2px solid var(--surface-2);
  border-radius: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
}
.quiz-name-input:focus {
  border-color: var(--accent-ink);
}
.quiz-name-input::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

/* Quiz responsive */
@media (max-width: 480px) {
  .quiz-title { font-size: 22px; }
  .quiz-screen { padding: 20px 20px 28px; }
  .quiz-name-input { font-size: 18px; }
}

/* ===== APP SHELL ===== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

/* ===== HEADER ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1;
  min-width: 0;
  overflow: hidden;
}
.header-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-subtitle {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 380px) {
  .header-subtitle { display: none; }
  .new-chat-btn { padding: 6px 10px; font-size: 12px; }
  .header-left { gap: 6px; }
}

.mode-hint {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 16px;
  text-align: center;
  line-height: 1.4;
  flex-shrink: 0;
  border-bottom: 1px solid transparent;
}
.mode-hint strong { font-weight: 600; }

.mode-hint-helpline {
  background: rgba(var(--accent-rgb), 0.1);
  border-bottom-color: rgba(var(--accent-rgb), 0.2);
}
.mode-hint-helpline strong { color: var(--accent-ink); }

/* Voice replies on/off — small icon toggle beside New Chat */
.voice-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  color: var(--accent-ink);
  background: var(--accent-dim);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.voice-toggle-btn:hover { background: rgba(var(--accent-rgb), 0.25); }
.voice-toggle-btn.voice-toggle-muted {
  color: var(--text-dim);
  background: var(--surface-2);
}

.new-chat-btn {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent-ink);
  background: var(--accent-dim);
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.new-chat-btn:hover { background: rgba(var(--accent-rgb), 0.25); }

/* ===== CHAT AREA ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Messages */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: fadeInUp 0.25s ease-out;
  margin-bottom: 4px;
}
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

.user-bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 16px 16px 4px 16px;
}

.assistant-bubble {
  background: var(--surface-2);
  color: var(--text);
  border-radius: 16px 16px 16px 4px;
}

.interim-bubble {
  background: rgba(var(--accent-rgb), 0.15);
  color: var(--accent-ink);
  border-radius: 16px 16px 4px 16px;
  border: 1px dashed rgba(var(--accent-rgb), 0.3);
  font-style: italic;
}

/* Transcribing bubble: user-side, dots-only, signals "your message is
   being processed". Reuses .typing-dot keyframes. */
.transcribing-bubble {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
  font-style: normal;
}
.transcribing-bubble .typing-dot {
  background: var(--accent-ink);
}

/* Typing dots */
.typing-bubble {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
}
.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 1.4s ease-in-out infinite;
}

/* ===== ERROR BAR ===== */
.error-bar {
  padding: 8px 16px;
  background: rgba(var(--red-rgb), 0.12);
  color: var(--red-ink);
  text-align: center;
  font-size: 13px;
  flex-shrink: 0;
}

/* ===== CONTROLS ===== */
.controls {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.mic-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  position: relative;
}

.mic-btn.idle {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.3);
  animation: pulse 2.5s ease-in-out infinite;
}

.mic-btn.listening {
  background: var(--red);
  color: white;
  box-shadow: 0 0 24px rgba(var(--red-rgb), 0.4);
  animation: none;
}

.mic-btn.processing {
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: default;
  animation: none;
}

.mic-btn.speaking {
  background: var(--green);
  color: var(--on-accent);
  box-shadow: 0 0 18px rgba(var(--green-rgb), 0.35);
  animation: pulse 1.5s ease-in-out infinite;
}

.mic-label {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 500;
}

/* Wave */
.wave-viz {
  display: flex;
  gap: 3px;
  align-items: center;
  justify-content: center;
  height: 24px;
}
.wave-bar {
  width: 3px;
  background: var(--red);
  border-radius: 2px;
  animation: waveBar 0.8s ease-in-out infinite;
}
.wave-bar.reactive {
  /* Height is driven by JS from live mic level — disable the keyframe
     animation and let the inline style take over. Short transition keeps
     motion smooth between RAF updates. */
  animation: none;
  height: 4px;
  transition: height 60ms ease-out;
}

/* Text input */
.text-form {
  display: flex;
  gap: 8px;
  width: 100%;
}

.text-input {
  flex: 1;
  padding: 10px 16px;
  border-radius: 24px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  /* 16px minimum: with pinch-zoom re-enabled, iOS auto-zooms the page
     when focusing an input whose font is smaller than 16px. */
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.text-input:focus {
  border-color: var(--accent-ink);
}
.text-input::placeholder {
  color: var(--text-dim);
}

/* Version label under the controls — theme-aware (the old hardcoded
   #555 was near-invisible against the dark theme). */
.version-label {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin: 12px 0 4px;
  opacity: 0.7;
}

.start-over-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  opacity: 0.9;
}
.start-over-link:hover { opacity: 1; }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.send-btn.active {
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.browser-warn {
  font-size: 11px;
  color: var(--red-ink);
  text-align: center;
  padding: 2px 8px;
  background: rgba(var(--red-rgb), 0.08);
  border-radius: 6px;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

@keyframes waveBar {
  0%, 100% { height: 6px; }
  50% { height: 20px; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .bubble { max-width: 85%; font-size: 14px; }
  .mic-btn { width: 56px; height: 56px; }
}

@media (min-width: 641px) {
  .app-shell {
    border-left: 1px solid var(--surface-2);
    border-right: 1px solid var(--surface-2);
  }
}

/* Scrollbar */
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 4px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Landing Gate ── */
.gate-screen {
  min-height: 100vh; /* fallback for browsers without dvh */
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: var(--bg);
  color: var(--text);
}
.gate-inner {
  max-width: 460px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.gate-eyebrow {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 5px 12px;
  border: 1px solid var(--text-dim);
  border-radius: 999px;
  color: var(--text-dim);
  margin-bottom: 24px;
}
.gate-title {
  font-size: 40px;
  font-weight: 700;
  margin: 0 0 18px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.gate-lede {
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-dim);
  margin: 0 0 32px;
  max-width: 400px;
}
.gate-cta {
  background: var(--accent);
  color: var(--accent-ink, #111);
  font-weight: 600;
  font-size: 17px;
  padding: 16px 36px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}
.gate-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(var(--accent-rgb), 0.35);
}
.gate-cta:active { transform: translateY(0); }
.gate-note {
  font-size: 13px;
  color: var(--text-dim);
  opacity: 0.75;
  margin: 18px 0 0;
}
@media (max-width: 480px) {
  .gate-title { font-size: 32px; }
  .gate-lede { font-size: 15px; }
}

/* ── Visual aid card — the assistant's "shown, not spoken" channel ── */
.visual-aid {
  margin-top: 10px;
  padding: 10px 14px;
  border-left: 3px solid #ffd21f;
  border-radius: 8px;
  background: rgba(255, 210, 31, 0.08);
  font-size: 0.92em;
  line-height: 1.5;
}
.visual-aid p { margin: 6px 0; }
.visual-aid p:first-child { margin-top: 0; }
.visual-aid p:last-child { margin-bottom: 0; }
.visual-aid ul { margin: 6px 0; padding-left: 18px; }
.visual-aid li { margin: 4px 0; }
.visual-aid strong { font-weight: 700; }

/* ── Sandbox: A/B variant pill (mode banner) ── */
.sot-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 10px;
  vertical-align: middle;
}
.sot-pill-label {
  font-weight: 600;
  color: var(--text);
}
.sot-pill-btn {
  min-width: 26px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.45);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
}
.sot-pill-btn:hover { color: var(--text); }
.sot-pill-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1a2e;
}
