@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@300..700&family=Overlock+SC&family=Silkscreen:wght@400;700&display=swap');

:root {
  /* Colours */
  --primary: hsl(150, 20%, 25%);
  --secondary: hsl(131, 22%, 29%);
  --light: hsl(0, 0%, 90%);
  --dark: hsl(0, 0%, 10%);

  /* Typography */
  --font-family-heading: "Overlock SC", sans-serif;
  --font-family-stats-display: "Silkscreen", sans-serif;
  --font-family-body: "Fredoka", sans-serif;
  --font-size-base: 1rem;
  --line-height-base: 1.2;

  /* Layout */
  --gap: 10px;
  --border-radius: 8px;
  --border-color: var(--primary);
  --boder-size: 5px;
  --box-shadow:
    inset 2px 2px 8px 2px hsla(0 0% 50% / 0.5),
    inset -2px -2px 8px 2px hsla(0 0% 10% / 0.8),
    3px 3px 3px 0px hsla(0 0% 0% / 0.5);
}

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

/* Global */
#main-header {
  grid-area: main-header;
}

#game-control {
  grid-area: game-control;
}

#scores {
  grid-area: scores;
}

#game-board {
  grid-area: game-board;
}

#main-footer {
  grid-area: main-footer;
}

body {
  font-family: var(--font-family-body);
  background: var(--light);
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: var(--gap);
  max-width: 400px;
  min-height: 100svh;
  margin: 0 auto;
  padding: var(--gap);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  grid-template-areas:
    "main-header"
    "game-control"
    "game-board"
    "scores"
    "main-footer"
  ;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family-heading);
  margin: 0;
  padding: 0;
}

p {
  margin: 0;
  margin-bottom: 0.5rem;
}

ol, ul, li {
  margin: 0;
  margin-bottom: 0.5rem;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  background-color: var(--light);
  color: var(--dark);
  font-family: var(--font-family-body);
  font-weight: 500;
  font-size: 1.2rem;
  line-height: var(--line-height-base);
  cursor: pointer;
  box-shadow:
    inset 2px 2px 8px hsla(0 0% 90% / 0.3),
    inset -2px -2px 8px hsla(0 0% 10% / 0.3),
    3px 3px 12px hsla(0 0% 0% / 0.5);
}

/* Header */
header, #scores {
  padding: var(--gap);
  border-radius: var(--border-radius);
  background-color: var(--primary);
  box-shadow: var(--box-shadow);
}

header h1 {
  color: var(--light);
  text-align: center;
}

/* Sidebar */
.sidebar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

/* Game Stats Section */
.stats-display {
  grid-column: span 2;
  --background-color: hsl(0, 0%, 15%);
  --text-color: hsl(129, 96%, 46%);
  display: flex;
  justify-content: space-around;
  border-radius: var(--border-radius);
  background-color: var(--background-color);
  background: linear-gradient(hsl(0, 0%, 18%) 0%,
      hsl(0, 0%, 12%) 100%);
  color: var(--text-color);
  text-shadow:
    0 0 2px #000,
    0 0 6px hsla(129, 96%, 56%, 0.9),
    0 0 12px hsla(129, 96%, 56%, 0.8),
    0 0 24px hsla(129, 96%, 56%, 0.6);
  box-shadow:
    inset 1px 1px 6px hsla(0, 0%, 90%, 0.2),
    inset -1px -1px 6px hsla(0, 0%, 90%, 0.2),
    0 0 8px hsla(129, 96%, 56%, 0.3),
    0 0 16px hsla(0, 0%, 0%, 0.5),
    3px 3px 12px hsla(0, 0%, 0%, 0.3);
}

.stat {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-stats-display);
  font-size: var(--font-size-base);
  padding: 1rem;
  margin: 0;
}

.stat p {
  font-size: 1.2rem;
  margin: 0;
}

.btn.instructions {
  color: var(--light);
  background: var(--secondary);
  box-shadow: var(--box-shadow);
}

