:root {
  color-scheme: light;
  
  /* Fonts */
  --font-brand: 'Quicksand', system-ui, sans-serif;
  --font-body: 'Outfit', system-ui, sans-serif;
  
  /* HSL Tailored Theme Colors */
  --bg-primary: 48, 20%, 97%; /* #F9F8F3 - Creamy Warm Alabaster */
  --bg-card: 45, 100%, 99%; /* #FFFDF9 - Pristine Sand */
  
  --color-teal: 190, 60%, 30%; /* #1E6B7B - Deep Calm Teal */
  --color-teal-light: 184, 50%, 89%; /* #D4F2F4 - Calm Soft Teal */
  --color-teal-dark: 190, 80%, 15%; /* #0D2F35 - Dark Pine/Ocean */
  
  --color-coral: 8, 70%, 58%; /* #E05A47 - Playful Coral */
  --color-coral-light: 7, 72%, 94%; /* #FCEAE6 - Soft Salmon */
  --color-coral-dark: 8, 80%, 25%; /* #731F14 - Deep Rust */
  
  --color-gold: 41, 100%, 47%; /* #F0A500 - Bright Honey Gold */
  --color-gold-light: 41, 100%, 94%; /* #FFF4E0 - Honey Cream */
  --color-gold-dark: 35, 75%, 26%; /* #734F14 - Deep Amber */
  
  --color-purple: 260, 45%, 45%; /* #6F4EB9 - Magical Purple */
  --color-purple-light: 260, 50%, 93%; /* #F0EAF8 - Lilac Mist */
  
  --color-text-dark: 210, 30%, 12%; /* #17202A - Obsidian */
  --color-text-muted: 200, 15%, 40%; /* #52616A - Storm Grey */
  --color-border: 41, 20%, 82%; /* #DED3C2 - Warm Sand Border */
  
  /* Visual Tokens */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 32px;
  
  --shadow-sm: 0 4px 12px rgba(29, 36, 42, 0.04);
  --shadow-md: 0 12px 28px -4px rgba(29, 36, 42, 0.08);
  --shadow-lg: 0 24px 48px -8px rgba(13, 47, 53, 0.12);
  --shadow-glow: 0 0 24px rgba(30, 107, 123, 0.25);
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Base resets and defaults */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background-color: hsl(var(--bg-primary));
  color: hsl(var(--color-text-dark));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-brand);
  font-weight: 700;
  margin-top: 0;
  color: hsl(var(--color-teal-dark));
}

button, input, textarea {
  font-family: inherit;
}

/* Animations */
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 16px rgba(30, 107, 123, 0.15); }
  50% { box-shadow: 0 0 28px rgba(30, 107, 123, 0.35); }
}

@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.02) translateY(-2px); }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

@keyframes rotate-slow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-24px) scale(0.95); }
  60% { transform: translateY(0) scale(1.05); }
}

@keyframes particle-fade {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(0.5); opacity: 0; }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: hsl(var(--color-border));
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--color-text-muted));
}

/* ----------------------------------------------------
   SETUP PAGE (Playful Modern EdTech Layout)
   ---------------------------------------------------- */
.setupPage {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 3rem 1.5rem;
  background: 
    radial-gradient(circle at 10% 20%, rgba(212, 242, 244, 0.4) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(252, 170, 155, 0.2) 0%, transparent 50%),
    hsl(var(--bg-primary));
}

.setupPanel {
  width: min(720px, 100%);
  padding: 3rem;
  background: hsl(var(--bg-card));
  border: 2px solid hsl(var(--color-border));
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 1.75rem;
  transition: var(--transition-smooth);
}

.setupPanel:hover {
  transform: translateY(-2px);
  box-shadow: 0 32px 64px -12px rgba(13, 47, 53, 0.16);
}

.brandRow {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 0.5rem;
}

.brandMark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, hsl(var(--color-teal)), hsl(var(--color-teal-dark)));
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.setupPanel h1 {
  font-size: clamp(1.75rem, 3.5vw, 2.5rem);
  color: hsl(var(--color-teal-dark));
  line-height: 1.15;
  margin: 0;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: hsl(var(--color-coral));
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--font-brand);
}

/* Inputs, Textareas, Labels */
label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.95rem;
  color: hsl(var(--color-teal-dark));
}

textarea, input[type="number"], input[type="text"] {
  width: 100%;
  border: 2px solid hsl(var(--color-border));
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  background-color: hsl(var(--bg-primary));
  color: hsl(var(--color-text-dark));
  font-size: 1rem;
  font-weight: 500;
  outline: none;
  transition: var(--transition-smooth);
}

