/* ═══════════════════════════════════════════════════
   Totoro Treehouse Archive — style.css
   Ghibli-inspired child-friendly theme
════════════════════════════════════════════════════ */

/* ── Variables ──────────────────────────────────── */
:root {
  --green-dark:   #4A7C59;
  --green-mid:    #5A9068;
  --green-light:  #6BCB77;
  --green-pale:   #D4EDDA;
  --brown:        #8B6F47;
  --brown-light:  #C4A882;
  --sky:          #87CEEB;
  --sky-light:    #D6EFFA;
  --cream:        #FFF9F0;
  --cream-dark:   #F5ECD8;
  --totoro-gray:  #7C8C7C;
  --totoro-belly: #EAEAEA;
  --white:        #FFFFFF;
  --text-dark:    #2D3E2D;
  --text-mid:     #4A5C4A;
  --text-light:   #7A8C7A;
  --shadow:       rgba(74, 124, 89, 0.18);
  --shadow-deep:  rgba(74, 124, 89, 0.32);

  --radius-sm:    12px;
  --radius-md:    16px;
  --radius-lg:    24px;
  --radius-xl:    32px;
  --radius-pill:  9999px;

  --font-head:    'Fredoka', system-ui, sans-serif;
  --font-body:    system-ui, -apple-system, sans-serif;

  --transition:   0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-fast: 0.15s ease;
}

/* ── Reset & Base ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--text-dark);
  overflow: hidden;
}

a { color: var(--green-dark); text-decoration: underline; }
a:hover { color: var(--green-mid); }

img { display: block; max-width: 100%; }

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

input, select {
  font-family: inherit;
  font-size: 1rem;
}

/* ── Screens ────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.active { display: flex; flex-direction: column; }

/* ── Utility ────────────────────────────────────── */
.hidden { display: none !important; }

/* ══════════════════════════════════════════════════
   LOADING DOTS
══════════════════════════════════════════════════ */
.loading-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.loading-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green-mid);
  animation: bounce-dot 1.1s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.18s; }
.loading-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%            { transform: translateY(-10px); opacity: 1; }
}

/* ══════════════════════════════════════════════════
   SCREEN 1 — Child Select
══════════════════════════════════════════════════ */
.child-select-bg {
  flex: 1;
  background: linear-gradient(160deg, #c8e6c9 0%, #e8f5e9 40%, var(--cream) 100%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100%;
  padding: 24px 16px 40px;
}

/* Floating leaves decoration */
.floating-leaves {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.leaf {
  position: absolute;
  font-size: 1.6rem;
  animation: float-leaf 8s ease-in-out infinite;
  opacity: 0.4;
}

.leaf-1 { top: 8%;  left: 5%;  animation-delay: 0s;   animation-duration: 7s; }
.leaf-2 { top: 15%; right: 8%; animation-delay: 1.5s; animation-duration: 9s; }
.leaf-3 { top: 60%; left: 3%;  animation-delay: 3s;   animation-duration: 8s; }
.leaf-4 { top: 75%; right: 5%; animation-delay: 0.8s; animation-duration: 10s; }
.leaf-5 { top: 45%; right: 12%;animation-delay: 2.2s; animation-duration: 7.5s;}

@keyframes float-leaf {
  0%,100% { transform: translateY(0) rotate(0deg); }
  33%      { transform: translateY(-18px) rotate(8deg); }
  66%      { transform: translateY(8px) rotate(-5deg); }
}

.child-select-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* App logo / branding */
.app-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.app-title {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 700;
  color: var(--green-dark);
  text-align: center;
  line-height: 1.2;
  text-shadow: 0 2px 4px rgba(255,255,255,0.8);
}

.app-subtitle {
  font-family: var(--font-head);
  font-size: 1.1rem;
  color: var(--green-mid);
}

/* Small Totoro for logo */
.logo-totoro {
  position: relative;
  width: 70px;
  height: 70px;
}

.totoro-body-sm {
  position: relative;
  width: 60px;
  height: 62px;
  background: var(--totoro-gray);
  border-radius: 50% 50% 48% 48% / 55% 55% 45% 45%;
  margin: 0 auto;
}

.totoro-belly-sm {
  position: absolute;
  width: 34px;
  height: 36px;
  background: var(--totoro-belly);
  border-radius: 50%;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.totoro-eye-sm {
  position: absolute;
  width: 12px;
  height: 14px;
  background: white;
  border-radius: 50%;
  top: 16px;
}

.totoro-eye-left-sm  { left: 10px; }
.totoro-eye-right-sm { right: 10px; }

.totoro-eye-sm::after {
  content: '';
  position: absolute;
  width: 7px;
  height: 8px;
  background: #1a1a1a;
  border-radius: 50%;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
}

.totoro-nose-sm {
  position: absolute;
  width: 6px;
  height: 4px;
  background: #555;
  border-radius: 50%;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
}

.totoro-ear-sm {
  position: absolute;
  width: 12px;
  height: 18px;
  background: var(--totoro-gray);
  border-radius: 50% 50% 0 0;
  top: -14px;
}

.totoro-ear-left-sm  { left: 6px; transform: rotate(-10deg); }
.totoro-ear-right-sm { right: 6px; transform: rotate(10deg); }

.totoro-whisker-sm {
  position: absolute;
  height: 1.5px;
  background: #888;
  top: 34px;
  border-radius: 2px;
}

.totoro-whisker-l1 { width: 14px; left: -12px; transform: rotate(-5deg); }
.totoro-whisker-l2 { width: 14px; left: -12px; top: 38px; transform: rotate(5deg); }
.totoro-whisker-r1 { width: 14px; right: -12px; transform: rotate(5deg); }
.totoro-whisker-r2 { width: 14px; right: -12px; top: 38px; transform: rotate(-5deg); }

.totoro-leaf-sm {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.1rem;
}

/* Heading */
.select-heading {
  font-family: var(--font-head);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--green-dark);
  text-align: center;
}

/* Children grid */
.children-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
  width: 100%;
}

.child-card {
  background: var(--white);
  border: 3px solid transparent;
  border-radius: var(--radius-lg);
  padding: 20px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 12px var(--shadow);
  min-height: 130px;
}

.child-card:hover, .child-card:focus-visible {
  transform: translateY(-4px) scale(1.03);
  border-color: var(--green-light);
  box-shadow: 0 8px 24px var(--shadow-deep);
  outline: none;
}

.child-card:active { transform: scale(0.97); }

.child-card-avatar {
  font-size: 2.8rem;
  line-height: 1;
}

.child-card-name {
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-dark);
  text-align: center;
  word-break: break-word;
}

