/* ==========================================================================
   ABCsmooshy - Page layout, tiles & effects (on top of theme.css and styles.css)
   ========================================================================== */

.abc-bg {
  background: linear-gradient(160deg, #ffe2d2 0%, #e8dbff 55%, #cadfff 100%);
}

.abc-stage {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: calc(76px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px))
           calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
}

/* Zero-specificity reset so each button style below wins without !important */
:where(.abc-stage) button {
  font-family: var(--font-display);
  border: none;
  background: none;
  cursor: pointer;
  outline: none;
  color: var(--ink);
}

:where(.abc-stage) button:focus-visible {
  outline: 3px solid var(--sky-ink);
  outline-offset: 3px;
}

/* --- Category menu --- */
.abc-menu {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  /* Three rows of bubbles (each 1.08x as tall as wide) must fit under the title */
  --menu-w: min(100%, 720px, (100vh - 160px) / 1.12);
  --menu-w: min(100%, 720px, (100dvh - 160px) / 1.12);
}

.abc-menu-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
}

.menu-grid {
  width: var(--menu-w);
  margin: auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(10px, 2.2vmin, 22px);
}

.cat-bubble {
  aspect-ratio: 1 / 1.08;
  border-radius: 30px;
  background: var(--from);
  container-type: inline-size;
  /* A pressable bottom edge in the bubble's deeper shade */
  box-shadow: 0 6px 0 var(--to), 0 14px 24px rgba(58, 50, 83, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4%;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cat-bubble:hover {
  transform: translateY(-3px);
}

.cat-bubble:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--to), 0 6px 12px rgba(58, 50, 83, 0.08);
}

.cat-icon {
  font-size: 48px;
  font-size: 42cqw;
  line-height: 1;
  filter: drop-shadow(0 6px 8px rgba(58, 50, 83, 0.1));
}

.cat-name {
  font-family: var(--font-display);
  font-size: clamp(14px, 12cqw, 24px);
  font-weight: 600;
  color: var(--ink);
}

.is-wiggling {
  animation: wiggle 0.5s ease;
}

@keyframes wiggle {
  0% { transform: scale(1); }
  25% { transform: scale(1.12) rotate(-6deg); }
  50% { transform: scale(1.1) rotate(5deg); }
  75% { transform: scale(1.05) rotate(-3deg); }
  100% { transform: scale(1); }
}

/* --- Board: a screen of pictures with arrows --- */
.abc-board {
  height: 100%;
  display: grid;
  grid-template-columns: 84px 1fr 84px;
  grid-template-rows: auto auto 1fr 26px;
  grid-template-areas:
    "top    top    top"
    "prompt prompt prompt"
    "prev   grid   next"
    ".      dots   .";
  align-items: center;
}

.abc-board[hidden] {
  display: none;
}

/* Back chip + game button: the board's top row on small screens, up by the parent bar where there's room */
.board-top {
  grid-area: top;
  justify-self: start;
  z-index: 6;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* "All worlds": a clear way back to the category menu */
.board-back {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 20px 0 6px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 4px 0 var(--line), var(--shadow-soft);
  font-size: 19px;
  font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.board-back:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--line), var(--shadow-soft);
}

.board-back-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--coral);
  color: #ffffff;
}

.board-back-arrow svg {
  width: 60%;
  height: 60%;
}

/* The world you're in, as a plain title (not a button) */
.board-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.abc-grid {
  grid-area: grid;
  align-self: stretch;
  min-height: 0;
  min-width: 0;
  display: grid;
  justify-content: center;
  align-content: center;
  --cell: 160px;
}

.abc-grid.slide-next { animation: slideNext 0.35s cubic-bezier(0.25, 1, 0.5, 1); }
.abc-grid.slide-prev { animation: slidePrev 0.35s cubic-bezier(0.25, 1, 0.5, 1); }

