/* ==========================================================================
   Clay Play — Clay design tokens, quiet chrome, games first
   ========================================================================== */

@font-face {
  font-family: "Baloo 2";
  src: url("/assets/fonts/baloo2-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --canvas: #fffaf0;
  --surface-soft: #faf5e8;
  --surface-card: #f5f0e0;
  --surface-strong: #ebe6d6;
  --card: #fffdf7;
  --ink: #0a0a0a;
  --body: #3a3a3a;
  --muted: #6a6a6a;
  --muted-soft: #9a9a9a;
  --hairline: #e5e5e5;
  --hairline-warm: #eee5d3;

  --pink: #ff4d8b;
  --teal: #1a3a3a;
  --lavender: #b8a4ed;
  --peach: #ffb084;
  --ochre: #e8b94a;
  --mint: #a4d4c5;
  --coral: #ff6b5a;

  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --pill: 999px;

  --font-display: "Baloo 2", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;

  --shadow-card: 0 10px 24px -22px rgba(10, 10, 10, 0.35);
  --shadow-lift: 0 26px 44px -32px rgba(10, 10, 10, 0.5);

  --page: 1160px;
  --pad: clamp(18px, 4vw, 32px);

  --accent: var(--peach);
  --accent-ink: #2a1608;
  --accent-soft: #ffe8d9;
}

.accent-pink {
  --accent: var(--pink);
  --accent-ink: #2a0614;
  --accent-soft: #ffe3ec;
}
.accent-teal {
  --accent: var(--teal);
  --accent-ink: #ffffff;
  --accent-soft: #dfe9e6;
}
.accent-lavender {
  --accent: var(--lavender);
  --accent-ink: #141021;
  --accent-soft: #ece6fb;
}
.accent-peach {
  --accent: var(--peach);
  --accent-ink: #2a1608;
  --accent-soft: #ffe8d9;
}
.accent-ochre {
  --accent: var(--ochre);
  --accent-ink: #2a1f04;
  --accent-soft: #fbefcf;
}
.accent-mint {
  --accent: var(--mint);
  --accent-ink: #082019;
  --accent-soft: #e2f2ec;
}
.accent-coral {
  --accent: var(--coral);
  --accent-ink: #2a0a05;
  --accent-soft: #ffe1dc;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 76px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(620px 380px at 92% 0%, rgba(184, 164, 237, 0.12), transparent 72%);
}

/* 首页：内容不足一屏时把页脚压到视口底部 */
body.home {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

body.home > main {
  flex: 1 0 auto;
}

img,
svg {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

::selection {
  background: #ffd0e0;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  border-radius: 8px;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.025em;
  margin: 0;
}

p {
  margin: 0;
}

code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--body);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
}

.container {
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding-inline: var(--pad);
}

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

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 200;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  text-decoration: none;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 12px;
}

/* buttons ----------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

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

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--ink);
  color: #fff;
}

.btn-primary:hover {
  background: #1f1f1f;
}

.btn-ghost {
  border-color: var(--hairline);
  background: #fff;
}

.btn-ghost:hover {
  background: var(--surface-card);
}

.btn-lg {
  height: 52px;
  padding: 0 24px;
  border-radius: var(--radius-lg);
  font-size: 15px;
}

.btn .icon {
  width: 18px;
  height: 18px;
  flex: none;
}

/* header ------------------------------------------------------------------ */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 60;
  background: rgba(255, 250, 240, 0.92);
  border-bottom: 1px solid rgba(229, 229, 229, 0.75);
  backdrop-filter: blur(14px) saturate(1.2);
}

.nav-inner {
  min-height: 64px;
  display: flex;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(229, 229, 229, 0.9);
  border-radius: 13px;
  background: var(--surface-card);
}

.brand-mark img {
  width: 30px;
  height: 30px;
}

