:root {
  --sky-1: #7bdff2;
  --sky-2: #b2f7ef;
  --mint: #eff7f6;
  --bubble: #f7d6e0;
  --pink: #ff7eb6;
  --pink-deep: #ff5fa2;
  --sun: #ffd166;
  --grape: #9b5de5;
  --grape-deep: #7b3fc4;
  --teeth: #fffdf7;
  --gum: #ff8fab;
  --bug: #8ac926;
  --ink: #3a2e5c;
  --ink-soft: #6b5b95;
  --white: #ffffff;
  --shadow: rgba(58, 46, 92, 0.18);
  --display: 'Baloo 2', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--display);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body {
  background: linear-gradient(165deg, var(--sky-1) 0%, var(--sky-2) 55%, var(--mint) 100%);
}

html[dir="rtl"] body { font-family: 'Cairo', var(--display); }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
}

/* ---------- screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.98);
  transition: opacity .35s ease, transform .35s ease, visibility .35s;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 16px);
}
.screen.active { opacity: 1; visibility: visible; transform: scale(1); }

/* ---------- welcome / onboarding ---------- */
.welcome-screen { align-items: center; justify-content: center; overflow-y: auto; }
.welcome-inner {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 8px; padding: 8px 0;
}
.welcome-title { font-size: 30px; color: var(--ink); }
.welcome-sub { font-size: 14px; color: var(--ink-soft); font-weight: 600; margin-bottom: 4px; }
.welcome-pet { width: 150px; }
.welcome-pet svg { width: 100%; height: auto; }
.field-label { font-weight: 800; font-size: 16px; color: var(--ink); align-self: center; margin-top: 6px; }
.name-input {
  width: 100%; border: 3px solid var(--bubble); border-radius: 16px; padding: 12px 16px;
  font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--ink);
  background: var(--white); text-align: center;
}
.name-input:focus { outline: none; border-color: var(--pink); }
.name-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.name-chip {
  background: var(--white); border: 2px solid transparent; border-radius: 999px;
  padding: 8px 14px; font-family: var(--display); font-weight: 700; font-size: 15px;
  color: var(--ink-soft); cursor: pointer; box-shadow: 0 3px 0 var(--shadow);
}
.name-chip.selected { border-color: var(--pink); color: var(--pink-deep); }
.name-chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.welcome-screen .big-btn { width: 100%; margin-top: 10px; }
.lang-mini {
  background: none; border: none; font-family: var(--display); font-weight: 800;
  font-size: 16px; color: var(--ink-soft); cursor: pointer; padding: 6px;
}

.buddy-name-badge {
  position: absolute; bottom: 8%; left: 50%; transform: translateX(-50%);
  background: var(--white); color: var(--pink-deep); font-weight: 800; font-size: 16px;
  padding: 4px 16px; border-radius: 999px; box-shadow: 0 4px 0 var(--shadow);
  white-space: nowrap;
}
.buddy-name-badge:empty { display: none; }

/* ---------- chips / hud ---------- */
.home-top { display: flex; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,0.85);
  border: none; border-radius: 999px;
  padding: 8px 14px;
  font-family: var(--display); font-weight: 800; font-size: 18px;
  color: var(--ink); box-shadow: 0 4px 0 var(--shadow);
  cursor: pointer;
}
.chip:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--shadow); }
.chip-icon { font-size: 20px; }
.lang-chip { margin-inline-start: auto; }

/* ---------- pet stage ---------- */
.pet-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.home-pet { width: min(70vw, 320px); will-change: transform; }
.home-pet svg, .reward-pet svg { width: 100%; height: auto; display: block; }
.pet-shadow {
  position: absolute; bottom: 12%; left: 50%; transform: translateX(-50%);
  width: 46%; height: 26px; border-radius: 50%;
  background: var(--shadow); filter: blur(7px);
  animation: shadow-bob 3.2s ease-in-out infinite;
}
.speech-bubble {
  position: absolute; top: 4%; left: 50%; transform: translateX(-50%) scale(0);
  background: var(--white); color: var(--ink);
  padding: 10px 16px; border-radius: 18px; font-weight: 700; font-size: 17px;
  box-shadow: 0 4px 0 var(--shadow); max-width: 80%; text-align: center;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
}
.speech-bubble.show { transform: translateX(-50%) scale(1); }
.speech-bubble::after {
  content: ''; position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%);
  border: 10px solid transparent; border-top-color: var(--white); border-bottom: 0;
}

@keyframes shadow-bob { 0%,100%{ width:46%; opacity:.18 } 50%{ width:40%; opacity:.12 } }

