/* ===== מסע החלל של דוד — kid-friendly space theme ===== */
:root {
  --bg1: #1b1450;
  --bg2: #2a1e6e;
  --bg3: #3b2a8c;
  --accent: #ffd93b;
  --pink: #ff6ec7;
  --green: #4ade80;
  --red: #ff7a7a;
  --blue: #57c8ff;
  --purple: #b07bff;
  --orange: #ff9f43;
  --white: #ffffff;
  --card: rgba(255, 255, 255, 0.10);
  --card-solid: #2c2170;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 26px;
  --tap: 68px;
  font-size: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: 'Fredoka', 'Varela Round', system-ui, sans-serif;
  background: radial-gradient(circle at 50% 0%, var(--bg3) 0%, var(--bg2) 40%, var(--bg1) 100%);
  color: var(--white);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== Starfield ===== */
.stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(2px 2px at 70% 60%, #fff, transparent),
    radial-gradient(1px 1px at 40% 80%, #fff, transparent),
    radial-gradient(2px 2px at 85% 20%, #fff, transparent),
    radial-gradient(1px 1px at 10% 70%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 55% 15%, #fff, transparent),
    radial-gradient(1px 1px at 90% 85%, #fff, transparent),
    radial-gradient(2px 2px at 30% 50%, #fff, transparent);
  opacity: 0.55;
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.35; } to { opacity: 0.7; } }

/* ===== Top bar ===== */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  gap: 10px;
}
.icon-btn {
  width: 56px; height: 56px;
  border: none;
  border-radius: 20px;
  background: var(--card);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, background .2s;
}
.icon-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.2); }
.star-counter {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(90deg, var(--accent), var(--orange));
  color: #3a2600;
  font-weight: 700;
  font-size: 26px;
  padding: 8px 22px;
  border-radius: 30px;
  box-shadow: var(--shadow);
  min-width: 90px;
  justify-content: center;
}
.star-counter .star-icon { font-size: 24px; }
.star-counter.bump { animation: bump .4s ease; }
@keyframes bump { 0%,100%{transform:scale(1)} 40%{transform:scale(1.25)} }

/* ===== App container ===== */
.app {
  position: relative;
  z-index: 2;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ===== Generic screen ===== */
.screen { animation: fadeIn .35s ease; display: flex; flex-direction: column; flex: 1; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.screen-title {
  text-align: center;
  font-size: 34px;
  font-weight: 700;
  margin: 6px 0 14px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}

/* ===== Home / space map ===== */
.mascot-hero {
  text-align: center;
  font-size: 84px;
  margin: 6px 0;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 10px 16px rgba(0,0,0,0.4));
}
@keyframes float { 0%,100%{ transform: translateY(0) } 50%{ transform: translateY(-14px) } }
.hero-sub { text-align: center; font-size: 20px; opacity: .85; margin-bottom: 16px; }

.planet-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
}
.planet-card {
  position: relative;
  border: none;
  border-radius: var(--radius);
  padding: 20px 14px 18px;
  min-height: 168px;
  cursor: pointer;
  color: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  transition: transform .14s ease;
  overflow: hidden;
}
.planet-card:active { transform: scale(0.95); }
.planet-card .p-emoji { font-size: 60px; line-height: 1; filter: drop-shadow(0 6px 8px rgba(0,0,0,0.35)); }
.planet-card .p-name { font-size: 22px; font-weight: 700; }
.planet-card.locked { filter: grayscale(0.7) brightness(0.7); }
.planet-card .lock-badge {
  position: absolute; top: 10px; inset-inline-start: 10px;
  background: rgba(0,0,0,0.4); border-radius: 20px; padding: 4px 12px;
  font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 4px;
}
.pc-blue { background: linear-gradient(160deg, #57c8ff, #3a6cff); }
.pc-green { background: linear-gradient(160deg, #6ee7a8, #22a06b); }
.pc-pink { background: linear-gradient(160deg, #ff8fd0, #d94fa0); }
.pc-purple { background: linear-gradient(160deg, #c79bff, #8a4bff); }

/* ===== Big buttons ===== */
.big-btn {
  border: none;
  border-radius: 22px;
  padding: 16px 24px;
  font-family: inherit;
  font-size: 24px;
  font-weight: 600;
  color: #fff;
  background: var(--card-solid);
  cursor: pointer;
  box-shadow: var(--shadow);
  min-height: var(--tap);
  transition: transform .12s ease, filter .2s;
  margin: 8px 0;
}
.big-btn:active { transform: scale(0.94); }
.big-btn.primary { background: linear-gradient(90deg, var(--green), #22a06b); color: #06371f; }
.big-btn.danger { background: linear-gradient(90deg, #ff8a8a, #e14b4b); }
.big-btn.wide { width: 100%; max-width: 420px; margin-inline: auto; }

/* ===== Question card ===== */
.q-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
.q-card {
  background: var(--card);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  padding: 26px 30px;
  box-shadow: var(--shadow);
  text-align: center;
  min-width: min(88vw, 480px);
}
.q-prompt-emoji { font-size: 40px; margin-bottom: 6px; }
.q-text {
  font-size: clamp(44px, 12vw, 76px);
  font-weight: 700;
  letter-spacing: 2px;
  direction: ltr;
  unicode-bidi: isolate;
}
.q-hint { font-size: 20px; opacity: .8; margin-top: 8px; }

/* answer grid */
.answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 480px;
}
.answers.cols-3 { grid-template-columns: repeat(3, 1fr); }
.ans-btn {
  border: none;
  border-radius: 24px;
  padding: 22px 10px;
  font-family: inherit;
  font-size: clamp(30px, 8vw, 44px);
  font-weight: 700;
  color: #16204a;
  background: linear-gradient(160deg, #ffffff, #d6e6ff);
  cursor: pointer;
  box-shadow: var(--shadow);
  min-height: 84px;
  transition: transform .1s ease;
  direction: ltr;
}
.ans-btn:active { transform: scale(0.93); }
.ans-btn.correct { background: linear-gradient(160deg, #7bf0a8, #2fbd6a); color: #04331c; animation: pop .4s; }
.ans-btn.wrong { background: linear-gradient(160deg, #ffb0b0, #ff6b6b); color: #4a0d0d; animation: shake .4s; }
.ans-btn.reveal { outline: 4px solid var(--accent); }
@keyframes pop { 0%{transform:scale(1)} 50%{transform:scale(1.15)} 100%{transform:scale(1)} }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 75%{transform:translateX(8px)} }

/* progress hearts / dots */
.hud { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 6px 0 4px; flex-wrap: wrap; }
.hud-pill {
  background: var(--card); border-radius: 20px; padding: 6px 16px; font-size: 20px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.progress-dots { display: flex; gap: 8px; justify-content: center; margin: 4px 0; }
.dot { width: 16px; height: 16px; border-radius: 50%; background: rgba(255,255,255,0.25); }
.dot.done { background: var(--green); }
.dot.current { background: var(--accent); transform: scale(1.2); }

/* ===== Hebrew reading mode ===== */
.he-card { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.speaker-big {
  width: 130px; height: 130px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 64px; color: #16204a;
  background: radial-gradient(circle at 35% 30%, #fff, var(--accent));
  box-shadow: var(--shadow); animation: pulse 1.6s infinite;
}
.speaker-big:active { transform: scale(0.92); }
.speaker-mini {
  border: none; border-radius: 18px; padding: 8px 18px; font-family: inherit;
  font-size: 20px; font-weight: 600; color: #16204a; cursor: pointer;
  background: linear-gradient(160deg, #fff, #d6e6ff); box-shadow: var(--shadow);
}
.speaker-mini:active { transform: scale(0.94); }
.prompt-glyph { font-size: clamp(64px, 18vw, 120px); font-weight: 700; line-height: 1.1; direction: rtl; }
.prompt-emoji-big { font-size: clamp(80px, 22vw, 140px); line-height: 1; }
.prompt-hint { font-size: 20px; opacity: .85; margin-top: 4px; }
.he-opt { direction: rtl; font-weight: 700; }
.he-opt.emoji-opt { font-size: clamp(44px, 12vw, 64px); }
.he-answers .ans-btn { min-height: 96px; }

/* ===== Placement exam ===== */
.exam-intro { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px; }
.exam-intro .big-emoji { font-size: 90px; animation: float 3s ease-in-out infinite; }
.exam-intro p { font-size: 20px; opacity: .9; max-width: 420px; line-height: 1.5; }
.exam-result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px; }
.exam-result .level-badge {
  background: linear-gradient(160deg, var(--accent), var(--orange)); color: #3a2600;
  border-radius: 24px; padding: 18px 26px; box-shadow: var(--shadow); margin: 8px 0;
}
.exam-result .level-badge .lv-num { font-size: 46px; font-weight: 700; }
.exam-result .level-badge .lv-title { font-size: 24px; font-weight: 600; }

/* ===== Grown-ups / level picker ===== */
.grown-wrap { max-width: 560px; margin: 0 auto; width: 100%; }
.subject-block {
  background: var(--card); border-radius: var(--radius); padding: 18px 16px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.subject-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.subject-head .s-name { font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.subject-head .s-current { font-size: 18px; opacity: .85; }
.level-list { display: grid; grid-template-columns: 1fr; gap: 8px; }
.level-item {
  display: flex; align-items: center; gap: 12px; text-align: start;
  border: none; border-radius: 18px; padding: 12px 14px; cursor: pointer;
  background: rgba(255,255,255,0.08); color: #fff; font-family: inherit;
  transition: background .15s, transform .1s;
}
.level-item:active { transform: scale(0.98); }
.level-item.active { background: linear-gradient(90deg, var(--green), #22a06b); color: #04331c; }
.level-item .li-emoji { font-size: 30px; }
.level-item .li-text { display: flex; flex-direction: column; }
.level-item .li-title { font-size: 20px; font-weight: 700; }
.level-item .li-desc { font-size: 15px; opacity: .8; }
.level-item .li-num {
  margin-inline-start: auto; background: rgba(0,0,0,0.25); border-radius: 14px;
  padding: 4px 12px; font-weight: 700; font-size: 18px;
}
.exam-btn { width: 100%; margin-top: 10px; }

/* ===== Feedback banner ===== */
.feedback {
  min-height: 40px;
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  transition: opacity .2s;
}
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--accent); }

/* ===== Memory / cards grid ===== */
.card-grid { display: grid; gap: 12px; margin: 0 auto; width: 100%; max-width: 520px; }
.mem-card {
  aspect-ratio: 1;
  border-radius: 20px;
  border: none;
  font-size: clamp(30px, 9vw, 52px);
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(160deg, var(--purple), #6a3bd0);
  color: #fff;
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  transition: transform .18s ease;
  direction: ltr;
}
.mem-card.flipped { background: linear-gradient(160deg, #fff, #d6e6ff); color: #16204a; }
.mem-card.matched { background: linear-gradient(160deg, #7bf0a8, #2fbd6a); color: #04331c; }
.mem-card .back { font-size: 40px; }

/* ===== Sortable chips ===== */
.chip-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.chip {
  border: none; border-radius: 18px; padding: 16px 22px;
  font-size: 34px; font-weight: 700; color: #16204a;
  background: linear-gradient(160deg, #fff, #d6e6ff);
  box-shadow: var(--shadow); cursor: pointer; min-width: 64px; direction: ltr;
  transition: transform .1s ease;
}
.chip:active { transform: scale(0.92); }
.chip.picked { background: linear-gradient(160deg, #7bf0a8, #2fbd6a); color:#04331c; }
.slot-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 10px 0; min-height: 76px; }
.slot {
  width: 64px; height: 72px; border-radius: 18px; border: 3px dashed rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 700;
}

/* ===== Arcade ===== */
.arcade-stage {
  position: relative;
  flex: 1;
  min-height: 60vh;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(10,6,40,0.5), rgba(30,20,90,0.5));
  box-shadow: var(--shadow) inset;
}
.arcade-problem {
  position: absolute; top: 12px; inset-inline: 0; text-align: center;
  font-size: clamp(40px, 11vw, 64px); font-weight: 700; z-index: 4;
  direction: ltr; text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  pointer-events: none;
}
.balloon {
  position: absolute;
  width: 92px; height: 92px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 700; color: #16204a;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
  cursor: pointer; direction: ltr;
  will-change: transform;
}
.balloon::after {
  content: ''; position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 12px solid rgba(255,255,255,0.5);
}
.balloon.pop { animation: balloonPop .3s forwards; }
@keyframes balloonPop { to { transform: scale(1.6); opacity: 0; } }

/* ===== Adventure map ===== */
.level-path { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0; }
.level-node {
  width: 82px; height: 82px; border-radius: 50%; border: none;
  font-size: 30px; font-weight: 700; color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); position: relative;
  background: linear-gradient(160deg, var(--orange), #e07b1a);
  transition: transform .12s ease;
}
.level-node:active { transform: scale(0.92); }
.level-node.done { background: linear-gradient(160deg, var(--green), #22a06b); }
.level-node.locked { background: #4a437a; color: rgba(255,255,255,0.5); }
.level-node.current { outline: 4px solid var(--accent); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100%{ box-shadow: var(--shadow) } 50%{ box-shadow: 0 0 0 8px rgba(255,217,59,0.4) } }
.level-connector { width: 6px; height: 26px; background: rgba(255,255,255,0.25); border-radius: 3px; }

.pets-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 14px 0; }
.pet {
  width: 64px; height: 64px; border-radius: 18px; background: var(--card);
  display: flex; align-items: center; justify-content: center; font-size: 34px;
}
.pet.locked { filter: grayscale(1) brightness(0.5); }

/* ===== Modals ===== */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(6,4,26,0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .25s ease;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card-solid);
  border-radius: 30px;
  padding: 28px 24px;
  width: min(94vw, 440px);
  box-shadow: var(--shadow);
  text-align: center;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 90dvh; overflow-y: auto;
}
.modal-h { font-size: 30px; margin: 4px 0 14px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 22px; padding: 12px 6px; border-bottom: 1px solid rgba(255,255,255,0.12);
}
.setting-note { font-size: 15px; opacity: .6; margin: 14px 0 4px; }
.switch { width: 56px; height: 32px; -webkit-appearance: none; appearance: none; background: #55507f; border-radius: 20px; position: relative; cursor: pointer; transition: background .2s; }
.switch:checked { background: var(--green); }
.switch::after { content:''; position:absolute; top:3px; inset-inline-start:3px; width:26px; height:26px; border-radius:50%; background:#fff; transition: inset-inline-start .2s; }
.switch:checked::after { inset-inline-start: 27px; }
.select { font-family: inherit; font-size: 20px; padding: 8px 14px; border-radius: 14px; border: none; background:#fff; color:#16204a; }

.reward-card { align-items: center; }
.reward-emoji { font-size: 90px; animation: float 2s ease-in-out infinite; }
.reward-title { font-size: 34px; font-weight: 700; color: var(--accent); }
.reward-body { font-size: 22px; opacity: .95; margin: 6px 0 10px; }

/* ===== FX canvas ===== */
.fx { position: fixed; inset: 0; z-index: 15; pointer-events: none; }

.hidden { display: none !important; }

/* ===== Landscape / desktop tweaks ===== */
@media (min-width: 720px) {
  .planet-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .mascot-hero { font-size: 54px; }
  .screen-title { font-size: 26px; margin: 2px 0 8px; }
  .planet-card { min-height: 128px; }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; }
}