textarea:focus, input:focus {
  border-color: hsl(var(--color-teal));
  background-color: #ffffff;
  box-shadow: 0 0 0 4px rgba(30, 107, 123, 0.15);
}

.formGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

/* Mode selectors */
.modeGroup {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.modeButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  min-height: 52px;
  border: 2px solid hsl(var(--color-border));
  border-radius: var(--radius-md);
  background: hsl(var(--bg-card));
  color: hsl(var(--color-text-dark));
  font-family: var(--font-brand);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-spring);
}

.modeButton:hover {
  transform: translateY(-2px);
  border-color: hsl(var(--color-teal));
}

.modeButton.active {
  border-color: hsl(var(--color-teal));
  background-color: hsl(var(--color-teal-light));
  color: hsl(var(--color-teal-dark));
  box-shadow: var(--shadow-sm);
}

.modeButton.active svg {
  color: hsl(var(--color-teal));
}

/* Button systems */
.primaryButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 56px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, hsl(var(--color-coral)), #D24231);
  color: #ffffff;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(224, 90, 71, 0.3);
  transition: var(--transition-spring);
}

.primaryButton:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 32px rgba(224, 90, 71, 0.45);
}

.primaryButton:active {
  transform: translateY(-1px);
}

.primaryButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.primaryButton.compact {
  min-height: 48px;
  padding: 0 1.5rem;
  font-size: 1rem;
}

.secondaryButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  min-height: 48px;
  padding: 0 1.25rem;
  border: 2px solid hsl(var(--color-border));
  border-radius: var(--radius-md);
  background: hsl(var(--bg-card));
  color: hsl(var(--color-teal-dark));
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition-spring);
}

.secondaryButton:hover {
  transform: translateY(-2px);
  border-color: hsl(var(--color-teal));
  background-color: hsl(var(--color-teal-light));
}

.secondaryButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}


/* ----------------------------------------------------
   APP SHELL (Side Rail & Interactive Studio)
   ---------------------------------------------------- */
.appShell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  background-color: hsl(var(--bg-primary));
}

/* Sidebar Progress Panel */
.missionRail {
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 2rem 1.5rem;
  background-color: hsl(var(--color-teal-dark));
  color: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  box-shadow: 8px 0 32px rgba(13, 47, 53, 0.15);
  z-index: 10;
  overflow-y: auto;
}

.missionHeader {
  display: grid;
  gap: 0.5rem;
}

.missionHeader h1 {
  color: #ffffff;
  font-size: 1.65rem;
  line-height: 1.2;
  margin: 0;
}

.timer {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: hsl(var(--color-gold-light));
  font-family: var(--font-brand);
  font-weight: 700;
}

.progressMeter {
  height: 14px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.progressMeter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, hsl(var(--color-gold)), #FFC837);
  box-shadow: 0 0 12px rgba(240, 165, 0, 0.6);
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.assignmentBox {
  display: grid;
  gap: 0.5rem;
  padding: 1.15rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.assignmentBox span {
  color: hsl(var(--color-gold));
  font-family: var(--font-brand);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.assignmentBox p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.45;
  color: #E2EAEB;
}

/* Checklist Checklist Items */
.blockList {
  display: grid;
  gap: 0.75rem;
}

.blockItem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 58px;
  padding: 0.9rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.95rem;
  transition: var(--transition-spring);
}

.blockItem span {
  text-align: left;
  line-height: 1.3;
}

.blockItem strong {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.1);
  color: hsl(var(--color-text-muted));
}

.blockItem.active {
  background: #ffffff;
  color: hsl(var(--color-teal-dark));
  border-color: #ffffff;
  transform: scale(1.02);
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.blockItem.active strong {
  background: hsl(var(--color-teal-light));
  color: hsl(var(--color-teal-dark));
}

.blockItem.done {
  background: hsl(var(--color-teal-light));
  color: hsl(var(--color-teal-dark));
  border-color: transparent;
  opacity: 0.95;
}

.blockItem.done strong {
  background: hsl(var(--color-teal));
  color: #ffffff;
}

.scoreBox {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.15rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.scoreBox span {
  font-size: 0.9rem;
  font-weight: 500;
  color: #E2EAEB;
}

.scoreBox strong {
  font-family: var(--font-brand);
  font-size: 1.65rem;
  color: hsl(var(--color-gold));
  text-shadow: 0 0 10px rgba(240, 165, 0, 0.2);
}

/* ----------------------------------------------------
   WORK AREA (Premium Agentic Interactive Studio)
   ---------------------------------------------------- */
.workArea {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1.5rem 2rem;
  gap: 1.25rem;
  overflow: hidden;
}

.topBar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.topBar h2 {
  font-size: 1.45rem;
  color: hsl(var(--color-teal-dark));
  margin: 0;
}

.liveControls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.iconButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1rem;
  border: 2px solid hsl(var(--color-border));
  border-radius: var(--radius-md);
  background-color: hsl(var(--bg-card));
  color: hsl(var(--color-teal-dark));
  font-family: var(--font-brand);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-spring);
}

.iconButton:hover {
  transform: translateY(-2px);
  border-color: hsl(var(--color-teal));
  background-color: hsl(var(--color-teal-light));
}

.iconButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Floating Audio Status Badge */
.audioBadge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0 1rem;
  border-radius: var(--radius-md);
  background: hsl(var(--color-border));
  color: hsl(var(--color-text-muted));
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-brand);
  transition: var(--transition-smooth);
}

.audioBadge::before {
  content: '';
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background-color: hsl(var(--color-text-muted));
}

.audioBadge.ready {
  background: hsl(var(--color-teal-light));
  color: hsl(var(--color-teal-dark));
}
.audioBadge.ready::before {
  background-color: hsl(var(--color-teal));
}

.audioBadge.speaking {
  background: hsl(var(--color-gold-light));
  color: hsl(var(--color-gold-dark));
  animation: pulse-glow 1.5s infinite;
}
.audioBadge.speaking::before {
  background-color: hsl(var(--color-gold));
  animation: breathe 1s infinite;
}

.audioBadge.error {
  background: hsl(var(--color-coral-light));
  color: hsl(var(--color-coral-dark));
}
.audioBadge.error::before {
  background-color: hsl(var(--color-coral));
}


/* ----------------------------------------------------
   VOICE STAGE (Digital Human & Audio waves)
   ---------------------------------------------------- */
.voiceStage {
  position: relative;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 2rem;
  align-items: center;
  min-height: 180px;
  padding: 1.5rem 2rem;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: 
    radial-gradient(circle at 10% 20%, rgba(30, 107, 123, 0.15) 0%, transparent 45%),
    radial-gradient(circle at 90% 80%, rgba(224, 90, 71, 0.1) 0%, transparent 45%),
    #0E1724; /* Premium Dark Navy */
  box-shadow: var(--shadow-md);
  transition: var(--transition-smooth);
}

/* Active Glow Auras based on Session State */
.voiceStage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.03);
  transition: var(--transition-smooth);
}

/* Glowing Border States */
.voiceStage.ready { box-shadow: 0 16px 36px rgba(30, 107, 123, 0.12), inset 0 0 20px rgba(30, 107, 123, 0.15); }
.voiceStage.speaking { box-shadow: 0 16px 36px rgba(240, 165, 0, 0.15), inset 0 0 20px rgba(240, 165, 0, 0.15); }
.voiceStage.listening { box-shadow: 0 16px 36px rgba(30, 107, 123, 0.2), inset 0 0 20px rgba(30, 107, 123, 0.25); }
.voiceStage.connecting { box-shadow: 0 16px 36px rgba(111, 78, 185, 0.15), inset 0 0 20px rgba(111, 78, 185, 0.15); }

/* SVG Digital Coach Character "Sparky" Layout */
.digitalCoach {
  position: relative;
  width: 140px;
  height: 140px;
  display: grid;
  place-items: center;
}

.sparkySVG {
  width: 120px;
  height: 120px;
  overflow: visible;
}

/* Sparky Animations inside SVG */
.sparkyBody {
  transform-origin: 60px 75px;
  animation: breathe 3s ease-in-out infinite;
}

.sparkyEars {
  transform-origin: 60px 50px;
  transition: var(--transition-spring);
}

.sparkyEye {
  transition: var(--transition-smooth);
}

/* Listening Mode: Ears Perk Up, Body leans forward slightly */
.voiceStage.listening .sparkyEars {
  transform: scaleY(1.1) translateY(-3px);
}
.voiceStage.listening .sparkyBody {
  animation: breathe 1.5s ease-in-out infinite;
}

/* Thinking Mode: Head/Body swings/wiggles, Purple Glow */
.voiceStage.connecting .sparkyBody,
.voiceStage.thinking .sparkyBody {
  animation: wiggle 2.5s ease-in-out infinite;
}

