@import url("https://fonts.googleapis.com/css2?family=Heebo:wght@100;200;300;400;500;600;700;800;900&family=IBM+Plex+Mono:wght@100;200;300;400;500;600;700&family=Inconsolata:wght@200;300;400;500;600;700;800;900&display=swap");

@font-face {
  font-family: "DejaVu Sans Mono Bold";
  src: url("./ui/fonts/DejaVuSansMono-Bold.ttf") format("truetype");
  font-weight: bold;
  font-style: bold;
}

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

::selection {
  background-color: hsla(95.8, 98.3%, 22.7%, 0.6);
  color: white;
}

:root {
  --accent: hsl(115, 100%, 45%);
  --secondaryAccent: hsl(87, 100%, 51%);
}

* {
  margin: 0;
  padding: 0;
  font: inherit;
}

img,
picture,
svg,
video {
  display: block;
  max-width: 100%;
}

html {
  height: 100%;
  font-size: 10px;
}

body {
  min-height: 100%;
  background-color: hsl(105, 5%, 4%);
  background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.6)), url("./ui/images/tactical-bg.svg");
  background-size: 500px;
  background-repeat: repeat;
  background-attachment: fixed;
  font-family: Heebo, sans-serif;
  font-size: 1.4rem;
  line-height: 1.35;
  color: white;
}

h1,
h2 {
  line-height: 1;
}

h1 {
  color: white;
  font-size: 5rem;
  font-weight: 800;
}

h2 {
  font-size: 1.8rem;
  font-weight: bold;
  margin-bottom: 20px;
}

p+* {
  margin-top: 15px;
}

li+li {
  margin-top: 10px;
}

a {
  text-decoration: none;
  color: var(--accent);
  transition: 0.2s color ease;
}

a:hover {
  color: hsl(0, 100%, 82%);
}




/* ----- Buttons ----- */
button {
  position: relative;
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.6rem;
  transition: 0.2s all ease;
}

button:disabled {
  opacity: 0.5;
  cursor: auto;
}

.btn-primary,
.btn-secondary-dark {
  font-weight: bold;
  padding: 15px 30px;
}

.btn-primary {
  border: 3px solid var(--accent);
  box-shadow: -4px 5px var(--accent);
  color: var(--accent);
  background: none;
  padding: 15px 30px;
}

.btn-secondary-dark {
  border: 3px solid white;
  box-shadow: -4px 5px white;
  color: white;
  background: none;
  padding: 15px 30px;
}

.btn-start {
  padding: 20px 40px;
  animation-delay: 0.7s;
}

@media (hover: hover) {
  .btn-primary:hover {
    background-color: var(--accent);
    color: black;
  }

  .btn-secondary-dark:hover {
    background-color: white;
    color: black;
  }
}




.battleship-logo {
  font-family: "DejaVu Sans Mono Bold", monospace;
  font-size: 0.8rem;
  font-weight: inherit;
  color: var(--accent);
}

/* ----- Placement screen ----- */
.game_logo {
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  padding-top: 30px;
}

.game_placement {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  column-gap: 75px;
  row-gap: 25px;
  padding: 30px 0;
}

.placement_instructions {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.instructions_about {
  padding: 15px;
  border: 1px solid hsl(0, 0%, 31%);
  background-color: hsl(120, 4%, 5%);
  text-align: center;
}

/* Board section */
.placement_board {
  margin: auto;
}

/* Ships section */
.ships_actions {
  display: flex;
  gap: 20px;
  margin-bottom: 40px;
}

.ships_actions>button {
  flex-grow: 1;
}

.ships_available {
  min-height: 400px;
  display: flex;
  gap: 15px;
  flex-direction: column;
  align-items: flex-start;
}

.ships_available .ship {
  position: relative;
  top: 0%;
  left: 0%;
}

.ships_available.vertical {
  flex-direction: row;
}

.placement_start {
  display: flex;
  justify-content: center;
  grid-column: 2 / 3;
}




/* ----- Game screen ----- */
.game {
  display: flex;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  padding-top: 50px;
  padding-bottom: 50px;
}

.game_header {
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 30px;
  text-align: center;
}

.game_status {
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.8rem;
  font-weight: bold;
  text-align: center;
  margin-bottom: 50px;
  padding: 20px;
  border: 1px solid var(--accent);
  background-color: hsla(120, 50%, 17%, 0.18);
}

#turnStatus {
  display: inline-block;
}

.game_boards {
  display: grid;
  gap: 130px;
  justify-content: space-between;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  margin-top: 50px;
}

.game_boards .board,
.game_boards .board-enemy {
  margin-top: 45px;
}




/* ----- Boards ----- */
.board,
.board-enemy {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  border: 2px solid var(--accent);
  aspect-ratio: 1 / 1;
  flex-grow: 1;
  counter-reset: numberCoords letterCoords;
}