.child-card-age {
  font-size: 0.8rem;
  color: var(--text-light);
  background: var(--green-pale);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
}

.child-card-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

.btn-edit-child {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--white);
  border: 1px solid var(--green-pale);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  box-shadow: 0 2px 6px var(--shadow);
  z-index: 1;
}

.child-card-wrapper:hover .btn-edit-child {
  opacity: 1;
}

.btn-delete-child {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: var(--white);
  border: 1px solid #f5c6c6;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  box-shadow: 0 2px 6px var(--shadow);
  z-index: 1;
}

.child-card-wrapper:hover .btn-delete-child {
  opacity: 1;
}

.btn-merge-child {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: var(--white);
  border: 1px solid var(--green-pale);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  box-shadow: 0 2px 6px var(--shadow);
  z-index: 1;
}

.child-card-wrapper:hover .btn-merge-child {
  opacity: 1;
}

.merge-pending .child-card {
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(107,203,119,0.4);
}

.card--no-dob {
  border-color: #f5c6c6 !important;
  opacity: 0.85;
}

.merge-banner {
  grid-column: 1 / -1;
  background: #fffbe6;
  border: 1px solid #f5d76e;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-family: var(--font-head);
  font-size: 0.9rem;
  color: #7a6000;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-merge-cancel {
  margin-left: auto;
  background: none;
  border: 1px solid #c8a800;
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-family: var(--font-head);
  font-size: 0.85rem;
  color: #7a6000;
  cursor: pointer;
}

.child-card-loading {
  grid-column: 1 / -1;
  padding: 32px;
  display: flex;
  justify-content: center;
}

/* Create child button */
.btn-create-child {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: 3px dashed var(--green-light);
  border-radius: var(--radius-lg);
  padding: 14px 28px;
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--green-dark);
  transition: all var(--transition);
  box-shadow: 0 2px 8px var(--shadow);
  min-height: 54px;
}

.btn-create-child:hover {
  background: var(--green-pale);
  border-color: var(--green-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--shadow);
}

.create-icon {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--green-light);
}

/* Auth error */
.btn-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-head);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-light);
  text-decoration: none;
  padding: 6px 14px;
  border: 1.5px solid var(--green-pale);
  border-radius: var(--radius-pill);
  background: var(--white);
  margin-bottom: 12px;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-home:hover {
  background: var(--green-pale);
  color: var(--text-dark);
}

