/* ==========================================================================
   Games hub.

   Chrome comes from css/theme.css so this matches Profile and Dashboard. The
   grid is auto-fit rather than the old `repeat(3, 1fr)`, which could not fit a
   fourth game — the reason tic-tac-toe had nowhere to appear.
   ========================================================================== */

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg-body);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  flex: 0 0 auto;
}

/* --- dashboard ----------------------------------------------------------- */

#games-dashboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 3rem 1rem 4rem;
  text-align: center;
}

#games-dashboard h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3rem);
  letter-spacing: 2px;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--primary-color), var(--highlight-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hub-subtitle {
  margin: 0 0 2.5rem;
  color: var(--text-secondary);
}

/* --- cards --------------------------------------------------------------- */

.game-card-container {
  display: grid;
  /* auto-fit, so a fifth game needs no CSS change */
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  width: 100%;
  max-width: 900px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 220px;
  padding: 1.75rem 1.25rem;
  font-family: inherit;
  text-align: center;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.game-card:hover {
  transform: translateY(-6px);
  border-color: var(--primary-color);
  box-shadow: var(--shadow-lg);
}

.game-card:focus-visible {
  outline: 3px solid var(--highlight-color);
  outline-offset: 3px;
}

.game-card .game-icon {
  display: block;
  font-size: 3.5rem;
  line-height: 1;
  color: var(--primary-color);
  transition: transform 0.3s ease, color 0.3s ease;
}

.game-card:hover .game-icon {
  transform: scale(1.12) rotate(-5deg);
  color: var(--highlight-color);
}

.game-card h3 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.game-blurb {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* --- game view ----------------------------------------------------------- */

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}

#game-container[hidden],
#games-dashboard[hidden] {
  display: none;
}

#game-frame {
  width: 100%;
  max-width: 900px;
  /* Was a fixed height="700px" attribute, which overflowed small screens and
     left dead space on large ones. */
  height: min(80vh, 720px);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
}

#back-button {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.7rem 1.5rem;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 2px solid var(--primary-color);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

#back-button:hover {
  background: var(--primary-color);
  color: var(--on-primary);
  transform: translateY(-2px);
}

#back-button:focus-visible {
  outline: 3px solid var(--highlight-color);
  outline-offset: 3px;
}

/* --- theme toggle -------------------------------------------------------- */

.theme-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  z-index: 1000;
  color: var(--on-primary);
  font-size: 1.5rem;
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: var(--shadow-xl);
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--highlight-color);
  outline-offset: 3px;
}

.icon-sun {
  display: none;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: block;
}

/* --- motion preferences -------------------------------------------------- */

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

  .game-card:hover,
  #back-button:hover,
  .theme-toggle:hover {
    transform: none;
  }
}
