* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background-color: rgb(15, 35, 55);
  background-image: linear-gradient(to bottom, rgb(10, 20, 35), rgb(32, 77, 104));
}

h1 {
  color: rgb(50, 213, 228);
  letter-spacing: 30px;
  width: 100%;
  text-shadow: 0 0 10px rgba(41, 168, 180, 0.5);
  margin-bottom: 15px;
}

h2 {
  color: aquamarine;
}

h3 {
  color:aliceblue;
}

.gamearena {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto;
  width: 90%;
  max-width: 900px;
}

.gridcontainer {
  justify-content: center;
}

.grid {
  display: grid;
  gap: 1px;
  width: fit-content;
  height: fit-content;
  grid-template-columns: repeat(10,30px); 
  grid-template-rows: repeat(10,30px);
  border-radius: 8px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
  border: 2px solid rgb(31, 38, 95);
  margin: 0 auto;
}

.cell {
  width: 30px; 
  height: 30px; 
  border: 1px solid rgba(255, 255, 255, 0.2); 
  background-color: rgba(173, 216, 230, 0.7); 
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.cell.preview {
  background: lightblue;
}

.cell.preview.valid {
  background-color: aquamarine
}

.cell.preview.invalid {
  background-color: rgb(227, 32, 32);
}

.cell.ship {
  background-color: gray;
}

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 5px 2px rgba(159, 51, 4, 0.6);
  }
  50% {
    box-shadow: 0 0 8px 4px rgba(181, 19, 7, 0.8);
  }
}

.cell.hit {
  background-color: rgb(203, 42, 5);
  position: relative;
  overflow: visible;
  box-shadow: 0 0 8px 2px rgba(255, 100, 0, 0.7);
  animation: glow 1.5s infinite ease-in-out;
} 

.cell.hit::after {
  content: "x";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 16px;
  font-weight: bold;
  color: white;
}

@keyframes ripple {
  0% {
    width: 0px;
    height: 0px;
    opacity: 1;
  }
  100% {
    width: 25px;
    height: 25px;
    opacity: 0;
  }
}

.cell.miss {
  position: relative;
  overflow: hidden;
}

.cell.miss::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background-color: white;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: ripple 1.5s ease-in-out;
}

@keyframes sink {
  0% { 
    transform: rotate(0deg);
    opacity: 1;
  }
  20% { 
    transform: rotate(5deg);
    opacity: 0.9;
  }
  40% { 
    transform: rotate(-8deg);
    opacity: 0.8;
  }
  60% { 
    transform: rotate(8deg);
    opacity: 0.6;
  }
  80% { 
    transform: rotate(-5deg);
    opacity: 0.4;
  }
  100% { 
    transform: rotate(0deg);
    opacity: 0.2;
  }
}

.cell.sunk {
  background-color: darkred;
  position: relative;
  animation: sink 2s ease-in-out forwards;
}

.cell.sunk::after {
  content: "✗";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  font-weight: bold;
  color: white;
}

.cell:hover {
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
  z-index: 2;
  transition: all 0.15s ease-out;
  opacity: 100%;
}

#play-again {
  visibility: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 15px;
  width: fit-content;
  margin: 0 auto;
  cursor: pointer;
}

#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
  padding: 10px;
  gap: 15px;
}

#ship-placement {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  padding: 10px;
  gap: 10px;
  margin: 0 auto;
}

#controls :hover {
  cursor: pointer;
}

button {
  background: linear-gradient(to bottom, rgb(42, 125, 162), rgb(29, 85, 112));
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.2s ease;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2);
  margin: 5px;
}

button:hover {
  background: linear-gradient(to bottom, rgb(53, 144, 185), rgb(35, 96, 133));
  transform: translateY(-2px);
  box-shadow: 0 5px 8px rgba(0, 0, 0, 0.3);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
}

button.selected {
  background: linear-gradient(to bottom, rgb(60, 165, 92), rgb(40, 145, 66));
  box-shadow: 0 0 10px rgba(60, 165, 92, 0.5);
}

button:disabled {
  background: linear-gradient(to bottom, rgb(106, 122, 132), rgb(77, 90, 100));
  color: rgb(160, 160, 160);
  cursor: not-allowed;
  opacity: 0.7;
  transform: none;
  box-shadow: none;
}

button:disabled:hover {
  background: linear-gradient(to bottom, rgb(106, 122, 132), rgb(77, 90, 100));
  transform: none;
  box-shadow: none;
}

@media (max-height: 500px) and (orientation: landscape) {
  body {
    height: auto;
    min-height: 100vh;
  }
  
  .gamearena {
    margin: 10px auto;
  }
  
  h1 {
    margin-top: 5px;
    margin-bottom: 5px;
    font-size: 1.2rem;
  }
  
  h2, h3 {
    margin: 5px 0;
    font-size: 1rem;
  }
}

.instructions-link {
  color: rgb(41, 168, 180);
  text-decoration: none;
  margin-top: 10px;
  display: inline-block;
  border: 1px solid rgb(41, 168, 180, 0.5);
  padding: 5px 10px;
  border-radius: 5px;
  transition: background-color 0.2s, color 0.2s;
}

.instructions-link:hover {
  background-color: rgba(41, 168, 180, 0.2);
  color: white;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-in-out;
}

.modal-overlay:target {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: rgb(15, 35, 55);
  background-image: linear-gradient(to bottom, rgb(10, 20, 35), rgb(32, 77, 104));
  padding: 30px 40px;
  border-radius: 10px;
  max-width: 600px;
  width: 90%;
  position: relative;
  color: rgb(180, 210, 220);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-align: left;
  line-height: 1.6;
}

.modal-content h3 {
  margin-top: 0;
  color: aliceblue;
  text-align: center;
}

.modal-content ol {
  padding-left: 25px;
}

.modal-close-button {
  position: absolute;
  top: 10px;
  right: 15px;
  color: rgb(170, 170, 170);
  font-size: 28px;
  font-weight: bold;
  text-decoration: none;
  line-height: 1;
}

.modal-close-button:hover,
.modal-close-button:focus {
  color: white;
  cursor: pointer;
}