.brand-text strong {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* categories -------------------------------------------------------------- */
.browse {
  padding-top: clamp(16px, 2.2vw, 24px);
  padding-bottom: clamp(24px, 4vw, 44px);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 4px;
  margin-bottom: 18px;
}

.chip {
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}

.chip:hover {
  background: var(--surface-card);
  color: var(--ink);
}

.chip.is-active {
  background: var(--surface-card);
  color: var(--ink);
  font-weight: 600;
}

/* game grid --------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.game-card {
  position: relative;
  padding: 8px;
  border: 1px solid var(--hairline-warm);
  border-radius: var(--radius-xl);
  background: var(--card);
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  animation: rise 0.45s both;
  animation-delay: var(--delay, 0ms);
}

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

.game-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-lg);
}

.game-cover-wrap {
  position: relative;
}

.game-cover {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border-radius: 16px;
  background: var(--accent-soft);
}

.game-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}

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

.cover-fallback {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(110% 100% at 20% 10%, rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0) 60%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
}

.cover-fallback::before {
  content: "";
  position: absolute;
  width: 56%;
  aspect-ratio: 1;
  border-radius: 46% 54% 52% 48% / 52% 44% 56% 48%;
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(-12deg);
}

.cover-fallback .cover-icon {
  position: relative;
  z-index: 1;
  font-size: 44px;
  line-height: 1;
  transform: rotate(-4deg);
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.14));
}

.cover-fallback .cover-spark {
  position: absolute;
  top: 12%;
  right: 13%;
  font-size: 18px;
  opacity: 0.65;
}

.badge-featured {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  padding: 4px 10px;
  border-radius: var(--pill);
  background: rgba(255, 255, 255, 0.92);
  color: #6b4a00;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.game-body {
  padding: 13px 8px 6px;
}

.game-body h3 {
  overflow: hidden;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.game-summary {
  display: -webkit-box;
  min-height: 2.9em;
  margin-top: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.game-card .game-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 11px;
  color: var(--muted-soft);
  font-size: 12px;
}

.game-meta-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.meta-dot {
  width: 3px;
  height: 3px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
}

.game-open {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
}

.game-open svg {
  width: 14px;
  height: 14px;
  transition: transform 0.16s ease;
}

.game-card:hover .game-open svg {
  transform: translateX(3px);
}

/* skeleton ---------------------------------------------------------------- */
.game-card.is-skeleton {
  pointer-events: none;
  animation: none;
  box-shadow: none;
}

.game-card.is-skeleton .game-cover {
  background: #f2ecdd;
}

.skeleton-line {
  display: block;
  height: 10px;
  margin: 10px 2px;
  border-radius: 6px;
  background: linear-gradient(90deg, #efe8d8 25%, #f7f1e3 37%, #efe8d8 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}

.skeleton-line.w30 { width: 30%; }
.skeleton-line.w35 { width: 35%; }
.skeleton-line.w40 { width: 40%; }
.skeleton-line.w50 { width: 50%; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w70 { width: 70%; }
.skeleton-line.w80 { width: 80%; }
.skeleton-line.w85 { width: 85%; }
.skeleton-line.w90 { width: 90%; }

/* empty ------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 36px 24px;
  border: 1px dashed #dbd1bb;
  border-radius: var(--radius-xl);
  background: var(--surface-soft);
  text-align: center;
}

.empty-state img {
  width: 76px;
  height: auto;
  opacity: 0.9;
}

.empty-state p {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
}

/* footer ------------------------------------------------------------------ */
.site-footer {
  margin-top: auto;
  border-top: 1px solid rgba(229, 229, 229, 0.8);
  background: var(--surface-soft);
}

.footer-inner {
  padding-top: 18px;
  padding-bottom: 28px;
  color: var(--muted-soft);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-inner a {
  color: inherit;
  text-decoration: none;
}

.footer-inner a:hover {
  text-decoration: underline;
}

/* play page --------------------------------------------------------------- */
body.play-page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.play-bar {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-right: max(10px, env(safe-area-inset-right));
  padding-bottom: 8px;
  padding-left: max(10px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--hairline);
  background: var(--canvas);
}

.play-bar .back {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
}

.play-bar .back svg {
  width: 18px;
  height: 18px;
}

.play-title {
  flex: 1;
  min-width: 0;
}

.play-title h1 {
  overflow: hidden;
  font-size: clamp(16px, 2vw, 20px);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.play-title p {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.play-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.play-actions .btn {
  height: 40px;
  padding: 0 14px;
}

.play-main {
  flex: 1;
  min-height: 0;
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
}

.stage-wrap {
  width: 100%;
  max-width: 1600px;
  height: 100%;
  margin: 0 auto;
  padding-left: max(clamp(8px, 1.4vw, 20px), env(safe-area-inset-left));
  padding-right: max(clamp(8px, 1.4vw, 20px), env(safe-area-inset-right));
}

.stage {
  position: relative;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--hairline-warm);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 50px -44px rgba(10, 10, 10, 0.5);
}

.stage:fullscreen {
  height: 100%;
  border: 0;
  border-radius: 0;
}

.stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13.5px;
  transition: opacity 0.25s;
}

.stage-loading.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loader {
  display: flex;
  gap: 8px;
}

.loader span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--pink);
  animation: bounce 0.9s ease-in-out infinite;
}

.loader span:nth-child(2) {
  animation-delay: 0.12s;
  background: var(--ochre);
}

.loader span:nth-child(3) {
  animation-delay: 0.24s;
  background: var(--mint);
}

.stage-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  background: var(--surface-soft);
  text-align: center;
}

.stage-error img {
  width: min(130px, 30vw);
  margin-bottom: 4px;
}

.stage-error h2 {
  font-size: 24px;
}

.stage-error p {
  max-width: 34em;
  color: var(--muted);
  font-size: 13.5px;
}

.stage-error .btn {
  margin-top: 12px;
}

.result-count {
  padding: 0 16px;
  color: var(--muted);
  font-size: 13px;
}

/* 404 --------------------------------------------------------------------- */
.error-page {
  display: grid;
  place-items: center;
  min-height: 68vh;
  padding: 48px 20px;
  text-align: center;
}

.error-page img {
  width: min(180px, 44vw);
  margin-bottom: 8px;
}

.error-page h1 {
  margin-bottom: 10px;
  font-size: clamp(30px, 5vw, 44px);
}

.error-page p {
  max-width: 32em;
  margin: 0 auto 24px;
  color: var(--muted);
  font-size: 14.5px;
}

/* toast ------------------------------------------------------------------- */
.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 11px 15px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 22px 34px -24px rgba(0, 0, 0, 0.7);
}

.toast.error {
  background: #a30f36;
}

.toast.success {
  background: #0f5132;
}

/* animations -------------------------------------------------------------- */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

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

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* responsive -------------------------------------------------------------- */
@media (max-width: 1000px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .nav-inner {
    min-height: 60px;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .game-summary {
    min-height: 0;
  }

  .play-bar {
    gap: 8px;
    padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px
      max(10px, env(safe-area-inset-left));
  }

  .play-bar .back {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .play-title p {
    display: none;
  }

  .play-actions .btn {
    width: 38px;
    height: 38px;
    padding: 0;
  }

  .play-actions .label {
    display: none;
  }

  .play-main {
    padding: 0 0 env(safe-area-inset-bottom);
  }

  .stage-wrap {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .stage {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }
}

/* 横屏手机：把纵向空间全部让给游戏 */
@media (max-height: 520px) {
  .play-bar {
    gap: 8px;
    padding: max(4px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 4px
      max(10px, env(safe-area-inset-left));
  }

  .play-bar .back {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  .play-title h1 {
    font-size: 15px;
  }

  .play-title p {
    display: none;
  }

  .play-actions .btn {
    width: 34px;
    height: 34px;
    padding: 0;
  }

  .play-actions .label {
    display: none;
  }

  .play-main {
    padding: 0 0 env(safe-area-inset-bottom);
  }

  .stage-wrap {
    padding: 0 max(6px, env(safe-area-inset-right)) 6px max(6px, env(safe-area-inset-left));
  }

  .stage {
    border-radius: 12px;
  }

  .stage-loading p {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
