/* Puzzle Play — puzzle tile hub layout */

:root {
  --color-primary: #7C3AED;
  --color-accent: #06B6D4;
  --color-highlight: #FBBF24;
  --color-bg: #FFFFFF;
  --color-surface: #FFFFFF;
  --color-text: #1E293B;
  --color-text-muted: #64748B;
  --font-body: 'Nunito', system-ui, sans-serif;
  --font-display: 'Fredoka', 'Nunito', sans-serif;
  --puzzle-gap: 10px;
  --header-height: 64px;
  --page-padding: 14px;
  --grid-gap: 14px;
  --tile-row: 148px;
  --transition: 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  height: 100%;
  background: #5B21B6;
}

body {
  font-family: var(--font-body);
  color: var(--color-text);
  overflow-x: hidden;
  min-height: 100%;
}

/* Home page — full gradient + pattern (not white) */
body.puzzle-body {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background-color: #6366F1;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.08'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
    radial-gradient(circle at 20% 15%, rgba(251, 191, 36, 0.35) 0%, transparent 45%),
    radial-gradient(circle at 85% 25%, rgba(244, 114, 182, 0.3) 0%, transparent 40%),
    radial-gradient(circle at 50% 90%, rgba(34, 211, 238, 0.28) 0%, transparent 42%),
    linear-gradient(145deg, #4F46E5 0%, #7C3AED 30%, #C026D3 55%, #0891B2 100%);
  background-attachment: fixed;
  background-size: 60px 60px, 100% 100%, 100% 100%, 100% 100%, 100% 100%;
}

/* Sticky header — solid theme background */
.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: calc(var(--header-height) + var(--safe-top));
  min-height: calc(var(--header-height) + var(--safe-top));
  padding: var(--safe-top) calc(1.1rem + var(--safe-right)) 0 calc(0.65rem + var(--safe-left));
  background: linear-gradient(105deg, #4C1D95 0%, #6D28D9 42%, #7C3AED 100%);
  border-bottom: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 20px rgba(76, 29, 149, 0.35);
  transition: box-shadow 0.3s ease, background 0.3s ease;
}

.site-header.is-scrolled {
  box-shadow: 0 8px 28px rgba(49, 16, 120, 0.45);
  background: linear-gradient(105deg, #3B0764 0%, #5B21B6 45%, #6D28D9 100%);
}

.site-header__logo {
  display: flex;
  align-items: stretch;
  gap: 0.55rem;
  height: 100%;
  text-decoration: none;
  color: #fff;
  flex-shrink: 0;
  padding: 6px 0;
}

.site-header__logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  aspect-ratio: 1;
  font-size: calc(var(--header-height) - 18px);
  line-height: 1;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.site-header__logo-text {
  display: flex;
  align-items: center;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.site-header__nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.site-header__menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
  flex-shrink: 0;
}

.site-header__menu-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.28);
}

.site-header__menu-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.site-header__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: background 0.2s, transform 0.2s, border-color 0.2s;
  cursor: pointer;
  white-space: nowrap;
}

.site-header__link:hover,
.site-header__link:focus-visible {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.45);
  transform: scale(1.04);
  outline: none;
}

.site-header__btn {
  font: inherit;
  appearance: none;
}

.site-header__btn.muted {
  opacity: 0.55;
}

.puzzle-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(148px, 100%), 1fr));
  grid-auto-rows: var(--tile-row);
  grid-auto-flow: dense;
  gap: var(--grid-gap);
  padding: var(--page-padding);
  padding-bottom: var(--page-padding);
  min-height: calc(100vh - var(--header-height));
  min-height: calc(100dvh - var(--header-height));
  align-content: start;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

.puzzle-tile {
  position: relative;
  display: block;
  border-radius: 20px;
  overflow: hidden;
  text-decoration: none;
  color: #fff;
  background: #64748B;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.12),
    0 12px 28px rgba(0, 0, 0, 0.22),
    0 0 0 4px rgba(255, 255, 255, 0.48);
  transition: transform var(--transition), box-shadow 0.25s;
  animation: tilePop 0.45s ease backwards;
  cursor: pointer;
  border: none;
  min-height: 44px;
  isolation: isolate;
}

.puzzle-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  pointer-events: none;
  z-index: 3;
}

