/* index.css */
* {
  box-sizing: border-box;
}

body {
  overflow: hidden;
  display: flex;
  container-type: size;
  background: #f0e6cb;
  flex-direction: column;
  gap: 1rem;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 1rem;
}

main {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  justify-content: center;
  align-items:  center;
  gap: 1rem;
}

nav {
  display: flex;
  justify-content: center;
  align-items:  center;
  gap: 2rem;
}

nav button {
  --bg: #f5f5dd;
  --fg: #897c69;
  display: inline-flex;
  color: var(--fg);
  background: var(--bg);
  cursor: pointer;
  border: none;
  border-radius: 1.5rem;
  align-items:  center;
  gap: .5rem;
  padding: 8px;
  transition: all .2s;
  font-size: 1.5rem;
  font-weight: bold;
  transform: none;
}

nav button:active {
  --bg: #0bc5b7;
  --fg: #b6fdfc;
  --shadow: #554b3380;
  outline: 8px solid #fff;
}

nav button:hover {
  --bg: #0bc5b7;
  --fg: #b6fdfc;
  --shadow: #554b3380;
  outline: 8px solid #fff;
}

nav button:active {
  box-shadow: .25rem .25rem .5rem var(--shadow);
  transform: translate(2px, 2px);
}

nav button[data-shortcut]:before {
  content: attr(data-shortcut);
  box-sizing: border-box;
  display: inline-flex;
  background: var(--fg);
  color: var(--bg);
  border-radius: 1000px;
  justify-content: center;
  align-items:  center;
  width: 2rem;
  height: 2rem;
  padding-bottom: 4px;
  font-weight: 500;
}

h1 {
  text-align: center;
  color: #0bc5b7;
  margin: 0;
}

h1.won {
  color: violet;
  text-shadow: 2px 2px teal;
}

h1.lost {
  color: red;
}

game-board {
  --bg: #a268fd;
  --tile: #fff3;
  --flipped: #f3eedb;
  --gap: 4px;
  --grid-size: 5;
  aspect-ratio: 1;
  display: flex;
  background: var(--bg);
  gap: var(--gap);
  border-radius: 16px;
  flex-direction: column;
  max-width: 300px;
  height: 40%;
  max-height: 300px;
  padding: 8px;
  transition: all .5s;
  transform: scale(1);
}

game-board.target.won {
  background: #0003;
  transform: scale(.8);
}

game-board.board.green {
  background: #60c267;
}

game-board.board.won {
  z-index: 50;
  position: absolute;
  bottom: -2rem;
  right: -2rem;
  transform: scale(.5);
}

game-row {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(var(--grid-size), 1fr);
}

game-tile {
  background: var(--tile);
  aspect-ratio: 1;
  border-radius: 8px;
  transition: all .25s;
  transform: scaleX(1);
}

game-tile.flipped {
  background: var(--flipped);
  transform: scaleX(-1);
}

.board:not(.won) game-tile {
  cursor: pointer;
}

.board:not(.won) game-tile:hover {
  outline: 4px solid #3d1e6a80;
  outline-offset: 4px;
  z-index: 10;
}

.board:not(.won) game-tile.flipped:hover {
  outline: 4px solid #ffffff80;
}

@container (aspect-ratio > 1) {
  main {
    flex-direction: row;
  }

  game-board {
    height: unset;
    width: 40%;
  }
}

@keyframes translate-in-top {
  0% {
    transform: translate(-1000px, -1000px) rotate(var(--deg));
    opacity: 0;
  }

  100% {
    transform: translate(0, 0) rotate(var(--deg));
    opacity: 1;
  }
}

@keyframes translate-in-bottom {
  0% {
    transform: translate(1000px, 1000px) rotate(var(--deg));
    opacity: 0;
  }

  100% {
    transform: translate(0, 0) rotate(var(--deg));
    opacity: 1;
  }
}

game-dialog-wrapper {
  --deg: -8deg;
  --bg: #f5f5dd;
  --fg: #897c69;
  --line1: #0bc5b7;
  --line2: #4dd4cc;
  --lines: repeating-linear-gradient(45deg, var(--line1) 0px, var(--line1) 10px, var(--line2) 10px, var(--line2) 20px);
  position: fixed;
  display: flex;
  justify-content: center;
  align-items:  center;
  width: 100vw;
  height: 100vh;
  padding: 2rem;
  top: 0;
  left: 0;
}

game-dialog-wrapper:before {
  content: "";
  position: absolute;
  background: var(--lines);
  z-index: -1;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

game-dialog-wrapper:after {
  animation: translate-in-bottom .25s forwards;
  content: "";
  position: absolute;
  z-index: -1;
  background: #f2f2da;
  width: 200%;
  height: 75%;
  top: 15%;
  left: -50%;
  transform: rotate(-4deg);
  box-shadow: 24px 24px 24px #00000040;
}

game-dialog-wrapper game-dialog {
  --bg: #fff9;
  --fg: #897c69;
  text-align: center;
  position: relative;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--fg);
  border-radius: 12rem 16rem;
  margin: 0;
  padding: 1rem 4rem;
  font-size: 2rem;
  font-weight: bold;
}

game-dialog-wrapper button {
  --deg: 0deg;
  animation: translate-in-bottom .5s forwards;
  position: absolute;
  font: inherit;
  cursor: pointer;
  color: #fff;
  white-space: nowrap;
  background: #fb8b8e;
  border: none;
  border-radius: 2rem;
  padding: 1rem 2rem;
  transition: all .2s;
  right: 0;
}

game-dialog-wrapper button:focus {
  outline: 8px solid #fb8b8e;
  outline-offset: 8px;
}

game-dialog-wrapper button:hover {
  outline: 8px solid #fb8b8e;
  outline-offset: 8px;
}

game-dialog-wrapper button:hover {
  background: #eb6b6e;
}

game-dialog-wrapper button:active {
  transform: translate(2px, 2px);
}

game-dialog-wrapper dialog-label {
  --deg: -4deg;
  animation: translate-in-top .5s forwards;
  position: absolute;
  background: var(--bg);
  color: #0bc5b7;
  border-radius: 1000px;
  padding: 1rem;
  font-size: 2rem;
  top: -3rem;
  left: -2rem;
  transform: rotate(-12deg);
}

@container (width < 600px) {
  nav {
    justify-content: space-between;
  }

  nav button {
    display: none;
  }

  nav button[data-shortcut="u"], nav button[data-shortcut="n"] {
    display: inline-flex;
  }

  game-dialog-wrapper game-dialog {
    padding: 0 2rem;
  }
}
