/* ============================================================
   KID CLAUD design system
   Themes set CSS variables on <body class="theme-*">; every
   component below only reads variables, never theme names.
   ============================================================ */

* { box-sizing: border-box; }

:root {
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-card: 0 10px 30px rgba(20, 20, 60, 0.18);
  --shadow-pop: 0 4px 0 rgba(0, 0, 0, 0.12);
}

/* ---------- themes ---------- */
body.theme-space {
  --bg-gradient: linear-gradient(160deg, #1b1f5e 0%, #372a7a 45%, #6b3fa0 100%);
  --on-bg: #ffffff;
  --card-bg: rgba(255, 255, 255, 0.94);
  --accent: #7c5ce0;
  --accent-2: #38c8b4;
  --fun: linear-gradient(135deg, #7c5ce0, #b06ab3);
  --text: #26224a;
  --muted: #8a87a8;
  --danger: #ff5d73;
  --gold: #ffcf5c;
}
body.theme-ocean {
  --bg-gradient: linear-gradient(165deg, #0077b6 0%, #0096c7 40%, #48cae4 100%);
  --on-bg: #ffffff;
  --card-bg: rgba(255, 255, 255, 0.94);
  --accent: #0077b6;
  --accent-2: #ff8fab;
  --fun: linear-gradient(135deg, #0096c7, #00b4d8);
  --text: #103954;
  --muted: #7a97a8;
  --danger: #ef476f;
  --gold: #ffd166;
}
body.theme-jungle {
  --bg-gradient: linear-gradient(160deg, #24632e 0%, #3f8f3f 45%, #8ac926 100%);
  --on-bg: #ffffff;
  --card-bg: rgba(255, 255, 255, 0.94);
  --accent: #2f7a35;
  --accent-2: #ff9f1c;
  --fun: linear-gradient(135deg, #3f8f3f, #6fbf3f);
  --text: #1e3d22;
  --muted: #7f9a82;
  --danger: #e5484d;
  --gold: #ffca3a;
}
body.theme-candy {
  --bg-gradient: linear-gradient(160deg, #ff8fb1 0%, #ffb3c6 45%, #ffd6e8 100%);
  --on-bg: #7a2948;
  --card-bg: rgba(255, 255, 255, 0.95);
  --accent: #e94f8a;
  --accent-2: #7c5ce0;
  --fun: linear-gradient(135deg, #ff6f91, #e94f8a);
  --text: #5a2140;
  --muted: #b58aa0;
  --danger: #d90452;
  --gold: #ffb703;
}

/* ---------- base ---------- */
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  /* The gradient lives on the fixed #bg-layer, not the body:
     background-attachment: fixed forces expensive full-page repaints and
     drops layers on some GPUs (board/robot were vanishing). */
  background: none;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

#app { flex: 1; max-width: 520px; margin: 0 auto; padding: 14px 16px 8px; width: 100%; position: relative; z-index: 1; }

.demo-disclaimer {
  font-size: 10.5px; color: var(--on-bg); opacity: 0.75; text-align: center;
  padding: 8px 16px 14px; max-width: 520px; margin: 0 auto; position: relative; z-index: 1;
}

.boot-splash {
  color: var(--on-bg); text-align: center; font-size: 20px; font-weight: 600; padding-top: 30vh;
}
.dots::after { content: '...'; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- animated background layer ---------- */
#bg-layer {
  position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0;
  background: var(--bg-gradient);
  transition: background 0.5s ease;
}
.bg-bit {
  position: absolute; bottom: -12vh; will-change: transform, opacity;
  animation: floatUp linear infinite; opacity: 0;
}
@keyframes floatUp {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  8%   { opacity: 0.85; }
  92%  { opacity: 0.85; }
  100% { transform: translateY(-118vh) rotate(28deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .bg-bit { display: none; }
  * { animation-duration: 0.001s !important; }
}

/* ---------- cards & headings ---------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.card h2 { margin: 0 0 10px; font-size: 21px; font-weight: 700; }
.card h3 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }

.page-title {
  color: var(--on-bg); font-size: 24px; font-weight: 700; margin: 4px 2px 12px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

/* ---------- nav ---------- */
.top-nav {
  display: flex; gap: 4px; align-items: center;
  background: rgba(255,255,255,0.25);
  border-radius: 999px; padding: 6px; margin: 4px 0 16px;
}
.top-nav button {
  flex: 1; border: none; background: transparent; padding: 9px 4px; border-radius: 999px;
  cursor: pointer; font-size: 13.5px; font-weight: 600; font-family: inherit;
  color: var(--on-bg); transition: transform 0.12s ease, background 0.2s ease;
  white-space: nowrap;
}
.top-nav button:active { transform: scale(0.94); }
.top-nav button.active { background: var(--card-bg); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.top-nav .theme-btn { flex: 0 0 auto; font-size: 18px; padding: 7px 11px; }

/* ---------- buttons ---------- */
button.primary, button.secondary {
  border: none; border-radius: 999px; padding: 12px 22px; cursor: pointer;
  font-size: 15px; font-weight: 700; font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s ease;
  box-shadow: var(--shadow-pop);
}
button.primary { background: var(--fun); color: #fff; }
button.secondary { background: #fff; color: var(--accent); border: 2.5px solid var(--accent); }
button.primary:active, button.secondary:active { transform: translateY(2px) scale(0.97); box-shadow: 0 1px 0 rgba(0,0,0,0.12); }
button.primary:hover, button.secondary:hover { filter: brightness(1.06); }
button:disabled { opacity: 0.45; cursor: default; filter: grayscale(0.4); }

/* ---------- band picker ---------- */
.band-hero { text-align: center; padding-top: 4vh; }
.band-hero .robot-slot { animation: bob 3.2s ease-in-out infinite; display: inline-block; }
.band-hero h1 { color: var(--on-bg); font-size: 30px; margin: 8px 0 2px; text-shadow: 0 2px 10px rgba(0,0,0,0.3); }
.band-hero p { color: var(--on-bg); opacity: 0.9; margin: 0 0 20px; font-size: 15.5px; }
.band-picker { display: flex; flex-direction: column; gap: 12px; }
.band-option {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--card-bg); border: none; border-radius: var(--radius-lg);
  padding: 16px 18px; cursor: pointer; font-family: inherit;
  box-shadow: var(--shadow-card); transition: transform 0.15s ease;
}
.band-option:hover { transform: translateY(-3px) scale(1.015); }
.band-option:active { transform: scale(0.97); }
.band-option .band-emoji { font-size: 34px; }
.band-option .band-name { font-size: 18px; font-weight: 700; color: var(--text); }
.band-option .band-desc { font-size: 13px; color: var(--muted); }

/* ---------- home ---------- */
.kidclaud-greeting { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.kidclaud-greeting .robot-slot { animation: bob 3.2s ease-in-out infinite; }
.greeting-name { font-weight: 700; font-size: 18px; color: var(--on-bg); text-shadow: 0 1px 6px rgba(0,0,0,0.25); }
.greeting-sub { font-size: 13.5px; color: var(--on-bg); opacity: 0.88; }
.robot-slot svg { width: 72px; height: 72px; display: block; margin: 0 auto; }
.kidclaud-greeting .robot-slot svg { margin: 0; }

.world-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 6px 0 14px; }
.world-tile {
  border: none; border-radius: var(--radius-lg); padding: 16px 14px; text-align: left;
  font-family: inherit; font-weight: 700; font-size: 15px; color: #fff; cursor: pointer;
  box-shadow: var(--shadow-card); transition: transform 0.15s ease;
  display: flex; flex-direction: column; gap: 4px; min-height: 96px; justify-content: center;
}
.world-tile .tile-emoji { font-size: 30px; line-height: 1; }
.world-tile .sub { font-weight: 500; font-size: 12px; opacity: 0.92; }
.world-tile:not(:disabled):hover { transform: translateY(-3px) rotate(-0.5deg) scale(1.02); }
.world-tile:not(:disabled):active { transform: scale(0.96); }
.world-tile:disabled { cursor: default; filter: saturate(0.35) opacity(0.75); }
.tile-circuit { background: linear-gradient(135deg, #f7b733, #fc4a1a); }
.tile-games   { background: linear-gradient(135deg, #36d1dc, #5b86e5); }
.tile-studio  { background: linear-gradient(135deg, #b06ab3, #7c5ce0); }
.tile-soon    { background: linear-gradient(135deg, #9aa2b5, #6c7383); }

/* ---------- chat ---------- */
.chat-log { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; margin-bottom: 12px; }
.chat-line { padding: 10px 14px; border-radius: 18px; max-width: 86%; font-size: 14.5px; line-height: 1.45; animation: popIn 0.25s ease; }
.chat-line.child { align-self: flex-end; background: var(--fun); color: #fff; border-bottom-right-radius: 6px; }
.chat-line.kidclaud { align-self: flex-start; background: #f1eefc; color: var(--text); border-bottom-left-radius: 6px; }

.mic-button {
  width: 84px; height: 84px; border-radius: 50%; border: none;
  background: var(--fun); color: #fff; font-size: 34px; cursor: pointer;
  display: block; margin: 14px auto 6px; position: relative;
  box-shadow: 0 8px 22px rgba(0,0,0,0.28); transition: transform 0.15s ease;
}
.mic-button:active { transform: scale(0.92); }
.mic-button.listening { background: linear-gradient(135deg, #ff5d73, #ff8e53); animation: micPulse 1.1s ease-in-out infinite; }
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 93, 115, 0.55); }
  50%      { box-shadow: 0 0 0 18px rgba(255, 93, 115, 0); }
}

.text-input {
  width: 100%; padding: 12px 16px; border-radius: 999px; border: 2.5px solid #e6e1f5;
  font-size: 15px; font-family: inherit; color: var(--text); outline: none;
  transition: border-color 0.2s ease;
}
.text-input:focus { border-color: var(--accent); }

/* ---------- game hub ---------- */
.game-card {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  background: var(--card-bg); border: none; border-radius: var(--radius-lg);
  padding: 18px; margin-bottom: 12px; cursor: pointer; font-family: inherit;
  box-shadow: var(--shadow-card); transition: transform 0.15s ease;
}
.game-card:hover { transform: translateY(-3px) scale(1.01); }
.game-card:active { transform: scale(0.97); }
.game-card .game-emoji { font-size: 40px; }
.game-card .game-name { font-size: 18px; font-weight: 700; color: var(--text); }
.game-card .game-desc { font-size: 13px; color: var(--muted); }

.back-link {
  background: none; border: none; color: var(--on-bg); font-family: inherit; font-weight: 600;
  font-size: 14px; cursor: pointer; padding: 4px 2px; margin-bottom: 6px; opacity: 0.9;
}

/* ---------- tic-tac-toe ---------- */
.ttt-board {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; max-width: 310px;
  margin: 14px auto; background: var(--fun); padding: 12px; border-radius: 20px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.18);
}
.ttt-cell {
  aspect-ratio: 1; background: #ffffff; border-radius: var(--radius-md); border: none;
  font-size: 40px; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  transition: transform 0.12s ease, background 0.2s ease;
}
.ttt-cell:not(:disabled):hover { background: #f3edff; }
.ttt-cell:active { transform: scale(0.94); }
.ttt-cell .mark { animation: markPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); display: block; }
.ttt-cell.win-cell { background: var(--gold); animation: winFlash 0.6s ease 3; }
@keyframes markPop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
@keyframes winFlash { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.35); } }
.score-row { display: flex; justify-content: center; gap: 18px; font-weight: 700; font-size: 14.5px; margin-top: 4px; }
.think-bubble {
  background: #fff8e1; border-radius: var(--radius-md); padding: 10px 14px;
  font-size: 13.5px; color: #7a6520; margin-top: 10px; animation: popIn 0.25s ease;
}

/* ---------- word rescue ---------- */
.balloon-row { display: flex; justify-content: center; gap: 6px; font-size: 26px; min-height: 34px; }
.balloon { display: inline-block; animation: bob 2.6s ease-in-out infinite; }
.balloon.popped { animation: popAway 0.45s ease forwards; }
@keyframes popAway { 0% { transform: scale(1); opacity: 1; } 40% { transform: scale(1.5); } 100% { transform: scale(0); opacity: 0; } }
.word-slots { display: flex; justify-content: center; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.word-slot {
  width: 38px; height: 46px; border-bottom: 4px solid var(--accent); font-size: 28px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.word-slot.revealed { animation: markPop 0.3s ease; }
.letter-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 12px; }
.letter-key {
  aspect-ratio: 1; border: none; border-radius: 10px; background: #f4f1fd; font-family: inherit;
  font-size: 16px; font-weight: 700; color: var(--text); cursor: pointer; transition: transform 0.1s ease;
}
.letter-key:not(:disabled):hover { background: #e9e3fb; }
.letter-key:active { transform: scale(0.9); }
.letter-key.hit { background: #b8ecc9; color: #1c6b3a; }
.letter-key.miss { background: #ffd4dc; color: #a1233d; }
.hint-chip {
  display: inline-block; background: #fff3cd; color: #7a6520; border-radius: 999px;
  padding: 5px 14px; font-size: 13.5px; font-weight: 600;
}

/* ---------- star catcher ---------- */
.catcher-wrap { position: relative; }
.catcher-canvas { width: 100%; border-radius: var(--radius-md); display: block; touch-action: none; background: #101638; }
.catcher-hud { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 15px; margin: 8px 2px; }
.touch-controls { display: flex; gap: 10px; margin-top: 8px; }
.touch-controls button {
  flex: 1; font-size: 24px; padding: 12px; border: none; border-radius: var(--radius-md);
  background: #f4f1fd; cursor: pointer; font-family: inherit; transition: transform 0.1s ease;
}
.touch-controls button:active { transform: scale(0.94); background: #e9e3fb; }
.param-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.param-chip {
  background: #f4f1fd; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
  color: var(--text);
}
.param-chip.changed { animation: chipGlow 1s ease 2; }
@keyframes chipGlow { 0%, 100% { background: #f4f1fd; } 50% { background: var(--gold); transform: scale(1.08); } }

/* ---------- circuit city (matching game) ---------- */
.match-stats { display: flex; justify-content: space-between; font-weight: 700; font-size: 14.5px; margin-bottom: 10px; }
.match-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.match-card {
  aspect-ratio: 3 / 3.6; border: none; border-radius: var(--radius-md); cursor: pointer;
  font-family: inherit; padding: 4px; background: var(--fun);
  box-shadow: 0 3px 6px rgba(0,0,0,0.2); transition: transform 0.15s ease;
  display: flex; align-items: center; justify-content: center;
}
.match-card:not(.flipped):hover { transform: translateY(-2px) scale(1.03); }
.match-card:active { transform: scale(0.94); }
.match-card .match-back {
  color: #fff; font-size: 30px; font-weight: 700; text-shadow: 0 2px 4px rgba(0,0,0,0.25);
}
.match-card.flipped { background: #ffffff; cursor: default; }
.match-card .match-face {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  animation: markPop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1); width: 100%;
}
.match-card .match-face svg { width: 82%; height: auto; }
.match-card .match-name { font-size: 10.5px; font-weight: 700; color: var(--text); text-align: center; line-height: 1.1; }
.match-card.matched { outline: 3px solid #3fb950; outline-offset: -3px; }
.match-card.wrong { animation: shake 0.4s ease; outline: 3px solid var(--danger); outline-offset: -3px; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); }
}

.detail-sheet {
  background: var(--card-bg); border-radius: var(--radius-lg); padding: 20px;
  width: min(440px, 92vw); max-height: 86vh; overflow-y: auto; animation: popIn 0.25s ease;
}
.detail-sheet h2 { margin: 0 0 2px; font-size: 22px; }
.detail-tagline { margin: 0 0 12px; color: var(--muted); font-weight: 600; font-size: 14.5px; }
.detail-images { display: flex; gap: 12px; justify-content: center; margin-bottom: 12px; }
.detail-image {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #f4f1fd; border-radius: var(--radius-md); padding: 10px; flex: 1; max-width: 170px;
}
.detail-image svg { width: 100%; max-width: 130px; height: auto; }
.detail-image-label { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; }
.detail-facts { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 7px; }
.detail-facts li { font-size: 14px; line-height: 1.45; }

/* ---------- dashboard ---------- */
.alert-row { border-left: 5px solid var(--muted); padding: 9px 12px; margin-bottom: 7px; border-radius: 10px; background: #f7f5fd; font-size: 13.5px; }
.alert-row.priority { border-color: var(--danger); background: #fdf0f3; }
.alert-row.notable { border-color: #e0a323; background: #fdf8ec; }
.alert-row.progress { border-color: var(--accent-2); }
.rule-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1.5px solid #efeaf8; font-size: 14.5px; }
.rule-row input[type='number'] { font-family: inherit; font-size: 15px; padding: 6px 10px; border-radius: 10px; border: 2px solid #e6e1f5; width: 72px; }
.rule-row input[type='checkbox'] { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- theme picker overlay ---------- */
.theme-overlay {
  position: fixed; inset: 0; background: rgba(15, 12, 40, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; animation: popIn 0.2s ease;
}
.theme-sheet { background: var(--card-bg); border-radius: var(--radius-lg); padding: 20px; width: min(420px, 90vw); }
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.theme-tile {
  border: 3px solid transparent; border-radius: var(--radius-md); padding: 14px; cursor: pointer;
  font-family: inherit; text-align: center; color: #fff; font-weight: 700; font-size: 15px;
  transition: transform 0.15s ease;
}
.theme-tile:hover { transform: scale(1.04); }
.theme-tile.selected { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 207, 92, 0.4); }
.theme-tile .theme-emoji { font-size: 30px; display: block; }

/* ---------- shared animations ---------- */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes popIn { 0% { transform: scale(0.85); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.confetti-bit {
  position: fixed; top: -5vh; z-index: 100; pointer-events: none; will-change: transform;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(112vh) rotate(540deg); opacity: 0.7; }
}

.status-line { text-align: center; font-size: 13px; color: var(--muted); min-height: 18px; }