.puzzle-tile:hover,
.puzzle-tile:focus-visible {
  transform: scale(1.05);
  box-shadow:
    0 8px 12px rgba(0, 0, 0, 0.15),
    0 20px 44px rgba(0, 0, 0, 0.28),
    0 0 0 4px #fff;
  outline: none;
}

.puzzle-tile:active {
  transform: scale(0.98);
}

.puzzle-tile--wide {
  grid-column: span 2;
}

.puzzle-tile--tall {
  grid-row: span 2;
}

.puzzle-tile--big {
  grid-column: span 2;
  grid-row: span 2;
}

.puzzle-tile__art {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.puzzle-tile__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.02);
  transition: transform 0.35s ease;
}

.puzzle-tile:hover .puzzle-tile__art img {
  transform: scale(1.08);
}

.puzzle-tile__shine {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.28) 0%,
    transparent 42%,
    transparent 100%
  );
  pointer-events: none;
}

.puzzle-tile__title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
  padding: 2.2rem 0.7rem 0.65rem;
  line-height: 1.15;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.35) 55%, transparent 100%);
}

@keyframes tilePop {
  0% {
    opacity: 0;
    transform: scale(0.88) translateY(12px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-header {
    transition: none;
  }

  .site-header__nav {
    transition: none;
  }

  .puzzle-tile {
    animation: none;
    transition: none;
  }

  .puzzle-tile:hover .puzzle-tile__art img {
    transform: scale(1.02);
  }
}

@media (max-width: 768px) {
  body.puzzle-body {
    background-attachment: scroll;
  }
}

/* ── Responsive: tablet & below ── */
@media (max-width: 768px) {
  :root {
    --page-padding: 12px;
    --grid-gap: 12px;
  }

  .puzzle-tile__title {
    font-size: 0.82rem;
    padding: 1.8rem 0.6rem 0.55rem;
  }
}

/* ── Responsive: mobile ── */
@media (max-width: 640px) {
  .site-header {
    flex-wrap: wrap;
    align-content: flex-start;
    height: calc(var(--header-height) + var(--safe-top));
    min-height: calc(var(--header-height) + var(--safe-top));
    max-height: calc(var(--header-height) + var(--safe-top));
    overflow: visible;
  }

  .site-header:has(.site-header__nav.is-open) {
    height: auto;
    max-height: none;
  }

  .site-header__menu-btn {
    display: inline-flex;
  }

  .site-header__nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.65rem 0 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    margin-top: 0.35rem;
  }

  .site-header__nav.is-open {
    display: flex;
  }

  .site-header__link {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  :root {
    --header-height: 56px;
    --tile-row: 130px;
    --page-padding: 10px;
    --grid-gap: 10px;
  }

  .site-header__logo-text {
    font-size: 1rem;
  }

  .site-header__logo-mark {
    border-radius: 12px;
  }

  .puzzle-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .puzzle-tile--wide,
  .puzzle-tile--big {
    grid-column: span 2;
  }

  .puzzle-tile--tall,
  .puzzle-tile--big {
    grid-row: span 1;
  }

  .puzzle-tile {
    border-radius: 16px;
    box-shadow:
      0 3px 5px rgba(0, 0, 0, 0.1),
      0 8px 20px rgba(0, 0, 0, 0.18),
      0 0 0 3px rgba(255, 255, 255, 0.48);
  }

  .puzzle-tile__title {
    font-size: 0.78rem;
  }
}

@media (max-width: 360px) {
  .site-header__logo-text {
    display: none;
  }

  .site-header__logo {
    gap: 0;
  }
}

/* ── Responsive: large screens ── */
@media (min-width: 900px) {
  :root {
    --page-padding: 18px;
    --grid-gap: 16px;
    --tile-row: 172px;
  }
}

@media (min-width: 1200px) {
  :root {
    --page-padding: 22px;
    --grid-gap: 18px;
    --tile-row: 180px;
  }

  .puzzle-grid {
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  }
}

@media (hover: none) {
  .puzzle-tile:hover,
  .puzzle-tile:focus-visible {
    transform: none;
  }

  .puzzle-tile:hover .puzzle-tile__art img {
    transform: scale(1.02);
  }

  .site-header__link:hover {
    transform: none;
  }
}

/* ── Site footer (SEO content) ── */
.site-footer {
  position: relative;
  z-index: 1;
  background: linear-gradient(180deg, #2E1065 0%, #1E1B4B 100%);
  color: rgba(255, 255, 255, 0.92);
  border-top: 2px solid rgba(255, 255, 255, 0.1);
  padding: 2.5rem var(--page-padding) calc(1.5rem + var(--safe-bottom));
  padding-left: calc(var(--page-padding) + var(--safe-left));
  padding-right: calc(var(--page-padding) + var(--safe-right));
}

.site-footer__inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.site-footer__about h2,
.site-footer__topics h2 {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 3vw, 1.45rem);
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.75rem;
  line-height: 1.25;
}

.site-footer__about p,
.site-footer__topics p {
  font-size: clamp(0.88rem, 2.2vw, 0.95rem);
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.78);
  max-width: 72ch;
}

.site-footer__about p + p {
  margin-top: 0.75rem;
}

.site-footer__columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: 1.5rem 2rem;
}

