*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Fredoka One', 'Arial Rounded MT Bold', system-ui, sans-serif;
}

canvas { display: block; }

/* ─── SCREENS ─────────────────────────────────────────────────────────────── */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.screen.active { display: flex; }

/* ─── MENU ────────────────────────────────────────────────────────────────── */

#screen-menu {
  background: linear-gradient(135deg, #ff6b9d, #c77dff, #4ecdc4, #ffd93d);
  background-size: 400% 400%;
  animation: menuGradient 10s ease infinite;
  align-items: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@keyframes menuGradient {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Floating decorative emojis */
.menu-floaties {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.floatie {
  position: absolute;
  bottom: -60px;
  left: var(--x);
  font-size: 1.8rem;
  animation: floatUp var(--d) linear var(--delay) infinite;
}

@keyframes floatUp {
  0%   { transform: translateY(0) rotate(0deg);   opacity: 0; }
  8%   { opacity: 0.35; }
  92%  { opacity: 0.35; }
  100% { transform: translateY(calc(-100vh - 70px)) rotate(360deg); opacity: 0; }
}

/* Menu content */
.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 20px max(80px, calc(env(safe-area-inset-bottom) + 60px));
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.menu-title {
  font-size: clamp(52px, 14vw, 88px);
  color: #fff;
  text-shadow: 0 5px 0 rgba(0,0,0,.15), 0 10px 30px rgba(0,0,0,.2);
  letter-spacing: 2px;
  animation: titleBounce 2.5s ease-in-out infinite;
  line-height: 1;
}

@keyframes titleBounce {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50%       { transform: translateY(-10px) rotate(1deg); }
}

.menu-subtitle {
  font-size: clamp(16px, 4.5vw, 22px);
  color: rgba(255,255,255,.85);
  letter-spacing: 3px;
  margin-bottom: 4px;
}

.menu-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
}

/* lone last card in an odd-count grid — centre it at half width */
.menu-cards > .game-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  width: calc(50% - 7px);
  margin-left: auto;
  margin-right: auto;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px 14px;
  border: none;
  border-radius: 28px;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  box-shadow: 0 8px 0 rgba(0,0,0,.18), 0 14px 30px rgba(0,0,0,.2);
  transition: transform .12s ease, box-shadow .12s ease;
  -webkit-appearance: none;
}

.game-card:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 rgba(0,0,0,.18), 0 6px 15px rgba(0,0,0,.2);
}