.board {
  background-color: hsla(120, 43.8%, 6.3%, 0.25);
}

.board-enemy {
  background: none;
  border: 2px solid hsl(0, 0%, 100%);
}

.placement_board .board_box,
.placement_board .ship>div {
  width: 40px;
  height: 40px;
}

.board_box,
.ship>div {
  width: 42px;
  height: 42px;
}

.board_box {
  position: relative;
  display: grid;
  align-items: center;
  justify-items: center;
  border: 1px solid hsl(116, 71.4%, 8%);
  text-align: center;
  font-size: 0.8rem;
  transition: 0.25s background-color, 0.25s border ease;
  -webkit-user-select: none;
  /* Safari */
  -moz-user-select: none;
  /* Firefox */
  -ms-user-select: none;
  /* IE10+/Edge */
  user-select: none;
  /* Standard */
}

.board_box::before,
.board_box::after {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  font-size: 1.4rem;
  font-family: Heebo, sans-serif;
  color: white;
}

.board_box:nth-last-of-type(10n)::after {
  content: counter(numberCoords);
  top: 0%;
  transform: translateX(-100%);
  counter-increment: numberCoords;
}

.board_box:nth-child(-n+10)::before {
  content: counter(letterCoords, upper-alpha);
  transform: translateY(-100%);
  counter-increment: letterCoords;
}

.board-enemy>.board_box {
  border: 1px solid hsla(0, 0%, 13%, 0.85);
}

.board-enemy>.board_box:not(.not-available):hover {
  cursor: pointer;
  background-color: hsla(0, 0%, 58.4%, 0.4);
  border: 1px solid white;
}

.board-enemy>.board_box.hit:hover,
.board-enemy>.board_box.not-available:hover {
  background-color: none;
}

.board_box.hit {
  color: red;
  font-weight: 400;
  line-height: 1;
  font-size: 2.5rem;
  font-family: "IBM Plex Mono", monospace;
  position: relative;
  z-index: 2;
  color: var(--secondaryAccent);
  border-color: hsl(119, 100%, 16%);
  background-color: hsl(119, 100%, 16%);
}

.board_box-marker {
  font-weight: 500;
}

.board_box.loading .board_box-marker {
  position: relative;
  width: 18px;
  height: 18px;
}

.board_box.loading .board_box-marker::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--secondaryAccent);
  animation: spin 0.8s linear infinite;
}

.not-playing {
  opacity: 0.6;
  pointer-events: none;
}

.ship-cell {
  background-color: hsla(0, 0%, 88.2%, 0.08);
}

.board_col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.board_title {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1rem;
  color: white;
}

.board_my,
.board_enemy {
  display: flex;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.lobby_container {
  width: min(820px, 95vw);
}

.lobby_card {
  background-color: hsla(0, 0%, 0%, 0.85);
  border: 2px solid white;
  box-shadow: -4px 5px white;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: white;
}

.lobby_meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.05rem;
}

.lobby_k {
  opacity: 0.85;
}

.lobby_v {
  word-break: break-all;
}

.lobby_label {
  font-family: Heebo, sans-serif;
  font-weight: 600;
}

.lobby_input {
  padding: 10px 12px;
  border: 1px solid hsla(0, 0%, 100%, 0.35);
  background: hsla(0, 0%, 0%, 0.2);
  color: white;
  font-family: "IBM Plex Mono", monospace;
}

.lobby_actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.lobby_join {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lobby_btn {
  width: fit-content;
}

.lobby_error {
  min-height: 18px;
  color: var(--secondaryAccent);
  font-family: "IBM Plex Mono", monospace;
  font-size: 1rem;
}

.lobby_section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lobby_players {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  font-size: 1.15rem;
  line-height: 1.5;
}

#roomStatus {
  font-size: 1.25rem;
  line-height: 1.6;
}

.lobby_bar {
  width: 100%;
  margin-bottom: 16px;
  grid-column: 1 / -1;
}

/* Ships */
.ship {
  display: grid;
  grid-auto-flow: column;
  outline: 2px solid white;
  z-index: 1;
  position: absolute;
  top: -1px;
  left: -1px;
  background-color: hsla(0, 0%, 88.2%, 0.1);
  transition: background 0.15s ease;
}

.ship.sunk {
  outline-color: var(--secondaryAccent);
  background: none;
}

.ship.vertical {
  grid-auto-flow: row;
}

/* Dragging classes */
.draggable {
  cursor: move;
}

.dragging {
  opacity: 0.5;
}

.ship.draggable:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.board_box>.draggable.dragging {
  visibility: hidden;
  opacity: 0;
  z-index: 0;
  transition: 0.01s;
}

