/* ========================================
   common.css — shared theme
   ======================================== */

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

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-hover: #f5f5f5;
  --text: #2d2d2d;
  --text-mid: #5a5a5a;
  --text-dim: #9a9a9a;
  --red: #e60012;
  --blue: #00c3e3;
  --gold: #f5a623;
  --green: #00c36a;
  --purple: #7b61ff;
  --orange: #ff7b00;
  --radius: 6px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Nunito', 'M PLUS Rounded 1c', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: calc(var(--header-h) + var(--safe-top));
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Floating sparkle particles ── */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  background: var(--red);
  border-radius: 50%;
  opacity: 0;
  animation: particle-float 10s ease-in-out infinite;
  will-change: transform, opacity;
}

.particle:nth-child(1)  { left: 10%; animation-delay: 0s; }
.particle:nth-child(2)  { left: 25%; animation-delay: 1.2s; }
.particle:nth-child(3)  { left: 40%; animation-delay: 2.5s; }
.particle:nth-child(4)  { left: 55%; animation-delay: 0.8s; }
.particle:nth-child(5)  { left: 70%; animation-delay: 3.1s; }
.particle:nth-child(6)  { left: 85%; animation-delay: 1.8s; }
.particle:nth-child(7)  { left: 15%; animation-delay: 4.2s; }
.particle:nth-child(8)  { left: 50%; animation-delay: 5s; }
.particle:nth-child(9)  { left: 80%; animation-delay: 2s; }
.particle:nth-child(10) { left: 35%; animation-delay: 3.8s; }

@keyframes particle-float {
  0%   { transform: translateY(100vh) scale(0); opacity: 0; }
  10%  { opacity: 0.3; }
  90%  { opacity: 0.2; }
  100% { transform: translateY(-20vh) scale(1); opacity: 0; }
}

/* ── Header ── */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: calc(24px + var(--safe-left));
  padding-right: calc(24px + var(--safe-right));
  z-index: 100;
  animation: header-slide 0.6s cubic-bezier(0.16,1,0.3,1) both;
}

@keyframes header-slide {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.header-logo {
  font-weight: 900;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  flex-shrink: 0;
}

.header-logo:hover { transform: scale(1.05); }
.header-logo .dot { color: var(--red); }

/* Desktop nav */
.header-nav {
  display: flex;
  gap: 4px;
}

.header-nav a {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-mid);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 4px;
  position: relative;
  transition: color 0.2s;
  white-space: nowrap;
}

.header-nav a::after {
  content: '';
  position: absolute;
  bottom: 2px; left: 50%; right: 50%;
  height: 2px;
  background: var(--red);
  border-radius: 1px;
  transition: left 0.25s cubic-bezier(0.34,1.56,0.64,1),
              right 0.25s cubic-bezier(0.34,1.56,0.64,1);
}

.header-nav a:hover { color: var(--text); }
.header-nav a:hover::after { left: 20%; right: 20%; }

/* Hamburger button (mobile only) */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 110;
  -webkit-tap-highlight-color: transparent;
}

.menu-toggle span,
.menu-toggle span::before,
.menu-toggle span::after {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-mid);
  border-radius: 1px;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1),
              opacity 0.2s;
}

.menu-toggle span::before,
.menu-toggle span::after {
  content: '';
  position: absolute;
}

.menu-toggle span::before { transform: translateY(-7px); }
.menu-toggle span::after  { transform: translateY(7px); }

.menu-toggle.active span { background: transparent; }
.menu-toggle.active span::before { transform: rotate(45deg); }
.menu-toggle.active span::after  { transform: rotate(-45deg); }

/* Mobile drawer */
.mobile-drawer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  pointer-events: none;
}

.mobile-drawer.open { pointer-events: auto; }

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.3s;
}

.mobile-drawer.open .drawer-backdrop { opacity: 1; }

.drawer-panel {
  position: absolute;
  top: 0; right: 0;
  width: min(280px, 80vw);
  height: 100%;
  background: #fff;
  padding: calc(var(--header-h) + var(--safe-top) + 1.5rem) 1.5rem calc(2rem + var(--safe-bottom));
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.16,1,0.3,1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: -4px 0 20px rgba(0,0,0,0.08);
}

.mobile-drawer.open .drawer-panel { transform: translateX(0); }

.drawer-panel a {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  padding: 14px 16px;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s, transform 0.2s;
  min-height: 48px;
}

.drawer-panel a:hover,
.drawer-panel a:active {
  background: rgba(0,0,0,0.04);
}