.pop-card      { background: linear-gradient(135deg, #ff6b9d 0%, #ff8e53 100%); }
.reveal-card   { background: linear-gradient(135deg, #4ecdc4 0%, #44b8e0 100%); }
.grow-card     { background: linear-gradient(135deg, #9b59b6 0%, #e91e8c 100%); }
.rain-card     { background: linear-gradient(135deg, #56CCF2 0%, #2F80ED 100%); }
.stickers-card { background: linear-gradient(135deg, #f9c74f 0%, #f8961e 100%); }
.memory-card   { background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%); }
.connect-card  { background: linear-gradient(135deg, #f12711 0%, #f5af19 100%); }
.spot-card     { background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%); }

.card-emoji {
  font-size: 46px;
  line-height: 1;
  animation: cardWiggle 3s ease-in-out infinite;
}

.reveal-card   .card-emoji { animation-delay: -1.5s; }
.grow-card     .card-emoji { animation-delay: -3s;   }
.rain-card     .card-emoji { animation-delay: -4.5s; }
.stickers-card .card-emoji { animation-delay: -0.7s; }
.memory-card   .card-emoji { animation-delay: -2.2s; }
.connect-card  .card-emoji { animation-delay: -1.1s; }
.spot-card     .card-emoji { animation-delay: -3.8s; }

@keyframes cardWiggle {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  30%       { transform: rotate(6deg) scale(1.12); }
  70%       { transform: rotate(-4deg) scale(.96); }
}

.card-title {
  font-size: clamp(22px, 5.5vw, 30px);
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.15);
  line-height: 1;
}

.card-desc {
  font-size: clamp(11px, 2.8vw, 14px);
  color: rgba(255,255,255,.82);
  line-height: 1.2;
}

/* ─── HUD ─────────────────────────────────────────────────────────────────── */

.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
  pointer-events: none;
}

.back-btn {
  font-size: 28px;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  transition: transform .1s ease;
  flex-shrink: 0;
}

.back-btn:active { transform: scale(.88); }

.round-badge {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: max(14px, env(safe-area-inset-top));
  background: rgba(255,255,255,.92);
  color: #b36bff;
  padding: 7px 20px;
  border-radius: 22px;
  font-size: 18px;
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
  white-space: nowrap;
  pointer-events: none;
}

/* ─── POP GAME ────────────────────────────────────────────────────────────── */

#screen-pop {
  background: linear-gradient(150deg, #f0e6ff 0%, #d8eeff 100%);
}

#canvas-pop {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* Round complete overlay */
.round-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease;
  background: rgba(255,255,255,0);
}

.round-overlay.visible {
  opacity: 1;
  background: rgba(255,255,255,.35);
}

.overlay-inner {
  text-align: center;
  transform: scale(0);
  opacity: 0;
  transition: transform .4s cubic-bezier(.34,1.56,.64,1), opacity .25s ease;
}

.round-overlay.visible .overlay-inner {
  transform: scale(1);
  opacity: 1;
}

.overlay-emoji {
  font-size: 80px;
  line-height: 1;
  display: block;
}

.overlay-msg {
  font-size: clamp(42px, 12vw, 64px);
  color: #b36bff;
  text-shadow: 0 4px 0 rgba(0,0,0,.1);
  margin-top: 8px;
}

.overlay-sub {
  font-size: clamp(18px, 5vw, 24px);
  color: rgba(80,40,120,.6);
  margin-top: 6px;
}

/* ─── REVEAL GAME ─────────────────────────────────────────────────────────── */

#screen-reveal {
  background: radial-gradient(ellipse at 50% 60%, #1e0a40 0%, #080015 100%);
}

#canvas-reveal {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.reveal-hint {
  position: fixed;
  bottom: max(36px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.5);
  font-size: 20px;
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 10;
  transition: opacity 1s ease;
  white-space: nowrap;
}

.reveal-hint.gone { opacity: 0; }

/* ─── GROW GAME ────────────────────────────────────────────────────────────── */

#screen-grow {
  background: radial-gradient(ellipse at 50% 50%, #4a0080 0%, #150030 100%);
}

#canvas-grow {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* ─── RAIN GAME ────────────────────────────────────────────────────────────── */

#screen-rain {
  background: linear-gradient(180deg, #87ceeb 0%, #4aac6b 100%);
}

#canvas-rain {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* ─── STICKERS GAME ────────────────────────────────────────────────────────── */

#screen-stickers { background: #fff; }

#canvas-stickers {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.stickers-hint {
  position: fixed;
  bottom: max(36px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.7);
  font-size: 20px;
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 10;
  transition: opacity 1s ease;
  white-space: nowrap;
  text-shadow: 0 1px 6px rgba(0,0,0,.3);
}

.stickers-hint.gone { opacity: 0; }

/* ─── MEMORY GAME ─────────────────────────────────────────────────────────── */

#screen-memory {
  background: linear-gradient(150deg, #fce4ec 0%, #e8eaf6 100%);
}

#canvas-memory {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.memory-win-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease;
}

.memory-win-overlay.visible {
  opacity: 1;
  background: rgba(255,255,255,.4);
}

.memory-win-overlay.visible .overlay-inner {
  transform: scale(1);
  opacity: 1;
  pointer-events: all;
}

.memory-replay-btn {
  display: block;
  margin: 20px auto 0;
  padding: 14px 44px;
  border: none;
  border-radius: 50px;
  font-family: inherit;
  font-size: clamp(20px, 5.5vw, 26px);
  color: #fff;
  background: linear-gradient(135deg, #ff6b9d, #c77dff);
  box-shadow: 0 6px 0 rgba(179,107,255,.45);
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease;
}

.memory-replay-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(179,107,255,.45);
}

/* ─── MENU FOOTER ─────────────────────────────────────────────────────────── */

.menu-footer {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  z-index: 2;
  pointer-events: none;
}

.menu-dedication {
  display: block;
  color: rgba(255,255,255,.28);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.3px;
  padding: 2px 0 6px;
}

.menu-privacy-link {
  background: none;
  border: none;
  color: rgba(255,255,255,.38);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 8px 20px;
  pointer-events: all;
  letter-spacing: 0.5px;
}

/* ─── PARENT GATE ─────────────────────────────────────────────────────────── */

.parent-gate-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity .25s ease;
  padding: 20px;
}

.parent-gate-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.parent-gate-card {
  background: #fff;
  border-radius: 28px;
  padding: 36px 28px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  transform: scale(.88);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
}

.parent-gate-overlay.visible .parent-gate-card {
  transform: scale(1);
}

.gate-icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 12px;
}

.gate-heading {
  font-family: 'Fredoka One', inherit;
  font-size: 24px;
  color: #333;
  margin-bottom: 6px;
}

.gate-desc {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: #777;
  margin-bottom: 14px;
}

.gate-question {
  font-family: 'Fredoka One', inherit;
  font-size: 44px;
  color: #9b59b6;
  margin-bottom: 16px;
  letter-spacing: 2px;
}

.gate-input {
  display: block;
  width: 100%;
  padding: 14px;
  border: 2px solid #ddd;
  border-radius: 16px;
  font-family: 'Fredoka One', inherit;
  font-size: 32px;
  text-align: center;
  color: #333;
  outline: none;
  transition: border-color .15s ease;
  margin-bottom: 18px;
  background: #f8f8f8;
  -webkit-appearance: none;
  appearance: none;
  -moz-appearance: textfield;
}

.gate-input::-webkit-outer-spin-button,
.gate-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.gate-input:focus {
  border-color: #9b59b6;
  background: #fff;
}

@keyframes gateShake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-6px); }
  80%       { transform: translateX(6px); }
}