/* ---------- home actions ---------- */
.home-actions { display: flex; flex-direction: column; gap: 14px; }
.big-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  border: none; border-radius: 26px;
  background: linear-gradient(180deg, var(--pink) 0%, var(--pink-deep) 100%);
  color: var(--white); font-family: var(--display); font-weight: 800;
  font-size: 28px; padding: 20px; cursor: pointer;
  box-shadow: 0 7px 0 var(--pink-deep), 0 12px 18px var(--shadow);
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--pink-deep); }
.big-btn-emoji { font-size: 34px; animation: wiggle 1.4s ease-in-out infinite; }
@keyframes wiggle { 0%,100%{ transform: rotate(-12deg) } 50%{ transform: rotate(12deg) } }

.mini-actions { display: flex; gap: 10px; }
.mini-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(255,255,255,0.85); border: none; border-radius: 20px;
  padding: 12px 6px; cursor: pointer; box-shadow: 0 5px 0 var(--shadow);
  font-family: var(--display);
}
.mini-btn span { font-size: 28px; }
.mini-btn small { font-weight: 700; font-size: 13px; color: var(--ink-soft); }
.mini-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--shadow); }

/* ---------- session ---------- */
.session-screen { background: linear-gradient(165deg, #cff5ff 0%, #e8fbf8 100%); }
.session-hud { display: flex; align-items: center; gap: 12px; }
.quit-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.8); font-size: 20px; font-weight: 800;
  color: var(--ink-soft); cursor: pointer; box-shadow: 0 4px 0 var(--shadow);
}
.timer-ring { position: relative; width: 76px; height: 76px; }
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255,255,255,0.7); stroke-width: 10; }
.ring-fg {
  fill: none; stroke: var(--pink); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 327; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear;
}
.timer-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: var(--ink);
}
.quadrant-dots { display: flex; gap: 8px; margin-inline-start: auto; }
.qdot { width: 16px; height: 16px; border-radius: 50%; background: rgba(255,255,255,0.7); transition: all .3s; }
.qdot.active { background: var(--sun); transform: scale(1.25); box-shadow: 0 0 0 4px rgba(255,209,102,.4); }
.qdot.done { background: var(--bug); }

.coach-banner {
  margin: 12px 0 6px; text-align: center; font-weight: 800; font-size: 21px;
  color: var(--ink); min-height: 30px;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s;
}
.coach-banner.pop { animation: bannerPop .4s ease; }
@keyframes bannerPop { 0%{ transform: scale(.7); opacity:0 } 60%{ transform: scale(1.08) } 100%{ transform: scale(1); opacity:1 } }

#game-canvas { flex: 1; width: 100%; border-radius: 28px; touch-action: none; }

.brush-hint {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; color: var(--ink-soft); padding: 12px 0 2px; font-size: 16px;
  transition: opacity .4s;
}
.hint-finger { font-size: 22px; animation: scrubMove 1.1s ease-in-out infinite; }
@keyframes scrubMove { 0%,100%{ transform: translateX(-8px) rotate(-8deg) } 50%{ transform: translateX(8px) rotate(8deg) } }

/* ---------- reward ---------- */
.reward-screen { align-items: center; justify-content: center; background: linear-gradient(165deg, var(--grape) 0%, var(--pink) 100%); }
.reward-card {
  background: var(--white); border-radius: 32px; padding: 26px 22px 22px;
  width: 100%; max-width: 380px; text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,.25);
  animation: cardIn .5s cubic-bezier(.34,1.56,.64,1);
}
@keyframes cardIn { from{ transform: scale(.7); opacity:0 } to{ transform: scale(1); opacity:1 } }
.reward-pet { width: 150px; margin: -70px auto 0; }
.reward-title { font-size: 26px; margin: 8px 0 4px; color: var(--ink); }
.reward-stars { font-size: 38px; letter-spacing: 4px; min-height: 46px; }
.reward-stars .pop-star { display: inline-block; animation: starPop .4s backwards; }
@keyframes starPop { from{ transform: scale(0) rotate(-40deg) } to{ transform: scale(1) } }
.reward-streak { font-weight: 800; color: var(--pink-deep); font-size: 19px; margin-bottom: 8px; }
.reward-unlock {
  background: var(--mint); border-radius: 20px; padding: 14px; margin: 6px 0 14px;
  font-weight: 700; color: var(--ink);
}
.reward-unlock .unlock-pet { width: 90px; margin: 4px auto 0; }
.done-btn { width: 100%; font-size: 24px; padding: 16px; }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute; top: -20px; width: 12px; height: 12px; border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- sheet (closet / stickers) ---------- */
.sheet-screen, .parent-screen { justify-content: flex-end; background: rgba(58,46,92,0.45); padding: 0; }
.sheet, .parent-panel {
  background: var(--mint); width: 100%; max-width: 560px; margin: 0 auto;
  border-radius: 28px 28px 0 0; padding: 18px 18px calc(var(--safe-bottom) + 22px);
  max-height: 88%; display: flex; flex-direction: column;
  animation: sheetUp .4s cubic-bezier(.34,1.4,.64,1);
}
@keyframes sheetUp { from{ transform: translateY(100%) } to{ transform: translateY(0) } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 24px; color: var(--ink); }
.sheet-close, .quit-btn { }
.sheet-close {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.9); font-size: 18px; font-weight: 800; color: var(--ink-soft);
  cursor: pointer; box-shadow: 0 3px 0 var(--shadow);
}
.sheet-body, .parent-body { overflow-y: auto; }

