:root {
  --color-bg: #eef1f8;
  --color-surface: #ffffff;
  --color-sidebar: #ffffff;
  --color-border: #e2e6f0;
  --color-text: #1e2233;
  --color-muted: #6b7180;
  --color-accent: #6d5efc;
  --color-accent-soft: #eeebff;
  --color-accent-hover: #5a4be0;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-hover: 0 10px 28px rgba(16, 24, 40, 0.12);

  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2rem;

  --text-h1: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem);
  --text-h2: clamp(1.15rem, 1rem + 0.7vw, 1.5rem);

  --duration: 200ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --sidebar-width: 240px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  background-image:
    radial-gradient(1200px 600px at 100% -5%, rgba(109, 94, 252, 0.10), transparent 55%),
    radial-gradient(900px 500px at -10% 0%, rgba(14, 165, 164, 0.08), transparent 50%);
  background-attachment: fixed;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* Layout: sidebar + content */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-2);
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: var(--space-4);
  padding: 0 var(--space-1);
}

.sidebar .brand img { width: 30px; height: 30px; }

.cat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  padding: 0 var(--space-1);
  margin: var(--space-3) 0 var(--space-1);
}

.cat-nav { display: flex; flex-direction: column; gap: 2px; }

.cat-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.6rem var(--space-1);
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-weight: 500;
  font-size: 0.95rem;
  transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
}

.cat-nav a:hover { background: var(--color-bg); color: var(--color-text); }

.cat-nav a.active {
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
  font-weight: 600;
}

/* Content */
.content { padding: var(--space-4); }

.content-head { margin-bottom: var(--space-4); }

.content-head h1 {
  font-size: var(--text-h1);
  margin: 0 0 var(--space-1);
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #6d5efc, #0ea5a4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.content-head p { color: var(--color-muted); margin: 0; }

.section { margin-bottom: var(--space-4); }

.section > h2 {
  font-size: var(--text-h2);
  margin: 0 0 var(--space-3);
  letter-spacing: -0.01em;
}

/* Game grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-3);
}

.game-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.game-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.game-card:focus-within { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.game-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, #eeebff, #d8f3f0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  overflow: hidden;
}

.game-thumb .thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Emoji is only the fallback: hidden while the image is present. */
.game-thumb .thumb-emoji { display: none; }
.game-thumb.no-img .thumb-emoji { display: block; }

.game-body { padding: var(--space-2); }
.game-body h3 { margin: 0 0 4px; font-size: 0.98rem; }
.game-body .tag { color: var(--color-muted); font-size: 0.8rem; }

/* Footer */
/* SEO intro block above the footer */
.seo-intro {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: 0.92rem;
  line-height: 1.65;
  max-width: 900px;
}
.seo-intro h2 { font-size: var(--text-h2); color: var(--color-text); margin: 0 0 var(--space-2); }
.seo-intro p { margin: 0 0 var(--space-2); }
.seo-intro a { color: var(--color-accent); }
.seo-intro a:hover { color: var(--color-accent-hover); }

.content-footer,
.site-footer {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  color: var(--color-muted);
  font-size: 0.9rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
}

.footer-links a {
  color: var(--color-muted);
  font-weight: 500;
  transition: color var(--duration) var(--ease);
}

.footer-links a:hover { color: var(--color-accent); }

/* Content / legal pages */
.page-doc { max-width: 760px; }
.page-doc h1 { font-size: var(--text-h1); margin: 0 0 var(--space-1); letter-spacing: -0.02em; }
.page-doc .updated { color: var(--color-muted); font-size: 0.9rem; margin: 0 0 var(--space-4); }
.page-doc h2 { font-size: var(--text-h2); margin: var(--space-4) 0 var(--space-2); }
.page-doc p, .page-doc li { color: var(--color-text); }
.page-doc ul { padding-left: 1.2rem; }
.page-doc li { margin-bottom: 0.4rem; }
.page-doc a { color: var(--color-accent); }
.page-doc a:hover { color: var(--color-accent-hover); }

.contact-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-top: var(--space-3);
}
.contact-card strong { color: var(--color-text); }

/* Play page */
.play-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--space-3);
  align-items: start;
  margin-bottom: var(--space-3);
}

.play-main { min-width: 0; }

.play-frame {
  position: relative;
  background: #0b0d12;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-hover);
  aspect-ratio: 16 / 10;
  /* Keep the play area compact and centered rather than full-width. */
  max-width: 800px;
  margin: 0 auto var(--space-3);
}

.play-frame iframe, .play-frame canvas, .play-frame ruffle-player, .play-frame > embed {
  width: 100%; height: 100%; border: 0; display: block;
}

/* Pre-roll ad overlay */
.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: radial-gradient(circle at 50% 40%, #1c2030, #0b0d12);
  text-align: center;
}

.overlay-ad {
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
  font-weight: 600;
}

.overlay-ad:not(.ad-live) {
  width: 300px;
  height: 250px;
  background: repeating-linear-gradient(45deg, #12151f, #12151f 12px, #171b28 12px, #171b28 24px);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-sm);
}

.overlay-play {
  font-size: 1.1rem;
  padding: 0.8rem 2rem;
}

.overlay-status {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.95rem;
  margin: 0;
  min-height: 1.2em;
}

/* Multi-part loading progress */
.load-progress {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 10px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.load-bar {
  width: 0;
  height: 100%;
  background: var(--color-accent);
  transition: width 200ms linear;
}

.load-label {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% + 18px);
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9rem;
  margin: 0;
}

.play-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-3);
  color: #fff;
  text-align: center;
}
.play-error .muted { color: rgba(255, 255, 255, 0.5); font-size: 0.85rem; }