.gate-input.shake {
  animation: gateShake .4s ease;
  border-color: #e74c3c;
}

.gate-buttons {
  display: flex;
  gap: 12px;
}

.gate-btn {
  flex: 1;
  padding: 14px 20px;
  border: none;
  border-radius: 50px;
  font-family: 'Fredoka One', inherit;
  font-size: 18px;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease;
}

.gate-btn:active { transform: translateY(3px); }

.gate-cancel  { background: #f0f0f0; color: #666; }

.gate-confirm {
  background: linear-gradient(135deg, #9b59b6, #c77dff);
  color: #fff;
  box-shadow: 0 4px 0 rgba(155,89,182,.4);
}

.gate-confirm:active {
  box-shadow: 0 1px 0 rgba(155,89,182,.4);
}

/* ─── PRIVACY SCREEN ──────────────────────────────────────────────────────── */

#screen-privacy {
  background: #f2f2f7;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.privacy-header {
  display: flex;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px max(16px, env(safe-area-inset-left));
  background: #fff;
  border-bottom: 1px solid #e5e5ea;
  flex-shrink: 0;
  gap: 8px;
}

.privacy-header .back-btn {
  background: rgba(0,0,0,.06);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  flex-shrink: 0;
}

.privacy-title-bar {
  flex: 1;
  text-align: center;
  font-size: 18px;
  color: #1c1c1e;
  /* offset the back-btn so the text is visually centred */
  padding-right: 52px;
}

.privacy-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.privacy-content {
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 18px max(36px, env(safe-area-inset-bottom));
  color: #3a3a3c;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  user-select: text;
  -webkit-user-select: text;
}

.privacy-summary {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
  border: 1.5px solid #e5e5ea;
}

.privacy-summary p  { margin-bottom: 10px; }
.privacy-summary ul { padding-left: 18px; }
.privacy-summary li { margin-bottom: 8px; }

.privacy-section-title {
  font-family: 'Fredoka One', inherit;
  font-size: 21px;
  color: #9b59b6;
  margin-bottom: 12px;
}

.privacy-effective-date {
  font-size: 12px;
  color: #8e8e93;
  margin-bottom: 20px;
  letter-spacing: 0.3px;
}

.privacy-h2 {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #1c1c1e;
  margin: 28px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e5e5ea;
}

.privacy-h3 {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #3a3a3c;
  margin: 16px 0 6px;
}

.privacy-content p  { margin-bottom: 10px; }

.privacy-content ul,
.privacy-content ol { padding-left: 20px; margin-bottom: 10px; }

.privacy-content li { margin-bottom: 5px; }

.privacy-content code {
  font-size: 13px;
  background: #f2f2f7;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
}

.privacy-link {
  color: #9b59b6;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ─── MENU FOOTER LANGUAGE BUTTON ────────────────────────────────────────── */

.menu-lang-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.38);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 8px 20px;
  pointer-events: all;
  letter-spacing: 0.5px;
}

