/* IIAI-Buddy - mobile-first styles.
   Themes are applied with data-theme="<id>" on <body> or on a single card.
   To add a theme: add a [data-theme="..."] block here and an entry in THEMES (js/api.js). */

:root,
[data-theme] {
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 20px;
}

/* ---------- Themes ---------- */

:root,
[data-theme="bright"] {            /* Sunny: orange, cheerful */
  --bg: #fff7e6;
  --surface: #ffffff;
  --text: #2b2140;
  --muted: #7a6f8a;
  --accent: #ff7a2f;
  --accent-text: #ffffff;
  --border: #ffe2b8;
  --shadow: 0 8px 22px rgba(255, 122, 47, 0.18);
  --card: linear-gradient(135deg, #ffb347, #ff6f61);
  --card-text: #ffffff;
}

[data-theme="ocean"] {             /* Ocean: blue, fresh */
  --bg: #eaf6ff;
  --surface: #ffffff;
  --text: #0f2a44;
  --muted: #5d7890;
  --accent: #1e90ff;
  --accent-text: #ffffff;
  --border: #cde6fb;
  --shadow: 0 8px 22px rgba(30, 144, 255, 0.18);
  --card: linear-gradient(135deg, #36d1dc, #1e6fff);
  --card-text: #ffffff;
}

[data-theme="jungle"] {            /* Jungle: green, outdoors */
  --bg: #eefaea;
  --surface: #ffffff;
  --text: #1d3318;
  --muted: #62785b;
  --accent: #2fae4f;
  --accent-text: #ffffff;
  --border: #d3efc9;
  --shadow: 0 8px 22px rgba(47, 174, 79, 0.18);
  --card: linear-gradient(135deg, #a8e063, #2fae4f);
  --card-text: #ffffff;
}

[data-theme="candy"] {             /* Candy: pink and purple */
  --bg: #fff0f7;
  --surface: #ffffff;
  --text: #3d1736;
  --muted: #8a6583;
  --accent: #e8459b;
  --accent-text: #ffffff;
  --border: #fbd3e8;
  --shadow: 0 8px 22px rgba(232, 69, 155, 0.18);
  --card: linear-gradient(135deg, #ff9ad5, #a66cff);
  --card-text: #ffffff;
}

[data-theme="paper"] {             /* Paper: clean and minimal */
  --bg: #f4f4f1;
  --surface: #ffffff;
  --text: #1f1f1f;
  --muted: #74746f;
  --accent: #1f1f1f;
  --accent-text: #ffffff;
  --border: #e3e3de;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
  --card: linear-gradient(135deg, #ffffff, #e9e9e4);
  --card-text: #1f1f1f;
}

[data-theme="calm"] {              /* Midnight: dark with mint, music-app feel */
  --bg: #12141c;
  --surface: #1c2030;
  --text: #e8eaf2;
  --muted: #9298ad;
  --accent: #5ee6b0;
  --accent-text: #0d1a14;
  --border: #2a3045;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --card: linear-gradient(135deg, #1f2433, #2d3550);
  --card-text: #e8eaf2;
}

[data-theme="space"] {             /* Galaxy: deep purple */
  --bg: #140f2b;
  --surface: #211a45;
  --text: #ece8ff;
  --muted: #a39cc9;
  --accent: #9b7bff;
  --accent-text: #ffffff;
  --border: #33296a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --card: linear-gradient(135deg, #2b1f63, #6a3fb8);
  --card-text: #ffffff;
}

[data-theme="neon"] {              /* Neon: dark gamer with pink and cyan */
  --bg: #0b0b10;
  --surface: #17171f;
  --text: #f1f1f6;
  --muted: #8f8fa3;
  --accent: #ff2e88;
  --accent-text: #ffffff;
  --border: #2a2a38;
  --shadow: 0 8px 24px rgba(255, 46, 136, 0.15);
  --card: linear-gradient(135deg, #ff2e88, #2ee6ff);
  --card-text: #0b0b10;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.25s ease, color 0.25s ease;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

h1 { font-size: 1.8rem; margin: 8px 0 4px; }
h2 { font-size: 1.2rem; margin: 24px 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

/* ---------- Profile picker ---------- */

.profile-list { display: grid; gap: 16px; }

.profile-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--card-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.profile-card:active { transform: scale(0.97); }
.profile-card .avatar { font-size: 3rem; line-height: 1; }
.profile-card .name { font-size: 1.4rem; font-weight: 800; }
.profile-card .meta { opacity: 0.85; margin-top: 2px; }

/* ---------- Home ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; }
.back { color: var(--muted); text-decoration: none; font-weight: 700; padding: 8px 0; }

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
  padding: 20px;
  background: var(--card);
  color: var(--card-text);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero .avatar { font-size: 3.2rem; line-height: 1; }
.hero .subtitle { color: inherit; opacity: 0.85; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 8px;
  text-align: center;
}
.stat .value { font-size: 1.3rem; font-weight: 800; }
.stat .label { font-size: 0.8rem; color: var(--muted); }

.mission-list { display: grid; gap: 12px; }
.mission {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}
.mission .icon {
  flex: 0 0 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.4rem;
}
.mission .title { font-weight: 800; }
.mission .title-id { color: var(--muted); font-size: 0.9rem; }
.mission.locked { opacity: 0.55; }
.mission.locked .icon { background: var(--border); color: var(--muted); }

.notice {
  padding: 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* ---------- Theme picker (bottom sheet) ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.sheet-backdrop[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
  border-radius: 24px 24px 0 0;
}
.sheet h2 { margin-top: 0; }

.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.theme-option {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.theme-option .swatch {
  height: 56px;
  border-radius: 12px;
  background: var(--card);
  display: flex;
  align-items: flex-end;
  padding: 6px;
}
.theme-option .dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}
.theme-option.selected { border-color: var(--accent); }

/* ---------- Talk page ---------- */

.talk-page { overflow: hidden; }

.talk-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}

.talk-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.talk-header .back { font-size: 1.4rem; padding: 4px 8px 4px 0; }
.talk-title { flex: 1; min-width: 0; font-weight: 800; }
.talk-title #missionTitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.talk-sub { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.talk-avatar { font-size: 2rem; line-height: 1; }

.scene {
  flex: 0 0 auto;
  margin: 10px 16px 0;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 2.4rem;
  line-height: 1.3;
  letter-spacing: 4px;
  text-align: center;
  word-break: break-all;
}
.scene[hidden] { display: none; }
.scene.has-image { padding: 6px; font-size: 1rem; letter-spacing: 0; }
.scene.has-image img {
  display: block;
  width: 100%;
  max-height: 32vh;
  object-fit: contain;
  border-radius: calc(var(--radius) - 6px);
}
.mission .icon.has-image { padding: 0; overflow: hidden; background: var(--border); }
.mission .icon.has-image img { width: 100%; height: 100%; object-fit: cover; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.msg { display: flex; flex-direction: column; gap: 6px; max-width: 85%; }
.msg.buddy { align-self: flex-start; align-items: flex-start; }
.msg.child { align-self: flex-end; align-items: flex-end; }

.bubble {
  position: relative;
  padding: 12px 16px;
  border-radius: 20px;
  font-size: 1.1rem;
  line-height: 1.4;
  word-wrap: break-word;
}
.msg.buddy .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  padding-right: 48px;
}
.msg.child .bubble {
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 6px;
}

.replay-btn {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}

.help-id, .new-word, .correction {
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  color: var(--muted);
}
.new-word b { color: var(--text); }
.correction { border-style: solid; color: var(--text); }
.correction span { font-weight: 700; }

.xp-badge {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--accent);
  animation: pop 0.4s ease;
}

@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

.thinking .bubble { display: flex; gap: 6px; padding: 16px 20px; }
.thinking .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}

.chat-notice {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.input-bar input {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
}
.send-btn {
  flex: 0 0 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.3rem;
  cursor: pointer;
}
.send-btn:disabled, .input-bar input:disabled { opacity: 0.5; }

.done-bar {
  display: grid;
  gap: 10px;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
}
.done-bar[hidden] { display: none; }
.done-text { font-weight: 800; font-size: 1.1rem; }

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 24px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  text-decoration: none;
  cursor: pointer;
}
.primary-btn:disabled { opacity: 0.6; }

.start-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
  z-index: 20;
}
.start-overlay[hidden] { display: none; }
.start-card { text-align: center; max-width: 360px; }
.start-avatar { font-size: 5rem; line-height: 1; margin-bottom: 8px; }
.start-card .subtitle { margin-bottom: 20px; }
.start-error { margin-top: 12px; color: var(--muted); min-height: 1.2em; }

/* ---------- Mic controls (M4) ---------- */

.header-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
}

.controls {
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.controls[hidden] { display: none; }

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 340px;
  margin: 0 auto;
}

.side-btn {
  width: 52px;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.3rem;
  cursor: pointer;
}
.side-btn.active { border-color: var(--accent); }
.side-btn.placeholder { visibility: hidden; }

.mic-btn {
  position: relative;
  width: 96px;
  height: 96px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.mic-btn[hidden] { display: none; }
.mic-btn:active { transform: scale(0.95); }
.mic-btn:disabled { opacity: 0.45; }
.mic-icon { position: relative; font-size: 2.4rem; line-height: 1; pointer-events: none; }

.mic-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.08s linear, opacity 0.2s ease;
}
.mic-btn.recording { background: #e53950; color: #fff; }
.mic-btn.recording .mic-ring { opacity: 0.6; border-color: #e53950; animation: ring-pulse 1.2s infinite ease-out; }
/* Last 5 seconds of the allowed recording: amber ring, faster pulse (no countdown numbers). */
.mic-btn.recording.near-end .mic-ring { border-color: #ffb020; opacity: 0.9; animation-duration: 0.6s; }
.mic-btn.busy .mic-icon { animation: blink 1.2s infinite ease-in-out; }

@keyframes ring-pulse {
  0% { box-shadow: 0 0 0 0 rgba(229, 57, 80, 0.45); }
  100% { box-shadow: 0 0 0 18px rgba(229, 57, 80, 0); }
}

.mic-hint {
  text-align: center;
  margin-top: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  min-height: 1.3em;
}

.controls .input-bar {
  padding: 12px 0 0;
  border-top: none;
  background: transparent;
}
.input-bar[hidden] { display: none; }

/* Settings sheet */
.setting { display: block; margin-bottom: 18px; }
.setting-label { display: block; font-weight: 800; margin-bottom: 8px; }
.setting small { color: var(--muted); font-weight: 600; }
.setting.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting.toggle input { width: 26px; height: 26px; accent-color: var(--accent); flex: 0 0 auto; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented button {
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.segmented button.active { border-color: var(--accent); background: var(--surface); }
.sheet .primary-btn { width: 100%; }

.timing {
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.8;
  padding-left: 4px;
}

/* ---------- Results & progress (M5) ---------- */

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 24px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  text-decoration: none;
}

.level-box { margin-top: 16px; }
.home-level { margin-top: 12px; }
.level-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.level-line b { color: var(--text); }
.level-bar {
  height: 12px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.level-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.9s ease;
}

.mission-stars {
  margin-left: auto;
  padding-left: 8px;
  color: #f5b301;
  font-size: 1rem;
  letter-spacing: 1px;
  white-space: nowrap;
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.result-overlay[hidden] { display: none; }
.result-card { width: 100%; max-width: 420px; text-align: center; margin: auto 0; }
.result-card h1 { margin: 4px 0 0; }

.result-stars { display: flex; justify-content: center; gap: 6px; }
.result-stars .star {
  font-size: 3.6rem;
  line-height: 1;
  color: var(--border);
  transform: scale(0.4);
  opacity: 0;
  animation: star-in 0.5s ease forwards;
}
.result-stars .star.on { color: #f5b301; text-shadow: 0 4px 14px rgba(245, 179, 1, 0.45); }
@keyframes star-in {
  0% { transform: scale(0.4) rotate(-30deg); opacity: 0; }
  70% { transform: scale(1.2) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.result-total { font-size: 3rem; font-weight: 900; margin: 4px 0 16px; }
.result-total small { font-size: 1.1rem; color: var(--muted); font-weight: 700; }

.score-rows {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
}
.score-row { display: grid; grid-template-columns: 9.5em 1fr 3.2em; align-items: center; gap: 10px; font-size: 0.9rem; }
.score-row .label { font-weight: 700; }
.score-row .bar { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.score-row .fill { display: block; width: 0; height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.8s ease; }
.score-row .pts { text-align: right; color: var(--muted); font-weight: 700; }

.result-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.result-chip {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 1rem;
}

.level-up {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--card);
  color: var(--card-text);
  font-weight: 800;
  animation: pop 0.5s ease;
}
.level-up[hidden] { display: none; }

.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }

@media (max-width: 360px) {
  .score-row { grid-template-columns: 8em 1fr 3em; font-size: 0.8rem; }
}

/* ---------- M6: install hint, time limit, parent page ---------- */

.install-box {
  display: grid;
  gap: 12px;
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px dashed var(--accent);
  font-size: 0.95rem;
  line-height: 1.45;
}
.install-box[hidden] { display: none; }
.install-box .primary-btn[hidden] { display: none; }

.parent-link {
  display: block;
  margin-top: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}

.time-left {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
}
.time-left[hidden] { display: none; }
.time-left.up { border-color: var(--accent); }

/* PIN pad */
.pin-view { max-width: 320px; margin: 0 auto; text-align: center; }
.pin-view[hidden] { display: none; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 8px 0; min-height: 18px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dot.on { background: var(--text); border-color: var(--text); }
.pin-error { min-height: 1.4em; color: #d33; font-weight: 700; font-size: 0.9rem; margin-bottom: 8px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-key {
  height: 64px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.5rem;
  font-weight: 800;
  cursor: pointer;
}
.pin-key:active { transform: scale(0.96); }
.pin-key.ok { background: var(--accent); color: var(--accent-text); font-size: 1.1rem; }

/* Parent summary */
.parent-children { display: grid; gap: 18px; }
.parent-card {
  padding: 18px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.parent-head { display: flex; align-items: center; gap: 12px; }
.parent-head h2 { margin: 0; }
.parent-avatar { font-size: 2.6rem; line-height: 1; }
.muted { color: var(--muted); font-size: 0.85rem; }
.parent-block { margin-top: 16px; }
.parent-label { font-weight: 800; font-size: 0.9rem; margin-bottom: 8px; }
.parent-card .stats { margin-top: 16px; }
.parent-card .stat { background: var(--bg); }

.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 120px; }
.week-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.week-val { font-size: 0.7rem; color: var(--muted); min-height: 1em; }
.week-track { flex: 1; width: 100%; max-width: 28px; display: flex; align-items: flex-end; background: var(--bg); border-radius: 8px; overflow: hidden; }
.week-bar { width: 100%; background: var(--accent); border-radius: 8px 8px 0 0; }
.week-day { font-size: 0.7rem; color: var(--muted); }

.parent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.parent-list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 0.9rem;
}
.parent-list.mistakes li { flex-direction: column; }
.parent-list .said { color: var(--muted); }
.parent-list .better { font-weight: 700; }

.word-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.word-chip { padding: 6px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 0.85rem; }

.parent-note { margin-top: 20px; color: var(--muted); font-size: 0.8rem; line-height: 1.5; }

/* ---------- Admin: mission editor ---------- */

.admin-link { width: 100%; margin-bottom: 16px; text-decoration: none; }
.admin-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.admin-tab {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.admin-tab.active { border-color: var(--accent); }
.admin-list { display: grid; gap: 10px; }
.admin-level { margin: 14px 0 0; font-size: 1rem; color: var(--muted); }
.admin-mission { width: 100%; font: inherit; text-align: left; cursor: pointer; }

.admin-form { display: grid; gap: 12px; max-height: 92vh; }
.admin-form label { display: grid; gap: 4px; font-weight: 700; font-size: 0.9rem; }
.admin-form input,
.admin-form select,
.admin-form textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}
.admin-form textarea { resize: vertical; }
.admin-form fieldset { display: grid; gap: 12px; margin: 0; padding: 12px; border: 1px dashed var(--border); border-radius: 14px; }
.admin-form fieldset[hidden] { display: none; }
.admin-form legend { font-weight: 800; padding: 0 6px; }
.admin-row { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 8px; }
.admin-image { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; }
.admin-image-preview {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}
.admin-image-preview img { width: 100%; height: 100%; object-fit: cover; }
.admin-image-actions { display: grid; gap: 6px; justify-items: start; }
.admin-image-actions .icon-btn { display: inline-flex; align-items: center; font-size: 0.9rem; }
.admin-actions { display: grid; gap: 8px; }
.admin-actions .secondary-btn { width: 100%; }
.danger-btn {
  min-height: 48px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #d93025;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.admin-views { margin: 8px 0 16px; }
.admin-add { width: 100%; margin-bottom: 12px; }

.login-card {
  display: grid;
  gap: 12px;
  padding: 20px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card label { display: grid; gap: 4px; font-weight: 700; }
.login-card input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
}
.login-card .muted { margin: 0; text-align: center; }
.admin-form label.admin-check { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.admin-form label.admin-check input { width: auto; }
.topbar a.icon-btn { display: inline-flex; align-items: center; text-decoration: none; }

/* ---------- Daily mission, words, memories ---------- */

.daily-card {
  margin: 16px 0 4px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
}
.daily-card.done { opacity: 0.75; }
.daily-label { display: flex; justify-content: space-between; align-items: center; font-weight: 800; margin-bottom: 8px; }
.daily-bonus { font-size: 0.85rem; padding: 2px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.25); }
.daily-mission {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.daily-mission .icon {
  flex: 0 0 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--bg);
  font-size: 1.4rem;
}
.daily-mission .title { font-weight: 800; }
.daily-mission .title-id { color: var(--muted); font-size: 0.9rem; }

.words-link {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.words-quiz-btn { width: 100%; margin: 16px 0 4px; }
.words-hint { text-align: center; margin: 0 0 8px; }
.word-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.word-card {
  position: relative;
  min-height: 110px;
  padding: 14px 10px 10px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: center;
}
.word-card.mastered { border-color: #f5b301; }
.word-en { font-size: 1.25rem; font-weight: 800; word-break: break-word; }
.word-id { color: var(--muted); visibility: hidden; }
.word-card.flipped .word-id { visibility: visible; }
.word-dots { font-size: 0.75rem; color: var(--muted); letter-spacing: 2px; }
.word-card .speak-btn { position: absolute; top: 6px; right: 8px; }
.speak-btn { border: none; background: none; font-size: 1.2rem; cursor: pointer; padding: 4px; }

.quiz-card { text-align: center; }
.quiz-word { font-size: 2rem; font-weight: 800; margin: 8px 0 16px; }
.quiz-options { display: grid; gap: 10px; }
.quiz-option {
  min-height: 52px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.quiz-option.right { border-color: #1e9e5a; background: rgba(30, 158, 90, 0.15); }
.quiz-option.wrong { border-color: #d93025; background: rgba(217, 48, 37, 0.12); }
.quiz-feedback { min-height: 1.5em; margin-top: 12px; font-weight: 800; }
.quiz-question[hidden], .quiz-end[hidden] { display: none; }

.memory-list { display: flex; flex-wrap: wrap; gap: 8px; }
.memory-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.memory-chip button {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
}
.memory-clear { margin-top: 8px; min-height: 36px; font-size: 0.85rem; }

/* ---------- Celebrations, badges, album ---------- */

.confetti-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.confetti {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation-name: confetti-fall;
  animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1);
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  to { transform: translate(var(--drift), 105vh) rotate(var(--spin)); opacity: 0.8; }
}

.toast-stack {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 70;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-weight: 800;
  text-align: center;
  animation: toast-in 0.3s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }

.new-rewards { display: grid; gap: 8px; margin-top: 12px; }
.new-reward {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--bg);
  border: 2px solid #f5b301;
  font-weight: 800;
  text-align: left;
  animation: pop-in 0.5s ease-out both;
}
.new-reward .big { font-size: 1.8rem; }
.new-reward small { display: block; font-weight: 600; color: var(--muted); }
@keyframes pop-in { from { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.05); } }

.home-links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.home-links .words-link { margin: 0; }

.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.album-item {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  padding: 12px 6px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  font-size: 0.75rem;
}
.album-item .big {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  font-size: 2.2rem;
  border-radius: 50%;
  background: var(--bg);
  overflow: hidden;
}
.album-item .big img { width: 100%; height: 100%; object-fit: cover; }
.album-item .name { font-weight: 800; font-size: 0.8rem; }
.album-item .muted { font-size: 0.7rem; }
.album-item.missing .big { filter: grayscale(1); opacity: 0.35; }
.album-item.gold { border: 2px solid #f5b301; }
.album-item.gold .big { box-shadow: 0 0 0 3px #f5b301; }
.album-bar { width: 80%; height: 5px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.album-bar span { display: block; height: 100%; background: var(--accent); }

/* ---------- Kids: dressed-up buddy and garden ---------- */

.buddy { position: relative; display: inline-grid; place-items: center; line-height: 1; }
.buddy-item { position: absolute; pointer-events: none; }
.buddy-head { top: -0.42em; left: 50%; transform: translateX(-50%); font-size: 0.6em; }
.buddy-face { top: 0.18em; left: 50%; transform: translateX(-50%); font-size: 0.42em; }
.buddy-hand { bottom: -0.1em; right: -0.32em; font-size: 0.5em; }

.kids-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.garden-card {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 14px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: center;
  text-decoration: none;
}
.garden-plant { font-size: 3rem; line-height: 1.1; transition: transform 0.4s; }
.garden-card.thirsty .garden-plant { transform: rotate(-12deg) scale(0.9); filter: saturate(0.5); }
.garden-card.fresh .garden-plant { animation: sway 2.8s ease-in-out infinite; }
@keyframes sway { 50% { transform: rotate(5deg); } }
.garden-title { font-weight: 800; font-size: 0.9rem; }
.garden-note { color: var(--muted); font-size: 0.8rem; }
.garden-card .buddy { font-size: 3rem; margin-top: 8px; }

.wardrobe-preview { display: grid; place-items: center; padding: 28px 0 12px; }
.wardrobe-preview .buddy { font-size: 6rem; }
.wardrobe-slot h2 { margin: 18px 0 8px; }
.wardrobe-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.wardrobe-item {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}
.wardrobe-item .big { font-size: 1.9rem; }
.wardrobe-item.selected { border-color: var(--accent); background: var(--bg); }
.wardrobe-item:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Family goal and weekly report ---------- */

.family-card {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--accent);
}
.family-head { font-weight: 800; margin-bottom: 8px; }
.family-text { margin-top: 8px; font-size: 0.9rem; color: var(--muted); }
.family-reward { margin-top: 4px; font-weight: 700; }
.family-form { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; margin-top: 12px; }
.family-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  min-width: 0;
}
.family-form .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.family-form .actions button { flex: 1; min-height: 44px; }
.family-members { margin-top: 10px; display: grid; gap: 4px; font-size: 0.9rem; }
.family-members div { display: flex; justify-content: space-between; }

.report-tabs { margin: 8px 0 12px; }
.report-card { margin-bottom: 12px; }
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.report-grid .stat { background: var(--bg); }
.report-change { font-size: 0.75rem; font-weight: 700; }
.report-change.up { color: #1e9e5a; }
.report-change.down { color: #d93025; }
.report-best {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  font-style: italic;
}
.report-copy { width: 100%; margin-top: 12px; }

/* Elements with the hidden attribute always stay hidden, even when a class sets display. */
[hidden] { display: none !important; }

/* ---------- Login page ---------- */

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, #7cc8ff 0%, #b8e3ff 45%, #fff3d6 100%);
  color: #2b2140;
  overflow-x: hidden;
}
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.cloud { position: absolute; font-size: 4.5rem; opacity: 0.9; animation: drift linear infinite; }
.cloud.c1 { top: 6%; animation-duration: 38s; }
.cloud.c2 { top: 22%; font-size: 3rem; animation-duration: 52s; animation-delay: -20s; }
.cloud.c3 { top: 58%; font-size: 3.6rem; animation-duration: 45s; animation-delay: -32s; opacity: 0.7; }
@keyframes drift { from { transform: translateX(-20vw); } to { transform: translateX(120vw); } }

.float-letter {
  position: absolute;
  bottom: -40px;
  font-family: "Baloo 2", var(--font);
  font-weight: 800;
  font-size: 1.8rem;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 2px 6px rgba(43, 33, 64, 0.15);
  animation: rise linear infinite;
}
.float-letter.l1 { left: 6%; animation-duration: 14s; }
.float-letter.l2 { left: 20%; animation-duration: 18s; animation-delay: -6s; color: #ffd23f; }
.float-letter.l3 { left: 34%; animation-duration: 16s; animation-delay: -10s; }
.float-letter.l4 { left: 52%; animation-duration: 20s; animation-delay: -3s; color: #ff8fab; }
.float-letter.l5 { left: 68%; animation-duration: 15s; animation-delay: -12s; }
.float-letter.l6 { left: 80%; animation-duration: 17s; animation-delay: -8s; font-size: 1.4rem; }
.float-letter.l7 { left: 90%; animation-duration: 21s; animation-delay: -15s; font-size: 1.4rem; }
.float-letter.l8 { left: 44%; animation-duration: 19s; animation-delay: -1s; color: #3bceac; }
@keyframes rise {
  from { transform: translateY(0) rotate(-10deg); opacity: 0; }
  10% { opacity: 1; }
  to { transform: translateY(-110vh) rotate(15deg); opacity: 0; }
}

.login-wrap {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.login-logo { text-align: center; position: relative; }
.login-logo h1 {
  margin: 0;
  font-family: "Baloo 2", var(--font);
  font-weight: 800;
  font-size: 2.6rem;
  line-height: 1.05;
  color: #ffffff;
  text-shadow: 0 3px 0 #ff7a2f, 0 6px 14px rgba(43, 33, 64, 0.2);
  letter-spacing: 0.5px;
}
.login-logo h1 span { color: #ffd23f; }
.login-logo p { margin: 6px 0 0; font-weight: 700; color: #2b4a66; }
.logo-bubble {
  display: inline-block;
  margin-bottom: 4px;
  padding: 4px 14px;
  border-radius: 999px 999px 999px 4px;
  background: #ff7a2f;
  color: #fff;
  font-family: "Baloo 2", var(--font);
  font-weight: 800;
  font-size: 1.1rem;
  animation: wiggle 2.4s ease-in-out infinite;
}
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg) scale(1.08); } }

.crew { position: relative; margin: 16px 0 10px; text-align: center; z-index: 1; }
.crew-bubble {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 18px;
  background: #ffffff;
  color: #2b2140;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(43, 33, 64, 0.15);
  position: relative;
}
.crew-bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #ffffff;
  border-bottom: 0;
}
.crew-bubble.pop { animation: pop-in 0.35s ease-out; }
.crew-row { display: flex; justify-content: center; gap: 18px; margin-top: 10px; }
.crew-char { display: grid; justify-items: center; transition: transform 0.35s ease; }
.crew-face {
  font-size: 3.4rem;
  line-height: 1;
  display: inline-block;
  filter: drop-shadow(0 6px 8px rgba(43, 33, 64, 0.2));
  animation: bob 2.2s ease-in-out infinite;
}
.crew-char:nth-child(2) .crew-face { animation-delay: -0.7s; }
.crew-char:nth-child(3) .crew-face { animation-delay: -1.4s; }
.crew-name { font-size: 0.75rem; font-weight: 800; color: #2b4a66; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(4deg); } }

/* look: lean in towards the form; shy: duck behind the card; cheer: jump; oops: tilt */
.crew.look .crew-char { transform: translateY(4px) scale(1.06); }
.crew.shy .crew-char { transform: translateY(22px) scale(0.85); opacity: 0.55; }
.crew.shy .crew-name { opacity: 0; }
.crew.cheer .crew-face { animation: jump 0.5s ease-in-out infinite; }
.crew.oops .crew-char { transform: rotate(-12deg); }
@keyframes jump { 50% { transform: translateY(-22px) rotate(-8deg); } }

.login-card.fancy {
  box-sizing: border-box;
  width: 100%;
  position: relative;
  z-index: 2;
  padding: 22px 18px 18px;
  border: 3px solid #ffffff;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 16px 40px rgba(43, 74, 102, 0.22);
}
.login-field { display: grid; gap: 6px; }
.login-label { font-weight: 800; color: #2b2140; }
.login-card.fancy input {
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px;
  border: 2px solid #ffe2b8;
  border-radius: 16px;
  background: #fffaf0;
  color: #2b2140;
  font: inherit;
  font-size: 1.05rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.login-card.fancy input:focus { outline: none; border-color: #ff7a2f; box-shadow: 0 0 0 4px rgba(255, 122, 47, 0.18); }
.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 52px; }
.show-pw {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  font-size: 1.3rem;
  padding: 8px;
  cursor: pointer;
}
.login-btn {
  width: 100%;
  min-height: 56px;
  font-size: 1.2rem;
  background: linear-gradient(135deg, #ffb347, #ff6f61);
  color: #fff;
  box-shadow: 0 6px 0 #d9533f, 0 10px 20px rgba(255, 111, 97, 0.3);
  transition: transform 0.1s, box-shadow 0.1s;
}
.login-btn:hover { transform: translateY(-1px); }
.login-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #d9533f, 0 4px 10px rgba(255, 111, 97, 0.3); }
.login-help { text-align: center; margin: 0; }
.login-card.shake { animation: shake 0.45s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.login-page .parent-link { color: #2b4a66; }
.login-page .install-box { margin-top: 16px; box-sizing: border-box; width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .cloud, .float-letter, .logo-bubble, .crew-face { animation: none; }
  .float-letter { display: none; }
}
.login-card.fancy .pin-error { margin: -4px 0 -6px; min-height: 1.2em; text-align: center; }
.family-actions { margin-left: auto; display: flex; gap: 6px; }
.admin-families { margin-top: 24px; }
.account-card { margin-top: 12px; }
.account-card h2 { margin: 0 0 4px; }
.account-show { display: flex !important; align-items: center; gap: 8px; font-weight: 600 !important; }
.account-show input { width: auto; }
.account-ok { padding: 10px 12px; border-radius: 12px; background: rgba(30, 158, 90, 0.12); color: #1e7a48; font-weight: 700; }
.account-logout { width: 100%; margin-top: 16px; }
.topbar-actions { display: flex; gap: 8px; }
.crew-face img { width: 84px; height: 84px; display: block; }
.crew-row { gap: 10px; }

/* ---------- Profile picker ("Siapa yang mau latihan?") ---------- */

.picker .login-logo h1 { font-size: 2.1rem; }
.picker-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 22px; }
.picker-tile {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  padding: 16px 8px 14px;
  border: 3px solid #ffffff;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 24px rgba(43, 74, 102, 0.18);
  color: #2b2140;
  font: inherit;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.picker-tile:hover, .picker-tile:focus-visible { transform: translateY(-3px) scale(1.02); box-shadow: 0 14px 28px rgba(43, 74, 102, 0.25); }
.picker-tile:active { transform: scale(0.97); }
.picker-img { width: 92px; height: 92px; display: block; }
.char-emoji { display: grid; place-items: center; font-size: 4rem; }
.picker-name { font-family: "Baloo 2", var(--font); font-weight: 800; font-size: 1.3rem; line-height: 1.1; }
.picker-sub { font-size: 0.8rem; color: #6b6380; }
.picker-add { border-style: dashed; border-color: #b8d9f2; background: rgba(255, 255, 255, 0.6); }
.picker-plus {
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e8f4ff;
  color: #3aa0ea;
  font-size: 3rem;
  font-weight: 800;
}
.picker-actions { display: grid; gap: 10px; margin-top: 26px; }
.picker-parent, .picker-logout {
  min-height: 50px;
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.picker-parent { display: flex; justify-content: center; gap: 8px; border: 2px solid #ffffff; background: rgba(255, 255, 255, 0.85); color: #2b2140; }
.picker-logout { border: none; background: none; color: #2b4a66; }

.pin-sheet { text-align: center; }
.pin-sheet .admin-form { text-align: left; }
.pin-cancel { width: 100%; margin-top: 12px; text-decoration: none; }
.char-img { width: 100%; height: 100%; object-fit: contain; }
.link-btn { border: none; background: none; padding: 0; color: #ff6f3c; font: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; }
.register-title { margin: 0; font-family: "Baloo 2", var(--font); text-align: center; }

/* ---------- Parent area tabs ---------- */
.parent-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 16px; }
.parent-tabs button {
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
}
.parent-tabs button.active { border-color: var(--accent); background: var(--bg); }
.kid-pic { background: #e8f4ff; padding: 2px; }
.kid-pic img { width: 100%; height: 100%; object-fit: contain; }
.ok-text { color: #1e7a48; }
.account-card label { display: grid; gap: 4px; font-weight: 700; }
.account-card input, .account-card select {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* ---------- Admin console ---------- */
.admin-console-tabs { grid-template-columns: repeat(4, 1fr); }
.pending-note { border: 2px solid #f5b301; color: var(--text); font-weight: 700; margin-bottom: 12px; }
.account-row { align-items: flex-start; }
.account-row.pending { border-color: #f5b301; }
.account-row.off { opacity: 0.6; }
.account-actions { flex-direction: column; align-items: flex-end; }
.account-actions .icon-btn { font-size: 0.8rem; min-height: 36px; padding: 6px 10px; }
.status-pill { padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 800; white-space: nowrap; }
.status-pill.ok { background: rgba(30, 158, 90, 0.15); color: #1e7a48; }
.status-pill.pending { background: rgba(245, 179, 1, 0.2); color: #8a6400; }
.status-pill.off { background: rgba(217, 48, 37, 0.12); color: #b3261e; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.admin-form-check { display: flex !important; align-items: center; gap: 8px; }
.admin-form-check input { width: auto !important; }
.buddy-base img { width: 1.15em; height: 1.15em; display: block; }
.parent-avatar { width: 56px; height: 56px; flex: 0 0 56px; display: grid; place-items: center; }
.parent-avatar .char-img { width: 56px; height: 56px; }
.parent-avatar .char-emoji { font-size: 2.6rem; }
.picker-parent { align-items: center; }
.pin-forgot { display: block; margin: 14px auto 0; font-size: 0.85rem; }

/* ---------- Ambient animations (home and other pages) ---------- */

.ambient { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.ambient + .page, .ambient ~ .page { position: relative; z-index: 1; }
.ambient-item {
  position: absolute;
  bottom: -50px;
  font-family: "Baloo 2", var(--font);
  font-weight: 800;
  color: var(--accent);
  opacity: 0;
  animation: ambient-rise linear infinite;
}
.ambient-kids .ambient-item { --max-opacity: 0.35; }
.ambient-teens .ambient-item { --max-opacity: 0.25; }
.ambient-adult .ambient-item { --max-opacity: 0.16; }
@keyframes ambient-rise {
  from { transform: translateY(0) rotate(-10deg); opacity: 0; }
  10% { opacity: var(--max-opacity, 0.85); }
  85% { opacity: var(--max-opacity, 0.85); }
  to { transform: translateY(-110vh) rotate(15deg); opacity: 0; }
}

/* Hero: floating character with a speech bubble */
.hero { position: relative; overflow: visible; }
.hero .avatar { animation: bob 2.4s ease-in-out infinite; }
.hero-bubble {
  position: absolute;
  top: -14px;
  left: 70px;
  padding: 4px 12px;
  border-radius: 14px 14px 14px 4px;
  background: #ffffff;
  color: #2b2140;
  font-size: 0.85rem;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(43, 33, 64, 0.18);
  white-space: nowrap;
}
.hero-bubble.pop { animation: pop-in 0.35s ease-out; }

/* Cards slide in one after another */
.page.enter > * { animation: fade-up 0.5s ease-out both; }
.page.enter > *:nth-child(2) { animation-delay: 0.05s; }
.page.enter > *:nth-child(3) { animation-delay: 0.1s; }
.page.enter > *:nth-child(4) { animation-delay: 0.15s; }
.page.enter > *:nth-child(5) { animation-delay: 0.2s; }
.page.enter > *:nth-child(6) { animation-delay: 0.25s; }
.page.enter > *:nth-child(7) { animation-delay: 0.3s; }
.page.enter > *:nth-child(8) { animation-delay: 0.35s; }
.page.enter > *:nth-child(9) { animation-delay: 0.4s; }
.page.enter > *:nth-child(n + 10) { animation-delay: 0.45s; }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } }

.mission-list .mission { animation: fade-up 0.45s ease-out both; }
.mission .icon { transition: transform 0.2s; }
.mission:hover .icon, .mission:active .icon { transform: rotate(-8deg) scale(1.1); }
.mission:active { transform: scale(0.98); }

/* Daily mission: soft shine sweeping across */
.daily-card { position: relative; overflow: hidden; }
.daily-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  animation: shine 4.5s ease-in-out infinite;
  pointer-events: none;
}
.daily-card.done::after { display: none; }
@keyframes shine { 0%, 60% { left: -60%; } 100% { left: 130%; } }

.garden-card:hover .garden-plant { transform: scale(1.1) rotate(-4deg); }
.garden-card .buddy { animation: bob 2.6s ease-in-out infinite; animation-delay: -1s; }

/* Profile picker: characters float, tiles pop in */
.picker-tile { animation: pop-in 0.5s ease-out both; }
.picker-tile:nth-child(2) { animation-delay: 0.08s; }
.picker-tile:nth-child(3) { animation-delay: 0.16s; }
.picker-tile:nth-child(4) { animation-delay: 0.24s; }
.picker-tile:nth-child(n + 5) { animation-delay: 0.32s; }
.picker-img { animation: bob 2.4s ease-in-out infinite; }
.picker-tile:nth-child(2) .picker-img { animation-delay: -0.8s; }
.picker-tile:nth-child(3) .picker-img { animation-delay: -1.6s; }
.picker-tile:hover .picker-img { animation-duration: 0.8s; }

@media (prefers-reduced-motion: reduce) {
  .ambient, .hero-bubble.pop, .daily-card::after { display: none; animation: none; }
  .hero .avatar, .page.enter > *, .mission-list .mission, .picker-tile, .picker-img, .garden-card .buddy { animation: none; }
}

/* Keep floating background decorations behind the centered content column (not out on wide screens). */
.ambient, .sky {
  left: 50%;
  right: auto;
  width: min(100%, 640px);
  transform: translateX(-50%);
}
.cloud { animation-name: drift-column; }
@keyframes drift-column { from { left: -25%; } to { left: 105%; } }

/* ---------- Family room ---------- */
.room-members { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.room-member {
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 72px;
  padding: 8px 6px;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  font-size: 0.75rem;
  font-weight: 800;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.room-member.speaking { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255, 122, 47, 0.2); transform: translateY(-2px); }
.room-member.speaking .room-member-pic { animation: bob 1.2s ease-in-out infinite; }
.room-member.offline { opacity: 0.45; }
.room-member.empty { color: var(--muted); border-style: dashed; place-content: center; min-height: 70px; }
.room-member-pic { width: 42px; height: 42px; display: grid; place-items: center; }
.room-member-pic .char-img { width: 42px; height: 42px; }
.room-member-pic .char-emoji { font-size: 2rem; }
.room-member-xp { color: var(--accent); font-size: 0.7rem; }
.room-lobby { padding: 16px; overflow-y: auto; }
.room-modes { display: grid; gap: 10px; margin: 12px 0 18px; }
.room-mode {
  min-height: 54px;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
}
.room-mode.selected { border-color: var(--accent); background: var(--bg); }
.room-start { width: 100%; }
.room-msg-name { font-size: 0.75rem; font-weight: 800; color: var(--muted); padding: 0 6px; }
.room-chat .msg.child:not(.mine) .bubble { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.room-system { align-self: center; font-size: 0.8rem; color: var(--muted); padding: 2px 10px; }
.controls.my-turn .mic-btn { box-shadow: 0 0 0 6px rgba(255, 122, 47, 0.25); }
.room-end { width: auto; padding: 0 12px; font-weight: 800; }
.room-enter-art { font-size: 4rem; }
.home-links.three { grid-template-columns: 1fr 1fr; }
.room-link { justify-content: center; background: var(--accent); color: var(--accent-text); border-color: transparent; }
.room-chat .msg.child:not(.mine) { align-self: flex-start; align-items: flex-start; }

/* ---------- Public rooms ---------- */
.public-rules {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px dashed var(--border);
  font-size: 0.9rem;
}
.public-auto { width: 100%; margin: 16px 0 4px; }
.public-room { align-items: center; }
.public-seats { margin-left: auto; font-weight: 800; color: var(--muted); }
.room-member { position: relative; }
.room-report {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-size: 0.75rem;
  cursor: pointer;
}
.public-link { background: #3aa0ea; }
.room-history-box { margin-top: 24px; }
.room-history-card { margin-bottom: 12px; }
.room-history-card h3 { margin: 0 0 8px; }
.room-history { margin-top: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; background: var(--bg); }
.room-history summary { cursor: pointer; font-weight: 700; }
.room-history-lines { display: grid; gap: 4px; margin-top: 8px; font-size: 0.9rem; }
.room-line.host { color: var(--muted); }
.room-line.mine { background: rgba(255, 122, 47, 0.08); border-radius: 6px; padding: 2px 4px; }
.room-line-flag { color: #b3261e; font-size: 0.8rem; }
.room-limit { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; margin-bottom: 12px; }
.room-limit label { display: grid; gap: 4px; font-weight: 700; }
.room-limit input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); font: inherit; }
.room-limit .muted { grid-column: 1 / -1; }

/* Bilingual coach: sentence to say back. */
.repeat-card {
  align-self: stretch; margin: 0; width: 100%; box-sizing: border-box;
  padding: 10px 44px 10px 12px; border-radius: 14px; position: relative;
  background: var(--surface); color: var(--text); border: 2px dashed var(--accent);
}
.repeat-label { font-size: 0.8rem; color: var(--muted); }
.repeat-text { font-weight: 800; font-size: 1.1rem; color: var(--text); }
.repeat-card .mini-replay { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }
.mini-replay {
  border: 0; background: transparent; font-size: 1.1rem; cursor: pointer; padding: 2px 6px; margin-left: 4px;
}

/* Parent area: short hint under a form field. */
.small-note { font-size: 0.85rem; margin: -4px 0 6px; }

/* ---------- Home: the three group rooms in one row ---------- */
.home-links.room-links { grid-template-columns: repeat(3, 1fr); }
.room-links .room-link { flex-direction: column; gap: 2px; text-align: center; font-size: 0.85rem; padding: 10px 4px; }
.room-links .room-link span { line-height: 1.15; }
.friends-link { background: #2fb67a; }

/* ---------- Video call (family / friends rooms) ---------- */
.video-bar { display: flex; gap: 8px; padding: 6px 12px; flex-wrap: wrap; }
.video-btn {
  border: 2px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 6px 12px; font: inherit; font-weight: 800; font-size: 0.9rem; cursor: pointer;
}
.video-btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.video-btn.off { opacity: 0.6; }
.video-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 0 12px 6px; }
.video-grid[data-count="1"] { grid-template-columns: minmax(0, 160px); }
.video-tile { position: relative; aspect-ratio: 4 / 3; background: #1d1830; border-radius: 12px; overflow: hidden; }
.video-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-tile.me video { transform: scaleX(-1); } /* mirror like a selfie */
.video-name {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 0.75rem; font-weight: 700;
}

/* ---------- Friends ---------- */
.friend-avatar { width: 100%; height: 100%; object-fit: contain; }
.invite-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px dashed var(--border); }
.invite-code { font-family: ui-monospace, Consolas, monospace; font-size: 1.3rem; font-weight: 800; letter-spacing: 2px; }
.small-btn { width: auto; padding: 6px 10px; font-size: 0.85rem; }
.center-note { text-align: center; margin: -4px 0 12px; }

/* ---------- Who is online (home room buttons) ---------- */
.room-live { display: block; font-size: 0.7rem; font-weight: 700; opacity: 0.9; min-height: 1em; }
.room-link.has-people { animation: room-pulse 2.4s ease-in-out infinite; }
@keyframes room-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
  50% { box-shadow: 0 0 0 5px rgba(47, 182, 122, 0.35); }
}
@media (prefers-reduced-motion: reduce) { .room-link.has-people { animation: none; } }

/* ---------- Room type colours inside a room ---------- */
.room-badge { font-size: 0.72rem; font-weight: 800; padding: 1px 8px; border-radius: 999px; display: inline-block; margin-top: 2px; }
body[data-room-kind="family"] .room-badge { background: #ffe8d6; color: #b4531a; }
body[data-room-kind="friends"] .room-badge { background: #d8f5e7; color: #1b7a50; }
body[data-room-kind="public"] .room-badge { background: #dcecff; color: #1f5fa8; }
body[data-room-kind="family"] .talk-header { box-shadow: inset 0 -4px 0 #ff7a2f; }
body[data-room-kind="friends"] .talk-header { box-shadow: inset 0 -4px 0 #2fb67a; }
body[data-room-kind="public"] .talk-header { box-shadow: inset 0 -4px 0 #3b8fe8; }
.check-row { display: flex !important; align-items: center; gap: 8px; font-weight: 700; }
.check-row input { width: 20px; height: 20px; }

/* Admin check mode */
.preview-banner {
  margin: 0 0 12px; padding: 8px 12px; border-radius: 12px; font-size: 0.8rem; font-weight: 700;
  background: #fff4c2; color: #6b5200; border: 1px dashed #e0b400;
}
.self-accept { display: grid; gap: 8px; margin-top: 12px; }
.self-accept label { display: grid; gap: 4px; font-weight: 700; }

/* ---------- Membership + vouchers ---------- */
.membership-line.expired { color: #c0392b; font-weight: 800; }
.membership-box { border: 1px dashed var(--border); border-radius: 14px; padding: 10px; display: grid; gap: 8px; }
.membership-head { font-weight: 800; }
.membership-text { font-weight: 700; }
.membership-add, .membership-date, .voucher-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.membership-date input { padding: 6px 8px; border-radius: 10px; border: 1px solid var(--border); font: inherit; }
.membership-history { display: grid; gap: 2px; font-size: 0.8rem; }
.registration-rule { margin: 12px 0; }
.voucher-row.used, .voucher-row.expired, .voucher-row.revoked { opacity: 0.7; }
.membership-banner {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 14px; font-weight: 700; font-size: 0.9rem;
  background: #fff4c2; color: #6b5200; border: 1px dashed #e0b400;
}
.membership-banner.expired { background: #ffe1dc; color: #8a2414; border-color: #e06a50; }
.membership-banner form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.membership-banner input { flex: 1; min-width: 140px; padding: 8px 10px; border-radius: 10px; border: 1px solid #d9c27a; font: inherit; }
.lock-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 14, 40, 0.75);
}
.lock-card { background: var(--surface); color: var(--text); border-radius: 22px; padding: 24px; max-width: 360px; text-align: center; display: grid; gap: 10px; }
.lock-card .big { font-size: 3rem; }
.voucher-info { font-size: 0.85rem; font-weight: 700; min-height: 1em; margin: -4px 0 6px; }
.voucher-info.ok { color: #1e7a48; }
.voucher-info.bad { color: #c0392b; }
.brand-tag { margin: -6px 0 4px; font-size: 0.8rem; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; opacity: 0.85; }