/* ── Always-On Mic Toggle ────────────────────────── */
.btn-always-on {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cream-dark);
  border: 2px solid var(--green-pale);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.btn-always-on:hover {
  border-color: var(--green-mid);
}

.btn-always-on.active {
  background: var(--green-light);
  border-color: var(--green-dark);
  animation: pulse-ring 2s ease-in-out infinite;
}

.btn-always-on.active.paused {
  background: #ffd166;
  border-color: #d4a017;
  animation: none;
}

@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,124,89,0.35); }
  50%       { box-shadow: 0 0 0 7px rgba(74,124,89,0); }
}

.auth-error {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  font-size: 1rem;
  color: #856404;
  text-align: center;
}

/* ══════════════════════════════════════════════════
   SCREEN 2 — Create Child
══════════════════════════════════════════════════ */
#screen-create-child {
  background: linear-gradient(150deg, #e8f5e9 0%, var(--cream) 100%);
  align-items: center;
  padding: 24px 16px 40px;
}

.create-child-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.btn-back {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 600;
  color: var(--green-dark);
  background: var(--white);
  border: 2px solid var(--green-pale);
  border-radius: var(--radius-pill);
  padding: 8px 18px;
  min-height: 40px;
  transition: all var(--transition-fast);
}

.btn-back:hover {
  background: var(--green-pale);
  border-color: var(--green-light);
}

.create-heading {
  font-family: var(--font-head);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--green-dark);
  text-align: center;
}

.avatar-preview-wrap {
  display: flex;
  justify-content: center;
}

.avatar-preview {
  width: 90px;
  height: 90px;
  background: var(--cream-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  border: 4px solid var(--green-light);
  box-shadow: 0 4px 16px var(--shadow);
  transition: transform var(--transition);
}

.avatar-preview.pop { animation: avatar-pop 0.35s cubic-bezier(0.34,1.56,0.64,1); }

@keyframes avatar-pop {
  0%  { transform: scale(1); }
  50% { transform: scale(1.25); }
  100%{ transform: scale(1); }
}

/* Form */
.form-group { display: flex; flex-direction: column; gap: 8px; }

.form-label {
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-dark);
}

.form-input, .form-select {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--green-pale);
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  background: var(--white);
  color: var(--text-dark);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  min-height: 52px;
}

.form-input:focus, .form-select:focus {
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(107,203,119,0.25);
}

.dob-age-display {
  margin-top: 8px;
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 600;
  min-height: 1.4em;
}

/* Avatar picker */
.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.avatar-option {
  width: 52px;
  height: 52px;
  font-size: 1.7rem;
  border-radius: var(--radius-sm);
  border: 3px solid transparent;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 2px 6px var(--shadow);
}

.avatar-option:hover  { transform: scale(1.15); border-color: var(--green-light); }
.avatar-option.active { border-color: var(--green-dark); background: var(--green-pale); transform: scale(1.1); }

/* Buttons */
.btn-primary {
  padding: 16px 28px;
  background: linear-gradient(135deg, var(--green-mid), var(--green-dark));
  color: var(--white);
  border-radius: var(--radius-pill);
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  min-height: 56px;
  box-shadow: 0 4px 16px var(--shadow-deep);
  transition: all var(--transition);
  letter-spacing: 0.3px;
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--shadow-deep);
}

.btn-primary:active { transform: scale(0.97); }

.btn-save { width: 100%; }

.form-error {
  color: #c0392b;
  font-size: 0.95rem;
  background: #fde8e8;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
}

/* ══════════════════════════════════════════════════
   SCREEN 3 — Main Q&A
══════════════════════════════════════════════════ */
#screen-main {
  background: var(--cream);
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#screen-main.active { display: flex; }

/* ── Header ── */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--white);
  border-bottom: 2px solid var(--green-pale);
  box-shadow: 0 2px 8px var(--shadow);
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 60px;
}

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

.btn-icon {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--green-dark);
  background: var(--green-pale);
  border: 2px solid transparent;
  min-height: 40px;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn-icon:hover {
  background: var(--green-light);
  color: var(--white);
  border-color: var(--green-dark);
}

.child-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--cream-dark);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--cream-dark);
}

.header-avatar { font-size: 1.3rem; }

.header-name {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dark);
}

.header-age-badge {
  font-size: 0.75rem;
  background: var(--green-pale);
  color: var(--green-dark);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: 600;
}

