/* Styled after the buttons in the blog: flat tabs that grow, invert and fade a picture in. */

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, sans-serif;
  background-color: #f5f5f5;
  color: #212121;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

/* =========================================================
   Layout
   ========================================================= */

#header {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 24px 16px 32px;
  text-align: center;
}

#header h1 {
  margin: 0 0 20px;
  font-size: 32px;
  letter-spacing: 0.05em;
}

#header h1 span {
  display: inline-block;
}

#header h1:hover span {
  animation: fade-out 0.5s forwards;
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 820px;
}

/* =========================================================
   Buttons
   ========================================================= */

.square-tab {
  position: relative;
  display: block;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  isolation: isolate;
  background-color: #f5f5f5;
  color: #212121;
  border: 3px solid #212121;
  border-radius: 16px;
  font-size: 22px;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

/* The picture waits underneath until the button is hovered or focused */
.tiedye-button {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

/* The name starts centred and slides to the bottom as the picture appears */
.label {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  padding: 6px 10px;
  transition: top 0.3s ease, transform 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}

.square-tab:hover,
.square-tab:focus-visible {
  z-index: 1;
  transform: scale(1.06);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
  background-color: #212121;
  color: #ffffff;
}

.square-tab:focus-visible {
  outline: 3px solid #2196f3;
  outline-offset: 3px;
}

.square-tab:hover .tiedye-button,
.square-tab:focus-visible .tiedye-button {
  opacity: 1;
}

.square-tab:hover .label,
.square-tab:focus-visible .label {
  top: 100%;
  transform: translateY(-100%);
  background-color: rgba(0, 0, 0, 0.75);
  color: #ffffff;
}

/* =========================================================
   Dark Mode Toggle Switch
   ========================================================= */

.switch {
  position: absolute;
  top: 16px;
  right: 16px;
  display: inline-block;
  width: 60px;
  height: 34px;
  z-index: 10;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 34px;
}

.slider::before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: #fff;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #2196f3;
}

input:checked + .slider::before {
  transform: translateX(26px);
}

input:focus-visible + .slider {
  outline: 3px solid #2196f3;
  outline-offset: 3px;
}

/* =========================================================
   Dark Mode
   ========================================================= */

.dark-mode body {
  background-color: #121212;
  color: #f5f5f5;
}

.dark-mode .square-tab {
  background-color: #212121;
  border-color: #f5f5f5;
  color: #f5f5f5;
}

.dark-mode .square-tab:hover,
.dark-mode .square-tab:focus-visible {
  background-color: #f5f5f5;
  color: #212121;
}

/* =========================================================
   Smaller screens and touch screens
   ========================================================= */

@media (max-width: 760px) {
  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  /* Nine games in two columns: centre the one left over */
  .game-grid .square-tab:last-child {
    grid-column: 1 / -1;
    justify-self: center;
    width: calc(50% - 7px);
  }

  .square-tab {
    font-size: 15px;
  }

  .label {
    padding: 4px 6px;
    line-height: 1.25;
  }

  #header {
    padding-top: 68px;
  }
}

/* No mouse to hover with: pictures fade in one after another when the page opens */
@media (hover: none) {
  .tiedye-button {
    animation: fade-in 0.8s ease forwards;
  }

  .label {
    top: 100%;
    transform: translateY(-100%);
    background-color: rgba(0, 0, 0, 0.75);
    color: #ffffff;
  }

  .game-grid .square-tab:nth-child(2) .tiedye-button { animation-delay: 0.08s; }
  .game-grid .square-tab:nth-child(3) .tiedye-button { animation-delay: 0.16s; }
  .game-grid .square-tab:nth-child(4) .tiedye-button { animation-delay: 0.24s; }
  .game-grid .square-tab:nth-child(5) .tiedye-button { animation-delay: 0.32s; }
  .game-grid .square-tab:nth-child(6) .tiedye-button { animation-delay: 0.4s; }
  .game-grid .square-tab:nth-child(7) .tiedye-button { animation-delay: 0.48s; }
  .game-grid .square-tab:nth-child(8) .tiedye-button { animation-delay: 0.56s; }
  .game-grid .square-tab:nth-child(9) .tiedye-button { animation-delay: 0.64s; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .square-tab,
  .tiedye-button,
  .label,
  .slider,
  .slider::before {
    transition: none;
  }

  .square-tab:hover,
  .square-tab:focus-visible {
    transform: none;
  }

  .tiedye-button {
    animation-duration: 1ms;
    animation-delay: 0s !important;
  }

  #header h1:hover span {
    animation: none;
  }
}
