/* ============================================================
 * Candy Playground · 糖果游乐场 — styles
 * Bright, cute, playful cartoon look (poki.com vibes).
 * Soft pink → blue gradient, candy palette, rounded everything,
 * pill buttons, soft diffuse shadows, a smiling cloud mascot and
 * drifting cloud/star/heart decorations. Fredoka (rounded) is
 * self-hosted for Latin; Chinese uses the bold rounded system
 * stack. Zero external dependencies, no Google Fonts / CDN.
 * ============================================================ */

/* ---------- self-hosted rounded font (Fredoka, OFL 1.1) ---------- */
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/fredoka-latin-400.woff2") format("woff2");
}
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/fredoka-latin-600.woff2") format("woff2");
}
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/fredoka-latin-700.woff2") format("woff2");
}

/* ---------- tokens ---------- */
:root {
  --pink: #FF6B9D;
  --purple: #B388FF;
  --teal: #4DD0C9;
  --yellow: #FFD54F;
  --blue: #64B5F6;
  --coral: #FF8A65;
  --ink: #4A4A55;
  --ink-soft: #6B6B7A;
  --card-ink: #5F5F6E;
  /* darker text tints derived from the candy palette (see palette note) */
  --pink-text: #E64980;
  --blue-text: #4A86D0;
  --blue-deep: #4F9BEA;
  --bg-gradient: linear-gradient(180deg, #FFF1F5 0%, #F4EAFD 55%, #EAF4FF 100%);
  --play-font: "Fredoka", "Baloo 2", ui-rounded, "Hiragino Maru Gothic ProN",
    Quicksand, "Segoe UI", system-ui, sans-serif;
  --sys-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
    "Helvetica Neue", Arial, sans-serif;
  --shadow-card: 0 10px 24px rgba(178, 150, 210, 0.18);
  --shadow-card-hover: 0 20px 38px rgba(178, 150, 210, 0.28);
  --radius-card: 22px;
}

/* ---------- reset / base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sys-font);
  color: var(--ink);
  background: var(--bg-gradient);
  background-attachment: fixed;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
button { font-family: inherit; }
a { color: var(--purple); }
::selection { background: var(--yellow); color: var(--ink); }

body.no-scroll { overflow: hidden; }

[hidden] { display: none !important; }

.font-play { font-family: var(--play-font); }

/* hide the symbol-defs container completely */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 100;
  background: var(--purple);
  color: #fff;
  padding: 10px 18px;
  font-weight: 700;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(179, 136, 255, 0.4);
}
.skip-link:focus { left: 8px; }

/* ---------- cute pill buttons ---------- */
.pbtn {
  font-family: var(--sys-font);
  font-weight: 700;
  font-size: 14px;
  color: #571333; /* deep berry text — white-on-candy fails WCAG AA, so darken the text instead */
  background: linear-gradient(180deg, #FF8AB0, var(--pink));
  border: 0;
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 16px rgba(255, 107, 157, 0.34);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.pbtn:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 11px 24px rgba(255, 107, 157, 0.42);
}
.pbtn:active {
  transform: translateY(1px) scale(0.96);
  box-shadow: 0 3px 8px rgba(255, 107, 157, 0.3);
}
.pbtn:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }

.pbtn--lang {
  background: linear-gradient(180deg, #C39BFF, var(--purple));
  box-shadow: 0 6px 16px rgba(179, 136, 255, 0.34);
  padding: 9px 18px;
  letter-spacing: 1px;
}
.pbtn--lang:hover { box-shadow: 0 11px 24px rgba(179, 136, 255, 0.44); }
.pbtn--lang:active { box-shadow: 0 3px 8px rgba(179, 136, 255, 0.32); }

.pbtn--filter {
  background: #fff;
  color: var(--purple);
  font-size: 13px;
  padding: 8px 15px;
  box-shadow: 0 4px 12px rgba(178, 150, 210, 0.16);
}
.pbtn--filter:hover { box-shadow: 0 8px 18px rgba(178, 150, 210, 0.26); }
.pbtn--filter.is-active {
  background: linear-gradient(180deg, var(--blue), var(--blue-deep));
  /* no color override: keeps the berry .pbtn text readable on the blue gradient */
  box-shadow: 0 6px 16px rgba(100, 181, 246, 0.4);
}
.pbtn--filter.is-active:hover { box-shadow: 0 10px 22px rgba(100, 181, 246, 0.5); }

.pbtn--play {
  /* inline-flex kept for justify-content centering on small screens */
  display: inline-flex;
  font-size: 18px;
  letter-spacing: 1px;
  padding: 16px 36px;
  background: linear-gradient(180deg, #FF93B7, #FF5F93);
  box-shadow: 0 10px 24px rgba(255, 107, 157, 0.4);
}
.pbtn--play:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 16px 32px rgba(255, 107, 157, 0.5);
  animation: wobble 0.6s ease infinite;
}
.pbtn--play:active {
  animation: none; /* wobble animates transform, so cancel it so the press-down scales */
  transform: translateY(1px) scale(0.96);
  box-shadow: 0 5px 12px rgba(255, 107, 157, 0.36);
}
.pbtn__label { display: inline-block; }

.pbtn--close {
  background: linear-gradient(180deg, var(--coral), #FF6B5E);
  box-shadow: 0 5px 12px rgba(255, 138, 101, 0.4);
  font-size: 16px;
  line-height: 1;
  padding: 9px 14px;
}

/* ---------- nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 18px rgba(178, 150, 210, 0.14);
}
.nav__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand__logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(160deg, #FFD1E3, var(--pink));
  box-shadow: 0 6px 14px rgba(255, 107, 157, 0.35);
}
.brand__mascot { width: 30px; height: 30px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__name { font-weight: 900; font-size: 18px; letter-spacing: 0.5px; }
.brand__sub { font-size: 11px; font-weight: 600; color: var(--purple); letter-spacing: 1.5px; }

/* ---------- soft floating decorations ---------- */
.deco {
  position: absolute;
  pointer-events: none;
}
.deco__svg { width: 100%; height: 100%; }

.deco--cloud { opacity: 0.6; filter: blur(1.5px); animation: drift 9s ease-in-out infinite; }
.deco--c1 { width: 120px; height: 72px; top: 9%; left: 6%; }
.deco--c2 { width: 170px; height: 102px; top: 20%; right: 6%; opacity: 0.45; animation-duration: 12s; animation-delay: 1s; }
.deco--c3 { width: 84px; height: 50px; top: 52%; left: 14%; opacity: 0.38; animation-duration: 10s; animation-delay: 2.2s; }

.deco--star { width: 34px; height: 34px; animation: twinkle 2.6s ease-in-out infinite alternate; }
.deco--s1 { top: 15%; right: 17%; }
.deco--s2 { top: 42%; left: 9%; width: 26px; height: 26px; animation-delay: 0.8s; }
.deco--s3 { top: 30%; right: 8%; width: 22px; height: 22px; animation-delay: 1.4s; }

.deco--heart { width: 26px; height: 24px; opacity: 0.85; animation: drift 7s ease-in-out infinite; }
.deco--h1 { bottom: 24%; left: 20%; animation-delay: 0.4s; }
.deco--h2 { top: 23%; left: 43%; width: 20px; height: 18px; animation-delay: 1.7s; }

/* ---------- hero ---------- */
.hero {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: max(540px, 86vh);
  overflow: hidden;
  background:
    radial-gradient(600px 320px at 12% 12%, rgba(255, 214, 235, 0.8), transparent 70%),
    radial-gradient(560px 340px at 88% 18%, rgba(214, 233, 255, 0.9), transparent 70%),
    radial-gradient(480px 300px at 50% 92%, rgba(255, 236, 214, 0.6), transparent 70%);
}
.hero__sky { position: absolute; inset: 0; pointer-events: none; }
.hero__inner {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 56px 20px 30px;
}

.hero__title { margin: 0 0 14px; }
/* Only the active language's line is shown; the toggle swaps html[lang]. */
.hero__title-en {
  display: none;
  font-size: clamp(34px, 8vw, 72px);
  font-weight: 700;
  color: var(--blue-text);
  letter-spacing: 1px;
  line-height: 1.1;
  text-shadow: 0 4px 16px rgba(255, 255, 255, 0.9);
}
.hero__title-zh {
  display: block;
  font-family: var(--sys-font);
  font-weight: 900;
  font-size: clamp(40px, 9vw, 76px);
  color: var(--pink-text);
  line-height: 1.08;
  letter-spacing: 2px;
  text-shadow: 0 4px 16px rgba(255, 255, 255, 0.9);
}
html[lang="en"] .hero__title-en { display: block; }
html[lang="en"] .hero__title-zh { display: none; }
.hero__tagline {
  margin: 0 0 14px;
  font-size: clamp(14px, 2.6vw, 19px);
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  padding: 9px 20px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(178, 150, 210, 0.18);
}

.hero__mascot { margin: 8px 0 22px; }
.mascot {
  width: clamp(120px, 20vw, 180px);
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 12px 18px rgba(178, 150, 210, 0.3));
  animation: bob 4s ease-in-out infinite;
}
.mascot__shadow {
  display: block;
  width: 64%; /* ~60-70% of the mascot's width so the bob stays believable */
  aspect-ratio: 5 / 1;
  margin: 4px auto 0;
  background: rgba(122, 122, 136, 0.18);
  border-radius: 50%;
  animation: shadowPulse 4s ease-in-out infinite;
}

/* ---------- games section ---------- */
.games {
  scroll-margin-top: 84px;
  padding: 48px 20px 72px;
}
.games__inner { max-width: 1100px; margin: 0 auto; }
.games__head { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.games__deco { display: inline-flex; }
.games__deco svg { width: 30px; height: 30px; filter: drop-shadow(0 4px 8px rgba(255, 107, 157, 0.35)); }
.games__title {
  margin: 0;
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--ink);
}

.controls {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 28px;
}
.search {
  position: relative;
  flex: 1 1 280px;
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(178, 150, 210, 0.16);
  transition: box-shadow 0.2s ease;
}
.search:focus-within { box-shadow: 0 8px 22px rgba(179, 136, 255, 0.3); }
.search__icon { padding-left: 16px; display: inline-flex; align-items: center; }
.search__icon svg { width: 18px; height: 18px; flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 12px 16px 12px 10px;
  font-family: var(--sys-font);
  font-size: 15px;
  color: var(--ink);
  border-radius: 999px;
}
.search input::placeholder { color: #8f8a9c; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; }

.games__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 26px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 13px;
  text-align: left;
  padding: 16px;
  background: #fff;
  border: 0;
  border-radius: var(--radius-card);
  cursor: pointer;
  color: var(--ink);
  font-family: var(--sys-font);
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: cardIn 0.4s ease backwards; /* stagger via inline animation-delay */
}
.card:hover {
  transform: translateY(-8px) scale(1.02) rotate(-1deg);
  box-shadow: var(--shadow-card-hover);
}
.card:active {
  transform: translateY(-2px) scale(0.99) rotate(0deg);
  box-shadow: 0 6px 14px rgba(178, 150, 210, 0.2);
}
.card:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
/* keystroke re-renders skip the entrance animation (set by renderGrid) */
.card.no-anim { animation: none; }

.card__icon {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: var(--card-color, var(--purple));
  box-shadow:
    inset 0 -8px 0 rgba(0, 0, 0, 0.08),
    0 10px 20px rgba(178, 150, 210, 0.28);
}
.card__emoji {
  font-size: clamp(40px, 7vw, 56px);
  line-height: 1;
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.14));
}
.card__meta { display: flex; flex-direction: column; gap: 2px; }
.card__title-zh { font-size: 16px; font-weight: 900; }
.card__title-en { font-size: 12px; font-weight: 500; color: var(--card-ink); letter-spacing: 0.3px; }
.card__tag {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--tag-color, var(--blue));
  padding: 4px 12px;
  border-radius: 999px;
}