@keyframes slideNext {
  from { transform: translateX(60px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes slidePrev {
  from { transform: translateX(-60px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.abc-cell {
  position: relative;
  margin: 8%;
  overflow: hidden;
  container-type: size;
  cursor: pointer;
  border-radius: 28%;
  background: var(--surface);
  box-shadow: 0 5px 0 var(--line), 0 12px 24px rgba(58, 50, 83, 0.07);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.abc-cell:hover {
  transform: translateY(-3px);
}

.cell-fig {
  position: relative;
  z-index: 1;
  width: 62%;
  height: 62%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.42);
  line-height: 1;
}

.cell-label {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: clamp(13px, calc(var(--cell) * 0.12), 26px);
  font-weight: 500;
  color: var(--ink);
  margin-top: 2%;
  white-space: nowrap;
}

/* Hebrew meaning under the English word */
.cell-he {
  position: relative;
  z-index: 1;
  font-family: system-ui, 'Segoe UI', Arial, sans-serif;
  font-size: clamp(11px, calc(var(--cell) * 0.085), 19px);
  font-weight: 700;
  line-height: 1.2;
  color: var(--lilac-ink);
}

.cell-label b {
  font-weight: 600;
  color: var(--coral);
}

.abc-arrow {
  width: 68px;
  height: 68px;
  justify-self: center;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 4px 0 var(--line), var(--shadow-soft);
  font-size: 24px;
  color: var(--coral);
  transition: transform 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.abc-arrow:active {
  transform: scale(0.9);
}

.abc-arrow--prev { grid-area: prev; }
.abc-arrow--next { grid-area: next; }

.abc-dots {
  grid-area: dots;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e3dbd1;
  transition: all 0.3s ease;
}

.dot.active {
  width: 26px;
  border-radius: 6px;
  background: var(--coral);
}

.abc-board.single-page .abc-arrow,
.abc-board.single-page .abc-dots {
  visibility: hidden;
}

/* Tall screens (phones held upright): arrows go under the pictures */
@media (max-aspect-ratio: 4/5) {
  .abc-board {
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto auto 1fr 84px;
    grid-template-areas:
      "top    top    top"
      "prompt prompt prompt"
      "grid   grid   grid"
      "prev   dots   next";
  }
}

/* --- Pictures --- */
.fig-emoji {
  filter: drop-shadow(0 6px 8px rgba(58, 50, 83, 0.1));
}

.fig-letter,
.fig-number {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15em;
  line-height: 1;
  color: var(--tile-color, var(--coral));
}

/* Letters and numbers take turns in five colors (letters sit in a slot with their sound button) */
.abc-grid > :nth-child(5n + 2) { --tile-color: var(--sky-ink); }
.abc-grid > :nth-child(5n + 3) { --tile-color: #e5a200; }
.abc-grid > :nth-child(5n + 4) { --tile-color: var(--mint-ink); }
.abc-grid > :nth-child(5n + 5) { --tile-color: var(--lilac-ink); }

.fig-letter-pic {
  position: absolute;
  right: -12%;
  bottom: -10%;
  font-size: 0.42em;
}

.fig-swatch {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 3px rgba(58, 50, 83, 0.08), inset 0 -8px 0 rgba(0, 0, 0, 0.08);
}

.fig-shape {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 6px 8px rgba(58, 50, 83, 0.12));
}

/* --- Effects: each picture does its trick inside its own tile --- */
.abc-cell.is-playing {
  box-shadow: 0 0 0 5px var(--coral-soft), 0 5px 0 var(--line), 0 12px 24px rgba(58, 50, 83, 0.07);
}

/* Layer behind the picture for splashes, paint, stamps and counting */
.cell-fx {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.abc-cell.fx-hop .cell-fig { animation: fxHop 1.1s ease; }
.abc-cell.fx-splash .cell-fig,
.abc-cell.fx-paint .cell-fig { animation: fxSquish 0.7s ease; }
.abc-cell.fx-drive .cell-fig { animation: tileDrive 1.3s cubic-bezier(0.45, 0, 0.55, 1); }
.abc-cell.fx-fly .cell-fig { animation: tileFly 1.4s cubic-bezier(0.45, 0, 0.55, 1); }
.abc-cell.fx-stamp .cell-fig { animation: fxSpin 0.9s cubic-bezier(0.34, 1.3, 0.64, 1); }
.abc-cell.fx-boing .cell-fig,
.abc-cell.fx-count .cell-fig { animation: fxBoing 0.9s ease; }
.abc-cell.fx-letter .cell-fig { animation: fxSquish 0.6s ease; }
.abc-cell.fx-letter .fig-letter-pic { animation: picPop 1.2s cubic-bezier(0.34, 1.4, 0.64, 1); }

/* Counting: the word steps aside while the pictures fill the tile */
.cell-label {
  transition: opacity 0.2s ease;
}

.abc-cell.fx-count .cell-label {
  opacity: 0;
}

/* Paint: keep the word readable on any color */
.abc-cell.fx-paint .cell-label {
  padding: 0 0.45em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
}

@keyframes fxHop {
  0%, 100% { transform: translateY(0) rotate(0); }
  15% { transform: translateY(0) scale(1.1, 0.88); }
  32% { transform: translateY(-16%) rotate(-8deg); }
  48% { transform: translateY(0) scale(1.08, 0.9); }
  64% { transform: translateY(-10%) rotate(8deg); }
  80% { transform: translateY(0) scale(1.04, 0.96); }
}

@keyframes fxSquish {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.18, 0.84); }
  55% { transform: scale(0.92, 1.1); }
  75% { transform: scale(1.05, 0.96); }
}

/* Vehicles drive out of one side of the tile and come back in from the other */
@keyframes tileDrive {
  0% { transform: translateX(0); }
  10% { transform: translateX(6%) rotate(3deg); }
  45% { transform: translateX(-150%); }
  45.1% { transform: translateX(150%); }
  90% { transform: translateX(-3%); }
  100% { transform: translateX(0); }
}

@keyframes tileFly {
  0% { transform: translate(0, 0); }
  10% { transform: translate(-5%, 5%); }
  45% { transform: translate(150%, -150%); }
  45.1% { transform: translate(-150%, 150%); }
  92% { transform: translate(2%, -2%); }
  100% { transform: translate(0, 0); }
}

@keyframes fxSpin {
  0% { transform: rotate(0) scale(1); }
  60% { transform: rotate(380deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes fxBoing {
  0%, 100% { transform: scale(1); }
  20% { transform: scale(1.25, 0.75); }
  40% { transform: scale(0.85, 1.2); }
  60% { transform: scale(1.1, 0.92); }
  80% { transform: scale(0.97, 1.03); }
}

@keyframes picPop {
  0%, 100% { transform: scale(1) rotate(0); }
  35% { transform: scale(1.9) rotate(-12deg); }
  60% { transform: scale(1.6) rotate(8deg); }
}

/* Hearts, paws, notes and sparkles float up inside the tile */
.tile-bubble {
  position: absolute;
  bottom: 14%;
  font-size: calc(var(--cell) * 0.13);
  line-height: 1;
  opacity: 0;
  animation: bubbleUp 1.2s ease-out forwards;
}

@keyframes bubbleUp {
  0% { transform: translate(-50%, 0) scale(0.5); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(-50%, calc(var(--cell) * -0.62)) scale(1.1); opacity: 0; }
}

/* Juice drops */
.tile-drop {
  position: absolute;
  left: 50%;
  top: 44%;
  width: calc(var(--cell) * 0.07);
  height: calc(var(--cell) * 0.07);
  border-radius: 50%;
  animation: dropOut 0.8s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes dropOut {
  0% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.5); opacity: 0; }
}

/* Paint: the color fills the tile from the tap, then fades */
.tile-wash {
  position: absolute;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  animation: washGrow 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes washGrow {
  0% { transform: scale(0); opacity: 0.95; }
  35% { transform: scale(var(--grow)); opacity: 0.95; }
  70% { transform: scale(var(--grow)); opacity: 0.8; }
  100% { transform: scale(var(--grow)); opacity: 0; }
}

/* Shapes: little stamps */
.tile-stamp {
  position: absolute;
  width: calc(var(--cell) * 0.15);
  height: calc(var(--cell) * 0.15);
  transform: translate(-50%, -50%) scale(0);
  animation: stampIn 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.stamp-shape {
  width: 100%;
  height: 100%;
  overflow: visible;
}

@keyframes stampIn {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  40% { transform: translate(-50%, -50%) scale(1) rotate(var(--turn)); opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.7) rotate(var(--turn)); opacity: 0; }
}

/* Numbers: pictures pop out of the number into a ring */
.tile-count {
  position: absolute;
  left: 50%;
  top: 46%;
  font-size: calc(var(--cell) * 0.12);
  line-height: 1;
  transform: translate(-50%, -50%) scale(0);
  animation: countPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes countPop {
  0% { transform: translate(-50%, -50%) scale(0); }
  100% { transform: translate(calc(var(--x) - 50%), calc(var(--y) - 50%)) scale(1); }
}

/* Animals: the tile, and its own sound button under it */
.abc-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: calc(var(--cell) * 0.08);
}

.abc-slot > .abc-cell {
  flex: none;
  width: calc(var(--cell) * 0.84);
  height: calc(var(--cell) * 0.84);
  margin: 0;
}

.cell-sound {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: max(52px, calc(var(--cell) * 0.4));
  height: max(34px, calc(var(--cell) * 0.17));
  /* clear of the tile's bottom edge, with a real gap even on small phones */
  margin-top: max(14px, calc(var(--cell) * 0.1));
  border-radius: 999px;
  background: var(--lilac-ink);
  box-shadow: 0 4px 0 #5a40a8;
  color: #ffffff;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
}

.cell-sound svg {
  width: 62%;
  height: 62%;
}

.cell-sound:hover {
  background: #7f64d4;
}

.cell-sound:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #5a40a8;
}

@media (min-width: 760px) {
  .board-top {
    position: fixed;
    top: calc(16px + env(safe-area-inset-top, 0px));
    left: calc(16px + env(safe-area-inset-left, 0px));
  }
  .abc-menu-title {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top, 0px));
    left: calc(20px + env(safe-area-inset-left, 0px));
  }
  .abc-menu {
    --menu-w: min(100%, 720px, (100vh - 110px) / 1.12);
    --menu-w: min(100%, 720px, (100dvh - 110px) / 1.12);
  }
}

@media (max-width: 600px) {
  .abc-board { grid-template-columns: 64px 1fr 64px; }
  .abc-arrow { width: 56px; height: 56px; font-size: 22px; }
  .board-back,
  .quiz-toggle { height: 46px; font-size: 17px; padding: 0 16px 0 12px; }
  .board-back { padding-left: 5px; }
  .board-back-arrow { width: 36px; height: 36px; }
  .board-title { font-size: 18px; }
}

/* Narrow phones: the back button and the game button need the row; the tiles show the world anyway */
@media (max-width: 480px) {
  .board-title { display: none; }
  .quiz-question { font-size: 19px; }
  .abc-menu-title { font-size: 18px; }
}

@media (max-width: 600px) and (max-aspect-ratio: 4/5) {
  .abc-board { grid-template-columns: 1fr auto 1fr; }
}

/* --- "Where is the…?" game --- */
.quiz-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px 0 16px;
  border-radius: 999px;
  background: var(--lilac-ink);
  box-shadow: 0 4px 0 #5a40a8;
  font-size: 19px;
  font-weight: 600;
  color: #ffffff;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

:where(.abc-stage) .quiz-toggle {
  color: #ffffff;
}

.quiz-toggle:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #5a40a8;
}

/* In the game it turns back into a quiet "Learn" button */
.abc-board.is-quiz .quiz-toggle {
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--ink);
}

.quiz-prompt {
  grid-area: prompt;
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
  margin: 4px 0 10px;
  padding: 7px 8px 7px 7px;
  border-radius: 30px;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.quiz-prompt[hidden] {
  display: none;
}

.quiz-repeat {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--lilac-ink);
  box-shadow: 0 3px 0 #5a40a8;
}

:where(.abc-stage) .quiz-repeat {
  color: #ffffff;
}

.quiz-repeat svg {
  width: 60%;
  height: 60%;
}

.quiz-repeat:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #5a40a8;
}

.quiz-question {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
  text-wrap: balance;
}

.quiz-stars {
  flex: none;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--butter);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--butter-ink);
}

.abc-board.is-quiz .abc-arrow,
.abc-board.is-quiz .abc-dots {
  visibility: hidden;
}

/* Right answer: green ring. Wrong: a little shake, then it stays faded */
.abc-cell.is-right {
  box-shadow: 0 0 0 6px #7fd3a8, 0 5px 0 var(--line), 0 12px 24px rgba(58, 50, 83, 0.07);
}

.abc-cell.is-wrong {
  opacity: 0.4;
  animation: tileShake 0.45s ease;
  cursor: default;
}

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

@media (prefers-reduced-motion: reduce) {
  .abc-cell .cell-fig,
  .ambient-orb {
    animation: none !important;
  }
}