/* Home: Load more + empty state */
.load-more-wrap { text-align: center; margin-top: var(--space-4); }
.grid-empty { color: var(--color-muted); padding: var(--space-4) 0; }

/* Right rail */
.play-rail {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* Ad containers: the placeholder look is ONLY for the dev/empty state.
   Once AdSense fills a unit, .ad-live strips all box styling so the
   container shrink-wraps the <ins> and never overflows its column. */
.ad-slot,
.ad-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  color: var(--color-muted);
  font-size: 0.9rem;
  font-weight: 600;
  overflow: hidden;
}

/* Placeholder (empty) sizing + dashed look. */
.ad-slot:not(.ad-live) {
  width: 300px;
  height: 600px;
  background: repeating-linear-gradient(45deg, var(--color-surface), var(--color-surface) 12px, var(--color-bg) 12px, var(--color-bg) 24px);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}

.ad-banner:not(.ad-live) {
  width: 100%;
  min-height: 90px;
  margin-top: var(--space-3);
  background: repeating-linear-gradient(45deg, var(--color-surface), var(--color-surface) 12px, var(--color-bg) 12px, var(--color-bg) 24px);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}

/* Live (filled) state: no border/background, wrap tightly around the ad. */
.ad-slot.ad-live,
.ad-banner.ad-live {
  display: block;
  width: auto;
  height: auto;
  min-height: 0;
  border: 0;
  background: none;
  margin: 0 auto;
}
.ad-banner.ad-live { margin-top: var(--space-3); }

/* The AdSense <ins> should never exceed its column width. */
.ad-slot .adsbygoogle,
.ad-banner .adsbygoogle,
.overlay-ad .adsbygoogle {
  max-width: 100%;
}

.rail-games > h2 { font-size: 1.05rem; margin: 0 0 var(--space-2); }

.rail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }

.rail-list a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease);
}

.rail-list a:hover { background: var(--color-surface); border-color: var(--color-border); }
.rail-list a:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.rail-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: linear-gradient(135deg, #e6fffb, #ccfbf1);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.rail-thumb .rail-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rail-thumb .rail-emoji { display: none; }
.rail-thumb.no-img .rail-emoji { display: block; }

.rail-info { display: flex; flex-direction: column; line-height: 1.3; }
.rail-info strong { font-size: 0.92rem; }

.play-toolbar {
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.play-toolbar h1 { font-size: var(--text-h2); margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background var(--duration) var(--ease);
}

.btn:hover { background: var(--color-accent-hover); }
.btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.play-desc { max-width: 760px; }
.play-desc h2 { font-size: var(--text-h2); margin-top: var(--space-4); }
.play-desc p { color: var(--color-text); }

/* Breadcrumb */
.breadcrumb {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: var(--space-2);
}
.breadcrumb a { color: var(--color-muted); }
.breadcrumb a:hover { color: var(--color-accent); }
.breadcrumb span[aria-current] { color: var(--color-text); font-weight: 500; }

/* Toolbar secondary actions (below game frame) */
.toolbar-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: center;
}

.btn-outline {
  background: transparent;
  color: var(--color-accent-hover);
  border: 1px solid var(--color-border);
}
.btn-outline:hover { background: var(--color-accent-soft); border-color: var(--color-accent); }

/* Game meta bar */
.game-meta {
  max-width: 900px;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) 0;
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.meta-item { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; color: var(--color-muted); }
.meta-item strong { color: var(--color-text); font-weight: 600; }
.meta-badge {
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.rating { color: #f59e0b; letter-spacing: 1px; }

/* How to play */
.howto {
  max-width: 760px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-top: var(--space-3);
}
.howto h3 { margin: 0 0 var(--space-2); font-size: 1.05rem; }
.howto ul { margin: 0; padding-left: 1.2rem; color: var(--color-muted); }
.howto li { margin-bottom: 0.4rem; }
.key {
  display: inline-block;
  min-width: 1.4rem;
  text-align: center;
  padding: 0.1rem 0.4rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
}

/* Related games */
.related { margin-top: var(--space-4); }
.related > h2 { font-size: var(--text-h2); margin: 0 0 var(--space-3); }

/* Home page: content + sticky ad rail */
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--space-4);
  align-items: start;
}

.content-grid > main { min-width: 0; }

.home-rail { align-self: stretch; }

.ad-sticky {
  position: sticky;
  top: var(--space-3);
}

/* Stack the right rail below the game on narrower viewports */
@media (max-width: 1024px) {
  .content-grid { grid-template-columns: 1fr; }
  .home-rail { display: none; }
  .play-stage { grid-template-columns: 1fr; }
  .play-rail { flex-direction: row; flex-wrap: wrap; gap: var(--space-3); }
  .ad-slot { width: 100%; height: 120px; }
  .rail-games { flex: 1; min-width: 240px; }
  .rail-list { flex-direction: row; flex-wrap: wrap; }
  .rail-list li { flex: 1 1 200px; }
}

/* Mobile: sidebar becomes top bar */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }
  .cat-nav { flex-direction: row; flex-wrap: wrap; }
  .cat-label { display: none; }
  .content { padding: var(--space-3) var(--space-2); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto; }
}
