/* ============================================================================
   Games Sphere — src/css/styles.css
   太空/星系 Recipe F 主题 (AGENTS.md §3)
   业主授权 10 字段常量,见 SPEC §1.1.1 + AGENTS.md §1
   Brand tokens from CONFIG: 粉 #F72585 / 紫 #2E1A6E
   ============================================================================ */

:root {
  /* Brand */
  --color-pink:        #F72585;
  --color-purple:      #2E1A6E;
  --color-cyan:        #4ECDC4;
  --color-gold:        #FFD93D;

  /* Space */
  --color-space-deep:  #0A0E27;
  --color-space-mid:   #14163D;
  --color-space-card:  #1A1B3F;
  --color-space-edge:  #2A2C5A;
  --color-star:        #E8E9F3;
  --color-text:        #FFFFFF;
  --color-text-dim:    #B4B6D5;
  --color-text-muted:  #7A7CA0;

  /* Layout */
  --max-w:             480px;
  --top-nav-h:         56px;
  --drawer-w:          280px;
  --radius-card:       14px;
  --radius-pill:       999px;
  --gap:               12px;

  /* Typography */
  --font-heading:      "Fredoka One", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body:         "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Animation */
  --t-fast:            140ms ease;
  --t-mid:             240ms ease;
}

/* ============================================================================
   Reset
   ============================================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; min-height: 100vh; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-space-deep);
  background-image:
    radial-gradient(ellipse at top, var(--color-purple) 0%, var(--color-space-deep) 55%),
    radial-gradient(ellipse at bottom right, rgba(78, 205, 196, 0.15) 0%, transparent 60%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { display: block; max-width: 100%; height: auto; }
ol, ul { list-style: none; }

/* Star field background (SPEC §16 星空纹理) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 20% 30%, var(--color-star), transparent),
    radial-gradient(1px 1px at 60% 70%, rgba(232,233,243,0.6), transparent),
    radial-gradient(2px 2px at 80% 20%, var(--color-cyan), transparent),
    radial-gradient(1px 1px at 35% 80%, var(--color-star), transparent),
    radial-gradient(1px 1px at 90% 50%, rgba(232,233,243,0.5), transparent),
    radial-gradient(1.5px 1.5px at 15% 60%, var(--color-gold), transparent),
    radial-gradient(1px 1px at 70% 35%, var(--color-star), transparent),
    radial-gradient(1px 1px at 45% 15%, rgba(232,233,243,0.7), transparent);
  background-size: 100% 100%;
  animation: twinkle 4.5s ease-in-out infinite alternate;
  z-index: 0;
}
@keyframes twinkle {
  0%   { opacity: 0.55; }
  50%  { opacity: 0.85; }
  100% { opacity: 0.55; }
}

/* ============================================================================
   App frame (mobile-first, max 480px PC centered)
   SPEC §4.4 强约束: 禁 overflow:hidden (会破坏 sticky)
   ============================================================================ */
.app-frame {
  position: relative;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100vh;
  background: rgba(20, 22, 61, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* ============================================================================
   Top nav (SPEC §4.4 强约束: 唯一, 第一个子元素, margin:0 auto 居中)
   ============================================================================ */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--top-nav-h);
  padding: 0 12px;
  background: linear-gradient(180deg, rgba(46, 26, 110, 0.95) 0%, rgba(46, 26, 110, 0.78) 100%);
  border-bottom: 1px solid rgba(247, 37, 133, 0.25);
  width: var(--max-w);
  margin: 0 auto;
  max-width: 100%;
}
.top-nav__logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-heading);
  font-size: 17px;
  letter-spacing: 0.5px;
  color: var(--color-text);
  flex: 1;
}
.top-nav__logo-icon { color: var(--color-pink); display: flex; }
.top-nav__logo-text { color: var(--color-text); }
.top-nav__btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--color-text);
  transition: background var(--t-fast);
}
.top-nav__btn:hover { background: rgba(255, 255, 255, 0.1); }
.top-nav__btn:active { background: rgba(247, 37, 133, 0.2); }

/* ============================================================================
   Drawer (SPEC §4.4 强约束: 直接吃视口右边缘, transform 加 30px buffer)
   ============================================================================ */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--drawer-w);
  max-width: 80vw;
  height: 100vh;
  background: var(--color-space-mid);
  border-left: 1px solid rgba(247, 37, 133, 0.3);
  z-index: 100;
  transform: translateX(calc(100% + 30px));
  transition: transform var(--t-mid);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.4);
}
.drawer.is-open { transform: translateX(0); }
.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-heading);
}
.drawer__title { font-size: 18px; color: var(--color-text); }
.drawer__close { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-pill); }
.drawer__close:hover { background: rgba(255, 255, 255, 0.1); }
.drawer__nav { padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.drawer__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--color-text);
  font-weight: 600;
  transition: background var(--t-fast);
}
.drawer__link:hover { background: rgba(247, 37, 133, 0.12); }
.drawer__link-icon { display: flex; color: var(--color-cyan); }
.drawer__cats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.drawer__cat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--color-space-card);
  border-radius: var(--radius-card);
  font-size: 13px;
  color: var(--color-text);
  border: 1px solid transparent;
  transition: border-color var(--t-fast);
}
.drawer__cat:hover { border-color: var(--color-pink); }
.drawer__cat-count { margin-left: auto; color: var(--color-text-muted); font-size: 11px; }
.drawer__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-mid);
}
.drawer__backdrop.is-open { opacity: 1; pointer-events: auto; }