/* ── Main content ── */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  scroll-behavior: smooth;
}

/* ── Totoro Scene ── */
.totoro-area {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--white);
  padding: 20px 16px 10px;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.totoro-scene {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  max-width: 600px;
  width: 100%;
}

/* ─────────────────────────────────────────────────
   CSS-ONLY TOTORO MASCOT (120px tall)
───────────────────────────────────────────────── */
.totoro {
  position: relative;
  width: 90px;
  height: 120px;
  flex-shrink: 0;
}

.totoro-leaf {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.6rem;
  z-index: 3;
  animation: leaf-sway 3s ease-in-out infinite;
}

@keyframes leaf-sway {
  0%,100% { transform: translateX(-50%) rotate(-8deg); }
  50%      { transform: translateX(-50%) rotate(8deg); }
}

.totoro-ear {
  position: absolute;
  width: 22px;
  height: 34px;
  background: var(--totoro-gray);
  border-radius: 50% 50% 0 0;
  top: 8px;
  z-index: 1;
}

.totoro-ear::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 14px;
  background: #9aA89a;
  border-radius: 50% 50% 0 0;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.totoro-ear-left  { left: 4px;  transform: rotate(-12deg); }
.totoro-ear-right { right: 4px; transform: rotate(12deg); }

.totoro-body {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 90px;
  height: 100px;
  background: var(--totoro-gray);
  border-radius: 45px 45px 40px 40px / 50px 50px 40px 40px;
  z-index: 2;
  overflow: hidden;
}

/* Subtle texture */
.totoro-body::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 30%, rgba(255,255,255,0.12) 0%, transparent 60%);
}

.totoro-belly {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 54px;
  height: 60px;
  background: var(--totoro-belly);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.totoro-belly-pattern {
  width: 32px;
  height: 38px;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 5px,
    rgba(150,150,150,0.15) 5px,
    rgba(150,150,150,0.15) 6px
  );
  border-radius: 50%;
}

.totoro-face {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  text-align: center;
}

.totoro-eye {
  position: absolute;
  width: 18px;
  height: 22px;
  background: white;
  border-radius: 50%;
  top: 0;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.totoro-eye-left  { left: 6px; }
.totoro-eye-right { right: 6px; }

.totoro-pupil {
  position: absolute;
  width: 10px;
  height: 12px;
  background: #1a1a2e;
  border-radius: 50%;
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.totoro-pupil::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 4px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
}

.totoro-nose {
  position: absolute;
  width: 10px;
  height: 7px;
  background: #6a6a6a;
  border-radius: 50%;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
}

/* Whiskers */
.totoro-whiskers-left,
.totoro-whiskers-right {
  position: absolute;
  top: 28px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.totoro-whiskers-left  { left: -8px; align-items: flex-end; }
.totoro-whiskers-right { right: -8px; align-items: flex-start; }

.totoro-whisker {
  height: 1.5px;
  background: rgba(100,100,100,0.7);
  border-radius: 2px;
}

.totoro-whiskers-left  .totoro-whisker:nth-child(1) { width: 20px; transform: rotate(-5deg); }
.totoro-whiskers-left  .totoro-whisker:nth-child(2) { width: 22px; transform: rotate(0deg); }
.totoro-whiskers-left  .totoro-whisker:nth-child(3) { width: 20px; transform: rotate(5deg); }
.totoro-whiskers-right .totoro-whisker:nth-child(1) { width: 20px; transform: rotate(5deg); }
.totoro-whiskers-right .totoro-whisker:nth-child(2) { width: 22px; transform: rotate(0deg); }
.totoro-whiskers-right .totoro-whisker:nth-child(3) { width: 20px; transform: rotate(-5deg); }

/* Totoro animation states */
.totoro.thinking .totoro-body { animation: totoro-think 0.7s ease-in-out infinite alternate; }
.totoro.happy    .totoro-body { animation: totoro-happy 0.4s ease-in-out 3; }

@keyframes totoro-think {
  from { transform: translateY(0); }
  to   { transform: translateY(-5px); }
}

@keyframes totoro-happy {
  0%,100% { transform: scale(1) rotate(0deg); }
  25%      { transform: scale(1.05) rotate(-3deg); }
  75%      { transform: scale(1.05) rotate(3deg); }
}

/* ── Speech Bubble ── */
.speech-bubble {
  position: relative;
  background: var(--white);
  border: 2.5px solid var(--green-pale);
  border-radius: var(--radius-lg);
  padding: 14px 16px 12px;
  flex: 1;
  max-width: 440px;
  box-shadow: 0 4px 16px var(--shadow);
  min-height: 60px;
}

/* Triangle pointer */
.speech-bubble::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 28px;
  border-width: 8px 16px 8px 0;
  border-style: solid;
  border-color: transparent var(--green-pale) transparent transparent;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  left: -12px;
  top: 29px;
  border-width: 7px 13px 7px 0;
  border-style: solid;
  border-color: transparent var(--white) transparent transparent;
}

.bubble-content {
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text-dark);
  min-height: 36px;
}

