/* === Speak English with Mira === */

:root {
  --cream: #F4EFE6;
  --cream-2: #EAE3D5;
  --paper: #FBF8F1;
  --ink: #1F1A14;
  --ink-2: #4A4239;
  --ink-3: #87796A;
  --line: rgba(31, 26, 20, 0.12);
  --coral: #E55934;
  --coral-soft: #F5D5C8;
  --sage: #6A8E5F;
  --sage-soft: #D4E0CB;
  --honey: #E8A33D;
  --honey-soft: #F4DDB2;

  --r-sm: 8px;
  --r: 14px;
  --r-lg: 22px;
  --r-xl: 32px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  font-feature-settings: "ss01", "ss02";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

.display {
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* ---- Stage ---- */
#root { height: 100%; }

.stage {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

/* ---- Scene background ---- */
.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  transition: background 600ms ease;
}

.scene svg.scene-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center 30%, transparent 0%, transparent 45%, rgba(31, 26, 20, 0.08) 100%);
  pointer-events: none;
}

/* ---- Top bar ---- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  padding: calc(var(--safe-top) + 14px) 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--cream);
  display: grid;
  place-items: center;
  font-family: "Bricolage Grotesque";
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.brand-name {
  font-family: "Bricolage Grotesque";
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand-sub {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: -2px;
}

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(251, 248, 241, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 120ms;
}
.icon-btn:hover { background: var(--paper); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---- Scenario pill ---- */
.scenario-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 8px;
  border-radius: 999px;
  background: rgba(251, 248, 241, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms;
}
.scenario-pill:hover { background: var(--paper); }
.scenario-pill .dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
}
.scenario-pill .chev {
  margin-left: 2px;
  opacity: 0.5;
}

/* ---- Avatar wrapper ---- */
.avatar-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -54%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.avatar-ring {
  position: relative;
  width: min(58vw, 320px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.avatar-ring .pulse {
  position: absolute;
  inset: -4%;
  border-radius: 50%;
  border: 2px solid rgba(229, 89, 52, 0);
  transition: border-color 300ms;
}

.avatar-ring.listening .pulse {
  border-color: rgba(229, 89, 52, 0.4);
  animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  100% { transform: scale(1.18); opacity: 0; }
}

.avatar-ring .pulse.p2 { animation-delay: 0.5s; }
.avatar-ring .pulse.p3 { animation-delay: 1s; }

.avatar-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 30px 40px rgba(31, 26, 20, 0.12));
}

.avatar-name {
  margin-top: 22px;
  font-family: "Bricolage Grotesque";
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-name .live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 0 rgba(106, 142, 95, 0.5);
  animation: live 2.4s ease-out infinite;
}

@keyframes live {
  0%, 100% { box-shadow: 0 0 0 0 rgba(106, 142, 95, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(106, 142, 95, 0); }
}

.avatar-status {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

/* ---- Caption / speech ---- */
.caption-area {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 200px);
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 0 24px;
  pointer-events: none;
}

.caption-card {
  pointer-events: auto;
  max-width: 640px;
  width: 100%;
  background: rgba(251, 248, 241, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--r-lg);
  padding: 18px 22px 18px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px -20px rgba(31, 26, 20, 0.18);
  position: relative;
}

.caption-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.caption-label.mira { color: var(--coral); }
.caption-label.user { color: var(--sage); }

.caption-text {
  font-family: "Bricolage Grotesque";
  font-weight: 500;
  font-size: clamp(20px, 3.2vw, 28px);
  line-height: 1.25;
  letter-spacing: -0.015em;
  color: var(--ink);
  text-wrap: pretty;
}

.caption-text .fix {
  background: linear-gradient(180deg, transparent 60%, var(--coral-soft) 60%);
  padding: 0 2px;
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}

.caption-text .fix-was {
  color: var(--ink-3);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  text-decoration-color: rgba(229, 89, 52, 0.5);
  font-weight: 400;
  margin-right: 6px;
}

.caption-text .typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--coral);
  margin-left: 3px;
  vertical-align: text-bottom;
  animation: blinkCursor 0.8s steps(2) infinite;
}

@keyframes blinkCursor { 50% { opacity: 0; } }

.caption-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
  font-family: inherit;
}
.chip:hover { background: var(--cream-2); border-color: var(--ink-3); }
.chip svg { width: 12px; height: 12px; }

.chip.suggested {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 500;
}

/* ---- User input (suggestions / try-again) ---- */
.suggest-row {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 140px);
  z-index: 15;
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 0 24px;
  flex-wrap: wrap;
  pointer-events: none;
}

.suggest-row .chip {
  pointer-events: auto;
  background: rgba(251, 248, 241, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 13px;
  padding: 8px 14px;
}

/* ---- Bottom control bar ---- */
.controls {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 25;
  padding: 16px 20px calc(var(--safe-bottom) + 22px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: linear-gradient(180deg, transparent, rgba(244, 239, 230, 0.7) 50%, var(--cream) 100%);
}

.control-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 120ms, transform 120ms;
}
.tool-btn:hover { background: var(--cream-2); }
.tool-btn:active { transform: scale(0.95); }
.tool-btn svg { width: 18px; height: 18px; }

.tool-btn.active {
  background: var(--ink);
  color: var(--cream);
  border-color: var(--ink);
}

.mic-btn {
  position: relative;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: var(--cream);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 120ms, background 200ms;
  box-shadow: 0 10px 30px -8px rgba(31, 26, 20, 0.35);
}
.mic-btn:hover { transform: translateY(-1px); }
.mic-btn:active { transform: scale(0.95); }
.mic-btn svg { width: 28px; height: 28px; }

.mic-btn.listening {
  background: var(--coral);
  animation: micPulse 1.4s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 89, 52, 0.4), 0 10px 30px -8px rgba(229, 89, 52, 0.5); }
  50% { box-shadow: 0 0 0 18px rgba(229, 89, 52, 0), 0 10px 30px -8px rgba(229, 89, 52, 0.5); }
}

