/* ==========================================================================
   Emma's Voice — Tablet-First Sensory-Friendly Speech Companion
   ========================================================================== */

:root {
  --bg: #eef4fb;
  --surface: #ffffff;
  --surface-soft: #f7faff;
  --border: #dce6f4;
  --text: #182538;
  --text-muted: #5a6d85;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --sky: #38bdf8;
  --amber: #f59e0b;
  --mint: #10b981;
  --mint-soft: #d1fae5;
  --coral: #f43f5e;
  --coral-soft: #ffe4e6;
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-pill: 999px;
  --shadow-card: 0 10px 30px rgba(24, 37, 56, 0.08);
  --shadow-soft: 0 4px 14px rgba(24, 37, 56, 0.06);
  --font-main: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-main);
  color: var(--text);
  background: radial-gradient(circle at top left, #f5f9ff 0%, var(--bg) 60%, #e7f0fb 100%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

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

.hidden {
  display: none !important;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  gap: 12px;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  min-height: 52px;
}

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

.brand-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 800;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  transition: all 0.25s ease;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #94a3b8;
  transition: background 0.25s ease;
}

.status-pill[data-state="tracking"] {
  border-color: #bae6fd;
  background: #f0f9ff;
  color: #0369a1;
}
.status-pill[data-state="tracking"] .status-dot {
  background: var(--sky);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.22);
}

.status-pill[data-state="moving"] {
  border-color: #fde68a;
  background: #fffbeb;
  color: #b45309;
}
.status-pill[data-state="moving"] .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.25);
}

.status-pill[data-state="reward"] {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #047857;
}
.status-pill[data-state="reward"] .status-dot {
  background: var(--mint);
  box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.28);
}

.status-pill[data-state="noface"] {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}
.status-pill[data-state="noface"] .status-dot {
  background: #fb923c;
}

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

/* Mode Switcher Pill (Moves | Words) */
.mode-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 15px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-tab.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.star-counter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  font-weight: 900;
  font-size: 1.05rem;
  box-shadow: var(--shadow-soft);
}

.star-counter .star-icon {
  color: #f59e0b;
  font-size: 1.2rem;
}

.pill-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
  overflow: hidden;
}

.pill-btn:active {
  transform: scale(0.96);
}

.calm-toggle[aria-pressed="true"] {
  background: #ede9fe;
  border-color: #c4b5fd;
  color: #5b21b6;
}

.parent-btn .hold-ring {
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, 0.16);
  transform-origin: left center;
  transform: scaleX(0);
  pointer-events: none;
}

.parent-btn.holding .hold-ring {
  transition: transform 1.4s linear;
  transform: scaleX(1);
}

/* Main Workspace Grid (Tablet Landscape — Amplified Right Animation Stage!) */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.24fr) minmax(370px, 1fr);
  gap: 14px;
  flex: 1;
  min-height: 0;
}

/* ==========================================================================
   LEFT: Camera Mirror & Tracking Stage
   ========================================================================== */
.camera-stage-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 12px;
  box-shadow: var(--shadow-card);
  min-height: 0;
}

.camera-viewport {
  position: relative;
  flex: 1;
  min-height: 240px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#cameraVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#trackingCanvas,
#celebrationCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#celebrationCanvas {
  z-index: 4;
}

/* Top HUD Container inside Camera Viewport (never overlaps) */
.viewport-hud-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: none;
}

