/* Rekenboog — iPad-first (portrait + landscape), iPhone fallback. Touch-first with
   large tap targets; four themes via body[data-theme]. */

:root {
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  --font: "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, "Helvetica Neue",
    Arial, sans-serif;
}

* { box-sizing: border-box; }

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

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

/* --- themes ---------------------------------------------------------------- */

body[data-theme="race"] {
  --bg: linear-gradient(160deg, #fff5f0, #ffe0d0);
  --text: #3a1f14;
  --accent: #e11d48;
  --accent-2: #f97316;
  --panel: #ffffff;
  --card: #fff7f2;
  --card-border: #fecdd3;
}

body[data-theme="dino"] {
  --bg: linear-gradient(160deg, #f0fdf4, #dcfce7);
  --text: #14361f;
  --accent: #15803d;
  --accent-2: #65a30d;
  --panel: #ffffff;
  --card: #f0fdf4;
  --card-border: #bbf7d0;
}

body[data-theme="princess"] {
  --bg: linear-gradient(160deg, #fdf2f8, #fce7f3);
  --text: #4a1d3a;
  --accent: #db2777;
  --accent-2: #a855f7;
  --panel: #ffffff;
  --card: #fdf2f8;
  --card-border: #fbcfe8;
}

body[data-theme="unicorn"] {
  --bg: linear-gradient(160deg, #f5f3ff, #e0f2fe, #fce7f3);
  --text: #2e1a47;
  --accent: #7c3aed;
  --accent-2: #06b6d4;
  --panel: #ffffff;
  --card: #faf5ff;
  --card-border: #ddd6fe;
}

/* --- layout ---------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand { font-size: 1.5rem; font-weight: 800; }

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

.coins {
  background: #fef3c7;
  color: #92400e;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 1.05rem;
}

.whoami { font-weight: 700; }

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px calc(40px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }
.muted { color: #6b7280; font-weight: 500; }

/* --- panels & buttons ------------------------------------------------------ */

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 22px;
}

.panel-title { margin: 0 0 16px; font-size: 1.3rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 12px 24px;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); }
.btn-ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 2px var(--card-border); }
.btn-admin { background: var(--accent-2); }
.btn-danger {
  background: #fff;
  color: var(--accent);
  min-height: 44px;
  min-width: 44px;
  padding: 6px 12px;
  font-size: 1.1rem;
  box-shadow: inset 0 0 0 2px var(--card-border);
}

/* --- celebration (full-screen emoji snow) ----------------------------------- */

.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}
.snow {
  position: absolute;
  top: -3rem;
  animation: snow-fall linear forwards;
  opacity: 0.92;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
}
@keyframes snow-fall {
  from { transform: translateY(-3rem) rotate(0deg); }
  to { transform: translateY(110vh) rotate(360deg); }
}

/* --- gate (login) ---------------------------------------------------------- */

.gate { text-align: center; }
.gate-title { font-size: 2.2rem; margin: 8px 0 24px; }

.kid-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kid-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 12px;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  position: relative;
  transition: transform 0.08s ease;
}
.kid-card:active { transform: scale(0.95); }
.kid-avatar { font-size: 3rem; }
.kid-pin { position: absolute; top: 10px; right: 12px; font-size: 1rem; }

.admin-panel { margin: 16px auto; max-width: 360px; }

/* --- forms ----------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 12px; }
.form input, .form select {
  min-height: 52px;
  padding: 0 16px;
  font: inherit;
  font-size: 1.1rem;
  border: 2px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
}
.form-error { color: var(--accent); font-weight: 700; min-height: 1.2em; }

.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-opt {
  font-size: 1.6rem;
  width: 52px; height: 52px;
  border: 2px solid var(--card-border);
  border-radius: 50%;
  background: var(--card);
  cursor: pointer;
}
.avatar-opt.selected { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent); }

/* --- grids ----------------------------------------------------------------- */

.theme-grid, .game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.theme-card, .game-card, .level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 12px;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.theme-card:active, .game-card:active, .level-card:active { transform: scale(0.96); }