.site-footer__col h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: #FBBF24;
  margin-bottom: 0.65rem;
  letter-spacing: 0.02em;
}

.site-footer__col ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.site-footer__col a {
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
  transition: color 0.2s;
}

.site-footer__col a:hover,
.site-footer__col a:focus-visible {
  color: #fff;
  text-decoration: underline;
  outline: none;
}

.site-footer__topics a {
  color: #A5F3FC;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-footer__topics a:hover,
.site-footer__topics a:focus-visible {
  color: #fff;
}

.site-footer__bottom {
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: center;
}

.site-footer__brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.site-footer__copy,
.site-footer__note {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.55);
}

.site-footer__noscript {
  padding: 1rem 0;
}

.site-footer__noscript h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.site-footer__noscript ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.site-footer__noscript a {
  color: rgba(255, 255, 255, 0.82);
}

@media (max-width: 640px) {
  .site-footer {
    padding-top: 2rem;
  }

  .site-footer__columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
  }
}

@media (max-width: 400px) {
  .site-footer__columns {
    grid-template-columns: 1fr;
  }
}

/* Confetti (win screens) */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  top: -10px;
  z-index: 9999;
  pointer-events: none;
  animation: confetti-fall 2.5s ease-out forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

.btn-icon {
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-icon.muted {
  opacity: 0.5;
}

/* Legal pages */
.legal-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem var(--page-padding) 2rem;
}

.legal-content {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  color: #1E293B;
}

.legal-content--center {
  text-align: center;
}

.legal-content h1 {
  font-family: var(--font-display);
  color: #4C1D95;
  margin-bottom: 0.75rem;
}

.legal-content h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: #5B21B6;
  margin: 1.25rem 0 0.5rem;
}

.legal-content p,
.legal-content li {
  line-height: 1.65;
  margin-bottom: 0.65rem;
}

.legal-content ul {
  padding-left: 1.25rem;
  margin-bottom: 0.75rem;
}

.legal-content a {
  color: #7C3AED;
}

.legal-back {
  margin-top: 1.5rem;
}

.site-footer--compact {
  padding-top: 1.25rem;
}

.site-footer__legal {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  margin-bottom: 0.5rem;
}

.site-footer__legal a {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
}

.site-footer__legal a:hover,
.site-footer__legal a:focus-visible {
  color: #fff;
  text-decoration: underline;
}

/* AdSense-ready slots — hidden unless html.ads-enabled */
.ad-slot {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  margin: 0.75rem auto;
  max-width: 728px;
  width: 100%;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed rgba(100, 116, 139, 0.35);
}

html.ads-enabled .ad-slot {
  display: flex;
}

.ad-slot__label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #94A3B8;
  margin-bottom: 0.35rem;
}

.ad-slot--home {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
}

/* Consent banner */
.consent-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  background: rgba(30, 27, 75, 0.96);
  color: #fff;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
}

.consent-banner__inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
}

.consent-banner p {
  flex: 1 1 280px;
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0;
}

.consent-banner a {
  color: #A5F3FC;
}

.consent-banner__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.consent-banner__btn {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: none;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}

.consent-banner__btn--accept {
  background: #7C3AED;
  color: #fff;
}

.consent-banner__btn--decline {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

@media (max-width: 640px) {
  .consent-banner__inner {
    flex-direction: column;
    align-items: stretch;
  }

  .consent-banner__actions {
    flex-direction: column;
  }
}
