:root {
  --bg: #0b1020;
  --panel: #141b2e;
  --text: #e8ecf8;
  --muted: #9aa6c4;
  --accent: #10b981;
  --accent-hover: #059669;
  --danger: #ef4444;
  --border: #24304d;
  --success: #22c55e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(circle at top, #0f2d1f, var(--bg) 60%);
  color: var(--text);
}

.shell {
  max-width: 680px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 3rem;
}

/* ── Header ──────────────────────────────────────── */
header { text-align: center; margin-bottom: 0.5rem; }

.logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}

.logo-icon { font-size: 2.2rem; line-height: 1; }

header h1 {
  margin: 0;
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #10b981, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ── Panel ───────────────────────────────────────── */
.panel {
  margin-top: 1.75rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
}

.hidden { display: none !important; }

/* ── Config layout ───────────────────────────────── */
.config-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 480px) {
  .config-row { grid-template-columns: 1fr; }
}

.config-section { margin-bottom: 1.1rem; }

.config-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.full-select {
  width: 100%;
  background: #0f1526;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.full-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Buttons ─────────────────────────────────────── */
button {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1.2rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

button.primary { background: var(--accent); color: white; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }
button.danger { background: var(--danger); color: white; font-weight: 600; }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}
button.ghost:hover { border-color: var(--accent); color: var(--text); }

.start-btn {
  width: 100%;
  padding: 0.85rem;
  font-size: 1.1rem;
  border-radius: 12px;
  letter-spacing: 0.02em;
}

.start-btn:hover:not(:disabled) { transform: translateY(-1px); }
.start-btn:active { transform: translateY(0); }

/* ── Status ──────────────────────────────────────── */
.actions { margin: 1.1rem 0 0.5rem; }
.status { color: var(--muted); font-size: 0.88rem; text-align: center; margin: 0; }

/* ── Session panel ───────────────────────────────── */
#session { position: relative; }

.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding-right: 72px; /* room for absolute teddy */
}

.session-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.badge { font-size: 0.83rem; }

.lang-badge {
  background: rgba(16,185,129,0.15);
  border: 1px solid rgba(16,185,129,0.4);
  border-radius: 20px;
  padding: 0.2rem 0.7rem;
  color: #34d399;
  font-weight: 600;
  font-size: 0.82rem;
}

.mode-badge {
  background: #1e2a42;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-size: 0.78rem;
  color: #7dd3fc;
}

/* ── Teddy bear — absolute upper-right of session panel ── */
#character-wrap {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  z-index: 5;
}

#lingua-bear {
  width: 58px;
  height: 52px;
  filter: drop-shadow(0 2px 8px rgba(212,149,106,0.45));
  transition: transform 0.3s ease;
}

#lingua-bear.speaking {
  animation: bear-bob 0.45s ease-in-out infinite alternate;
}

@keyframes bear-bob {
  from { transform: translateY(0px) rotate(-1.5deg); }
  to   { transform: translateY(-4px) rotate(1.5deg); }
}

#char-state-label {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.3s;
}

#char-state-label.speaking  { color: #34d399; }
#char-state-label.listening { color: #a5b4fc; }
#char-state-label.thinking  { color: #fbbf24; }

/* ── Section / curriculum selector (welcome panel) ── */
.section-label {
  color: var(--accent) !important;
}

/* ── Vocabulary panel — full width card grid ─────── */
#vocab-panel {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.65rem 0.8rem 0.8rem;
  margin-bottom: 0.75rem;
  max-height: 230px;
  overflow-y: auto;
  transition: opacity 0.3s, transform 0.3s, max-height 0.3s;
  transform-origin: top center;
}

#vocab-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scaleY(0.88);
  max-height: 0;
  padding: 0;
  margin: 0;
  border-width: 0;
  overflow: hidden;
}

#vocab-title {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #34d399;
  margin-bottom: 0.55rem;
}

/* Grid: fills width, ~75px min per card */
#vocab-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.45rem;
}

/* Phrase cards (greetings) — wider so the full phrase fits */
#vocab-cards.phrase-grid {
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
}

/* Number and ABC cards — tighter, the big character IS the visual */
#vocab-cards.number-grid,
#vocab-cards.abc-grid {
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
}

/* Big digit / letter — rendered from the emoji field */
.vc-num, .vc-letter {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  color: #34d399;
}

.vocab-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.05);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.25rem 0.4rem;
  cursor: pointer;
  transition: transform 0.18s, background 0.18s, border-color 0.18s, box-shadow 0.18s;
  animation: card-pop 0.35s cubic-bezier(.34,1.56,.64,1) backwards;
  user-select: none;
}