/* Live Tracking Legend */
.tracking-legend {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #f8fafc;
  font-size: 0.78rem;
  font-weight: 800;
  pointer-events: auto;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.swatch-outer { background: #38bdf8; }
.swatch-vertical { background: #34d399; }
.swatch-width { background: #fbbf24; }
.swatch-tongue { background: #ec4899; }

.legend-metrics {
  padding-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.25);
  color: #a7f3d0;
  font-variant-numeric: tabular-nums;
}

/* Viewport Controls */
.viewport-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  pointer-events: auto;
}

.icon-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}

.icon-chip:active {
  transform: scale(0.95);
}

.icon-chip.danger-chip {
  background: rgba(244, 63, 94, 0.82);
  border-color: rgba(255, 255, 255, 0.25);
}

/* Joyful Felicitation Banner */
.reinforcement-banner {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(24px) scale(0.86);
  opacity: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 16px 34px;
  border-radius: 28px;
  background: linear-gradient(180deg, #ffffff 0%, #f0fdf4 100%);
  border: 3.5px solid var(--mint);
  box-shadow: 0 20px 48px rgba(16, 185, 129, 0.38), 0 0 0 6px rgba(251, 191, 36, 0.22);
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.38s cubic-bezier(0.22, 1.25, 0.36, 1);
  text-align: center;
}

.reinforcement-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

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

.trophy-pop {
  font-size: 1.65rem;
  animation: gentleBounce 0.7s ease-in-out infinite alternate;
}

@keyframes gentleBounce {
  from { transform: translateY(0) rotate(-6deg); }
  to { transform: translateY(-5px) rotate(6deg); }
}

.reinforcement-emoji {
  font-size: 2.6rem;
  line-height: 1;
}

.reinforcement-word {
  font-size: 2.1rem;
  font-weight: 900;
  color: #065f46;
  line-height: 1.1;
}

.reinforcement-sub {
  font-size: 0.96rem;
  font-weight: 800;
  color: #059669;
}

/* Start Camera Welcome Overlay */
.camera-start-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at center, rgba(239, 246, 255, 0.98) 0%, rgba(219, 234, 254, 0.96) 100%);
}

.start-card {
  max-width: 470px;
  width: 100%;
  background: #ffffff;
  border-radius: 26px;
  padding: 26px 24px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(37, 99, 235, 0.14);
  border: 2px solid #dbeafe;
}

.start-illustration {
  margin-bottom: 10px;
}

.start-card h2 {
  margin: 0 0 8px;
  font-size: 1.55rem;
  font-weight: 900;
  color: var(--text);
}

.start-card p {
  margin: 0 0 18px;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--text-muted);
  font-weight: 700;
}

.start-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.primary-cta,
.secondary-cta,
.danger-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 54px;
  padding: 0 22px;
  border-radius: 18px;
  font-size: 1.05rem;
  font-weight: 900;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.primary-cta {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.32);
}

.secondary-cta {
  background: #f1f5f9;
  color: var(--text);
  border: 2px solid #cbd5e1;
}

.danger-cta {
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: #ffffff;
}

.primary-cta:active,
.secondary-cta:active,
.danger-cta:active {
  transform: scale(0.96);
}

.full-width {
  width: 100%;
}

.privacy-note {
  margin: 14px 0 0 !important;
  font-size: 0.84rem !important;
  color: #64748b !important;
}

.camera-error {
  margin: 12px 0 0 !important;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--coral-soft);
  color: #be123c !important;
  font-size: 0.88rem !important;
}

/* Loading Toast */
.loading-toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.86);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.9rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Bottom Active Word & Live Lip Meter Bar */
.active-word-bar {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 12px;
  flex-shrink: 0;
}

.active-word-trigger {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 20px;
  border: 2px solid #bfdbfe;
  background: linear-gradient(135deg, #eff6ff, #f8fbff);
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.active-word-trigger:active {
  transform: scale(0.98);
}

.active-word-trigger.pulse {
  border-color: var(--mint);
  background: linear-gradient(135deg, #ecfdf5, #f0fdfa);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.active-word-emoji {
  font-size: 2.7rem;
  line-height: 1;
  flex-shrink: 0;
}

.active-word-meta {
  min-width: 0;
  flex: 1;
}

.active-word-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.active-word-text {
  font-size: 1.75rem;
  font-weight: 900;
  color: var(--text);
  line-height: 1.1;
}

.speak-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.78rem;
  font-weight: 800;
}

.active-word-cue {
  margin-top: 3px;
  font-size: 0.86rem;
  line-height: 1.25;
  font-weight: 700;
  color: var(--text-muted);
}

/* Lip Movement Meter */
.lip-meter-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  padding: 12px 16px;
  border-radius: 20px;
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
}

.lip-meter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 800;
}

.meter-title {
  color: var(--text);
}

.meter-state {
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: #e2e8f0;
  color: #475569;
  font-size: 0.78rem;
}

.meter-state.moving {
  background: #fef3c7;
  color: #b45309;
}

.meter-state.triggered {
  background: #d1fae5;
  color: #047857;
}

.meter-track {
  position: relative;
  height: 16px;
  border-radius: var(--radius-pill);
  background: #e2e8f0;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, #38bdf8 0%, #f59e0b 65%, #10b981 100%);
  transition: width 0.08s linear;
}

.meter-threshold {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 58%;
  width: 3px;
  background: #1e293b;
  border-radius: 2px;
  opacity: 0.7;
}