.drawer-panel a:active { transform: scale(0.97); }

.drawer-icon {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 900;
  flex-shrink: 0;
  color: #fff;
}

/* ── Reusable game card ── */
.g-card,
.g-card:hover,
.g-card * {
  text-decoration: none;
}

.g-card {
  display: flex;
  background: var(--surface);
  border: 2px solid rgba(0,0,0,0.06);
  border-radius: var(--radius);
  color: var(--text);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  animation: g-card-in 0.5s cubic-bezier(0.16,1,0.3,1) both;
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 0.35s ease,
              border-color 0.3s ease,
              background 0.25s ease;
}

@keyframes g-card-in {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

@media (hover: hover) and (pointer: fine) {
  .g-card:hover {
    transform: translateY(-6px) scale(1.02);
    border-color: var(--card-accent, var(--red));
    box-shadow: 0 12px 32px rgba(0,0,0,0.1),
                0 0 0 1px var(--card-accent, var(--red));
  }
  .g-card:hover .g-icon {
    transform: scale(1.1) rotate(-3deg);
  }
}

.g-card:active {
  transform: translateY(-2px) scale(0.97);
  transition-duration: 0.1s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

/* Gradient icon */
.g-icon {
  width: 48px; min-width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 900;
  color: #fff; flex-shrink: 0; flex-grow: 0;
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 0.35s ease;
}

/* Page title */
.page-title {
  font-weight: 900;
  font-size: clamp(1.5rem, 5vw, 2rem);
  letter-spacing: -0.03em;
  margin-bottom: 0.3rem;
  opacity: 0;
  animation: g-card-in 0.6s 0.1s cubic-bezier(0.16,1,0.3,1) forwards;
}

.page-title .dot { color: var(--red); }

.page-subtitle {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 2rem;
  opacity: 0;
  animation: g-card-in 0.6s 0.2s cubic-bezier(0.16,1,0.3,1) forwards;
}

/* Search input */
.g-search {
  width: 100%;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  margin-bottom: 1.5rem;
}

.g-search:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(230,0,18,0.08);
}

.g-search::placeholder { color: var(--text-dim); }

/* Back link */
.g-back {
  display: inline-block;
  margin-top: 2rem;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  transition: color 0.2s, transform 0.2s;
}

.g-back:hover { color: var(--text); transform: translateX(-3px); }

/* ── Ripple effect ── */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(0,0,0,0.06);
  transform: scale(0);
  animation: ripple-expand 0.6s ease-out forwards;
  pointer-events: none;
  z-index: 3;
}

@keyframes ripple-expand {
  0%   { transform: scale(0); opacity: 1; }
  100% { transform: scale(4); opacity: 0; }
}

/* ── Page transition overlay ── */
.transition-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.8rem;
  pointer-events: none;
  opacity: 0;
}

.transition-overlay.active {
  pointer-events: auto;
  animation: transition-in 0.4s cubic-bezier(0.16,1,0.3,1) forwards;
}

.transition-label {
  font-weight: 900;
  font-size: clamp(2rem, 8vw, 3.2rem);
  color: #fff;
  letter-spacing: -0.03em;
  opacity: 0;
  transform: translateY(20px) scale(0.8);
}

.transition-overlay.active .transition-label {
  animation: transition-label-in 0.4s 0.25s cubic-bezier(0.34,1.56,0.64,1) forwards;
}

.transition-desc {
  font-weight: 700;
  font-size: clamp(0.7rem, 2.5vw, 0.9rem);
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.05em;
  opacity: 0;
  transform: translateY(10px);
}

.transition-overlay.active .transition-desc {
  animation: transition-desc-in 0.35s 0.4s cubic-bezier(0.16,1,0.3,1) forwards;
}

@keyframes transition-in {
  0%   { opacity: 0; clip-path: circle(0% at var(--cx, 50%) var(--cy, 50%)); }
  100% { opacity: 1; clip-path: circle(150% at var(--cx, 50%) var(--cy, 50%)); }
}

@keyframes transition-label-in {
  0%   { opacity: 0; transform: translateY(20px) scale(0.8); }
  100% { opacity: 1; transform: translateY(0)    scale(1); }
}

@keyframes transition-desc-in {
  0%   { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ── Responsive header ── */
@media (max-width: 767px) {
  .header-nav { gap: 2px; }
  .header-nav a { font-size: 0.62rem; padding: 4px 8px; }
}

@media (max-width: 600px) {
  .header-nav { display: none; }
  .menu-toggle { display: flex; }
  .mobile-drawer { display: block; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