/* Celebrating Mode: Sparky hops up and down! */
.sparkyHop {
  animation: hop 1s ease-in-out infinite;
}

/* Confused/Stuck Mode: Droopy visual look */
.sparkyStuck {
  transform: translateY(2px) rotate(4deg);
}

/* Sparky Aura behind back */
.sparkyAura {
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 999px;
  filter: blur(32px);
  z-index: 0;
  opacity: 0.15;
  background-color: #ffffff;
  transition: var(--transition-smooth);
}

.voiceStage.ready .sparkyAura { background-color: hsl(var(--color-teal)); opacity: 0.25; }
.voiceStage.speaking .sparkyAura { background-color: hsl(var(--color-gold)); opacity: 0.3; }
.voiceStage.listening .sparkyAura { background-color: hsl(var(--color-teal-light)); opacity: 0.35; }
.voiceStage.connecting .sparkyAura { background-color: hsl(var(--color-purple)); opacity: 0.25; }
.voiceStage.stuck .sparkyAura { background-color: hsl(var(--color-coral)); opacity: 0.25; }
.voiceStage.celebrating .sparkyAura { background-color: #FF007F; opacity: 0.35; }

/* VAD Waveform Overlay behind Sparky */
.liveVisualizerCanvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  opacity: 0.45;
}

.voiceCopy {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 0.35rem;
  align-self: center;
}

.voiceCopy .eyebrow {
  color: hsl(var(--color-gold));
}

.voiceCopy h3 {
  color: #ffffff;
  font-size: 1.5rem;
  line-height: 1.15;
  margin: 0;
}

.voiceCopy p {
  margin: 0;
  font-size: 0.95rem;
  color: #BAC7D5;
  line-height: 1.45;
  max-width: 600px;
}


/* ----------------------------------------------------
   COACH BUBBLE & AGENTIC CONVERSATION FLOW
   ---------------------------------------------------- */
.coachBubble {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-lg);
  background-color: hsl(var(--color-gold-light));
  border: 2px solid hsl(var(--color-coral));
  box-shadow: var(--shadow-md);
  transition: var(--transition-spring);
}

.coachBubble::before {
  content: "COACH NUDGE";
  position: absolute;
  top: -10px;
  left: 1.5rem;
  padding: 0.15rem 0.6rem;
  border-radius: 6px;
  background-color: hsl(var(--color-coral));
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-family: var(--font-brand);
}

.coachBubble svg {
  width: 32px;
  height: 32px;
  padding: 0.35rem;
  border-radius: var(--radius-md);
  background-color: hsl(var(--color-coral));
  color: #ffffff;
  flex-shrink: 0;
}

.coachBubblePlain,
.coachBubbleMd.messageMd {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.45;
  font-weight: 700;
  color: hsl(var(--color-teal-dark));
  font-family: var(--font-brand);
}

.coachBubble.pulse {
  transform: scale(1.015);
  box-shadow: 0 16px 40px rgba(224, 90, 71, 0.25);
  border-color: hsl(var(--color-teal));
}

/* Chat Scrolling Workspace */
.chatPanel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  background-color: hsl(var(--bg-card));
  border: 2px solid hsl(var(--color-border));
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.02);
}

/* Premium Conversational Bubbles */
.chatMessage {
  max-width: 82%;
  padding: 1.15rem 1.45rem;
  border-radius: var(--radius-lg);
  font-size: 1.05rem;
  line-height: 1.5;
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  position: relative;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.chatMessage::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 0;
  height: 0;
  border: 10px solid transparent;
}

/* Coach Bubble (Sand/Cream) */
.chatMessage.coach {
  align-self: flex-start;
  background-color: hsl(var(--bg-primary));
  border: 2px solid hsl(var(--color-border));
  color: hsl(var(--color-text-dark));
  border-bottom-left-radius: 4px;
}

.chatMessage.coach::before {
  content: 'STORY BUDDY';
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 0.72rem;
  color: hsl(var(--color-coral));
  letter-spacing: 0.05em;
  margin-bottom: -0.15rem;
}

/* Child Bubble (Calm Warm Teal Speech bubble) */
.chatMessage.child {
  align-self: flex-end;
  background-color: hsl(var(--color-teal-light));
  border: 2px solid hsl(var(--color-teal));
  color: hsl(var(--color-teal-dark));
  border-bottom-right-radius: 4px;
}