.starter-message p {
  margin-bottom: 4px;
  font-family: var(--font-head);
  font-size: 1.05rem;
  color: var(--green-dark);
}

.btn-speaker {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--green-dark);
  background: var(--green-pale);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-family: var(--font-head);
  font-weight: 600;
  transition: all var(--transition-fast);
  min-height: 36px;
}

.btn-speaker:hover {
  background: var(--green-light);
  color: var(--white);
}

/* ── Answer Image ── */
.answer-image-area {
  margin: 0 16px 10px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 4px 16px var(--shadow);
  background: var(--cream-dark);
  max-width: 480px;
  align-self: center;
  width: calc(100% - 32px);
}

.answer-image {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  display: block;
}

.image-caption {
  font-size: 0.8rem;
  color: var(--text-light);
  padding: 6px 12px 8px;
  text-align: center;
  font-style: italic;
}

/* ── Chat container ── */
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 16px 0;
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: msg-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes msg-in {
  from { transform: translateY(10px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.chat-message.child-msg { align-self: flex-end; align-items: flex-end; }
.chat-message.totoro-msg { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: 11px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.98rem;
  line-height: 1.5;
  max-width: 100%;
  word-wrap: break-word;
}

.child-msg  .chat-bubble {
  background: var(--sky-light);
  color: var(--text-dark);
  border-bottom-right-radius: 6px;
  border: 1.5px solid #b3d9f0;
}

.totoro-msg .chat-bubble {
  background: var(--green-pale);
  color: var(--text-dark);
  border-bottom-left-radius: 6px;
  border: 1.5px solid #b7e2c0;
}

.chat-role {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 3px;
  font-weight: 600;
  font-family: var(--font-head);
}

/* ── Suggestions ── */
.starter-suggestions,
.followup-suggestions {
  padding: 10px 16px;
}

.suggestions-label {
  font-family: var(--font-head);
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 8px;
  font-weight: 600;
}

.suggestions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggestion-pill {
  background: var(--white);
  border: 2px solid var(--green-light);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font-family: var(--font-head);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--green-dark);
  cursor: pointer;
  transition: all var(--transition);
  min-height: 40px;
  white-space: normal;
  text-align: left;
  line-height: 1.3;
}

.suggestion-pill:hover {
  background: var(--green-light);
  color: var(--white);
  border-color: var(--green-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

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

/* Colorful follow-up pills */
.followup-suggestions .suggestion-pill:nth-child(1) { border-color: #f4a261; color: #c05c00; }
.followup-suggestions .suggestion-pill:nth-child(1):hover { background: #f4a261; color: white; border-color: #c05c00; }
.followup-suggestions .suggestion-pill:nth-child(2) { border-color: #e76f51; color: #9d2d17; }
.followup-suggestions .suggestion-pill:nth-child(2):hover { background: #e76f51; color: white; border-color: #9d2d17; }
.followup-suggestions .suggestion-pill:nth-child(3) { border-color: #9b89d0; color: #4c3a8c; }
.followup-suggestions .suggestion-pill:nth-child(3):hover { background: #9b89d0; color: white; border-color: #4c3a8c; }

/* ── Loading state ── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
}

.loading-text {
  font-family: var(--font-head);
  font-size: 0.95rem;
  color: var(--text-light);
}

/* ── Typing animation ── */
@keyframes typing-cursor {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

.typing-cursor::after {
  content: '▍';
  display: inline-block;
  animation: typing-cursor 0.8s ease-in-out infinite;
  color: var(--green-mid);
  margin-left: 2px;
}

/* ── Karaoke word highlighting ── */
.kw {
  display: inline-block;
  transition: color 0.12s, background-color 0.12s, transform 0.12s, box-shadow 0.12s;
  border-radius: 4px;
  padding: 0 3px;
}
.kw-pending { color: var(--text-dark); }
.kw-active  {
  color: #1a1a1a;
  font-weight: 700;
  background: #ffe135;
  box-shadow: 0 2px 6px rgba(255,200,0,0.45);
  transform: scale(1.08);
}
.kw-done    { color: #a8b8a4; }

/* ── Input area ── */
.input-area {
  padding: 10px 12px 12px;
  background: var(--white);
  border-top: 2px solid var(--green-pale);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.interim-text {
  font-size: 0.9rem;
  color: var(--text-light);
  min-height: 20px;
  font-style: italic;
  padding: 0 4px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Mic button */
.btn-mic {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--green-mid), var(--green-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 4px 14px var(--shadow-deep);
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-mic:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px var(--shadow-deep);
}

.btn-mic:active { transform: scale(0.94); }

.btn-mic.listening {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  animation: mic-pulse 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(231,76,60,0.5);
}

@keyframes mic-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(231,76,60,0.55); }
  70%  { box-shadow: 0 0 0 14px rgba(231,76,60,0); }
  100% { box-shadow: 0 0 0 0 rgba(231,76,60,0); }
}

.mic-icon { line-height: 1; }

/* Text input */
.text-input-wrap { flex: 1; }

.question-input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--green-pale);
  border-radius: var(--radius-pill);
  font-size: 1rem;
  background: var(--cream);
  color: var(--text-dark);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 50px;
}

.question-input:focus {
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(107,203,119,0.22);
  background: var(--white);
}

.question-input::placeholder { color: var(--text-light); }

/* Send button */
.btn-send {
  width: 50px;
  height: 50px;
  min-width: 50px;
  border-radius: 50%;
  background: var(--green-dark);
  color: var(--white);
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: 0 3px 10px var(--shadow);
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--green-mid);
  transform: scale(1.08);
}

.btn-send:active { transform: scale(0.94); }
.btn-send:disabled { opacity: 0.45; transform: none; cursor: default; }

/* Rate limit */
.rate-limit-msg {
  font-family: var(--font-head);
  font-size: 0.9rem;
  color: #856404;
  background: #fff3cd;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  text-align: center;
}

/* ══════════════════════════════════════════════════
   SCREEN 4 — History
══════════════════════════════════════════════════ */
#screen-history {
  background: linear-gradient(150deg, #e8f5e9 0%, var(--cream) 100%);
  align-items: center;
}

.history-container {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.history-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 20px 14px;
  background: var(--white);
  border-bottom: 2px solid var(--green-pale);
  box-shadow: 0 2px 8px var(--shadow);
  flex-shrink: 0;
}

.history-heading {
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--green-dark);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: 0 3px 10px var(--shadow);
  border: 2px solid var(--green-pale);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.history-card:hover {
  border-color: var(--green-light);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px var(--shadow-deep);
}

.history-card-topic {
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--green-dark);
  margin-bottom: 4px;
}

.history-card-preview {
  font-size: 0.9rem;
  color: var(--text-mid);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-card-date {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 6px;
}

.history-loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.history-empty {
  text-align: center;
  color: var(--text-light);
  font-family: var(--font-head);
  font-size: 1.1rem;
  padding: 40px 20px;
}

/* ══════════════════════════════════════════════════
   SCREEN TRANSITIONS
══════════════════════════════════════════════════ */
.screen {
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.screen.slide-out {
  opacity: 0;
  transform: translateX(-20px);
  pointer-events: none;
}

.screen.slide-in {
  animation: slide-in-screen 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes slide-in-screen {
  from { opacity: 0; transform: translateX(20px) scale(0.98); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ══════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .app-title { font-size: 1.6rem; }
  .select-heading { font-size: 1.3rem; }
  .totoro { width: 72px; height: 96px; }
  .totoro-body { width: 72px; height: 80px; }
  .speech-bubble { padding: 12px 14px 10px; }
  .bubble-content { font-size: 0.95rem; }
  .btn-mic { width: 50px; height: 50px; min-width: 50px; }
  .children-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .header-right .btn-icon span:not([aria-hidden]) { display: none; }
}

@media (min-width: 768px) {
  .main-content { max-width: 700px; margin: 0 auto; width: 100%; }
  .totoro { width: 100px; height: 130px; }
  .totoro-body { width: 100px; height: 110px; }
  .speech-bubble { font-size: 1.05rem; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--green-pale); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--green-light); }

/* Focus styles for accessibility */
:focus-visible {
  outline: 3px solid var(--green-light);
  outline-offset: 2px;
}
