:root {
  --bg-sky: #e0f4ff;
  --bg-mint: #e8fbef;
  --bg-cream: #fff9eb;
  --card-bg: #ffffff;
  --text-main: #232946;
  --text-muted: #5b647d;
  --primary: #ff7b54;
  --primary-dark: #e25b34;
  --secondary: #38bdf8;
  --accent-yellow: #ffd166;
  --shadow-soft: 0 14px 30px -10px rgba(35, 41, 70, 0.14);
  --shadow-card: 0 10px 24px -6px rgba(35, 41, 70, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  color: var(--text-main);
  background: linear-gradient(155deg, var(--bg-sky) 0%, var(--bg-mint) 52%, var(--bg-cream) 100%);
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* Decorative background */
.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  filter: blur(1px);
  animation: floatSlow 18s ease-in-out infinite;
}

.cloud-1 {
  width: 210px;
  height: 64px;
  top: 6%;
  left: 4%;
}
.cloud-2 {
  width: 260px;
  height: 76px;
  top: 12%;
  right: 6%;
  animation-delay: -6s;
}
.cloud-3 {
  width: 170px;
  height: 52px;
  bottom: 14%;
  left: 12%;
  animation-delay: -11s;
}

.bubble {
  position: absolute;
  border-radius: 50%;
  opacity: 0.32;
}
.bubble-1 {
  width: 160px;
  height: 160px;
  background: #ffd166;
  bottom: -40px;
  right: 8%;
}
.bubble-2 {
  width: 110px;
  height: 110px;
  background: #7dd3fc;
  top: 42%;
  left: -30px;
}
.bubble-3 {
  width: 90px;
  height: 90px;
  background: #f9a8d4;
  top: 28%;
  right: -20px;
}

@keyframes floatSlow {
  0%, 100% {
    transform: translateY(0px) translateX(0px);
  }
  50% {
    transform: translateY(-10px) translateX(12px);
  }
}

/* Main Shell */
.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 44px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.portal-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-xl);
  padding: 18px 24px;
  box-shadow: var(--shadow-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  width: 64px;
  height: 64px;
  border-radius: 22px;
  background: linear-gradient(135deg, #ff9a3c, #ff5e7e);
  display: grid;
  place-items: center;
  font-size: 34px;
  box-shadow: 0 8px 0 #d9485f, 0 12px 20px rgba(255, 94, 126, 0.28);
  flex-shrink: 0;
  animation: bounceGentle 3s ease-in-out infinite;
}

@keyframes bounceGentle {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

.brand-title {
  margin: 0;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: clamp(1.45rem, 2.8vw, 2.15rem);
  font-weight: 800;
  line-height: 1.15;
  color: #1e293b;
}

.brand-subtitle {
  margin: 4px 0 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.game-counter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: #f1f5f9;
  font-weight: 800;
  font-size: 0.95rem;
  color: #334155;
}

.counter-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.22);
}

.btn-pill {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 10px 18px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--text-main);
  box-shadow: 0 4px 0 #cbd5e1;
  border: 2px solid #e2e8f0;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.btn-pill:hover {
  transform: translateY(-2px);
  background: #f8fafc;
}

.btn-pill:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #cbd5e1;
}

/* Toolbar */
.toolbar {
  margin-top: 22px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.search-box {
  position: relative;
  flex: 1 1 260px;
  max-width: 380px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 13px 18px 13px 44px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.92);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  box-shadow: 0 6px 18px rgba(35, 41, 70, 0.08);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
  border-color: var(--secondary);
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.25);
}

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

.cat-pill {
  border: 2px solid rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(35, 41, 70, 0.07);
  transition: all 0.16s ease;
}

.cat-pill:hover {
  transform: translateY(-2px);
  color: var(--text-main);
}

.cat-pill.active {
  background: linear-gradient(135deg, #38bdf8, #3b82f6);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 5px 0 #2563eb, 0 8px 16px rgba(59, 130, 246, 0.28);
}

/* Games Grid */
.portal-main {
  flex: 1;
  margin-top: 26px;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 24px;
}

.game-card {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 4px solid #ffffff;
  background: linear-gradient(135deg, var(--card-accent, #38bdf8), #6366f1);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.24s ease;
}

.game-card:hover,
.game-card:focus-visible {
  transform: translateY(-7px) scale(1.02);
  box-shadow: 0 22px 40px -10px rgba(35, 41, 70, 0.28);
  outline: none;
}

.game-card img.card-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.38s ease;
}

.game-card:hover img.card-cover {
  transform: scale(1.07);
}

.card-banner-emoji {
  font-size: 88px;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.22));
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
}

.game-card:hover .card-banner-emoji {
  transform: scale(1.14) rotate(-5deg);
}

.card-badges {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.badge-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.94);
  color: #1e293b;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
}

.badge-age {
  background: #fef08a;
  color: #854d0e;
}

.fav-btn {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.94);
  cursor: pointer;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
  transition: transform 0.16s ease;
}

.fav-btn:hover {
  transform: scale(1.14);
}

.card-play-badge {
  position: relative;
  z-index: 2;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 26px;
  padding-left: 4px;
  color: #ffffff;
  background: linear-gradient(135deg, #ff7b54, #ff5e62);
  border: 4px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  opacity: 0.92;
  transform: scale(0.95);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.22s ease;
}

.game-card:hover .card-play-badge {
  opacity: 1;
  transform: scale(1.1);
}

.card-title-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 28px 18px 14px;
  background: linear-gradient(to top, rgba(15, 23, 42, 0.82) 0%, rgba(15, 23, 42, 0.35) 60%, transparent 100%);
  pointer-events: none;
}

.card-title {
  margin: 0;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.38rem;
  font-weight: 800;
  line-height: 1.2;
  color: #ffffff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

/* Empty State */
.empty-state {
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-xl);
  padding: 48px 24px;
  max-width: 480px;
  margin: 30px auto;
  box-shadow: var(--shadow-soft);
}

.empty-emoji {
  font-size: 64px;
  margin-bottom: 10px;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-family: 'Baloo 2', cursive, sans-serif;
}

.empty-state p {
  margin: 0 0 20px;
  color: var(--text-muted);
}

.empty-state .btn-play {
  max-width: 240px;
}

/* Footer */
.portal-footer {
  margin-top: 38px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.portal-footer code {
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 800;
  color: #0f172a;
}

/* In-Page Player Modal */
.player-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #0f172a;
  display: flex;
  flex-direction: column;
}

.player-topbar {
  height: 60px;
  padding: 0 16px;
  background: linear-gradient(90deg, #1e293b, #0f172a);
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #ffffff;
}

.player-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.btn-player-back {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 8px 16px;
  border-radius: 999px;
  background: #ff7b54;
  color: #ffffff;
  box-shadow: 0 3px 0 #c2410c;
  white-space: nowrap;
  transition: transform 0.12s ease;
}

.btn-player-back:hover {
  transform: translateY(-1px);
}

.btn-player-back:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #c2410c;
}

.player-game-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.player-icon {
  font-size: 1.4rem;
}

.player-title {
  margin: 0;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-player-action {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 7px 13px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.btn-player-action:hover {
  background: rgba(255, 255, 255, 0.2);
}

.player-stage {
  flex: 1;
  position: relative;
  background: #020617;
}

.player-stage iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

@media (max-width: 640px) {
  .portal-header {
    padding: 16px;
  }
  .brand-logo {
    width: 52px;
    height: 52px;
    font-size: 28px;
  }
  .player-controls .btn-player-action {
    padding: 7px 10px;
    font-size: 0.82rem;
  }
  #openNewTabLink {
    display: none;
  }
}