.chatMessage.child::before {
  content: 'YOU';
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 0.72rem;
  color: hsl(var(--color-teal));
  letter-spacing: 0.05em;
  margin-bottom: -0.15rem;
  text-align: right;
}

.chatMessage.system {
  align-self: center;
  background-color: hsl(var(--color-border));
  border: 1px solid rgba(0,0,0,0.06);
  color: hsl(var(--color-text-muted));
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-brand);
}

.chatMessageMd p {
  margin: 0 0 0.5rem 0;
}
.chatMessageMd p:last-child {
  margin-bottom: 0;
}

/* Interactive Choices/Suggestions Grid */
.choiceGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.choiceGrid button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.15rem;
  border-radius: var(--radius-md);
  border: 2px solid hsl(var(--color-border));
  background-color: hsl(var(--bg-card));
  color: hsl(var(--color-text-dark));
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-spring);
}

.choiceGrid button:hover {
  transform: translateY(-2px);
  border-color: hsl(var(--color-teal));
  background-color: hsl(var(--color-teal-light));
  box-shadow: var(--shadow-md);
}

.choiceGrid button span {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.choiceGrid button strong {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 0.95rem;
  color: hsl(var(--color-teal-dark));
}

.choiceGrid button small {
  font-size: 0.78rem;
  color: hsl(var(--color-text-muted));
}

.choiceGrid button svg {
  color: hsl(var(--color-teal));
  flex-shrink: 0;
}

/* Vowel/Sentence Frames handwriting style cards */
.sentenceFrame {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1.15rem;
  border-radius: var(--radius-md);
  background: hsl(var(--color-gold-light));
  border: 2px dashed hsl(var(--color-border));
  margin-top: 0.25rem;
}

.sentenceFrame span {
  font-family: var(--font-brand);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background-color: hsl(var(--color-gold));
  color: hsl(var(--color-gold-dark));
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.sentenceFrame p {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.15rem;
  line-height: 1.45;
  color: hsl(var(--color-text-dark));
  letter-spacing: 0.02em;
}


/* ----------------------------------------------------
   ANSWER CONSOLE INPUT & ACTION PAD
   ---------------------------------------------------- */
.answerBox {
  display: grid;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-lg);
  background-color: hsl(var(--bg-card));
  border: 2px solid hsl(var(--color-border));
  box-shadow: var(--shadow-md);
}

.answerBox label {
  font-size: 0.85rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: hsl(var(--color-text-muted));
}

.answerBox textarea {
  background-color: hsl(var(--bg-primary));
  border-color: hsl(var(--color-border));
  padding: 1rem;
  font-size: 1.05rem;
  border-radius: var(--radius-md);
  resize: none;
}

.actionRow {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.actionButtonGroup {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

/* Voice Say It Active Mic Wave animation */
.microphonePulsing {
  position: relative;
  background-color: hsl(var(--color-coral-light)) !important;
  color: hsl(var(--color-coral-dark)) !important;
  border-color: hsl(var(--color-coral)) !important;
}

.microphonePulsing::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  border: 2px solid hsl(var(--color-coral));
  animation: soundPulse 1.2s infinite;
}

/* Summary report */
.summaryPanel {
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  background-color: hsl(var(--color-teal-light));
  border: 2px dashed hsl(var(--color-teal));
  display: grid;
  gap: 0.75rem;
  animation: fadeIn 0.4s ease;
}

.summaryPanel h3 {
  margin: 0;
  font-size: 1.25rem;
}

.summaryPanel p {
  margin: 0;
  line-height: 1.45;
  font-size: 0.98rem;
  color: hsl(var(--color-teal-dark));
}

.liveTranscript {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  background-color: hsl(var(--color-gold-light));
  border: 1px solid hsl(var(--color-border));
  display: grid;
  gap: 0.5rem;
}

.liveTranscript span {
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
  color: hsl(var(--color-gold-dark));
  letter-spacing: 0.05em;
}

.liveTranscript p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.4;
}


/* ----------------------------------------------------
   KIDS UTILITY MODALS (Breathing & Wizard Help)
   ---------------------------------------------------- */
.overlayMask {
  position: fixed;
  inset: 0;
  background-color: rgba(13, 47, 53, 0.4);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: grid;
  place-items: center;
  animation: fadeIn 0.3s ease;
}

.modalBox {
  width: min(540px, 92%);
  padding: 2.5rem;
  border-radius: var(--radius-xl);
  background-color: hsl(var(--bg-card));
  border: 3px solid hsl(var(--color-border));
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: scaleUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: grid;
  gap: 1.5rem;
}

@keyframes scaleUp {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modalBox h2 {
  font-size: 1.85rem;
  color: hsl(var(--color-teal-dark));
}

/* Breathing Bubble animation */
.breathingZone {
  width: 200px;
  height: 200px;
  margin: 0.5rem auto;
  display: grid;
  place-items: center;
}

.breathingCircle {
  width: 80px;
  height: 80px;
  border-radius: 999px;
  background: radial-gradient(circle, hsl(var(--color-teal-light)), hsl(var(--color-teal)));
  display: grid;
  place-items: center;
  color: #ffffff;
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 1.4rem;
  box-shadow: var(--shadow-glow);
  animation: breathingLoop 5s ease-in-out infinite;
}

@keyframes breathingLoop {
  0%, 100% { transform: scale(1); background: radial-gradient(circle, hsl(var(--color-teal-light)), hsl(var(--color-teal))); }
  40%, 60% { transform: scale(2); background: radial-gradient(circle, hsl(var(--color-gold-light)), hsl(var(--color-gold))); box-shadow: 0 0 40px rgba(240, 165, 0, 0.4); }
}

.breathingInstruction {
  font-family: var(--font-brand);
  font-size: 1.35rem;
  font-weight: 800;
  color: hsl(var(--color-coral));
}

.modalCountdownBar {
  height: 8px;
  background-color: hsl(var(--bg-primary));
  border-radius: 99px;
  overflow: hidden;
}

.modalCountdownBar span {
  display: block;
  height: 100%;
  background-color: hsl(var(--color-coral));
  transition: width 1s linear;
}

/* Help Wizard Cards Grid */
.helpCardsGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  text-align: left;
}

.helpCardItem {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.15rem;
  border-radius: var(--radius-md);
  border: 2px solid hsl(var(--color-border));
  background-color: hsl(var(--bg-card));
  cursor: pointer;
  transition: var(--transition-spring);
}

.helpCardItem:hover {
  transform: translateY(-2px);
  border-color: hsl(var(--color-coral));
  background-color: hsl(var(--color-coral-light));
}

.helpCardItem svg {
  color: hsl(var(--color-coral));
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  background-color: rgba(224, 90, 71, 0.08);
  flex-shrink: 0;
}

.helpCardContent h3 {
  font-size: 1.1rem;
  color: hsl(var(--color-teal-dark));
  margin-bottom: 0.15rem;
}

.helpCardContent p {
  margin: 0;
  font-size: 0.88rem;
  color: hsl(var(--color-text-muted));
  line-height: 1.35;
}


/* Animated Thinking/Typing Indicator for Coach */
.chatMessage.coach.thinking {
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.typingIndicator {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0.25rem 0;
}

.typingIndicator .dot {
  width: 8px;
  height: 8px;
  background-color: hsl(var(--color-purple));
  border-radius: 50%;
  display: inline-block;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typingIndicator .dot:nth-child(1) {
  animation-delay: -0.32s;
}

.typingIndicator .dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: scale(0.4);
    opacity: 0.45;
  }
  40% {
    transform: scale(1.15);
    opacity: 1;
  }
}


/* ----------------------------------------------------
   RESPONSIVE LAYOUT BREAKPOINTS
   ---------------------------------------------------- */
@media (max-width: 960px) {
  .appShell {
    grid-template-columns: 1fr;
  }
  
  .missionRail {
    height: auto;
    position: relative;
    box-shadow: none;
    border-bottom: 2px solid hsl(var(--color-border));
  }
  
  .workArea {
    height: auto;
    overflow-y: visible;
    padding: 1.5rem 1rem;
  }
  
  .chatPanel {
    max-height: 400px;
  }
}

@media (max-width: 600px) {
  .setupPanel {
    padding: 1.75rem;
  }
  
  .formGrid {
    grid-template-columns: 1fr;
  }
  
  .modeGroup {
    grid-template-columns: 1fr;
  }
  
  .voiceStage {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    padding: 1.5rem;
  }
  
  .digitalCoach {
    width: 100px;
    height: 100px;
  }
  
  .sparkySVG {
    width: 90px;
    height: 90px;
  }
  
  .actionRow {
    flex-direction: column;
  }
  
  .actionButtonGroup {
    flex-direction: column;
    width: 100%;
  }
  
  .actionButtonGroup button {
    width: 100%;
  }
  
  .answerBox .primaryButton {
    width: 100%;
  }
}
