@import url('https://fonts.googleapis.com/css2?family=Baloo+Bhaijaan+2:wght@500;600;700;800&display=swap');

:root {
  --purple: #7357d5;
  --purple-dark: #51389d;
  --lavender: #eee9ff;
  --pink: #ff6f91;
  --yellow: #ffd85b;
  --mint: #64d6b0;
  --sky: #69c8f2;
  --ink: #352d55;
  --cream: #fffaf0;
  --white: #ffffff;
  --card-back-start: #7f63dc;
  --card-back-end: #5d9fe2;
  --card-back-image: none;
  --shadow: 0 18px 45px rgba(74, 48, 130, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Baloo Bhaijaan 2", Tahoma, Arial, sans-serif;
  background:
    radial-gradient(circle at 10% 20%, rgba(255, 216, 91, 0.28) 0 70px, transparent 72px),
    radial-gradient(circle at 92% 80%, rgba(100, 214, 176, 0.25) 0 95px, transparent 97px),
    linear-gradient(145deg, #f2edff 0%, #fff8ef 48%, #e9f9ff 100%);
}

button {
  font: inherit;
}

.app-loading .game-shell,
.app-loading .play-shell { visibility: hidden; }

.login-screen {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  padding: 20px;
  place-items: center;
  background: linear-gradient(145deg, #f2edff, #fff8ef 55%, #e9f9ff);
}

.login-screen[hidden] { display: none; }
.login-card { width: min(420px, 100%); padding: 32px; border: 3px solid white; border-radius: 28px; background: rgba(255,255,255,.95); box-shadow: var(--shadow); }
.login-lock { font-size: 3.2rem; text-align: center; }
.login-card h1 { margin: 0; color: var(--ink); text-align: center; font-size: 1.9rem; text-shadow: none; }
.login-card > p { text-align: center; }
.login-card label, .settings-form label { display: block; margin: 12px 0 5px; font-weight: 800; }
.login-card input, .settings-form input[type="text"], .settings-form input[type="password"], .settings-form input[type="file"] { width: 100%; min-height: 46px; padding: 9px 12px; color: var(--ink); border: 2px solid #ded6f6; border-radius: 13px; background: white; outline: none; }
.login-card input:focus, .settings-form input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(115,87,213,.12); }
.form-message { min-height: 24px; margin: 7px 0; color: #b32954; font-weight: 700; }
.form-message.success { color: #208766; }
.primary-button, .secondary-button { width: 100%; padding: 11px 18px; border: 0; border-radius: 14px; cursor: pointer; color: white; font-weight: 800; }
.primary-button { background: var(--purple); box-shadow: 0 5px 0 var(--purple-dark); }
.secondary-button { background: #397fae; box-shadow: 0 5px 0 #286083; }

.game-shell {
  width: min(920px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 46px;
}

.hero {
  position: relative;
  overflow: hidden;
  min-height: 185px;
  padding: 34px 24px 28px;
  text-align: center;
  color: white;
  border-radius: 32px 32px 18px 18px;
  background: linear-gradient(135deg, #7255d3, #9f70e2 58%, #6dc9ed);
  box-shadow: var(--shadow);
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto -5% -25px;
  height: 52px;
  border-radius: 50% 50% 0 0;
  background: rgba(255, 255, 255, 0.13);
}

.eyebrow {
  margin: 0 0 2px;
  color: #fff0a8;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 1.5px;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1.12;
  text-shadow: 0 3px 0 rgba(67, 38, 129, 0.25);
}

.intro {
  margin: 7px 0 0;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 600;
}

.hero-star {
  position: absolute;
  color: var(--yellow);
  animation: twinkle 2.2s ease-in-out infinite;
}

.star-one { top: 28px; right: 8%; font-size: 28px; }
.star-two { bottom: 26px; left: 9%; font-size: 21px; animation-delay: 0.8s; }

.cloud {
  position: absolute;
  width: 74px;
  height: 25px;
  border-radius: 40px;
  background: rgba(255, 255, 255, 0.18);
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  bottom: 4px;
  border-radius: 50%;
  background: inherit;
}

.cloud::before { width: 34px; height: 34px; right: 10px; }
.cloud::after { width: 26px; height: 26px; left: 12px; }
.cloud-one { top: 40px; left: 7%; }
.cloud-two { bottom: 25px; right: 5%; transform: scale(0.75); }

.game-card,
.games-catalog {
  padding: 22px clamp(15px, 4vw, 34px) 30px;
  border: 2px solid rgba(115, 87, 213, 0.08);
  border-top: 0;
  border-radius: 0 0 28px 28px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.game-card[hidden], .games-catalog[hidden] { display: none; }
.catalog-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.section-kicker { margin: 0; color: var(--pink); font-size: .85rem; font-weight: 800; }
.catalog-heading h2 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.35rem); }
.games-count { display: flex; align-items: center; gap: 7px; padding: 7px 14px; color: var(--purple-dark); border-radius: 999px; background: var(--lavender); }
.games-count strong { font-size: 1.25rem; }
.catalog-description { margin: 4px 0 19px; color: #756d8d; }
.games-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 17px; }

.game-tile {
  position: relative;
  display: block;
  overflow: hidden;
  min-height: 220px;
  padding: 0;
  border: 0;
  border-radius: 24px;
  cursor: pointer;
  color: white;
  text-align: right;
  text-decoration: none;
  background: linear-gradient(145deg, #7255d3, #5abde6);
  box-shadow: 0 8px 0 rgba(79, 56, 154, .2), 0 13px 25px rgba(76, 54, 143, .14);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.game-tile:nth-child(3n + 2) { background: linear-gradient(145deg, #ed6f9d, #9b6fe0); }
.game-tile:nth-child(3n + 3) { background: linear-gradient(145deg, #43cba2, #5ea9e7); }
.game-tile:hover { transform: translateY(-5px); box-shadow: 0 11px 0 rgba(79, 56, 154, .17), 0 17px 30px rgba(76, 54, 143, .18); }
.tile-images { position: relative; display: flex; height: 145px; justify-content: center; align-items: center; padding-top: 14px; }
.tile-image { position: absolute; width: 84px; height: 106px; object-fit: cover; border: 3px solid white; border-radius: 13px; background: white; box-shadow: 0 7px 15px rgba(34, 25, 71, .22); }
.tile-image:nth-child(1) { transform: translateX(52px) rotate(10deg); }
.tile-image:nth-child(2) { z-index: 2; transform: translateY(-7px); }
.tile-image:nth-child(3) { transform: translateX(-52px) rotate(-10deg); }
.tile-info { display: flex; align-items: center; justify-content: space-between; padding: 7px 18px 15px; }
.tile-title { display: block; font-size: 1.3rem; font-weight: 800; }
.tile-subtitle { display: block; color: rgba(255,255,255,.85); font-size: .82rem; }
.tile-arrow { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 50%; background: rgba(255,255,255,.2); }
.remaining-note { margin: 21px 0 0; padding: 10px 15px; color: #725b22; text-align: center; border-radius: 14px; background: #fff5cc; }

.settings-panel { margin: 0 0 22px; border: 2px solid #e5ddfb; border-radius: 18px; background: #fbf9ff; }
.settings-panel summary { padding: 13px 17px; cursor: pointer; color: var(--purple-dark); font-weight: 800; }
.settings-content { display: grid; grid-template-columns: 1.4fr 1fr; gap: 22px; padding: 4px 18px 20px; border-top: 1px solid #ebe5fa; }
.upload-guide { grid-column: 1 / -1; margin-top: 14px; border: 2px solid #dcefe9; border-radius: 14px; background: #f2fcf8; }
.upload-guide summary { padding: 11px 14px; cursor: pointer; color: #23795f; font-weight: 800; }
.upload-guide-content { padding: 0 17px 12px; color: #48405f; }
.upload-guide-content ul { margin: 4px 0 10px; padding-right: 22px; }
.upload-guide-content li { margin: 5px 0; }
.upload-guide-content p { margin: 8px 0 0; }
.settings-form h3 { margin: 16px 0 6px; }
.settings-form small { display: block; margin-top: 4px; color: #756d8d; }
.color-setting { display: flex; align-items: center; gap: 10px; }
.color-setting input[type="color"] { width: 56px; height: 46px; padding: 3px; border: 2px solid #ded6f6; border-radius: 12px; background: white; }
.mini-card-preview { display: inline-block; width: 46px; height: 58px; margin-inline-start: auto; border: 3px solid white; border-radius: 9px; background: linear-gradient(145deg, var(--card-back-start), var(--card-back-end)); box-shadow: 0 4px 0 rgba(70,52,135,.17); }
.custom-card-back .mini-card-preview { background: var(--card-back-image) center / cover no-repeat; }
.back-image-preview { display: block; width: 95px; height: 95px; margin-top: 9px; padding: 6px; object-fit: contain; border: 2px dashed #cbbff0; border-radius: 13px; }
.back-image-preview[hidden] { display: none; }
.delete-image-button { margin-top: 9px; padding: 7px 12px; border: 0; border-radius: 11px; cursor: pointer; color: #a22d50; font-weight: 800; background: #ffe7ee; }
.delete-image-button[hidden] { display: none; }
.logout-button { grid-column: 1 / -1; justify-self: end; padding: 8px 15px; border: 0; border-radius: 12px; cursor: pointer; color: #a22d50; font-weight: 800; background: #ffe7ee; }

html.play-document { width: var(--embedded-width, 100%); max-width: 100%; min-width: 0; overflow-x: hidden; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.play-page { width: 100%; max-width: 100%; min-width: 0; overflow-x: hidden; background: #fff; }
.play-shell { width: min(1180px, 100%); max-width: 100%; min-width: 0; margin: 0 auto; padding: 16px 12px 32px; }
.play-shell .game-card { padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.play-toolbar { justify-content: center; }
.play-toolbar .difficulty { margin-inline: auto; }
.play-actions { display: flex; align-items: center; gap: 8px; }
.fullscreen-button { font-size: 1.35rem; font-weight: 800; }
html:fullscreen { height: 100%; overflow-y: auto; background: white; }
html:-webkit-full-screen { height: 100%; overflow-y: auto; background: white; }
html.page-fullscreen { height: 100%; overflow-y: auto; background: white; }
:fullscreen .play-shell { width: 100%; padding: 8px; }
:fullscreen .play-shell .game-card { min-height: calc(100vh - 16px); border-radius: 18px; box-shadow: none; }
:-webkit-full-screen .play-shell { width: 100%; padding: 8px; }
:-webkit-full-screen .play-shell .game-card { min-height: calc(100vh - 16px); border-radius: 18px; box-shadow: none; }
.mobile-fullscreen { overflow: auto; background: white; }
.mobile-fullscreen .play-shell { width: 100%; min-height: 100vh; min-height: 100dvh; padding: 4px; }
.mobile-fullscreen .play-shell .game-card { min-height: calc(100vh - 8px); min-height: calc(100dvh - 8px); border-radius: 12px; box-shadow: none; }
.mobile-fullscreen .play-shell { padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); }
.mobile-fullscreen .play-toolbar { position: sticky; top: 0; z-index: 5; padding-block: 8px; background: #fff; }
.game-error { width: min(520px, calc(100% - 30px)); margin: 80px auto; padding: 30px; text-align: center; border-radius: 24px; background: white; box-shadow: var(--shadow); }
.game-error h1 { color: var(--ink); font-size: 2rem; text-shadow: none; }

.toolbar,
.difficulty,
.stats,
.stat {
  display: flex;
  align-items: center;
}

.toolbar {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.back-button { display: flex; align-items: center; gap: 6px; padding: 7px 13px; border: 0; border-radius: 13px; cursor: pointer; color: var(--purple-dark); font-weight: 800; background: var(--lavender); }

.difficulty {
  flex-wrap: wrap;
  gap: 7px;
  font-weight: 700;
}

.level,
.sound-button {
  border: 0;
  cursor: pointer;
  color: var(--ink);
  background: var(--lavender);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.level {
  padding: 7px 15px;
  border-radius: 999px;
  font-weight: 700;
}

.level.active {
  color: white;
  background: var(--purple);
  box-shadow: 0 5px 0 var(--purple-dark);
}

.level.extreme { color: #9d3153; background: #ffe4ec; }
.level.extreme.active { color: white; background: #d84974; box-shadow: 0 5px 0 #a92e53; }

.sound-button {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  font-size: 1.2rem;
}

.level:hover,
.sound-button:hover,
.restart-button:hover,
.play-again:hover {
  transform: translateY(-2px);
}

.stats {
  justify-content: center;
  gap: clamp(8px, 2vw, 18px);
  margin: 0 auto 12px;
}

.stat {
  min-width: 120px;
  justify-content: center;
  gap: 9px;
  padding: 9px 13px;
  border-radius: 16px;
  background: #f7f4ff;
}

.moves-stat { border-bottom: 4px solid var(--pink); }
.time-stat { border-bottom: 4px solid var(--sky); }
.pairs-stat { border-bottom: 4px solid var(--yellow); }
.stat-icon { font-size: 1.4rem; }
.stat small { display: block; color: #746d8b; line-height: 1; }
.stat strong { display: block; font-size: 1.15rem; line-height: 1.25; }

.status-message {
  min-height: 28px;
  margin: 9px 0 14px;
  text-align: center;
  color: #6a6181;
  font-weight: 600;
}

.board {
  display: grid;
  width: min(100%, 680px);
  margin: 0 auto;
  gap: clamp(8px, 1.8vw, 14px);
  perspective: 1000px;
}

.board.easy { grid-template-columns: repeat(4, 1fr); }
.board.medium { grid-template-columns: repeat(4, 1fr); }
.board.hard { grid-template-columns: repeat(5, 1fr); }
.board.extreme { width: min(100%, 830px); grid-template-columns: repeat(8, 1fr); gap: 8px; }

.memory-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  cursor: pointer;
  background: transparent;
  transform-style: preserve-3d;
  transition: transform 450ms cubic-bezier(.2, .75, .3, 1.2);
}

.memory-card.is-flipped,
.memory-card.is-matched {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: clamp(12px, 2.5vw, 20px);
  backface-visibility: hidden;
  box-shadow: 0 6px 0 rgba(70, 52, 135, 0.16), 0 10px 22px rgba(65, 46, 125, 0.12);
}

.card-back {
  overflow: hidden;
  color: white;
  border: 4px solid white;
  background: linear-gradient(145deg, var(--card-back-start), var(--card-back-end));
}

.custom-card-back .card-back { background: var(--card-back-image) center / cover no-repeat; }
.custom-card-back .card-back::before { display: none; }

.card-back::before {
  content: "★";
  display: grid;
  width: 48%;
  aspect-ratio: 1;
  place-items: center;
  color: var(--yellow);
  border: 3px dashed rgba(255, 255, 255, 0.64);
  border-radius: 50%;
  font-size: clamp(1.2rem, 4vw, 2rem);
}

.card-front {
  overflow: hidden;
  border: 3px solid #eee8ff;
  background: var(--cream);
  transform: rotateY(180deg);
}

.card-front img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

.memory-card.is-matched .card-front {
  border-color: var(--mint);
  background: #eafff7;
  animation: matched 500ms ease;
}

.restart-button,
.play-again {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  cursor: pointer;
  color: white;
  font-weight: 800;
  transition: transform 160ms ease;
}

.restart-button {
  margin: 25px auto 0;
  padding: 11px 24px;
  border-radius: 16px;
  background: var(--pink);
  box-shadow: 0 6px 0 #cf476b;
}

.modal-backdrop {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  padding: 20px;
  place-items: center;
  background: rgba(43, 32, 76, 0.58);
  backdrop-filter: blur(5px);
}

.modal-backdrop[hidden] { display: none; }

.win-modal {
  width: min(430px, 100%);
  padding: 30px 24px;
  text-align: center;
  border: 5px solid white;
  border-radius: 30px;
  background: linear-gradient(160deg, #fffaf0, #f1ebff);
  box-shadow: 0 24px 70px rgba(29, 18, 65, 0.3);
  animation: pop-in 400ms cubic-bezier(.2, 1.4, .45, 1);
}

.trophy { font-size: 4.4rem; animation: trophy-bounce 1.3s ease-in-out infinite; }
.win-kicker { margin: 4px 0 0; color: var(--pink); font-size: 1.3rem; font-weight: 800; }
.win-modal h2 { margin: 0; font-size: 1.8rem; }
.win-modal p { margin: 7px 0; }
.earned-stars { margin: 10px 0 17px; color: #f5b900; font-size: 2rem; letter-spacing: 5px; }
.play-again { width: 100%; padding: 12px; border-radius: 16px; background: var(--purple); box-shadow: 0 6px 0 var(--purple-dark); }

.celebration {
  position: fixed;
  z-index: 20;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti {
  position: absolute;
  top: -30px;
  animation: fall 2.6s linear forwards;
}

@keyframes twinkle { 50% { opacity: 0.45; transform: scale(0.75) rotate(20deg); } }
@keyframes matched { 50% { transform: rotateY(180deg) scale(1.12); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.72); } }
@keyframes trophy-bounce { 50% { transform: translateY(-8px) rotate(4deg); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 620px) {
  .game-shell { width: min(100% - 18px, 920px); padding-top: 9px; }
  .hero { min-height: 160px; padding-top: 28px; border-radius: 24px 24px 14px 14px; }
  .game-card { padding-inline: 11px; }
  .toolbar { align-items: flex-start; }
  .difficulty > span { width: 100%; }
  .level { padding: 6px 12px; }
  .stats { gap: 6px; }
  .stat { min-width: 0; flex: 1; padding: 7px 4px; gap: 4px; }
  .stat-icon { font-size: 1.05rem; }
  .stat small { font-size: 0.7rem; }
  .stat strong { font-size: 0.95rem; }
  .board.hard { gap: 6px; }
  .board.extreme { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .board.hard .card-face { border-width: 2px; }
  .board.extreme .card-face { border-width: 2px; border-radius: 9px; }
  .games-grid { grid-template-columns: 1fr; }
  .game-tile { min-height: 205px; }
  .toolbar { flex-wrap: wrap; }
  .back-button { order: -2; }
  .sound-button { order: -1; }
  .difficulty { width: 100%; justify-content: center; }
  .settings-content { grid-template-columns: 1fr; }
  .logout-button { grid-column: 1; }
  .play-shell { width: min(100% - 10px, 1180px); padding-top: 6px; }
  .play-shell .game-card { padding-inline: 8px; border-radius: 18px; }
}

@media (min-width: 621px) and (max-width: 840px) {
  .games-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Public game sizing follows its measured container, including stale mobile iframe viewports. */
.play-page .play-shell { width: min(1180px, 100%); }
.play-page .play-shell .game-card { padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.play-page .toolbar { flex-wrap: wrap; align-items: center; }
.play-page .difficulty { max-width: 100%; justify-content: center; }
.play-page .stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(100%, 480px); }
.play-page .stat { min-width: 0; padding-inline: 4px; }
.play-page .board.easy, .play-page .board.medium { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.play-page .board.hard { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.play-page .board.extreme { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.play-page.compact-layout .play-shell { padding: 8px 8px 24px; }
.play-page.compact-layout .difficulty { width: 100%; }
.play-page.compact-layout .difficulty > span { width: 100%; }
.play-page.compact-layout .level { padding: 6px 12px; }
.play-page.compact-layout .stats { gap: 6px; }
.play-page.compact-layout .stat { padding: 7px 4px; gap: 4px; }
.play-page.compact-layout .stat-icon { font-size: 1.05rem; }
.play-page.compact-layout .stat small { font-size: .7rem; }
.play-page.compact-layout .stat strong { font-size: .95rem; }
.play-page.compact-layout .board { gap: 8px; }
.play-page.compact-layout .board.hard { gap: 6px; }
.play-page.compact-layout .board.extreme { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.play-page.compact-layout .board.hard .card-face { border-width: 2px; }
.play-page.compact-layout .board.extreme .card-face { border-width: 2px; border-radius: 9px; }
.play-page:not(.compact-layout) .difficulty { width: auto; }
.play-page:not(.compact-layout) .difficulty > span { width: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
