/* ============================================================
   Match Buddies — a take-turns matching game for little kids
   Direction: toy-like, candy-world, sunny. Rounded & bouncy.
   ============================================================ */

:root {
  --sky-top: #7ed0ff;
  --sky-bot: #baeaff;
  --sun: #ffd64d;
  --grass: #8fe38a;

  --p1: #ff7a59;        /* fox / player 1 = warm coral   */
  --p1-deep: #e85c3a;
  --p2: #9b6cff;        /* bunny / player 2 = grape       */
  --p2-deep: #7d4de0;

  --card-back-a: #ff8fb1;
  --card-back-b: #ffc24d;
  --ink: #3a2e4a;
  --paper: #fffaf2;
  --white: #ffffff;

  --shadow-soft: 0 8px 0 rgba(58, 46, 74, 0.12);
  --shadow-pop: 0 10px 24px rgba(58, 46, 74, 0.22);
  --radius: 26px;

  --font: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 55%, var(--grass) 100%);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/* -------- screen switching -------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 3vw, 28px);
}
.screen.is-active { display: flex; animation: screen-in 0.45s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes screen-in {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}

/* ============================================================
   TITLE SCREEN
   ============================================================ */
.clouds { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.cloud {
  position: absolute;
  background: #fff;
  border-radius: 100px;
  opacity: 0.9;
  filter: drop-shadow(0 8px 0 rgba(255,255,255,0.5));
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; background: #fff; border-radius: 50%;
}
.cloud.c1 { width: 120px; height: 42px; top: 14%; left: -140px; animation: drift 34s linear infinite; }
.cloud.c2 { width: 90px;  height: 34px; top: 30%; left: -140px; animation: drift 46s linear infinite 6s; }
.cloud.c3 { width: 150px; height: 52px; top: 8%;  left: -180px; animation: drift 40s linear infinite 12s; }
.cloud::before { width: 55%; height: 150%; top: -55%; left: 10%; }
.cloud::after  { width: 42%; height: 130%; top: -40%; right: 14%; }
@keyframes drift { to { transform: translateX(calc(100vw + 320px)); } }

.title-card {
  position: relative;
  z-index: 2;
  width: min(560px, 94vw);
  background: var(--paper);
  border: 6px solid #fff;
  border-radius: 36px;
  box-shadow: var(--shadow-pop), inset 0 0 0 3px rgba(255,214,77,0.4);
  padding: clamp(20px, 4vw, 34px);
  text-align: center;
}

.logo {
  margin: 0 0 6px;
  line-height: 0.92;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.logo-word {
  font-weight: 700;
  font-size: clamp(48px, 12.5vw, 82px);
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #ff4f96 0%, #ff3d6e 55%, #ff7a2e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(0 4px 0 rgba(58,46,74,0.18));
}
.logo-word:nth-child(2) {
  background: linear-gradient(180deg, #38a8ff 0%, #6a5bff 60%, #7d4de0 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.buddies {
  display: flex;
  justify-content: center;
  gap: clamp(14px, 5vw, 40px);
  margin: 8px 0 2px;
}
.buddy {
  font-size: clamp(56px, 16vw, 96px);
  display: inline-block;
  filter: drop-shadow(0 6px 0 rgba(58,46,74,0.14));
}
.buddy-a { animation: hop 1.6s ease-in-out infinite; }
.buddy-b { animation: hop 1.6s ease-in-out infinite 0.4s; }
@keyframes hop {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-16px) rotate(4deg); }
}

.tagline {
  font-size: clamp(15px, 3.6vw, 20px);
  color: #8a7fa0;
  font-weight: 600;
  margin: 4px 0 14px;
}

.choose-label {
  font-weight: 700;
  font-size: clamp(16px, 4vw, 21px);
  color: var(--ink);
  margin: 6px 0 10px;
}

.size-picker {
  display: flex;
  justify-content: center;
  gap: clamp(10px, 3vw, 18px);
  margin-bottom: 18px;
}
.size-btn {
  border: 4px solid #f0e6d6;
  background: #fff;
  border-radius: 22px;
  padding: 12px 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.15s cubic-bezier(.2,.9,.3,1.4), border-color 0.15s, box-shadow 0.15s;
  min-width: clamp(72px, 22vw, 104px);
}
.size-btn:hover { transform: translateY(-3px); }
.size-btn:active { transform: translateY(1px) scale(0.97); }
.size-btn.is-chosen {
  border-color: var(--sun);
  box-shadow: 0 0 0 4px rgba(255,214,77,0.35), var(--shadow-soft);
  transform: translateY(-2px);
}
.size-btn:focus-visible { outline: 4px solid var(--p2); outline-offset: 3px; }

.size-grid {
  display: grid;
  gap: 3px;
  align-content: center;
  justify-content: center;
}
.size-grid i {
  display: block;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--card-back-a), var(--card-back-b));
}
.s-easy   { grid-template-columns: repeat(3, 1fr); }
.s-easy i { width: 13px; height: 17px; }
.s-medium { grid-template-columns: repeat(4, 1fr); }
.s-medium i { width: 11px; height: 14px; }
.s-hard   { grid-template-columns: repeat(4, 1fr); }
.s-hard i { width: 9px; height: 12px; }
.size-star { font-size: 13px; letter-spacing: -1px; }