/* ============================================================================
   Search overlay
   ============================================================================ */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(10, 14, 39, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-mid);
}
.search-overlay.is-open { opacity: 1; pointer-events: auto; }
.search-overlay__panel { width: 100%; max-width: var(--max-w); }
.search-overlay__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--color-space-card);
  border: 1px solid rgba(247, 37, 133, 0.3);
  border-radius: var(--radius-pill);
  color: var(--color-text);
}
.search-overlay__input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--color-text);
  font-size: 15px;
  font-family: var(--font-body);
}
.search-overlay__input::placeholder { color: var(--color-text-muted); }
.search-overlay__close { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.search-overlay__quicklinks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 0;
}
.search-overlay__quicklink {
  padding: 8px 14px;
  background: var(--color-space-card);
  border-radius: var(--radius-pill);
  font-size: 13px;
  color: var(--color-text);
  border: 1px solid rgba(78, 205, 196, 0.2);
}
.search-overlay__results { padding-top: 8px; }
.search-overlay__result {
  display: block;
  padding: 10px 12px;
  background: var(--color-space-card);
  border-radius: var(--radius-card);
  margin-bottom: 8px;
  color: var(--color-text);
}

/* ============================================================================
   Main
   ============================================================================ */
.main { position: relative; z-index: 1; padding: 14px 14px 80px; }
.section-title {
  font-family: var(--font-heading);
  font-size: 17px;
  letter-spacing: 0.4px;
  margin: 18px 0 10px;
  color: var(--color-text);
}
.section-title::before {
  content: "✦";
  color: var(--color-cyan);
  margin-right: 6px;
  font-size: 14px;
}

/* ============================================================================
   Card grid (首页 + 列表 + 推荐)
   ============================================================================ */
.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}
.card {
  display: block;
  background: var(--color-space-card);
  border-radius: var(--radius-card);
  overflow: hidden;
  border: 1px solid rgba(78, 205, 196, 0.12);
  transition: transform var(--t-fast), border-color var(--t-fast);
}
.card:hover { transform: translateY(-2px); border-color: var(--color-pink); }
.card__thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, var(--color-purple) 0%, var(--color-space-deep) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card__thumb-img { width: 100%; height: 100%; object-fit: cover; }
.card__thumb-icon { font-size: 56px; line-height: 1; }
.card__body { padding: 8px 10px 10px; }
.card__title {
  font-family: var(--font-heading);
  font-size: 14px;
  margin-bottom: 4px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__meta { display: flex; gap: 8px; font-size: 11px; color: var(--color-text-dim); }
.card__rating { color: var(--color-gold); }
.card__plays { color: var(--color-text-muted); }

/* ============================================================================
   Game head (详情页)
   ============================================================================ */
.game-head {
  display: flex;
  gap: 14px;
  padding: 14px;
  background: linear-gradient(135deg, var(--color-purple) 0%, var(--color-space-deep) 100%);
  border-radius: var(--radius-card);
  border: 1px solid rgba(247, 37, 133, 0.25);
}
.game-head__cover {
  width: 88px;
  height: 88px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--color-space-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.15);
}
.game-head__cover-img { width: 100%; height: 100%; object-fit: cover; }
.game-head__cover-emoji { font-size: 56px; }
.game-head__body { flex: 1; min-width: 0; }
.game-head__title { font-family: var(--font-heading); font-size: 19px; margin-bottom: 4px; }
.game-head__subtitle { font-size: 13px; color: var(--color-text-dim); margin-bottom: 8px; }
.game-head__stats { display: flex; flex-wrap: wrap; gap: 6px; }
.stat {
  font-size: 11px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
  color: var(--color-text);
}
.stat--cat { background: rgba(247, 37, 133, 0.2); color: var(--color-pink); font-weight: 700; }

/* ============================================================================
   Play CTA
   ============================================================================ */
.play-cta {
  display: block;
  width: 100%;
  padding: 14px 16px;
  margin-top: 12px;
  background: linear-gradient(90deg, var(--color-pink) 0%, #FF4DA0 100%);
  color: #fff;
  text-align: center;
  font-family: var(--font-heading);
  font-size: 17px;
  letter-spacing: 0.5px;
  border-radius: var(--radius-pill);
  box-shadow: 0 4px 16px rgba(247, 37, 133, 0.35);
  transition: transform var(--t-fast);
}
.play-cta:hover { transform: scale(1.02); }
.play-cta:active { transform: scale(0.98); }

/* ============================================================================
   Game info / How to / Tags
   ============================================================================ */
.game-info__desc { color: var(--color-text-dim); font-size: 14px; line-height: 1.65; }
.howto__list { counter-reset: howto; padding-left: 0; }
.howto__list li {
  counter-increment: howto;
  padding: 8px 0 8px 30px;
  position: relative;
  color: var(--color-text-dim);
  font-size: 14px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}
.howto__list li::before {
  content: counter(howto);
  position: absolute;
  left: 0;
  top: 8px;
  width: 22px;
  height: 22px;
  background: var(--color-pink);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.tags__list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  padding: 4px 10px;
  background: rgba(78, 205, 196, 0.15);
  color: var(--color-cyan);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
}

/* ============================================================================
   Ad slots (placeholder, real ad code injected later)
   ============================================================================ */
.ad-slot {
  margin: 18px auto;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-card);
  text-align: center;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ad-slot--rectangle { min-height: 250px; max-width: 300px; }
.ad-slot--large-rectangle { min-height: 280px; max-width: 336px; }
.ad-slot__label { font-size: 10px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.ad-slot__placeholder { font-size: 13px; color: var(--color-text-muted); font-weight: 700; }

/* ============================================================================
   Consent banner (SPEC §6.7)
   ============================================================================ */
.consent-banner {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-w);
  background: rgba(20, 22, 61, 0.98);
  border-top: 1px solid rgba(247, 37, 133, 0.4);
  padding: 12px 14px;
  z-index: 80;
  opacity: 0;
  transition: opacity var(--t-mid);
  pointer-events: none;
}
.consent-banner.is-visible { opacity: 1; pointer-events: auto; }
.consent-banner__inner { display: flex; flex-direction: column; gap: 10px; }
.consent-banner__text { font-size: 12px; color: var(--color-text-dim); }
.consent-banner__text a { color: var(--color-cyan); text-decoration: underline; }
.consent-banner__actions { display: flex; gap: 8px; }
.consent-btn {
  flex: 1;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  transition: filter var(--t-fast);
}
.consent-btn:hover { filter: brightness(1.1); }
.consent-btn--accept { background: var(--color-pink); color: #fff; }
.consent-btn--reject { background: transparent; border-color: rgba(255,255,255,0.2); color: var(--color-text); }

/* ============================================================================
   Footer
   ============================================================================ */
.footer {
  padding: 22px 16px 30px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
  background: rgba(10, 14, 39, 0.5);
}
.footer__brand { font-family: var(--font-heading); font-size: 18px; color: var(--color-pink); margin-bottom: 4px; }
.footer__tag { font-size: 11px; color: var(--color-text-muted); margin-bottom: 12px; }
.footer__links { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-bottom: 12px; }
.footer__links a { font-size: 12px; color: var(--color-text-dim); }
.footer__links a:hover { color: var(--color-cyan); }
.footer__copy { font-size: 11px; color: var(--color-text-muted); }

/* ============================================================================
   Play page (game iframe host)
   ============================================================================ */
.play-frame {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--top-nav-h));
  border: 0;
  background: var(--color-space-deep);
}
.play-loader {
  position: absolute;
  inset: 0;
  background: var(--color-space-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: opacity 300ms ease;
}
.play-loader.is-hidden { opacity: 0; pointer-events: none; }
.play-loader__spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(247, 37, 133, 0.2);
  border-top-color: var(--color-pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   Reco grid (related games on detail page)
   ============================================================================ */
.reco-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

/* ============================================================================
   List page (search + filter)
   ============================================================================ */
.list-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  margin-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.list-toolbar::-webkit-scrollbar { display: none; }
.list-toolbar__pill {
  flex-shrink: 0;
  padding: 6px 12px;
  background: var(--color-space-card);
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--color-text);
  border: 1px solid transparent;
  white-space: nowrap;
}
.list-toolbar__pill.is-active { background: var(--color-pink); border-color: var(--color-pink); color: #fff; }

/* ============================================================================
   404 / privacy / terms / contact — text pages
   ============================================================================ */
.text-page h1 { font-family: var(--font-heading); font-size: 24px; margin-bottom: 14px; color: var(--color-pink); }
.text-page h2 { font-family: var(--font-heading); font-size: 18px; margin: 22px 0 10px; color: var(--color-text); }
.text-page p, .text-page li { color: var(--color-text-dim); font-size: 14px; line-height: 1.7; margin-bottom: 10px; }
.text-page ul { padding-left: 22px; list-style: disc; }

/* ============================================================================
   Responsive (PC centered, drawer unchanged per SPEC §4.4)
   ============================================================================ */
@media (min-width: 540px) {
  .app-frame { box-shadow: 0 0 32px rgba(0, 0, 0, 0.3); }
}
