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

:root {
  --bg:       #06050d;
  --surface:  #0f0e18;
  --border:   rgba(255, 255, 255, 0.06);
  --border-h: rgba(255, 255, 255, 0.14);
  --text:     #f0ecf7;
  --text-mid: rgba(230, 220, 245, 0.65);
  --text-dim: rgba(200, 190, 220, 0.35);
  --accent:   #c4a1ff;
  --accent-dim: rgba(196, 161, 255, 0.15);
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body:    'Inter', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow: hidden;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.4;
}

/* ── Title (rendered inside the grid's center cell) ── */

.title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5.5vw, 3.8rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.015em;
  background: linear-gradient(135deg, #d8c4ff, #f0e6ff, #c4a1ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: fadeUp 0.7s ease both;
}

.subtitle {
  margin-top: 10px;
  font-size: clamp(0.85rem, 1.6vw, 1.05rem);
  font-weight: 400;
  font-style: italic;
  color: var(--text-mid);
  letter-spacing: 0.01em;
  animation: fadeUp 0.7s ease 0.1s both;
}

/* ── Grid: 4 × 3 frame of square cards with title in the center ── */

#grid {
  position: relative;
  z-index: 1;
  margin: 0 auto;
  padding: clamp(20px, 3vh, 40px) clamp(20px, 3vw, 40px);
  display: grid;
  --grid-gap: clamp(16px, 2.2vw, 28px);
  gap: var(--grid-gap);
  justify-content: center;
  align-content: center;
  min-height: 100vh;
  --card-size: min(
    calc((100vw - 2 * clamp(20px, 3vw, 40px) - 3 * var(--grid-gap)) / 4),
    calc((100vh - 2 * clamp(20px, 3vh, 40px) - 2 * var(--grid-gap)) / 3)
  );
  grid-template-columns: repeat(4, var(--card-size));
  grid-template-rows: repeat(3, var(--card-size));
}

#center-text {
  grid-column: 2 / 4;
  grid-row: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: clamp(18px, 2.6vh, 32px) clamp(22px, 2.6vw, 40px);
  animation: fadeUp 0.9s ease 0.05s both;
}

/* ── Card ── */

.card {
  position: relative;
  display: block;
  border-radius: 14px;
  overflow: hidden;
  text-decoration: none;
  cursor: pointer;
  background: #0a0914;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.3s ease;
  box-shadow:
    0 6px 20px rgba(0,0,0,0.5),
    0 0 0 1px rgba(196, 161, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -1px 0 rgba(0, 0, 0, 0.4);
}

.card.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Light-background cards (thumbnails with white/off-white bg) */
.card.light-card {
  background: #f9fafc;
}

.card:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow:
    0 14px 36px rgba(0,0,0,0.6),
    0 0 0 1px rgba(196, 161, 255, 0.45),
    0 0 32px rgba(196, 161, 255, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ── Icon cards (for games without screenshots yet) ── */

.card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon .icon {
  font-size: clamp(2rem, 4vw, 3rem);
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card-icon:hover .icon {
  transform: scale(1.12);
}

/* ── Animations ── */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ── */

@media (max-width: 700px) {
  #grid {
    padding: 0 14px 14px;
    --row-gap: clamp(12px, 2.5vw, 18px);
  }
  #header { padding-left: 14px; padding-right: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .card { opacity: 1; transform: none; transition: none; }
  .title, .subtitle { animation: none; }
  html { scroll-behavior: auto; }
}

/* ── Music toggle ── */
#music-toggle {
  position: fixed;
  top: clamp(14px, 2.2vw, 22px);
  right: clamp(14px, 2.2vw, 22px);
  width: clamp(36px, 4vw, 44px);
  height: clamp(36px, 4vw, 44px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(30, 24, 46, 0.55);
  border: 1px solid var(--border);
  color: var(--text-mid);
  cursor: pointer;
  z-index: 30;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease, transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

#music-toggle svg {
  width: 58%;
  height: 58%;
}

#music-toggle:hover {
  color: var(--accent);
  border-color: var(--border-h);
  background: rgba(40, 32, 62, 0.7);
  transform: scale(1.05);
}

#music-toggle:active { transform: scale(0.94); }