/* -------- big play button -------- */
.big-btn {
  border: none;
  cursor: pointer;
  margin: 6px auto 0;
  width: clamp(96px, 26vw, 128px);
  height: clamp(96px, 26vw, 128px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7bed9f, #34c471);
  box-shadow: 0 10px 0 #23a15a, var(--shadow-pop);
  color: #fff;
  display: grid;
  place-items: center;
  transition: transform 0.12s, box-shadow 0.12s;
  animation: pulse 1.8s ease-in-out infinite;
}
.big-btn-icon { font-size: clamp(40px, 11vw, 56px); margin-left: 6px; line-height: 1; }
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(8px); box-shadow: 0 2px 0 #23a15a, var(--shadow-soft); }
.big-btn:focus-visible { outline: 5px solid #fff; outline-offset: 4px; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 10px 0 #23a15a, 0 0 0 0 rgba(52,196,113,0.5); }
  50% { box-shadow: 0 10px 0 #23a15a, 0 0 0 18px rgba(52,196,113,0); }
}

/* -------- mute button (corner) -------- */
.mute-btn {
  position: absolute;
  top: 16px; right: 16px;
  z-index: 5;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255,255,255,0.75);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-size: 26px;
  display: grid; place-items: center;
  transition: transform 0.12s;
}
.mute-btn:active { transform: scale(0.9); }
.mute-btn:focus-visible { outline: 4px solid var(--p2); outline-offset: 2px; }
.mute-off { display: none; }
body.is-muted .mute-on { display: none; }
body.is-muted .mute-off { display: inline; }

/* ============================================================
   GAME SCREEN
   ============================================================ */
#screen-game { justify-content: flex-start; gap: clamp(8px, 1.6vh, 16px); }

.scoreboard {
  width: min(920px, 100%);
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  padding-top: 6px;
}

.player {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.55);
  border: 4px solid transparent;
  border-radius: 22px;
  transition: transform 0.25s cubic-bezier(.2,.9,.3,1.3), box-shadow 0.25s, background 0.25s, border-color 0.25s, opacity 0.25s;
  min-width: 0;
}
.player-2 { flex-direction: row-reverse; }

.player-face {
  flex: 0 0 auto;
  width: clamp(52px, 13vw, 74px);
  height: clamp(52px, 13vw, 74px);
  border-radius: 50%;
  display: grid; place-items: center;
  background: #fff;
  box-shadow: var(--shadow-soft);
}
.player-emoji { font-size: clamp(30px, 8vw, 46px); line-height: 1; }
.player-1 .player-face { box-shadow: 0 6px 0 rgba(232,92,58,0.3); }
.player-2 .player-face { box-shadow: 0 6px 0 rgba(125,77,224,0.3); }

.player-basket {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-content: center;
  font-size: clamp(15px, 3.6vw, 22px);
  min-height: 30px;
  line-height: 1;
}
.player-2 .player-basket { justify-content: flex-end; }
.basket-item { animation: plop 0.4s cubic-bezier(.2,.9,.3,1.6) both; }
@keyframes plop {
  0% { transform: scale(0) rotate(-40deg); }
  70% { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1) rotate(0); }
}

/* active-turn styling */
.player.is-turn { transform: scale(1.05); }
.player-1.is-turn { background: var(--p1); border-color: #fff; box-shadow: var(--shadow-pop); color: #fff; }
.player-2.is-turn { background: var(--p2); border-color: #fff; box-shadow: var(--shadow-pop); color: #fff; }
.player:not(.is-turn) { opacity: 0.6; }
.player.is-turn .player-face { animation: wiggle 0.9s ease-in-out infinite; }
@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}

.turn-center {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: clamp(36px, 8vw, 56px);
  position: relative;
}
.turn-arrow {
  font-size: clamp(24px, 6vw, 36px);
  transition: transform 0.35s cubic-bezier(.2,.9,.3,1.4);
  animation: bob 1s ease-in-out infinite;
}
.turn-arrow.point-right { transform: scaleX(-1) rotate(-90deg); }
.turn-arrow.point-left  { transform: rotate(-90deg); }
@keyframes bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: 6px; }
}