/* ---------- cute coming-soon state ---------- */
.coming {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 28px 20px 46px;
}
.coming__mascot {
  width: clamp(140px, 22vw, 190px);
  height: auto;
  filter: drop-shadow(0 14px 20px rgba(178, 150, 210, 0.32));
  animation: bob 4s ease-in-out infinite;
}
.coming__shadow {
  display: block;
  width: min(30%, 96px); /* grounds the bob, like the hero mascot's shadow */
  aspect-ratio: 5 / 1;
  margin: 6px auto 0;
  background: rgba(122, 122, 136, 0.18);
  border-radius: 50%;
  animation: shadowPulse 4s ease-in-out infinite;
}
.coming__candy {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.coming__candy span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c, var(--pink));
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.08), 0 4px 10px rgba(178, 150, 210, 0.3);
  animation: candyBob 2.4s ease-in-out infinite;
}
.coming__candy span:nth-child(2) { animation-delay: 0.3s; }
.coming__candy span:nth-child(3) { animation-delay: 0.6s; }
.coming__candy span:nth-child(4) { animation-delay: 0.9s; }
.coming__title {
  margin: 12px 0 0;
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 900;
  color: var(--pink-text);
  letter-spacing: 1px;
}
.coming__hint {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.games__empty {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
  font-size: 16px;
  font-weight: 700;
}
.link {
  border: 0;
  background: none;
  color: var(--purple);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
  padding: 0;
}

/* ---------- play modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(74, 74, 85, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;   /* ignore clicks until the modal is actually visible */
  transition: opacity 0.2s ease;
}
.modal.is-open .modal__backdrop { opacity: 1; pointer-events: auto; }