.board_box.selected {
  background-color: hsla(118, 100%, 50%, 0.65);
}

.ship.invalid-move {
  outline: 2px solid red;
  background-color: hsla(0, 100%, 50%, 0.1);
}

.ship.invalid-move:hover {
  background-color: hsla(0, 100%, 50%, 0.1);
  transition: 0s ease;
}




/* ----- Win modal ----- */
.game_win-modal {
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

.game_win-modal.active {
  opacity: 1;
  pointer-events: all;
}

.win_msg {
  position: fixed;
  top: calc(50% - 30px);
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 575px;
  padding: 80px 80px 100px;
  text-align: center;
  border-bottom: 10px solid var(--accent);
  border-radius: 10px;
  background-color: hsl(220, 16.7%, 7.1%);
  box-shadow: 0px 8px 6.6px rgba(0, 0, 0, 0.041), 0px 23.7px 24.9px rgba(0, 0, 0, 0.055), 0px 52.9px 61.9px rgba(0, 0, 0, 0.062), 0px 107.1px 91.1px rgba(0, 0, 0, 0.067), 0px 181px 105px rgba(0, 0, 0, 0.07);
  transition: top 0.4s, opacity 0.4s ease;
  opacity: 0;
}

.win_msg.active {
  top: 50%;
  opacity: 1;
}

.win_msg-title {
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 20px;
}

.win_msg>p {
  font-size: 1.6rem;
  font-weight: 500;
  margin-bottom: 30px;
}

.win_msg-img {
  position: absolute;
  left: 0;
  bottom: 0;
  max-width: 500px;
  transform: translateX(-40%) translateY(30%);
  pointer-events: none;
}




/* ----- Utilities ----- */
.body-flex {
  display: flex;
  flex-direction: column;
}

.margin-auto-y {
  margin-top: auto;
  margin-bottom: auto;
}

.margin-auto-x {
  margin-left: auto;
  margin-right: auto;
}

.content-margin {
  margin-right: auto;
  margin-left: auto;
  max-width: 1400px;
  padding-left: 25px;
  padding-right: 25px;
}

.dark-overlay {
  top: 0;
  left: 0;
  position: fixed;
  width: 100%;
  min-height: 100vh;
  height: 100vh;
  background-color: hsla(103, 26%, 5%, 0.8);
}

.accent-color {
  color: var(--accent);
}

.txt-600 {
  font-weight: 600;
}




/* Queries */
@media screen and (max-width: 1300px) {
  .game {
    padding-top: 50px;
  }

  .game_status {
    font-size: 1.4rem;
    margin-bottom: 10px;
    padding: 15px;
  }

  .game_placement {
    column-gap: 60px;
  }

  .battleship-logo {
    font-size: 0.6rem;
  }

  .placement_board .board_box,
  .placement_board .ship>div,
  .board_box,
  .ship>div {
    width: 35px;
    height: 35px;
  }

  .board_box.hit {
    font-size: 1.8rem;
  }

  .board_box::before,
  .board_box::after {
    font-size: 1.2rem;
  }

  .win_msg {
    max-width: 525px;
    padding: 80px;
  }

  .win_msg-title {
    font-size: 3rem;
  }

  .win_msg-img {
    max-width: 400px;
    transform: translateX(-40%) translateY(35%);
  }

  .win_msg>p {
    margin-bottom: 20px;
  }
}

@media screen and (max-width: 1140px) {
  h2 {
    font-size: 1.6rem;
  }

  .game_placement {
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 1fr 1fr;
    padding-top: 50px;
    gap: 30px;
  }

  .placement_instructions {
    grid-column: 1 / 3;
    max-width: 90ch;
    margin: auto;
    margin-top: 25px;
    order: 4;
  }

  .placement_start {
    grid-column: 1 / 3;
  }

  .ships_actions {
    max-width: 400px;
  }

  .ships_available {
    min-height: auto;
    flex-direction: row;
    flex-wrap: wrap;
  }
}

@media screen and (max-width: 960px) {
  button {
    font-size: 1.4rem;
  }

  .game {
    padding-top: 30px;
    padding-bottom: 30px;
  }

  .game_boards {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 70px;
  }

  .placement_board .board_box,
  .placement_board .ship>div,
  .board_box,
  .ship>div {
    width: 30px;
    height: 30px;
  }
}


@media screen and (max-width: 768px) {
  h2 {
    font-size: 1.4rem;
  }
}

/* ----- Interactions ----- */
.explosion {
  position: fixed;
  width: 40px;
  height: 40px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 999;
  animation: explode 0.4s ease-out forwards;
  pointer-events: none;
}

@keyframes explode {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 1;
  }

  100% {
    transform: translate(-50%, -50%) scale(2.5);
    opacity: 0;
  }
}
