/* DuckyMath — game portal styles */

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-elevated: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --play: #3fb950;
  --play-hover: #56d364;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --header-h: 64px;
  --ad-rail-w: 160px;
  --game-min-h: 560px;
  --game-aspect: 16 / 9;
  --play-chrome: 210px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

/* ── Header ── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.25rem;
  white-space: nowrap;
}

.logo-duck {
  font-size: 1.5rem;
}

.search-wrap {
  flex: 1;
  max-width: 480px;
  margin: 0 auto;
}

.search-wrap input {
  width: 100%;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-wrap input:focus {
  border-color: var(--accent);
}

.nav-categories {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-categories::-webkit-scrollbar {
  display: none;
}

.nav-pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.nav-pill:hover,
.nav-pill.active {
  background: var(--bg-elevated);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Layout ── */

.container {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.section-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-count {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted, #94a3b8);
}

/* ── Game grid ── */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.game-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  aspect-ratio: 4 / 5;
  display: flex;
  flex-direction: column;
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.game-card-thumb {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, var(--thumb-a, #1a2744), var(--thumb-b, #0d1117));
}

.card-thumb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-card-thumb .card-thumb-emoji {
  font-size: 2.5rem;
}

.game-card-thumb .play-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 2rem;
}

.game-card:hover .play-hint {
  opacity: 1;
}

.game-card-body {
  padding: 0.65rem 0.75rem;
}

.game-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-card-cat {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.badge-new {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--play);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
}

/* Category thumb colors */
.cat-racing { --thumb-a: #1a3a5c; --thumb-b: #0d2137; }
.cat-puzzle { --thumb-a: #3d2a5c; --thumb-b: #1a1030; }
.cat-arcade { --thumb-a: #5c2a4a; --thumb-b: #2a1020; }
.cat-sports { --thumb-a: #1a5c3a; --thumb-b: #0d3020; }
.cat-shooter { --thumb-a: #5c1a1a; --thumb-b: #300d0d; }
.cat-platformer { --thumb-a: #1a4a5c; --thumb-b: #0d2830; }
.cat-action { --thumb-a: #5c3a1a; --thumb-b: #30200d; }
.cat-horror { --thumb-a: #2a1a3a; --thumb-b: #100820; }
.cat-idle { --thumb-a: #5c4a1a; --thumb-b: #30280d; }
.cat-retro { --thumb-a: #1a3a3a; --thumb-b: #0d2020; }

/* ── Footer ── */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 2.5rem 1.25rem 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.footer-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  max-width: 36rem;
}

.footer-logo {
  align-items: flex-start;
  gap: 0.65rem;
}

.footer-logo .logo-duck {
  font-size: 2rem;
  line-height: 1;
  margin-top: 0.1rem;
}

.footer-logo-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.footer-name {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.footer-subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.3;
}

.footer-about {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.6;
  font-size: 0.92rem;
}

.footer-social {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.footer-social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s;
}

.footer-social a:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--bg-elevated);
  transform: translateY(-2px);
}

.footer-social svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.footer-meta {
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.footer-meta p {
  margin: 0;
}

.footer-links a {
  color: var(--accent);
  margin-right: 1rem;
}

.footer-links a:last-child {
  margin-right: 0;
}

/* ── Play page ── */

.play-page .container {
  padding-top: 1rem;
}

.ad-slot {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
  min-height: 90px;
}

.ad-slot.ad-header {
  margin-bottom: 1rem;
  min-height: 90px;
}

.ad-slot.ad-rail {
  width: var(--ad-rail-w);
  flex-shrink: 0;
  display: none;
  align-self: center;
  height: var(--game-player-h, min(540px, calc(100vh - var(--play-chrome))));
  min-height: 0;
  max-height: calc(100vh - var(--play-chrome));
  overflow: hidden;
}

.ad-slot.ad-below {
  margin-top: 1.25rem;
  min-height: 250px;
}

/* Show rails only on desktop after play */
body.ads-active .ad-slot.ad-rail {
  display: flex;
}

body.fullscreen-mode .ad-slot.ad-rail,
body.fullscreen-mode .ad-slot.ad-header,
body.fullscreen-mode .ad-slot.ad-below {
  display: none !important;
}

.game-layout {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  justify-content: center;
}

.game-center {
  flex: 1;
  max-width: 960px;
  min-width: 0;
}

.game-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.game-title-bar h1 {
  margin: 0;
  font-size: 1.5rem;
}

.game-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}

.btn:hover {
  background: var(--bg-elevated);
  border-color: var(--accent);
}

.btn-primary {
  background: var(--play);
  border-color: var(--play);
  color: #000;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--play-hover);
  border-color: var(--play-hover);
}

/* ── Play page layout ── */

body.play-page {
  overflow-x: hidden;
}

body.play-page .container {
  padding-top: 0.75rem;
  padding-bottom: 2rem;
}

.play-viewport {
  overflow: hidden;
}

.ad-slot.ad-preplay {
  width: min(100%, 728px);
  min-height: 90px;
  margin: 0 auto 1.25rem;
  flex-direction: column;
  gap: 0.35rem;
}

.ad-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Centered game stage — clipped, no scrollbar inside player */
.game-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  overflow: hidden;
  margin: 0 auto;
}

.game-player {
  position: relative;
  flex-shrink: 0;
  width: min(960px, 100%);
  height: min(
    calc((100vw - 2.5rem) * 9 / 16),
    calc(100vh - var(--play-chrome))
  );
  max-width: 100%;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #000;
  box-shadow: var(--shadow);
}

/* Crop/scale game to fill player (cover) */
.game-frame-fit {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}

.game-frame-fit iframe {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  border: none;
  background: #000;
  transform: translate(-50%, -50%);
  transform-origin: center center;
}

.game-frame-fit.fit-cover iframe {
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  /* Slight overscale crops edges when game is larger than box */
  transform: translate(-50%, -50%) scale(1.12);
}

.game-player.playing .game-frame-fit iframe {
  display: block;
}

body.game-is-active .game-stage {
  overflow: hidden;
}

body.game-is-active .game-player {
  overflow: hidden;
}

/* ── Fullscreen: game fills entire monitor ── */
#game-player:fullscreen,
#game-player:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  margin: 0;
  padding: 0;
}

#game-player:fullscreen .game-frame-fit,
#game-player:-webkit-full-screen .game-frame-fit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#game-player:fullscreen .game-frame-fit iframe,
#game-player:-webkit-full-screen .game-frame-fit iframe {
  display: block !important;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
  transform: none !important;
}

body.fullscreen-mode {
  overflow: hidden;
}

body.fullscreen-mode .site-header,
body.fullscreen-mode .site-footer,
body.fullscreen-mode .play-meta,
body.fullscreen-mode .game-title-bar,
body.fullscreen-mode .ad-slot {
  display: none !important;
}

body.fullscreen-mode main.container {
  padding: 0;
  margin: 0;
  max-width: none;
  width: 100%;
}

body.fullscreen-mode .game-layout {
  margin: 0;
  padding: 0;
}

body.fullscreen-mode .game-center {
  max-width: none;
  width: 100%;
  height: 100vh;
}

body.fullscreen-mode .game-stage {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

body.fullscreen-mode #game-player {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border-radius: 0;
  border: none;
}

/* Play overlay */
.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center;
  z-index: 2;
  overflow: hidden;
}

.play-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
}

.play-overlay-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1rem;
  width: 100%;
  max-width: 100%;
}

.play-overlay h2 {
  margin: 0 0 1.25rem;
  font-size: 1.75rem;
}

.btn-play {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 2.5rem;
  font-size: 1.15rem;
  border: none;
  border-radius: 999px;
  background: var(--play);
  color: #000;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(63, 185, 80, 0.4);
  transition: transform 0.15s, background 0.15s;
  font-family: inherit;
}

.btn-play:hover {
  transform: scale(1.05);
  background: var(--play-hover);
}

.game-status {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.play-overlay.is-hidden {
  display: none;
}

/* Play again bar */
.play-again-bar {
  display: none;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  gap: 0.75rem;
  flex-direction: column;
  align-items: center;
}

.play-again-bar.visible {
  display: flex;
}

.game-description {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.game-description h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.game-description p {
  margin: 0;
  color: var(--text-muted);
}

.related-section {
  margin-top: 2rem;
}

.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

/* ── Legal pages ── */

.legal-page {
  max-width: 720px;
}

.legal-page h1 {
  margin-top: 0;
}

.legal-page h2 {
  margin-top: 2rem;
  font-size: 1.1rem;
}

.legal-page p,
.legal-page li {
  color: var(--text-muted);
}

/* ── Responsive ── */

@media (max-width: 1199px) {
  .ad-slot.ad-rail {
    display: none !important;
  }

  .game-layout {
    flex-direction: column;
  }
}

.play-meta {
  margin-top: 1.5rem;
}

@media (max-width: 768px) {
  .site-header {
    flex-wrap: wrap;
    height: auto;
    padding: 0.75rem 1rem;
  }

  .game-player {
    height: min(calc(100vh - var(--play-chrome)), calc((100vw - 2rem) * 9 / 16));
  }

  .ad-slot.ad-preplay {
    min-height: 60px;
  }

  .search-wrap {
    order: 3;
    max-width: 100%;
    width: 100%;
  }

  .nav-categories {
    display: none;
  }

  .game-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
  }

  .game-title-bar h1 {
    font-size: 1.2rem;
  }
}