/* ─── LANGUAGE PICKER OVERLAY ─────────────────────────────────────────────── */

.lang-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity .25s ease;
  padding: 20px;
}

.lang-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.lang-card {
  background: #fff;
  border-radius: 28px;
  padding: 28px 24px 20px;
  max-width: 300px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  transform: scale(.88);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lang-overlay.visible .lang-card {
  transform: scale(1);
}

.lang-card-title {
  font-family: 'Fredoka One', inherit;
  font-size: 20px;
  color: #9b59b6;
  margin-bottom: 4px;
}

.lang-opt {
  display: block;
  width: 100%;
  padding: 13px 20px;
  border: 2px solid #e5e5ea;
  border-radius: 50px;
  font-family: inherit;
  font-size: 18px;
  color: #333;
  background: #fff;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .1s ease;
}

.lang-opt:active {
  transform: scale(.96);
  background: #f2e9ff;
  border-color: #c77dff;
}

.lang-cancel {
  display: block;
  width: 100%;
  padding: 10px;
  border: none;
  background: none;
  font-size: 20px;
  color: #aaa;
  cursor: pointer;
  font-family: inherit;
  margin-top: 2px;
}

/* ─── CONNECT GAME ─────────────────────────────────────────────────────────── */

#screen-connect {
  background: linear-gradient(150deg, #0a0a2e 0%, #1a1a5e 100%);
}

#canvas-connect {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* ─── SPOT GAME ───────────────────────────────────────────────────────────── */

#screen-spot {
  background: linear-gradient(150deg, #fff8e1 0%, #ffebc2 100%);
}

#canvas-spot {
  position: absolute;
  inset: 0;
  touch-action: none;
}

/* ─── UPDATE TOAST ────────────────────────────────────────────────────────── */

#update-toast {
  position: fixed;
  bottom: max(32px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #b36bff;
  padding: 12px 28px;
  border-radius: 40px;
  font-size: 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  white-space: nowrap;
}

#update-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── SLEEP TIMER BUTTONS ─────────────────────────────────────────────────── */

.timer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-bottom: 8px;
  pointer-events: all;
  flex-wrap: wrap;
}

.timer-label {
  font-family: 'Fredoka One', inherit;
  font-size: 13px;
  color: rgba(255,255,255,.38);
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.timer-btn {
  background: rgba(255,255,255,0.12);
  border: 1.5px solid rgba(255,255,255,0.20);
  border-radius: 20px;
  color: rgba(255,255,255,0.45);
  font-family: 'Fredoka One', inherit;
  font-size: 13px;
  padding: 5px 13px;
  cursor: pointer;
  pointer-events: all;
  min-width: 40px;
  transition: background .2s, color .2s, border-color .2s;
}

.timer-btn:active { transform: scale(0.92); }

.timer-btn.active {
  background: rgba(255,255,255,0.30);
  border-color: rgba(255,255,255,0.60);
  color: rgba(255,255,255,0.95);
}

/* ─── SLEEP OVERLAY ────────────────────────────────────────────────────────── */

.sleep-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.5s ease;
}

.sleep-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#canvas-sleep {
  position: absolute;
  inset: 0;
  touch-action: none;
}

#sleep-gate-overlay {
  z-index: 9100;
}
