/* Memory for Kids — same palette, type and chunky buttons as the other games. */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --navy: #1f5fa4;
  --crimson: #ef5b5b;
  --gold: #ffcf3f;
  --green: #4cbb6c;
  --green-dark: #2f8f4c;
  --cream: #fff8ec;
  --ink: #23324a;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(#8fd4ff 0%, #bfe7ff 45%, #ffe9b8 100%);
  color: var(--ink);
  font-family: "Baloo 2", "Fredoka", "Quicksand", "Trebuchet MS", system-ui, sans-serif;
  font-weight: 700;
  touch-action: manipulation;
  user-select: none;
}

.screen { position: fixed; inset: 0; display: none; }
.screen.show { display: flex; flex-direction: column; }

/* ------------------------------ home ------------------------------ */
.home-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: calc(var(--sat) + 34px) 18px calc(var(--sab) + 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 14px; width: 100%; max-width: 560px; }
.brand-words { min-width: 0; }
.brand-mascot { width: 132px; height: 132px; flex: 0 0 auto; filter: drop-shadow(0 5px 4px rgba(20,50,90,.22)); }
.mascot-img { width: 100%; height: 100%; display: block; object-fit: contain; }
.brand-kicker { margin: 0; font-size: 17px; color: var(--navy); }
.brand-name { margin: -2px 0 0; font-size: clamp(38px,11vw,56px); line-height: .95; color: #fff; -webkit-text-stroke: 5px var(--navy); paint-order: stroke fill; text-shadow: 0 5px 0 var(--navy); letter-spacing: 0; }
.brand-sub { margin: 6px 0 0; font-size: 14px; color: #4b6b52; }
.game-title { width: 100%; max-width: 560px; margin: 2px 0 -4px; color: var(--navy); font-size: clamp(28px,7vw,42px); line-height: 1; text-align: center; text-shadow: 0 3px 0 #fff; letter-spacing: 0; }

.card {
  background: var(--cream);
  border: 4px solid #fff;
  border-radius: 22px;
  padding: 16px;
  box-shadow: 0 8px 0 rgba(31,95,164,.18), 0 14px 26px rgba(20,50,90,.16);
}
.card-title { margin: 0 0 8px; font-size: 18px; color: var(--navy); }
.card-note { margin: 0; font-size: 15px; color: #5b6b86; }

.name-input {
  width: 100%;
  font: inherit;
  font-size: 24px;
  padding: 12px;
  border-radius: 16px;
  border: 4px solid #ffd98a;
  background: #fff;
  text-align: center;
}
.name-input:focus { outline: none; border-color: var(--navy); }

.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.level {
  font: inherit;
  cursor: pointer;
  background: #fff;
  border: 4px solid #d8e6f5;
  border-radius: 18px;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  min-height: 92px;
}
.level-name { font-size: 18px; }
.level-note { font-size: 12px; color: #5b6b86; text-align: center; }
.level.lv-easy, .level.lv-medium, .level.lv-hard { background: #fff; border-color: #d8e6f5; }
.level.sel { border-color: var(--gold); background: #fffdf3; box-shadow: 0 0 0 4px rgba(255,207,63,.35); }
.level:active { transform: translateY(2px); }
.level-dots { display: flex; gap: 4px; }
.level-dots i { width: 8px; height: 8px; border-radius: 50%; background: #d7e3f5; }
.level-dots i.on { background: var(--gold); }

.play-btn {
  font: inherit; font-size: 24px; cursor: pointer;
  border: 0; border-radius: 18px; padding: 14px;
  color: #fff; background: var(--navy); box-shadow: 0 6px 0 #001a45;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.play-btn.small { font-size: 18px; padding: 10px 18px; }
.play-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #001a45; }
.play-tri { width: 0; height: 0; border-left: 16px solid #fff; border-top: 10px solid transparent; border-bottom: 10px solid transparent; }
.home-play { width: 100%; min-height: 76px; border-radius: 26px; background: linear-gradient(#57d47c,#3aa85c); box-shadow: 0 8px 0 var(--green-dark), 0 16px 26px rgba(20,80,40,.28); border: 4px solid #fff; }
.home-play:active { box-shadow: 0 3px 0 var(--green-dark); }

.home-toggles { display: flex; gap: 8px; justify-content: center; }
.toggle {
  font: inherit; cursor: pointer; font-size: 14px;
  border-radius: 999px; padding: 8px 16px;
  border: 3px solid #d7e3f5; background: #fff; color: #8795ad;
}
.toggle[aria-pressed="true"] { border-color: var(--navy); color: var(--navy); background: #e6efff; }

.voice-pick { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: 14px; }
.voice-pick select, .voice-pick button {
  font: inherit; font-size: 14px; padding: 6px 10px; border-radius: 10px;
  border: 3px solid #d7e3f5; background: #fff; color: var(--ink);
}
.voice-pick button { cursor: pointer; }

.star-line { margin: 0; text-align: center; font-size: 14px; color: var(--crimson); min-height: 18px; }
.footer-note { margin: 0; text-align: center; font-size: 12px; color: #8795ad; }

/* ------------------------------ game ------------------------------ */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--sat) + 6px) 10px 6px;
  background: var(--navy); color: #fff;
}
.tb-btn {
  font: inherit; font-size: 18px; cursor: pointer; line-height: 1;
  width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: rgba(255,255,255,.16); color: #fff;
}
.tb-btn.off { opacity: .45; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.scores { display: flex; flex-direction: column; line-height: 1.15; }
.scores span { font-size: 16px; }
.scores .moves { font-size: 12px; opacity: .85; }

.board-wrap {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
}
.board { display: grid; width: max-content; max-width: 100%; margin: auto; }

.mcard {
  position: relative;
  padding: 0; border: 0; background: transparent; cursor: pointer;
  aspect-ratio: 4 / 5;
  perspective: 700px;
}
.mface {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  border-radius: 14px;
  backface-visibility: hidden;
  transition: transform .34s ease;
  overflow: hidden;
}
.mback {
  background: var(--navy);
  border: 3px solid #001a45;
  box-shadow: 0 4px 0 #001a45;
  transform: rotateY(0deg);
}
.mback img { width: 100%; height: 100%; object-fit: cover; }
.mfront {
  background: #fff;
  border: 3px solid #d7e3f5;
  box-shadow: 0 4px 0 #d7e3f5;
  transform: rotateY(180deg);
  padding: 6px 4px 4px;
}
.mfront img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.mname {
  font-size: clamp(11px, 2.4vw, 17px);
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.mcard.flipped .mback { transform: rotateY(-180deg); }
.mcard.flipped .mfront { transform: rotateY(0deg); }
.mcard.done .mfront { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(251,191,36,.45), 0 4px 0 #e0a90f; }
.mcard.done { animation: pop .45s ease; }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.08); } 100% { transform: scale(1); } }

.board.calm .mface { transition: none; }
.board.calm .mcard.done { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .mface { transition: none; }
  .mcard.done { animation: none; }
}

.tip { flex: 0 0 auto; margin: 0; padding: 4px 10px calc(var(--sab) + 10px); text-align: center; font-size: 14px; color: #5b6b86; }

/* ---------------------------- overlays ---------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,22,46,.72); padding: 16px;
}
.overlay[hidden] { display: none; }
.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.win-card, .gate-card {
  position: relative;
  background: #fff; border-radius: 22px; padding: 20px;
  width: min(460px, 100%); text-align: center;
  box-shadow: 0 12px 0 rgba(0,0,0,.18);
}
.win-burst { font-size: 54px; }
.win-card h2 { margin: 6px 0; color: var(--navy); font-size: 26px; }
.win-card p { margin: 4px 0; color: #5b6b86; }
.win-stars { font-size: 32px; letter-spacing: .08em; }
.win-btns { margin-top: 14px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.ghost-btn {
  font: inherit; cursor: pointer; font-size: 16px;
  border-radius: 14px; padding: 12px 18px;
  border: 3px solid #d7e3f5; background: #fff; color: var(--navy);
}
.ghost-btn.wide { width: 100%; }

.gate-title { margin: 0 0 6px; color: var(--navy); font-size: 22px; }
.gate-pic { font-size: 50px; line-height: 1.1; }
.gate-q { margin: 6px 0 10px; font-size: 40px; letter-spacing: .06em; color: var(--ink); }
.gate-say { margin: 0 0 8px; font-size: 18px; color: #5b6b86; }
.gate-say .lit, .gate-q .lit { color: var(--gold); }
.gate-choices { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.gate-choice {
  font: inherit; cursor: pointer; font-size: 30px; min-width: 92px;
  padding: 14px 8px; border-radius: 18px;
  border: 0; background: var(--navy); color: #fff; box-shadow: 0 5px 0 #001a45;
}
.gate-choice:active { transform: translateY(3px); box-shadow: none; }
.gate-choice.wrong { background: #b9c4d6; box-shadow: none; opacity: .6; }
.gate-msg { margin: 10px 0 0; min-height: 20px; color: var(--crimson); }
.gate-again { margin-top: 10px; }
.gate-card.correct { background: #fffaf0; }

/* Match Maze Adventures: use the tablet's landscape width, not browser height. */
@media (orientation: landscape) and (min-width: 820px) {
  .home-scroll { display: grid; grid-template-columns: minmax(300px,1fr) minmax(340px,1.05fr); grid-template-areas: "brand title" "about levels" "name levels" "play levels" "tog tog" "voice voice" "back back" "star star"; gap: 10px 24px; align-content: start; justify-content: center; max-width: 1060px; padding-top: calc(var(--sat) + 18px); padding-bottom: calc(var(--sab) + 18px); }
  .brand { grid-area: brand; max-width: none; }
  .game-title { grid-area: title; max-width: none; align-self: end; margin: 0 0 -2px; font-size: 34px; }
  #aboutCard { grid-area: about; }
  #nameCard { grid-area: name; }
  #levelCard { grid-area: levels; align-self: start; }
  .home-play { grid-area: play; }
  .home-toggles { grid-area: tog; }
  .voice-pick { grid-area: voice; }
  .ghost-btn.wide { grid-area: back; justify-self: center; }
  .star-line { grid-area: star; }
  .footer-note { display: none; }
  .brand-name { font-size: 34px; }
  .brand-mascot { width: 96px; height: 96px; }
  .card { padding: 12px; }
  .level { min-height: 78px; padding: 10px 4px; }
  .gate-q { font-size: 32px; }
  .gate-choice { font-size: 24px; min-width: 76px; padding: 10px 8px; }
  .gate-pic { font-size: 38px; }
  .tip { display: none; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .brand-mascot { width: 96px; height: 96px; }
  .brand-name { font-size: 34px; }
  .home-play { min-height: 66px; font-size: 27px; }
  .home-scroll { align-content: start; gap: 11px; padding-top: calc(var(--sat) + 18px); }
}