.meter-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.word-stars-inline {
  color: #f59e0b;
  letter-spacing: 2px;
  font-size: 0.95rem;
}

/* ==========================================================================
   RIGHT: Side Panel (Watch & Copy Coach + Word Bank)
   ========================================================================== */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.coach-card,
.words-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 14px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
}

.coach-card {
  flex: 1.28;
  min-height: 0;
  gap: 10px;
}

.words-card {
  flex: 1;
  min-height: 0;
  gap: 9px;
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 900;
  color: var(--text);
}

.mode-badge {
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: #eff6ff;
  color: #2563eb;
  font-size: 0.72rem;
  font-weight: 800;
}

.mode-badge.parent-video {
  background: #ecfdf5;
  color: #047857;
}

/* Mini Switch */
.mini-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.mini-switch input {
  display: none;
}

.mini-slider {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  transition: background 0.2s ease;
}

.mini-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s ease;
}

.mini-switch input:checked + .mini-slider {
  background: var(--primary);
}

.mini-switch input:checked + .mini-slider::after {
  transform: translateX(14px);
}

.mini-switch-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-muted);
}

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

.buddy-picker {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
}

.buddy-chip {
  width: 30px;
  height: 28px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.18s ease;
}

.buddy-chip:active {
  transform: scale(0.92);
}

.buddy-chip.active {
  background: #dbeafe;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
  transform: scale(1.06);
}

/* Amplified 3D Coach Video Stage */
.coach-stage {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 235px;
  border-radius: 20px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #f8fbff 0%, #e0f2fe 58%, #cbdcf7 100%);
  border: 2px solid #bfdbfe;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75);
  cursor: grab;
}

.coach-stage:active {
  cursor: grabbing;
}

.coach-webgl-canvas,
.coach-guide-canvas,
#parentVideoPlayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.coach-guide-canvas {
  pointer-events: none;
  z-index: 3;
}

#parentVideoPlayer {
  object-fit: cover;
  z-index: 4;
}

.coach-loading-pill {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: rgba(15, 23, 42, 0.82);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.syllable-strip {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

.syllable-pill {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--text-muted);
  background: #f1f5f9;
  transition: all 0.14s ease;
}

.syllable-pill.active {
  background: var(--primary);
  color: #ffffff;
  transform: scale(1.08);
}

/* Coach Controls */
.coach-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.coach-controls .coach-btn {
  flex: 1 1 82px;
}

.coach-controls .coach-btn-primary {
  flex: 1.35 1 95px;
}

.coach-btn-danger {
  background: var(--coral-soft);
  border-color: #fda4af;
  color: #be123c;
}

.coach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 42px;
  padding: 0 8px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease;
}

.coach-btn:active {
  transform: scale(0.96);
}

.coach-btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.coach-btn.active {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1d4ed8;
}

/* Words to Learn Card */
.text-link-btn {
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
  color: #1d4ed8;
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.category-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  flex-shrink: 0;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.cat-chip {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s ease;
}

.cat-chip.active {
  background: var(--text);
  border-color: var(--text);
  color: #ffffff;
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  overflow-y: auto;
  padding: 2px 2px 6px;
  flex: 1;
  min-height: 0;
  align-content: start;
}

.word-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 98px;
  padding: 10px 8px;
  border-radius: 18px;
  border: 2px solid var(--border);
  background: var(--surface-soft);
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.word-tile:active {
  transform: scale(0.96);
}

.word-tile.selected {
  border-color: var(--primary);
  background: linear-gradient(180deg, #eff6ff 0%, #ffffff 100%);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.16);
}

.word-tile-emoji {
  font-size: 2rem;
  line-height: 1.1;
}

.word-tile-label {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--text);
}

.word-tile-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-muted);
}

.word-tile-stars {
  color: #f59e0b;
  font-size: 0.78rem;
  letter-spacing: 1px;
}

.video-dot {
  position: absolute;
  top: 7px;
  right: 8px;
  font-size: 0.76rem;
  background: #d1fae5;
  color: #047857;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 800;
}