/* -------- board -------- */
.board-wrap {
  flex: 1 1 auto;
  width: 100%;
  display: grid;
  place-items: center;
  min-height: 0;
}
.board {
  display: grid;
  gap: clamp(6px, 1.6vw, 14px);
  width: 100%;
  max-width: min(920px, 96vw);
  margin: 0 auto;
}

.card {
  position: relative;
  aspect-ratio: 3 / 4;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  perspective: 700px;
  transition: transform 0.15s;
}
.card:focus-visible { outline: 4px solid var(--p2-deep); outline-offset: 3px; border-radius: 16px; }
.card:active { transform: scale(0.96); }

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(.2,.8,.3,1.1);
  border-radius: clamp(12px, 2.4vw, 20px);
}
.card.is-flipped .card-inner,
.card.is-matched .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: inherit;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-soft);
}
.card-front {
  background: linear-gradient(135deg, var(--card-back-a), var(--card-back-b));
  border: 4px solid #fff;
}
.card-front::after {
  content: "★";
  font-size: clamp(26px, 7vw, 44px);
  color: rgba(255,255,255,0.9);
  text-shadow: 0 3px 0 rgba(0,0,0,0.08);
}
.card-back {
  background: var(--white);
  border: 4px solid #ffe9c2;
  transform: rotateY(180deg);
  font-size: clamp(30px, 9vw, 60px);
  line-height: 1;
}

.card.is-matched { cursor: default; }
.card.is-matched .card-inner { animation: matched-pop 0.6s cubic-bezier(.2,.9,.3,1.5); }
.card.is-matched .card-back {
  border-color: #7bed9f;
  background: #eafff0;
  box-shadow: 0 0 0 4px rgba(123,237,159,0.5);
}
@keyframes matched-pop {
  0% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.18); }
  100% { transform: rotateY(180deg) scale(1); }
}
.card.is-wrong .card-inner { animation: shake 0.45s; }
@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-7px); }
  75% { transform: rotateY(180deg) translateX(7px); }
}
.card.is-gone { visibility: hidden; }

/* -------- game footer -------- */
.game-footer {
  display: flex;
  gap: 14px;
  padding: 4px 0 max(8px, env(safe-area-inset-bottom));
}
.mini-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255,255,255,0.8);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-size: 24px;
  display: grid; place-items: center;
  transition: transform 0.12s;
}
.mini-btn:hover { transform: translateY(-2px); }
.mini-btn:active { transform: scale(0.9); }
.mini-btn:focus-visible { outline: 4px solid var(--p2); outline-offset: 2px; }
.mini-btn.ghost { background: rgba(255,255,255,0.55); margin: 12px auto 0; }

/* ============================================================
   WIN SCREEN
   ============================================================ */
#confetti { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.win-card {
  position: relative;
  z-index: 2;
  width: min(520px, 94vw);
  background: var(--paper);
  border: 6px solid #fff;
  border-radius: 36px;
  box-shadow: var(--shadow-pop);
  padding: clamp(22px, 5vw, 40px);
  text-align: center;
}
.win-title {
  margin: 0 0 18px;
  font-size: clamp(40px, 11vw, 68px);
  font-weight: 700;
  background: linear-gradient(180deg, #ff4f96 0%, #ff3d6e 55%, #ff9024 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(0 4px 0 rgba(58,46,74,0.16));
}

.podium {
  display: flex;
  justify-content: center;
  gap: clamp(18px, 7vw, 46px);
  margin-bottom: 24px;
}
.podium-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.podium-crown {
  font-size: clamp(28px, 8vw, 42px);
  opacity: 0;
  transform: translateY(10px) scale(0.5);
  transition: all 0.4s cubic-bezier(.2,.9,.3,1.6);
}
.podium-player.is-winner .podium-crown { opacity: 1; transform: translateY(0) scale(1); }
.podium-player.is-winner .podium-emoji { animation: hop 1.4s ease-in-out infinite; }
.podium-emoji {
  font-size: clamp(58px, 17vw, 92px);
  filter: drop-shadow(0 6px 0 rgba(58,46,74,0.14));
}
.podium-player:not(.is-winner) { opacity: 0.85; }
.podium-score {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  max-width: 130px;
  font-size: clamp(15px, 4vw, 20px);
  line-height: 1;
}

/* ============================================================
   RESPONSIVE — portrait / phones
   ============================================================ */
@media (max-width: 560px) {
  .scoreboard { gap: 6px; }
  .player { padding: 6px 8px; gap: 8px; flex-direction: column; text-align: center; }
  .player-2 { flex-direction: column; }
  .player-2 .player-basket { justify-content: center; }
  .turn-arrow.point-right { transform: scaleX(-1) rotate(-90deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.08s !important;
  }
  .cloud { display: none; }
}