.modal__panel {
  position: relative;
  width: min(460px, 100%);
  background: #fff;
  border-radius: 26px;
  box-shadow: 0 24px 60px rgba(74, 74, 85, 0.35);
  overflow: hidden;
  opacity: 0;
  transform: scale(0.9) translateY(24px);
  transition: opacity 0.18s ease, transform 0.24s ease;
}
.modal.is-open .modal__panel { opacity: 1; transform: none; }

.modal__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 14px 18px;
  border-bottom: 1px solid rgba(74, 74, 85, 0.08);
}
.modal__title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.modal__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  font-size: 26px;
  border-radius: 50%;
  background: var(--card-color, var(--purple));
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.08), 0 6px 14px rgba(178, 150, 210, 0.3);
}
.modal__names { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.modal__name-zh {
  font-size: 17px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal__name-en {
  font-size: 12px;
  font-weight: 500;
  color: var(--card-ink);
  letter-spacing: 0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal__body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 44px 22px 48px;
  text-align: center;
  background: linear-gradient(180deg, #FFF6F9, #F4F0FF);
}
.modal__soon { font-size: clamp(28px, 8vw, 36px); font-weight: 900; color: var(--pink-text); letter-spacing: 1px; }
.modal__hint { font-size: 14px; color: var(--ink-soft); }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid rgba(74, 74, 85, 0.08);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 28px 20px 36px;
  text-align: center;
}
.footer__inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.footer__made { margin: 0; font-size: 15px; font-weight: 800; }
.footer__copy { margin: 0; font-size: 13px; color: var(--ink-soft); }

/* ---------- keyframes ---------- */
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}
@keyframes shadowPulse {
  0%, 100% { opacity: 0.18; transform: scale(1); }
  50% { opacity: 0.12; transform: scale(0.86); }
}
@keyframes drift {
  0%, 100% { transform: translateY(0) translateX(0); }
  33% { transform: translateY(-10px) translateX(6px); }
  66% { transform: translateY(5px) translateX(-4px); }
}
@keyframes twinkle {
  from { opacity: 0.3; }
  to { opacity: 1; }
}
@keyframes wobble {
  0%, 100% { transform: translateY(-3px) scale(1.05) rotate(0deg); }
  25% { transform: translateY(-3px) scale(1.05) rotate(-1.5deg); }
  75% { transform: translateY(-3px) scale(1.05) rotate(1.5deg); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes candyBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* ---------- prefers-reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  .card,
  .card:hover,
  .card:active { transform: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .nav__inner { padding: 8px 14px; }
  .brand__sub { display: none; }
  .hero__inner { padding-top: 44px; }
  .controls { flex-direction: column; align-items: stretch; }
  .filters { justify-content: center; }
  .games__grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 18px; }
  .pbtn--play { width: min(320px, 100%); justify-content: center; }
  .modal { padding: 14px; }
}

@media (max-width: 420px) {
  .games__grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .card { padding: 12px; }
  .card__title-zh { font-size: 14px; }
  .card__title-en { font-size: 10px; }
  .card__tag { font-size: 10px; padding: 3px 9px; }
  .hero__tagline { font-size: 13px; }
}