.btn.instructions:hover {
  background-color: color-mix(in hsl, var(--secondary), white 20%);
  color: color-mix(in hsl, var(--light), white 20%);
}

/* Instructions Modal */
dialog {
  margin: auto var(--gap);
  max-width: 748px;
  padding: 20px;
  border: none;
  border-radius: 20px;
  background-color: var(--primary);
  color: var(--light);
  box-shadow: var(--box-shadow);
}

dialog h2 {
  margin: 0;
}

dialog[open] {
  display: grid;
  gap: var(--gap);
}

dialog:focus {
  outline: none;
}

dialog::backdrop {
  background-color: color-mix(in srgb, var(--primary) 60%, transparent);
}

.btn.new-game {
  color: var(--light);
  background-color: var(--primary);
  box-shadow: var(--box-shadow);
}

.btn.new-game:hover {
  background-color: color-mix(in hsl, var(--primary), white 20%);
  color: color-mix(in hsl, var(--light), white 20%);
}

/* Game Board */
#game-board {
  gap: var(--gap);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

/* Cards */
.card {
  --card-size: 180px;
  border-radius: var(--border-radius);
  position: relative;
  transform-style: preserve-3d;
  transition: all 0.5s ease-in-out;
  box-shadow: 2px 2px 3px 1px hsla(0 0% 0% / 0.5);
  cursor: pointer;
  max-width: var(--card-size);
  max-height: var(--card-size);
}

.card img {
  width: 100%;
}

.front {
  width: 100%;
  transform: rotateY(180deg);
}

.front, .back {
  height: 100%;
  width: 100%;
  border-radius: var(--border-radius);
  /* To make sure that the clicked card cannot be clicked twice */
  pointer-events: none;
}

.back {
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
  background-image: url("../images/ocarina.webp");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

/* Cards annimation */
.flip {
  transform: rotateY(180deg);
}

.flipped {
  pointer-events: none;
}

.matched {
  pointer-events: none;
}

/* Win Message */
.winMessage {
  grid-column: span 3;
  align-self: center;
  height: 300px;
  font-family: var(--font-family-body);
}

.winMessageText {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 1.5rem;
}

#scores {
  color: var(--light);
}

table {
  width: 100%;
  text-align: left;
}

/* Footer */
footer {
  border-radius: var(--border-radius);
  background-color: var(--primary);
  padding: var(--gap) calc(var(--gap) * 1.5);
  display: grid;
  gap: var(--gap);
  font-family: var(--font-family-body);
  color: var(--light);
  box-shadow: var(--box-shadow);
}

footer h2 {
  margin-top: 0;
  margin-bottom: var(--gap);
  font-weight: 600;
}

/* 404 Page */
.page-not-found {
  grid-column: 1 / -1;
  height: 100svh;
  align-content: center;
  text-align: center;
}

.page-not-found h1 {
  margin-bottom: 30px;
}

/*
  Devices 768px and larger
*/
@media (min-width: 768px) {
  body {
    max-width: 768px;
  }

  .sidebar {
    grid-template-columns: repeat(4, 1fr);
  }

  #game-board {
    grid-template-columns: repeat(4, 1fr);
  }

  .winMessage {
    grid-column: 1 / -1;
    justify-self: center;
    align-self: center;
  }

  .winMessageText {
    font-size: 3rem;
  }

  dialog {
    margin: auto;
    width: 400px;
  }
}

/*
  Devices 1024px and larger
*/
@media (min-width: 1024px) {
  body {
    height: 100svh;
    grid-template-columns: 250px 1fr;
    grid-template-rows: auto auto 1fr auto;
    max-width: 1200px;
    grid-template-areas:
      "main-header main-header"
      "game-control game-board"
      "scores game-board"
      "main-footer main-footer"
    ;
  }

  #game-board {
    justify-self: center;
    max-width: 800px;
  }

  .sidebar {
    grid-template-columns: 1fr;
    align-content: start;
  }

  .stats-display {
    grid-column: span 1;
    flex-direction: column;
  }
}