.theme-icon, .game-icon { font-size: 2.4rem; }
.game-desc { font-size: 0.85rem; font-weight: 600; color: #6b7280; }
.level-num { font-size: 1.8rem; color: var(--accent); }
.game-card.locked { opacity: 0.55; cursor: default; }
.soon {
  font-size: 0.7rem; font-weight: 800; color: #fff;
  background: var(--accent-2); padding: 2px 10px; border-radius: 999px;
}

/* --- level stepper + suggestion -------------------------------------------- */

.level-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.stepper { min-width: 64px; font-size: 1.6rem; }
.stepper:disabled { opacity: 0.3; cursor: default; }
.level-now {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 200px;
}
.level-now .level-num { font-size: 2.4rem; line-height: 1; }
.level-now .level-name { font-weight: 800; }
.level-hint { text-align: center; margin: 10px 0 0; }
.suggestion { margin-top: 14px; display: flex; justify-content: center; }
.suggestion-btn { width: 100%; max-width: 380px; }
.result-suggestion { font-weight: 800; font-size: 1.2rem; margin: 14px 0; }

/* --- game shared ----------------------------------------------------------- */

.game-wrap { min-height: 60vh; }
.game-hud { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.game-hint { text-align: center; font-weight: 700; color: #6b7280; }

.combo {
  font-weight: 800;
  font-size: 1.15rem;
  color: #f59e0b;
  min-width: 64px;
  text-align: center;
  transition: transform 0.15s ease;
}
.combo.lit { transform: scale(1.12); text-shadow: 0 0 8px rgba(245, 158, 11, 0.6); }

.timer { display: flex; align-items: center; gap: 7px; }
.timer-bar {
  position: relative;
  width: 76px;
  height: 10px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}
.timer-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  border-radius: 999px;
  background: #22c55e;
  transition: background 0.2s ease;
}
.timer.mid .timer-fill { background: #f59e0b; }
.timer.slow .timer-fill { background: #ef4444; }
.timer-label {
  font-weight: 800;
  font-size: 0.9rem;
  min-width: 22px;
  text-align: center;
  color: #16a34a;
}
.timer.mid .timer-label { color: #d97706; }
.timer.slow .timer-label { color: #dc2626; }

.match-clock { font-weight: 700; color: #6b7280; font-variant-numeric: tabular-nums; }

/* --- match ----------------------------------------------------------------- */

.match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.match-col { display: flex; flex-direction: column; gap: 12px; }

.card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 72px;
  padding: 12px;
  background: var(--card);
  border: 3px solid var(--card-border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
  position: relative;
}
.card-left { flex-wrap: wrap; }
.card-right { font-size: 1.7rem; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent); }
.card.matched { border-color: var(--accent-2); background: #ecfdf5; animation: pop 0.3s ease; }
.card.wrong { border-color: var(--accent); animation: shake 0.4s ease; }
.card.dragging { opacity: 0.9; width: 130px; transform-origin: top left; z-index: 50; }

@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.sparkle {
  position: absolute;
  font-size: 1.3rem;
  pointer-events: none;
  animation: sparkle 0.9s ease forwards;
}
@keyframes sparkle {
  0% { transform: translateY(0) scale(0.6); opacity: 1; }
  100% { transform: translateY(-34px) scale(1.4); opacity: 0; }
}

/* dots ---------------------------------------------------------------------- */

.dots { display: flex; gap: 8px; }
.dot-group { display: flex; flex-direction: column; gap: 4px; }
.dot-row { display: flex; gap: 5px; }
.dot { width: 16px; height: 16px; border-radius: 50%; background: transparent; }
.dot.on { background: var(--accent); }

.prompt { font-size: 1.5rem; }

/* --- adventure -------------------------------------------------------------- */

.jungle {
  position: relative;
  height: 130px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #aee3ff 0%, #bfe9b8 55%, #7dd38a 78%, #3f8f4f 100%);
  overflow: hidden;
  margin-bottom: 16px;
}
.jungle::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 18px;
  background: #3f8f4f;
}
.runner {
  position: absolute;
  right: 60px;
  bottom: 12px;
  font-size: 3rem;
  z-index: 2;
  animation: run 1.1s ease-in-out infinite;
}
.runner.jump { animation: jump 0.5s ease; }
@keyframes run {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
@keyframes jump {
  0% { transform: translateY(0) rotate(0); }
  40% { transform: translateY(-26px) rotate(-10deg); }
  100% { transform: translateY(0) rotate(0); }
}
.obstacle {
  position: absolute;
  left: -60px;
  bottom: 14px;
  font-size: 2.4rem;
  z-index: 1;
  animation: obstacle-run linear infinite;
}
@keyframes obstacle-run {
  from { left: -60px; }
  to { left: 100%; }
}

.hearts { font-size: 1.5rem; letter-spacing: 2px; }
.adv-score { font-weight: 800; font-size: 1.2rem; }

.adv-question {
  min-height: 120px;
  margin-bottom: 16px;
  cursor: default;
}
.adv-options { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.btn-option {
  flex: 1 1 140px;
  max-width: 220px;
  background: var(--accent-2);
}

.feedback {
  position: absolute;
  right: 12px;
  top: 8px;
  font-size: 1.4rem;
  font-weight: 800;
  animation: floatUp 0.7s ease forwards;
}
.feedback.good { color: #14532d; }
.feedback.bad { color: #7f1d1d; }
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-30px); } }

.damage { animation: damageFlash 0.35s ease; }
@keyframes damageFlash { 0%, 100% { filter: none; } 50% { filter: sepia(0.6) saturate(3) hue-rotate(-40deg); } }

.adv-end { text-align: center; font-size: 1.6rem; }

/* --- cannon ----------------------------------------------------------------- */

.cannon-question {
  min-height: 110px;
  margin-bottom: 12px;
  cursor: default;
}
.cannon-stage {
  position: relative;
  height: 210px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #dbeafe, #fef3c7);
  overflow: hidden;
}
.cannon {
  position: absolute;
  bottom: 6px;
  left: 6px;
  font-size: 2.6rem;
  transform: rotate(-20deg);
}
.ball {
  position: absolute;
  bottom: 22px;
  min-width: 60px;
  height: 60px;
  padding: 0 10px;
  border-radius: 50%;
  background: var(--accent-2);
  color: #fff;
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  font: inherit;
  font-weight: 800;
  font-size: 1.35rem;
  cursor: pointer;
  animation: cannon-fly 1.3s cubic-bezier(0.1, 0.8, 0.4, 1) both;
  animation-delay: var(--delay);
}
.ball.hit {
  background: #16a34a;
  animation: pop 0.3s ease;
}
.ball.miss {
  background: var(--accent);
  animation: shake 0.4s ease;
}
@keyframes cannon-fly {
  0% { transform: translate(var(--dx), -130px) scale(0.5); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(0, 0) scale(1); }
}

/* --- result ----------------------------------------------------------------- */

.result { text-align: center; }
.result-title { font-size: 2rem; }
.result-stats { display: flex; justify-content: center; gap: 18px; margin: 24px 0; flex-wrap: wrap; }
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--card); border: 3px solid var(--card-border);
  border-radius: var(--radius); padding: 18px 26px; min-width: 120px;
}
.stat-num { font-size: 2rem; font-weight: 800; }
.stat-label { color: #6b7280; font-weight: 700; }
.result-actions { display: flex; justify-content: center; gap: 14px; margin-top: 20px; }

/* --- leaderboard ------------------------------------------------------------ */

.board { list-style: none; padding: 0; margin: 16px 0; }
.board li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--card); margin-bottom: 8px; font-weight: 700;
}
.rank {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 800;
}
.board-avatar { font-size: 1.6rem; }
.board-name { flex: 1; }
.board-score { color: var(--accent); }

/* --- admin ------------------------------------------------------------------ */

.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: var(--radius-sm); padding: 12px 14px;
}
.user-main { flex: 1; display: flex; flex-direction: column; }
.user-stats { display: flex; flex-direction: column; align-items: flex-end; font-size: 0.9rem; font-weight: 700; color: #6b7280; }
.user-actions { display: flex; gap: 6px; }
.action-btn { min-height: 40px; min-width: 40px; padding: 6px 10px; font-size: 1.1rem; }

/* --- modal ------------------------------------------------------------------ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal .panel-title { margin: 0; text-align: center; }
.modal input {
  min-height: 52px;
  padding: 0 16px;
  font: inherit;
  font-size: 1.15rem;
  text-align: center;
  border: 2px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions .btn { flex: 1; }
.pin-avatar { font-size: 3rem; text-align: center; }
.pin-name { text-align: center; font-weight: 800; font-size: 1.4rem; }
.pin-hint { text-align: center; font-weight: 700; color: #6b7280; }

/* --- responsive ------------------------------------------------------------- */

@media (max-width: 640px) {
  .brand { font-size: 1.2rem; }
  .app { padding: 16px 12px calc(32px + env(safe-area-inset-bottom)); }
  .gate-title { font-size: 1.7rem; }
  .kid-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
  .kid-avatar { font-size: 2.4rem; }
  .kid-card { font-size: 1rem; padding: 14px 8px; }
  .match-board { gap: 10px; }
  .card { min-height: 60px; font-size: 1.15rem; padding: 8px; }
  .card-right { font-size: 1.4rem; }
  .dot { width: 13px; height: 13px; }
  .level-grid { grid-template-columns: 1fr; }
  .result-stats { gap: 10px; }
  .stat { min-width: 96px; padding: 14px 18px; }
  .stat-num { font-size: 1.5rem; }
  .btn { min-height: 50px; font-size: 1.05rem; padding: 10px 18px; }
}

@media (min-width: 641px) and (max-width: 1024px) {
  /* iPad: comfortable multi-column, slightly larger targets */
  .kid-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
