/* Piccola Italia — toddler-first: huge targets, no small UI, everything bounces. */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  touch-action: manipulation;          /* kills double-tap zoom on tablets */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;         /* no long-press image callout on iOS */
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Arial Rounded MT Bold", "Comic Sans MS", ui-rounded, system-ui, sans-serif;
  background: linear-gradient(160deg, #fef6e4 0%, #d4f1f9 100%);
}

#app {
  height: 100%;
  height: 100dvh;                      /* correct height under mobile browser bars */
  display: flex;
  flex-direction: column;
  /* keep content out of notches / home-indicator zones (PWA fullscreen) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- header ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  flex-shrink: 0;
}

.back-btn {
  border: none;
  background: #fff;
  border-radius: 24px;
  font-size: 34px;
  line-height: 1;
  padding: 12px 26px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

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

.screen-title {
  font-size: clamp(28px, 5vw, 44px);
  color: #444;
  letter-spacing: 1px;
}

/* ---------- home ---------- */

.home {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vh;
  padding: 4vh 4vw;
  overflow-y: auto;                    /* never trap content offscreen */
}

.home-title {
  font-size: clamp(34px, 6vw, 60px);
  color: #e0524d;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.08);
}

.home-grid {
  display: flex;
  gap: 4vw;
  width: 100%;
  max-width: 1100px;
  justify-content: center;
  flex-wrap: wrap;
}

.home-tile {
  flex: 1 1 240px;
  max-width: 340px;
  border: none;
  border-radius: 36px;
  padding: 4vh 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.15);
  animation: float 3s ease-in-out infinite;
}

.home-tile:nth-child(2) { animation-delay: 0.4s; }
.home-tile:nth-child(3) { animation-delay: 0.8s; }
.home-tile:active { transform: scale(0.94); }

.home-tile .big-emoji { font-size: clamp(64px, 10vw, 110px); }

.home-tile .label {
  font-size: clamp(24px, 3.5vw, 38px);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

/* ---------- grids of tiles ---------- */

.grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  padding: 10px 20px 30px;
  align-content: start;
}

.tile {
  border: none;
  border-radius: 28px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
  color: #fff;
}

.tile:active { transform: scale(0.92); }

.tile .tile-main {
  font-size: clamp(44px, 7vw, 72px);
  font-weight: bold;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

.tile .tile-sub { font-size: clamp(26px, 4vw, 40px); }

.tile .tile-word {
  font-size: clamp(18px, 2.6vw, 28px);
  max-width: 100%;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

/* ---------- book layout (words + showcase) ---------- */

.split {
  flex: 1;
  display: flex;
  overflow: hidden;
  gap: 12px;
  padding: 0 20px 20px;
}

.split .grid {
  flex: 1.15;
  padding: 10px 4px 30px;
}

.showcase {
  flex: 1;
  background: #fff;
  border: 6px solid #60a5fa;
  border-radius: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5vh;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.1);
  text-align: center;
  padding: 16px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;                  /* nothing may bleed outside the card */
}

.showcase:active { transform: scale(0.98); }

/* The visual (photo or emoji) takes whatever space is LEFT between the
   letter/number above and the word below — it shrinks, never overflows. */
.showcase-emoji {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(72px, 16vh, 200px);
  line-height: 1.1;
}

/* smaller emoji when it shares the showcase with a big letter/number */
.showcase-emoji.sm {
  font-size: clamp(48px, 10vh, 120px);
}

.showcase-letter {
  flex: none;
  font-size: clamp(52px, 10vh, 120px);
  font-weight: bold;
  line-height: 1;
}

.showcase-letter:empty { display: none; }

.showcase-word {
  flex: none;
  font-size: clamp(22px, 4vh, 44px);
  color: #999;
  letter-spacing: 2px;
}

/* portrait: showcase on top (like an open book page), grid scrolls below */
@media (orientation: portrait) {
  .split { flex-direction: column-reverse; }
  .showcase { flex: 0 0 44%; }
}

@media (orientation: portrait) and (max-width: 640px) {
  .showcase-letter { font-size: clamp(36px, 7vh, 72px); }
  .showcase-word { font-size: clamp(18px, 3vh, 30px); }
  .count-row .count-item { font-size: clamp(22px, 4.5vh, 44px); }
}

/* counting row inside the numbers showcase */

.count-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  max-width: 90%;
}

.count-row .count-item {
  font-size: clamp(38px, 7vh, 68px);
  opacity: 0.25;
  transform: scale(0.8);
  transition: all 0.25s ease;
}

.count-row .count-item.lit {
  opacity: 1;
  transform: scale(1.15);
}

/* ---------- photos (swap in over emoji when available) ---------- */

.photo {
  max-width: 100%;
  max-height: 100%;
  border-radius: 24px;
  object-fit: cover;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

/* photo fills the flexible visual area, never more (fixes portrait overflow) */
.showcase-emoji .photo { max-width: 100%; max-height: 100%; }

/* ---------- trova (Dov'è…?) ---------- */

.trova-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vh;
  padding: 0 20px 30px;
}

.trova-question {
  border: none;
  background: #fff;
  border-radius: 28px;
  padding: 16px 34px;
  font-size: clamp(24px, 4vw, 42px);
  font-family: inherit;
  color: #444;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12);
}

.trova-question:active { transform: scale(0.95); }

.trova-cards {
  display: flex;
  gap: 3vw;
  width: 100%;
  max-width: 1100px;
  justify-content: center;
}

.trova-card {
  flex: 1;
  max-width: 300px;
  aspect-ratio: 1;
  border: 8px solid transparent;
  background: #fff;
  border-radius: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.12);
  overflow: hidden;
  transition: opacity 0.3s ease;
}

.trova-card:active { transform: scale(0.94); }

.trova-visual {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(70px, 13vw, 150px);
}

.trova-visual .photo {
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
}

.trova-card.found { border-color: #34d399; }
.trova-card.dim { opacity: 0.3; }

.shake-once { animation: shake-once 0.4s ease; }

@keyframes shake-once {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-10px) rotate(-2deg); }
  75%      { transform: translateX(10px) rotate(2deg); }
}

/* ---------- phones ---------- */

@media (max-width: 640px) {
  /* home: 2×2 compact grid so all four modules fit one phone screen */
  .home { gap: 2.5vh; padding: 2.5vh 5vw; }
  .home-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
  .home-tile { max-width: none; padding: 22px 10px; animation: none; }
  .home-tile .big-emoji { font-size: 54px; }
  .home-tile .label { font-size: 22px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; padding: 8px 14px 24px; }
  .header { padding: 10px 14px; gap: 12px; }
  .back-btn { font-size: 26px; padding: 10px 20px; }
  .split { padding: 0 14px 14px; gap: 10px; }
}

/* trova: stack the three cards vertically on narrow portrait screens */
@media (max-width: 640px) and (orientation: portrait) {
  .trova-stage { gap: 2vh; padding-bottom: 16px; }
  .trova-question { font-size: 22px; padding: 12px 22px; }
  .trova-cards {
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-height: 0;
  }
  .trova-card {
    flex: none;
    height: 23dvh;
    width: auto;
    aspect-ratio: 1;
    max-width: none;
  }
}

/* ---------- confetti ---------- */

.confetti {
  position: fixed;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 99;
}

/* ---------- animations ---------- */

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

.bounce-once { animation: bounce-once 0.45s ease; }

@keyframes bounce-once {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25) rotate(-4deg); }
  100% { transform: scale(1); }
}