.item-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.item-card {
  background: var(--white); border-radius: 20px; padding: 12px 8px; text-align: center;
  box-shadow: 0 5px 0 var(--shadow); cursor: pointer; position: relative;
  border: 3px solid transparent; transition: transform .15s;
}
.item-card:active { transform: scale(.95); }
.item-card.selected { border-color: var(--pink); }
.item-card.locked { opacity: .55; }
.item-emoji { font-size: 40px; }
.item-name { font-weight: 700; font-size: 13px; margin-top: 4px; color: var(--ink-soft); }
.item-cost { font-size: 12px; font-weight: 800; color: var(--sun); }
.lock-badge { position: absolute; top: 6px; inset-inline-end: 6px; font-size: 16px; }

.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sticker-cell {
  aspect-ratio: 1; border-radius: 18px; background: var(--white);
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  box-shadow: inset 0 2px 6px var(--shadow);
}
.sticker-cell.empty { background: rgba(255,255,255,0.4); }
.sticker-cell.empty::after { content: '?'; font-size: 24px; color: var(--ink-soft); opacity: .5; }

/* ---------- parent corner ---------- */
.parent-body { display: flex; flex-direction: column; gap: 16px; }
.parent-card { background: var(--white); border-radius: 20px; padding: 16px; box-shadow: 0 5px 0 var(--shadow); }
.parent-card h3 { font-size: 17px; margin-bottom: 10px; color: var(--ink); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day {
  aspect-ratio: 1; border-radius: 10px; background: var(--mint);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--ink-soft);
}
.cal-day .dots { font-size: 9px; letter-spacing: -1px; }
.cal-day.full { background: var(--bug); color: var(--white); }
.cal-day.half { background: var(--sun); color: var(--white); }

.reward-row { display: flex; gap: 8px; align-items: center; }
.reward-row input {
  flex: 1; border: 2px solid var(--bubble); border-radius: 12px; padding: 10px 12px;
  font-family: var(--display); font-size: 15px; color: var(--ink); background: var(--mint);
}
.goal-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.goal-row label { font-weight: 700; font-size: 14px; color: var(--ink-soft); }
.goal-row input[type="number"] { width: 64px; }
.save-btn {
  background: var(--grape); color: var(--white); border: none; border-radius: 14px;
  padding: 10px 18px; font-family: var(--display); font-weight: 800; font-size: 15px;
  cursor: pointer; box-shadow: 0 4px 0 var(--grape-deep);
}
.save-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--grape-deep); }
.reward-progress { margin-top: 10px; font-weight: 700; color: var(--ink-soft); font-size: 14px; }
.reward-progress .bar { height: 14px; border-radius: 8px; background: var(--mint); overflow: hidden; margin-top: 6px; }
.reward-progress .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--sun), var(--pink)); border-radius: 8px; transition: width .5s; }
.danger-link { background: none; border: none; color: var(--ink-soft); text-decoration: underline; font-size: 13px; cursor: pointer; font-family: var(--display); }
.tip-list { font-size: 14px; color: var(--ink-soft); line-height: 1.6; padding-inline-start: 18px; }

/* ---------- parent gate ---------- */
.gate-overlay { position: absolute; inset: 0; background: rgba(58,46,92,0.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.gate-card { background: var(--white); border-radius: 24px; padding: 22px; width: 100%; max-width: 320px; text-align: center; }
.gate-card p { font-weight: 700; color: var(--ink-soft); margin-bottom: 10px; }
.gate-question { font-size: 34px; font-weight: 800; color: var(--ink); margin-bottom: 16px; }
.gate-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.gate-options button {
  background: var(--mint); border: none; border-radius: 14px; padding: 16px 0;
  font-family: var(--display); font-weight: 800; font-size: 22px; color: var(--ink); cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
}
.gate-options button:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--shadow); }
.gate-cancel { background: none; border: none; color: var(--ink-soft); font-family: var(--display); font-size: 15px; cursor: pointer; }

/* ---------- bits ---------- */
[hidden] { display: none !important; }
.float { animation: floaty 3.2s ease-in-out infinite; }
@keyframes floaty { 0%,100%{ transform: translateY(0) } 50%{ transform: translateY(-14px) } }