/* ==========================================================================
   MODALS (Parent Studio & Video Recorder)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-sheet {
  width: min(640px, 100%);
  max-height: 90dvh;
  background: var(--surface);
  border-radius: 26px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 14px;
  border-bottom: 1.5px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 900;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.close-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 900;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 18px;
  background: var(--surface-soft);
  border-bottom: 1.5px solid var(--border);
}

.modal-tab {
  padding: 9px 6px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
}

.modal-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-soft);
}

.modal-body {
  padding: 18px 22px 24px;
  overflow-y: auto;
  flex: 1;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.tab-panel.active {
  display: flex;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.setting-row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.setting-label {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.setting-value {
  font-size: 0.88rem;
  font-weight: 900;
  color: var(--primary);
}

.setting-help {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-muted);
  font-weight: 700;
}

.input-control {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1.5px solid #cbd5e1;
  background: #ffffff;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: normal;
}

select.input-control {
  padding-top: 0;
  padding-bottom: 0;
}

.range-control {
  width: 100%;
  accent-color: var(--primary);
  height: 8px;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.2s ease;
  cursor: pointer;
}

.slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}

/* Add Word Form & Manage List */
.add-word-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
}

.add-word-form h3,
.word-media-section h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 900;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 100px;
  gap: 8px;
}

.form-row:nth-of-type(2) {
  grid-template-columns: 1.3fr 1fr;
}

.emoji-input {
  text-align: center;
  font-size: 1.4rem;
}

.manage-words-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.manage-word-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: #ffffff;
}

.manage-word-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.manage-word-emoji {
  font-size: 1.5rem;
}

.manage-word-name {
  font-weight: 900;
  font-size: 0.96rem;
}

.manage-word-status {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
}

.manage-word-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.small-btn {
  padding: 7px 11px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.small-btn.primary {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.small-btn.danger {
  background: var(--coral-soft);
  border-color: #fecdd3;
  color: #be123c;
}

/* Stats & Progress */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 10px;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
}

.stat-num {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--primary);
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text-muted);
  text-align: center;
}

.progress-word-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 14px;
  background: #ffffff;
  border: 1.5px solid var(--border);
  font-weight: 800;
}

.danger-zone {
  padding-top: 8px;
  border-top: 1.5px dashed var(--border);
}

.danger-outline-btn {
  width: 100%;
  height: 46px;
  border-radius: 14px;
  border: 1.5px solid #fda4af;
  background: #fff1f2;
  color: #be123c;
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
}

/* Video Recorder Modal */
.recorder-sheet {
  width: min(540px, 100%);
}

.recorder-body {
  padding: 18px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.recorder-preview-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 18px;
  overflow: hidden;
  background: #0f172a;
}

#recorderPreviewVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#recorderPreviewVideo.playback-mode {
  transform: none;
}

.recorder-countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.45);
  color: #ffffff;
  font-size: 4.5rem;
  font-weight: 900;
}

.rec-indicator {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(225, 29, 72, 0.9);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 800;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  animation: pulseDot 1s infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.recorder-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.upload-label {
  cursor: pointer;
}

/* About & Research Modal Styling */
.about-modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.about-callout {
  padding: 12px 14px;
  border-radius: 14px;
  background: #ecfdf5;
  border: 1.5px solid #a7f3d0;
  color: #065f46;
  font-size: 0.88rem;
  font-weight: 700;
}

.about-section h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 900;
}

.research-item {
  padding: 11px 14px;
  margin-bottom: 8px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--primary);
}

.research-item > strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 3px;
}

.research-item p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-muted);
  font-weight: 700;
}

.about-clinical-note {
  padding: 12px 14px;
  border-radius: 14px;
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  color: #92400e;
  font-size: 0.82rem;
  line-height: 1.45;
  font-weight: 700;
}

/* Calm Mode Adjustments */
body.calm-mode {
  background: #f4f6f8;
}

body.calm-mode .reinforcement-banner {
  transition-duration: 0.45s;
  box-shadow: 0 10px 24px rgba(16, 185, 129, 0.16);
}

/* ==========================================================================
   RESPONSIVE: Tablet Portrait & Smaller Screens
   ========================================================================== */
@media (max-width: 920px) {
  html, body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .camera-viewport {
    min-height: 360px;
    aspect-ratio: 4 / 3;
  }

  .active-word-bar {
    grid-template-columns: 1fr;
  }

  .side-panel {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
    gap: 12px;
  }

  .words-card {
    max-height: 380px;
  }
}

@media (max-width: 680px) {
  .side-panel {
    grid-template-columns: 1fr;
  }

  .brand-text h1 {
    font-size: 1.15rem;
  }

  .pill-btn .btn-label {
    display: none;
  }

  .coach-controls {
    grid-template-columns: repeat(2, 1fr);
  }
}