.vocab-card:hover {
  background: rgba(16,185,129,0.12);
  border-color: rgba(16,185,129,0.5);
  transform: translateY(-3px) scale(1.05);
}

.vocab-card.highlighted {
  background: rgba(16,185,129,0.22);
  border-color: #34d399;
  transform: translateY(-4px) scale(1.1);
  box-shadow: 0 0 14px rgba(52,211,153,0.55);
  z-index: 1;
}

.vocab-card.selected {
  background: rgba(165,180,252,0.22);
  border-color: #a5b4fc;
  box-shadow: 0 0 14px rgba(165,180,252,0.5);
  transform: translateY(-2px) scale(1.04);
}

/* Authoritative drill state from the backend — which word is done vs. the
   one word Teddy is asking about right now */
.vocab-card.vocab-current {
  border-color: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251,191,36,0.35);
}

.vocab-card.vocab-done {
  opacity: 0.55;
  position: relative;
}

.vocab-card.vocab-done::after {
  content: "✓";
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #34d399;
  color: #052e22;
  font-size: 0.85rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--bg, #0b1220);
}

.vocab-card.rtl.vocab-done::after {
  right: auto;
  left: -8px;
}

/* Big emoji / color swatch */
.vocab-card .vc-emoji { font-size: 2.6rem; line-height: 1; }
.vocab-card .vc-swatch {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
}

/* German label with inline article coloring */
.vocab-card .vc-de {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.3rem;
  text-align: center;
  line-height: 1.25;
  word-break: break-word;
}

/* Article gender colors — helps kids absorb grammar */
.vocab-card .vc-de .art.der { color: #93c5fd; }   /* blue  — masculine */
.vocab-card .vc-de .art.die { color: #f9a8d4; }   /* pink  — feminine  */
.vocab-card .vc-de .art.das { color: #6ee7b7; }   /* green — neuter    */

/* Arabic: no der/die/das, so noun gender is colored directly (masculine/feminine only) */
.vocab-card .vc-de .art.gender-m { color: #93c5fd; }   /* blue — مذكر (masculine) */
.vocab-card .vc-de .art.gender-f { color: #f9a8d4; }   /* pink — مؤنث (feminine)  */

/* Arabic cards read right-to-left */
.vocab-card.rtl .vc-de {
  direction: rtl;
  unicode-bidi: isolate;
}

.vocab-card .vc-en {
  font-size: 0.52rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
  margin-top: 0.1rem;
}

.vocab-card:active { transform: scale(0.94); }

@keyframes card-pop {
  0%   { opacity: 0; transform: scale(0.45) translateY(12px) rotate(-8deg); }
  65%  { opacity: 1; transform: scale(1.1)  translateY(-3px) rotate(2deg);  }
  100% { opacity: 1; transform: scale(1)    translateY(0)    rotate(0deg);  }
}

/* ── Messages ────────────────────────────────────── */
.messages {
  min-height: 260px;
  max-height: 400px;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0a0f1e;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.msg { line-height: 1.5; font-size: 0.93rem; }
.msg .who { font-weight: 700; margin-right: 0.4rem; }

.msg.agent .who { color: #34d399; }
.msg.agent { color: var(--text); }

.msg.user .who { color: #a5b4fc; }
.msg.user { color: var(--text); }

.msg.system { color: var(--muted); font-size: 0.82rem; font-style: italic; }

/* Silent translation caption — its own line, text only, never spoken */
.msg.caption {
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
  margin-top: -0.15rem;
  margin-bottom: 0.3rem;
  margin-inline-start: 1.5rem;
}

/* ── Chat form ───────────────────────────────────── */
.chat-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.chat-form input {
  flex: 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1526;
  color: var(--text);
  padding: 0.65rem 0.85rem;
  font-size: 0.92rem;
  transition: border-color 0.15s;
}

.chat-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-form button {
  background: var(--accent);
  color: white;
  font-weight: 600;
  padding: 0.65rem 1.1rem;
}

.chat-form button:hover { background: var(--accent-hover); }

/* ── Feedback modal ──────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.modal h2 { margin: 0 0 0.35rem; font-size: 1.3rem; }
.modal-sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 1.5rem; }

.thumb-row {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.thumb-btn {
  font-size: 2rem;
  background: #0f1526;
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.thumb-btn:hover { border-color: var(--accent); transform: scale(1.08); }
.thumb-btn.selected-up { border-color: var(--success); background: rgba(34,197,94,0.12); }
.thumb-btn.selected-down { border-color: var(--danger); background: rgba(239,68,68,0.12); }

.feedback-textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1526;
  color: var(--text);
  padding: 0.65rem 0.8rem;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 1.25rem;
}

.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }
