/* ─── Palette (from design) ─── */
:root {
  --bg: #FFF8F0;
  --paper: #FFFFFF;
  --ink: #2A2A2E;
  --ink-soft: #6B6B73;
  --guide: #D6D5D2;
  --guide-dash: #BFBEB9;
  --pink: #FF2E7E;
  --pink-deep: #D81562;
  --pink-light: #FFB3D1;
  --blue: #1F6FEB;

  --heb: "Heebo", "Assistant", system-ui, sans-serif;
  --disp: "Secular One", "Heebo", system-ui, sans-serif;
  --hand: "Gveret Levin", "Caveat", cursive;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  font-family: var(--heb);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.view {
  height: 100dvh;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  position: relative;   /* anchor for absolutely-positioned overlays (validation banner) */
}
.view[hidden] { display: none; }
.screen { display: contents; }   /* legacy wrapper — pass-through */

/* ─── Splash view (01) ─── */
.view-splash {
  background: radial-gradient(circle at 50% 35%, #FFE4F0 0%, var(--bg) 70%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.splash-letters {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.floaty {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-family: var(--disp);
  font-size: var(--s);
  color: var(--c);
  transform: rotate(var(--r));
  opacity: 0.85;
  animation: floaty 3.6s ease-in-out infinite;
  animation-delay: var(--d);
  text-shadow: 0 4px 0 rgba(0,0,0,0.05);
  will-change: transform;
}
@keyframes floaty {
  0%, 100% { transform: rotate(var(--r)) translateY(0); }
  50%      { transform: rotate(var(--r)) translateY(-10px); }
}

.splash-title {
  position: relative;
  font-family: var(--hand);
  font-size: 56px;
  color: var(--pink-deep);
  text-align: center;
  line-height: 1.0;
  padding: 0 30px;
  text-shadow: 0 3px 0 rgba(216, 21, 98, 0.15);
  z-index: 1;
}
.splash-sub {
  position: relative;
  margin-top: 14px;
  font-family: var(--heb);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-soft);
  text-align: center;
  z-index: 1;
}
.splash-cta {
  position: relative;
  margin-top: 44px;
  height: 56px;
  padding: 0 44px;
  border-radius: 18px;
  border: none;
  cursor: pointer;
  background: linear-gradient(180deg, #FF6FAD 0%, var(--pink) 60%, var(--pink-deep) 100%);
  box-shadow:
    inset 0 -4px 0 rgba(0,0,0,0.14),
    inset 0 2px 0 rgba(255,255,255,0.45),
    0 6px 18px rgba(255, 46, 126, 0.35);
  color: #fff;
  font-family: var(--heb);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.3px;
  z-index: 1;
}

/* ─── Kid login view (02b) ─── */
.view-login {
  padding: 70px 28px 24px;
}
.login-title {
  font-family: var(--hand);
  font-size: 40px;
  color: var(--pink-deep);
  text-align: center;
  line-height: 1.0;
}
.login-sub {
  margin-top: 8px;
  font-family: var(--heb);
  font-size: 14px;
  color: var(--ink-soft);
  text-align: center;
}
.login-form {
  margin-top: 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-label {
  font-family: var(--heb);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.login-input {
  height: 52px;
  border-radius: 14px;
  border: 1.5px solid #E5E2DD;
  background: #fff;
  padding: 0 16px;
  font-family: var(--heb);
  font-size: 16px;
  color: var(--ink);
  direction: rtl;
  outline: none;
  box-sizing: border-box;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.login-input:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgba(255, 46, 126, 0.10);
}
.login-input.error {
  border-color: var(--pink);
}
.login-error {
  font-family: var(--heb);
  font-size: 13px;
  font-weight: 600;
  color: var(--pink);
  margin-top: 2px;
}
.login-submit {
  margin-top: 10px;
  height: 54px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  background: linear-gradient(180deg, #FF6FAD 0%, var(--pink) 60%, var(--pink-deep) 100%);
  box-shadow:
    inset 0 -4px 0 rgba(0,0,0,0.14),
    inset 0 2px 0 rgba(255,255,255,0.45),
    0 6px 18px rgba(255, 46, 126, 0.35);
  color: #fff;
  font-family: var(--heb);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.3px;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.login-submit:disabled {
  background: #E5E2DD;
  color: #A6A29B;
  box-shadow: none;
  cursor: default;
}
.login-donate {
  /* both auto margins in a flex column → distributes remaining space
     equally above and below, centring the button midway between the
     submit button and the bottom of the screen. */
  margin-top: auto;
  margin-bottom: auto;
  height: 50px;
  border-radius: 14px;
  cursor: pointer;
  border: 1.5px solid var(--pink-light);
  background: #FFF0F6;
  color: var(--pink-deep);
  font-family: var(--heb);
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ─── Home view ─── */
.view-home { padding: 60px 26px 24px; }

.home-title {
  font-family: var(--disp);
  font-size: 32px;
  color: var(--ink);
  text-align: center;
}
.home-subtitle {
  margin-top: 6px;
  font-family: var(--heb);
  font-size: 14px;
  color: var(--ink-soft);
  text-align: center;
}

.level-cards {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.level-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border-radius: 22px;
  border: 3px solid transparent;
  cursor: pointer;
  text-align: right;
  font: inherit;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  transition: transform 0.15s, box-shadow 0.2s;
}
.level-card:active { transform: scale(0.98); }

.level-card-beg { background: #FFE4EE; }
.level-card-beg .level-glyph span { color: var(--pink-deep); font-family: var(--disp); font-size: 80px; line-height: 1; }

.level-card-adv { background: #E4ECFF; }
.level-card-adv .level-glyph span { color: var(--blue); font-family: var(--hand); font-size: 56px; line-height: 1; }

.level-glyph {
  width: 96px; height: 96px; border-radius: 20px;
  background: #fff;
  display: grid; place-items: center;
  flex: 0 0 auto;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.05);
}
.level-text { flex: 1; min-width: 0; }
.level-title { font-family: var(--disp); font-size: 26px; color: var(--ink); }
.level-sub   { margin-top: 4px; font-family: var(--heb); font-size: 13px; color: var(--ink-soft); line-height: 1.4; }

/* Completed ribbon */
.ribbon {
  position: absolute;
  top: 10px;
  left: -8px;
  background: linear-gradient(180deg, #3FE39B 0%, #2EAE76 100%);
  color: #fff;
  font-family: var(--heb);
  font-size: 13px;
  font-weight: 800;
  padding: 6px 14px 6px 18px;
  border-radius: 999px 0 0 999px;
  box-shadow: 0 4px 10px rgba(63, 203, 133, 0.4);
  letter-spacing: 0.3px;
  animation: ribbonIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.ribbon[hidden] { display: none; }
.ribbon::after {
  content: "";
  position: absolute;
  bottom: -6px; left: 0;
  border: 4px solid transparent;
  border-top-color: #1f8556;
  border-right-color: #1f8556;
}
@keyframes ribbonIn {
  0%   { opacity: 0; transform: translateX(40px) rotate(-15deg) scale(0.6); }
  60%  { opacity: 1; transform: translateX(-4px) rotate(0deg) scale(1.05); }
  100% { opacity: 1; transform: translateX(0) rotate(0deg) scale(1); }
}

.home-tip {
  margin-top: auto;
  padding: 14px;
  border-radius: 14px;
  background: #FFFBEA;
  border: 1.5px dashed #FFD23F;
  display: flex; gap: 10px; align-items: flex-start;
}
.home-tip-icon { font-size: 20px; }
.home-tip-text { font-family: var(--heb); font-size: 13px; color: #7A5C00; line-height: 1.45; }

/* ─── Home button (in training top-bar) ─── */
.home-btn {
  width: 38px; height: 38px;
  border: none; border-radius: 19px;
  background: #fff;
  color: var(--pink-deep);
  cursor: pointer;
  display: grid; place-items: center;
  flex: 0 0 auto;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* ─── Top bar / candy progress ─── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 6px;
}

.close-btn {
  width: 30px; height: 30px;
  border: none; border-radius: 15px;
  background: transparent;
  color: #9A9A9A;
  cursor: pointer;
  display: grid; place-items: center;
  flex: 0 0 auto;
}

.progress {
  flex: 1;
  height: 22px;
  border-radius: 999px;
  background: #EFECE7;
  box-shadow: inset 0 2px 3px rgba(0,0,0,0.10);
  position: relative;
  overflow: hidden;
  direction: rtl;
}
.progress-fill {
  position: absolute; top: 0; bottom: 0; right: 0;
  width: 35%;
  border-radius: 999px;
  background: linear-gradient(180deg, #FF6FAD 0%, var(--pink) 45%, var(--pink-deep) 100%);
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.12),
    inset 0 2px 0 rgba(255,255,255,0.45),
    0 0 12px rgba(255,46,126,0.45);
  overflow: hidden;
  transition: width 0.4s ease;
}
.progress-stripes {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(115deg,
    rgba(255,255,255,0.32) 0 6px,
    rgba(255,255,255,0) 6px 14px);
  animation: candyStripes 2.4s linear infinite;
  mix-blend-mode: screen;
}
.progress-gloss {
  position: absolute; left: 6px; right: 6px; top: 3px; height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,0.55);
  filter: blur(0.4px);
}
.progress-sparkle {
  position: absolute; top: 50%;
  width: 8px; height: 8px; margin-top: -4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px 2px rgba(255,255,255,0.9);
  animation: candySparkle 2.4s ease-in-out infinite;
}
@keyframes candyStripes {
  0%   { background-position: 0 0; }
  100% { background-position: 28px 0; }
}
@keyframes candySparkle {
  0%   { right: 0%;  opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { right: 96%; opacity: 0; }
}

/* ─── Mode switch ─── */
.mode-switch {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 2px 18px 6px;
  flex: 0 0 auto;
}
.mode-btn {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1.5px solid #E5E2DD;
  background: #fff;
  font-family: var(--heb);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.mode-btn.active {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255,46,126,0.3);
}

/* word display (advanced mode) */
.big-word {
  font-family: var(--disp);
  font-size: clamp(40px, 8vw, 64px);
  line-height: 1;
  letter-spacing: 2px;
  direction: rtl;
  display: inline-flex;
  gap: 4px;
  color: #C8C7C2;
}
.big-word .letter-current {
  color: var(--blue);
  font-weight: 900;
  transform: translateY(-2px);
  text-shadow: 0 3px 0 #DDE9FE;
}

/* word position pips */
.word-pips {
  position: absolute;
  top: 12px;
  left: 14px;
  display: flex;
  gap: 6px;
  direction: rtl;
}
.word-pips .pip {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: #E5E2DD;
  transition: all 0.25s;
}
.word-pips .pip.done    { background: var(--green, #3FCB85); }
.word-pips .pip.current { width: 22px; background: var(--blue); }

/* ─── Phase label ─── */
.phase-label {
  text-align: center;
  font-family: var(--heb);
  font-size: 13px;
  font-weight: 700;
  color: var(--pink-deep);
  padding: 4px 18px 0;
  letter-spacing: 0.2px;
}

/* ─── Letter preview ─── */
.letter-preview {
  padding: 8px 24px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}
.big-letter {
  font-family: var(--disp);
  font-size: clamp(56px, 11vw, 88px);
  line-height: 1;
  color: var(--ink);
}
.hand-preview {
  width: 160px;
  height: clamp(70px, 11vh, 100px);
  display: block;
}
.hint-line {
  font-family: var(--heb);
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* ─── Writing area ─── */
.writing-area {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  margin: 4px 18px 10px;
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 4px 18px rgba(0,0,0,0.06), inset 0 0 0 1px #EFEDE8;
  overflow: hidden;
}
#tracer {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.step-indicator {
  position: absolute; top: 10px; left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  font-family: var(--heb);
  font-size: 11px;
  font-weight: 700;
  color: var(--pink-deep);
}
.step-indicator[hidden] { display: none; }

.tools {
  position: absolute; bottom: 10px; left: 10px;
  display: flex; gap: 8px;
}
.tool-btn {
  width: 36px; height: 36px;
  border: none; border-radius: 18px;
  background: #F1EFEA;
  cursor: pointer;
  display: grid; place-items: center;
}

/* ─── Validation feedback banner ─── */
/* Absolutely positioned overlay so it never causes layout shift.
   Anchored at the top of the screen (in the user's line of sight, away
   from the hand). Free to cover the preview letter — that's expected. */
.validation-banner {
  position: absolute;
  left: 18px;
  right: 18px;
  top: 64px;               /* just below the candy progress bar */
  z-index: 50;
  padding: 16px 18px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.14);
  animation: vbSlideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.validation-banner[hidden] { display: none; }

.validation-banner.success {
  background: linear-gradient(180deg, #DFFBE9 0%, #C8F2D6 100%);
  border: 1.5px solid #6DD79A;
  color: #1f8556;
}
.validation-banner.fail {
  background: linear-gradient(180deg, #FFE7EE 0%, #FFD0DD 100%);
  border: 1.5px solid #FF6FAD;
  color: var(--pink-deep);
}
.vb-icon {
  font-size: 28px;
  line-height: 1;
  flex: 0 0 auto;
}
.vb-content { flex: 1; min-width: 0; }
.vb-text {
  font-family: var(--heb);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}
.vb-score {
  font-family: var(--heb);
  font-size: 12px;
  font-weight: 600;
  opacity: 0.75;
  margin-top: 2px;
}
@keyframes vbSlideIn {
  /* slide down from above so the user sees it drop into view */
  0%   { opacity: 0; transform: translateY(-24px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0)     scale(1); }
}

/* ─── Nav buttons ─── */
.nav-buttons {
  padding: 0 18px 18px;
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}
.nav-btn {
  height: 52px;
  border-radius: 14px;
  cursor: pointer;
  font-family: var(--heb);
  font-size: 16px;
  font-weight: 800;
}
.nav-prev {
  flex: 1;
  border: 1.5px solid #E5E2DD;
  background: #fff;
  color: var(--ink);
}
.nav-prev:disabled {
  color: #BFBEB9;
  cursor: not-allowed;
}
/* ─── Phase celebration ─── */
.celebration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 100;
  overflow: hidden;
}
.celebration.active {
  opacity: 1;
}
.celebration::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(255,255,255,0.85), rgba(255,248,240,0.3) 60%, transparent 80%);
}
.celebration-particles {
  position: absolute;
  inset: 0;
}
.confetti-piece {
  position: absolute;
  top: -10%;
  will-change: transform, opacity;
  animation: confettiFall var(--dur, 2.6s) cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
  animation-delay: var(--delay, 0s);
}
.confetti-letter {
  font-family: var(--disp);
  font-weight: 800;
  font-size: var(--size, 44px);
  color: var(--col, #FF2E7E);
  text-shadow: 0 2px 0 rgba(0,0,0,0.05);
}
.confetti-paper {
  width: var(--size, 12px);
  height: calc(var(--size, 12px) * 1.6);
  background: var(--col, #FF2E7E);
  border-radius: 2px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}
@keyframes confettiFall {
  0% {
    transform: translate(var(--x-start, 0), -10vh) rotate(0deg);
    opacity: 0;
  }
  10% { opacity: 1; }
  100% {
    transform: translate(var(--x-end, 0), 110vh) rotate(var(--rot, 720deg));
    opacity: 0.9;
  }
}
.celebration-banner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  text-align: center;
  background: #fff;
  border-radius: 24px;
  padding: 24px 36px;
  box-shadow: 0 20px 60px rgba(255, 46, 126, 0.35), 0 4px 14px rgba(0,0,0,0.1);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.celebration.active .celebration-banner {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.celebration-emoji {
  font-size: 56px;
  line-height: 1;
}
.celebration-text {
  font-family: var(--disp);
  font-size: 32px;
  color: var(--pink-deep);
  margin-top: 6px;
}
.celebration-phase {
  font-family: var(--heb);
  font-size: 15px;
  color: var(--ink-soft);
  margin-top: 4px;
}

.nav-next {
  flex: 1.4;
  border: none;
  color: #fff;
  background: linear-gradient(180deg, #FF6FAD 0%, var(--pink) 60%, var(--pink-deep) 100%);
  box-shadow:
    inset 0 -4px 0 rgba(0,0,0,0.14),
    inset 0 2px 0 rgba(255,255,255,0.45),
    0 6px 16px rgba(255,46,126,0.3);
}
.nav-next.blue {
  background: linear-gradient(180deg, #5B95F7 0%, var(--blue) 60%, #154FB7 100%);
  box-shadow:
    inset 0 -4px 0 rgba(0,0,0,0.18),
    inset 0 2px 0 rgba(255,255,255,0.4),
    0 6px 16px rgba(31,111,235,0.35);
}