.mic-btn.thinking {
  background: var(--ink-2);
  cursor: wait;
}

.mic-btn.thinking::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--coral);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.mic-label {
  position: absolute;
  bottom: -22px;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ---- Waveform ---- */
.waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 38px;
}
.waveform .bar {
  width: 3px;
  background: var(--coral);
  border-radius: 2px;
  height: 30%;
  animation: wave 0.9s ease-in-out infinite;
}
.waveform .bar:nth-child(1) { animation-delay: 0.0s; }
.waveform .bar:nth-child(2) { animation-delay: 0.1s; }
.waveform .bar:nth-child(3) { animation-delay: 0.2s; }
.waveform .bar:nth-child(4) { animation-delay: 0.3s; }
.waveform .bar:nth-child(5) { animation-delay: 0.4s; }
.waveform .bar:nth-child(6) { animation-delay: 0.3s; }
.waveform .bar:nth-child(7) { animation-delay: 0.2s; }
.waveform .bar:nth-child(8) { animation-delay: 0.1s; }
.waveform .bar:nth-child(9) { animation-delay: 0.0s; }

@keyframes wave {
  0%, 100% { height: 25%; }
  50% { height: 90%; }
}

/* ---- Drawer (history sidebar) ---- */
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 26, 20, 0.4);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms;
}
.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: absolute;
  top: 0; bottom: 0;
  right: 0;
  width: min(420px, 92vw);
  background: var(--paper);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 280ms cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px -20px rgba(31, 26, 20, 0.2);
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  padding: calc(var(--safe-top) + 18px) 22px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.drawer-title {
  font-family: "Bricolage Grotesque";
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.history-turn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.history-turn:last-child { border-bottom: none; }

.history-meta {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.history-meta.mira { color: var(--coral); }
.history-meta.user { color: var(--sage); }
.history-text {
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}
.history-text .fix-was {
  color: var(--ink-3);
  text-decoration: line-through;
  font-size: 13px;
}
.history-text .fix {
  background: linear-gradient(180deg, transparent 65%, var(--coral-soft) 65%);
  padding: 0 1px;
}

.drawer-empty {
  font-size: 14px;
  color: var(--ink-3);
  text-align: center;
  padding: 40px 20px;
}

/* ---- Scenario sheet ---- */
.sheet {
  position: absolute;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 26, 20, 0.5);
  opacity: 0;
  transition: opacity 240ms;
}
.sheet.open .sheet-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--paper);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 22px 22px calc(var(--safe-bottom) + 24px);
  transform: translateY(100%);
  transition: transform 320ms cubic-bezier(.4,0,.2,1);
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: 0 -20px 50px -20px rgba(31, 26, 20, 0.2);
}
.sheet.open .sheet-panel { transform: translateY(0); pointer-events: auto; }

.sheet-grabber {
  width: 40px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 0 auto 18px;
}

.sheet h2 {
  font-family: "Bricolage Grotesque";
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  line-height: 1.1;
}
.sheet p.sub { color: var(--ink-3); font-size: 14px; margin: 0 0 18px; }

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 600px) {
  .scenario-grid { grid-template-columns: repeat(3, 1fr); }
}

.scenario-card {
  background: var(--cream);
  border: 1.5px solid transparent;
  border-radius: var(--r-lg);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms, transform 80ms;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}
.scenario-card:hover { border-color: var(--ink-3); }
.scenario-card.selected {
  border-color: var(--ink);
  background: var(--cream-2);
}
.scenario-card .sc-emoji {
  font-size: 22px;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--paper);
  display: grid;
  place-items: center;
}
.scenario-card .sc-label {
  font-family: "Bricolage Grotesque";
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.scenario-card .sc-desc {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.35;
}

.level-row {
  display: flex;
  gap: 8px;
  margin: 18px 0 22px;
  flex-wrap: wrap;
}
.level-chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--cream);
  border: 1.5px solid transparent;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-2);
  font-family: inherit;
  transition: border-color 120ms;
}
.level-chip:hover { border-color: var(--ink-3); }
.level-chip.active {
  background: var(--ink);
  color: var(--cream);
  border-color: var(--ink);
  font-weight: 500;
}

.sheet-cta {
  margin-top: 22px;
  width: 100%;
  padding: 16px;
  background: var(--ink);
  color: var(--cream);
  border: none;
  border-radius: var(--r);
  font-family: "Bricolage Grotesque";
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 120ms;
}
.sheet-cta:hover { background: var(--ink-2); }

/* ---- Tweaks panel positioning ---- */
.tweaks-overlay { z-index: 100; }

/* ---- Tablet/Desktop refinements ---- */
@media (min-width: 900px) {
  .avatar-ring { width: min(40vw, 360px); }
  .caption-area { bottom: 220px; }
  .suggest-row { bottom: 160px; }
}

@media (max-height: 700px) {
  .caption-area { bottom: calc(var(--safe-bottom) + 170px); }
  .suggest-row { bottom: calc(var(--safe-bottom) + 115px); }
  .avatar-wrap { transform: translate(-50%, -68%); }
  .avatar-ring { width: min(48vw, 240px); }
}

/* ---- Focus accessibility ---- */
:focus-visible {
  outline: 2px solid var(--coral);
  outline-offset: 2px;
}

button { font-family: inherit; }

@keyframes captionIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.caption-card { animation: captionIn 420ms cubic-bezier(.2,.7,.2,1); }
