@font-face {
  font-family: "AriW9500";
  src: url("ari-w9500-display.ttf");
  font-display: swap;
}

:root {
  --page-background: #bde0fe;
  --grid-border: #fedbbd;
  --panel-background: #000000af;
  --outline-color: purple;
  --cell-size: 50px;
  --board-columns: 24;
  --board-rows: 12;
}

html {
  min-height: 100vh;
  position: relative;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: "AriW9500", sans-serif;
  background-color: var(--page-background);
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

header,
footer {
  text-align: center;
}

section {
  display: flex;
  flex-direction: column;
}

footer {
  position: absolute;
  right: 0;
  bottom: 20px;
  left: 0;
  width: fit-content;
  margin: auto;
}

h1 {
  font-size: 40px;
}

h2 {
  font-size: 28px;
}

h3 {
  margin: 5px;
  font-size: 24px;
}

label{
  margin: 5px;
  font-size: 24px;
  display: inline-block;
}

button {
  position: relative;
  z-index: 1;
  width: 200px;
  height: 50px;
  margin-top: 20px;
  overflow: hidden;
  border: 0;
  font: 20px "AriW9500", sans-serif;
  cursor: pointer;
}

button::before,
button::after {
  content: "";
  position: absolute;
}

button::before {
  inset: -100%;
  z-index: -2;
  height: 300px;
  background: conic-gradient(from 0deg,
      #f00,
      #ff7f00,
      #ff0,
      #0f0,
      #00fffb,
      #b145ff,
      #9400d3,
      #f00);
  animation: rainbow 5s linear infinite reverse;
}

button::after {
  inset: 3px;
  z-index: -1;
  background: white;
}

@keyframes rainbow {
  to {
    transform: rotate(1turn);
  }
}

.cell {
  box-sizing: border-box;
  width: var(--cell-size);
  height: var(--cell-size);
  border: 2px solid var(--grid-border);
  background-color: #aaa;
}

#infoPlayer,
#grid {
  width: calc(var(--board-columns) * var(--cell-size));
  border: 2px solid var(--grid-border);
  outline: 5px solid var(--outline-color);
  background-color: var(--grid-border);
}

#infoPlayer {
  position: relative;
  display: flex;
  height: 300px;
  margin: 50px auto 0;
}

#score,
#lastScores,
#nextPiece {
  height: 300px;
  color: white;
  background-color: var(--panel-background);
}

#score {
  width: 600px;
}

#lastScores {
  width: 300px;
}

#scoreText {
  margin-left: 20px;
  font-size: 24px;
  text-decoration: underline;
}

#scoreRules {
  margin: 30px 0 0 20px;
  font-style: italic;
}

#nextPiece {
  position: absolute;
  right: 0;
  width: 300px;
  text-align: center;
}

#nextPieceViewport {
  position: absolute;
  right: 0;
  bottom: 5px;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 250px;
  height: 250px;
  margin: auto;
  border: 2px solid white;
}

#nextPieceImage {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

#grid {
  position: relative;
  display: grid;
  margin: 50px auto;
  grid-template-columns: repeat(var(--board-columns), var(--cell-size));
  grid-template-rows: repeat(var(--board-rows), var(--cell-size));
  height: calc(var(--board-rows) * var(--cell-size));
  overflow: hidden;
}

#activePieceBox {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  pointer-events: none;
  will-change: transform;
}

#activePiece {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  text-align: center;
  background: rgb(0 0 0 / 85%);
}

.hidden {
  display: none !important;
}

#verticalWarning {
  display: none;
}

#mobileControls {
  display: none;
}

#phoneInfos {
  display: flex;
}

@media (pointer: coarse) and (orientation: portrait) {
  h1 {
    font-size: 8dvw;
  }

  p {
    font-size: 4dvw;
  }

  #gameContainer {
    display: none;
  }

  #verticalWarning {
    position: fixed;
    inset: 0;
    z-index: 1000;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    padding: 30px;
    background: #bde0fe;
    text-align: center;
  }


}

@media (pointer: coarse) and (orientation: landscape) {
  #gameContainer {
    display: block;
    position: relative;
  }

  #verticalWarning {
    display: none;
  }

  footer,
  #scoreRules,
  header,
  h2 {
    display: none;
  }

  #infoPlayer {
    width: 300px;
    height: 600px;
    position: absolute;
    right: -320px;
    top: -50px;
  }

  #scoreText {
    font-size: 16px;
  }

  #score {
    width: 300px;
    height: 100px;
  }

  #lastScores {
    height: 200px;
    width:3000px;
    position: absolute;
    top: 100px;
    padding-left: 10px;
  }

  #nextPiece {
    position: absolute;
    top: 300px;
  }

  #grid {
    margin-top: 10px;
    margin-bottom: -300px;
    padding-bottom: 0px;
  }

  #mobileControls {
    position: fixed;
    inset: 0;
    z-index: 50;

    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    padding:
      15px max(15px, env(safe-area-inset-right)) max(15px, env(safe-area-inset-bottom)) max(15px, env(safe-area-inset-left));

    pointer-events: none;
  }

  .mobileButton {
    width: 50px;
    height: 50px;
    margin: 0;

    border: 2px solid white;
    border-radius: 15px;

    background: rgba(0, 0, 0, 0.65);
    color: white;
    font-size: 28px;

    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .mobileButton::before,
  .mobileButton::after {
    display: none;
  }

  .mobileButton:active {
    transform: scale(0.92);
    background: rgba(100, 0, 128, 0.85);
  }

  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(3, 50px);
    gap: 4px;
  }

  .dpadUp {
    grid-column: 2;
    grid-row: 1;
  }

  .dpadLeft {
    grid-column: 1;
    grid-row: 2;
  }

  .dpadRight {
    grid-column: 3;
    grid-row: 2;
  }

  .dpadDown {
    grid-column: 2;
    grid-row: 3;
  }

  .rotationControls {
    display: flex;
    gap: 20px;
  }
}

#gameViewport {
  width: 100%;
}

#gameWrapper {
  margin: 0 auto;
  overflow: hidden;
}

#gameScale {
  width: 1200px;
  transform-origin: top left;
  margin: auto;
}

#globalBestScore {
  font-weight: bold;
}