/* ── CSS Custom Properties ─────────────────────────────────── */
:root {
  --grid-columns: 26;
  --cell-size: 20px;
  --cell-gap: 1px;
  /* As colunas usam 1fr, então a célula renderizada = 598 / 26 ≈ 23px, não 20px.
     --cell-size só define a altura das células (height); a largura vem do 1fr.
     O valor 23 também é hardcoded em CELL_PX no script.js para posicionar sprites. */
  --grid-width: 598px;       /* 26 colunas × 23px ≈ 598px (ver CELL_PX em script.js) */
  --header-width: 598px;
  --header-height: 150px;
  --modal-max-width: 400px;
  --color-sea: rgb(213, 243, 253);
  --color-border: #333;
  --color-modal-bg: rgba(0, 0, 0, 0.5);
  --color-close-btn: #aaa;
}

/* ── Layout ────────────────────────────────────────────────── */
.container {
  margin-top: 10px;
  width: 100vw;
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* ── Header ────────────────────────────────────────────────── */
.header {
  width: var(--header-width);
  height: var(--header-height);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-column-gap: 0px;
  grid-row-gap: 0px;
}

.header button#startGame {
  grid-area: 2 / 2 / 3 / 4;
  justify-self: stretch;
}

.header input#gameCode {
  grid-area: 2 / 4 / 3 / 6;
  width: 145px;
  justify-self: stretch;
  margin-top: 10px;
  font-size: 1.6em;
  text-transform: uppercase;
  border: 1px solid #dedede;
  background-color: beige;
}

.header button#info {
  justify-self: end;
  grid-area: 1 / 5 / 2 / 7;
  margin-right: 5px;
}

.header div#box {
  grid-area: 2 / 2 / 3 / 6;
}

#buy-me-a-coffee {
  grid-area: 1 / 1 / 2 / 3;
}

.header div#box p {
  padding: 0;
  margin: 0;
  text-align: center;
}

.header #fleet-me {
  grid-area: 3 / 1 / 4 / 3;
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: start;
}

.header #fleet-enemy {
  grid-area: 3 / 5 / 4 / 7;
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: end;
}

.header #fleet-me span,
.header #fleet-enemy span {
  font-size: 0.85em;
  white-space: nowrap;
}

.header #fleet-me .fleet-count,
.header #fleet-enemy .fleet-count {
  font-size: 1.4em;
  font-weight: bold;
  line-height: 1;
}

.header #board-label {
  grid-area: 3 / 3 / 4 / 5;
  display: flex;
  flex-direction: column;
  justify-content: end;
  align-items: center;
}

.header #board-label > span:first-child {
  font-size: 1.6em;
  text-transform: capitalize;
}

/* ── Turn timer ────────────────────────────────────────────── */
#turn-timer {
  font-size: 1.05em;
  font-variant-numeric: tabular-nums;
  color: #555;
  min-height: 1.2em;
  line-height: 1;
}

#turn-timer.timer-urgent {
  color: #c0392b;
  font-weight: bold;
}

/* ── Connection indicator ──────────────────────────────────── */
#conn-indicator {
  grid-area: 1 / 3 / 2 / 5;
  align-self: center;
  justify-self: center;
  font-size: 0.72em;
  padding: 2px 7px;
  border-radius: 3px;
  white-space: nowrap;
}

#conn-indicator.conn-p2p {
  color: #27ae60;
  background: #eafaf1;
  border: 1px solid #a9dfbf;
}

#conn-indicator.conn-relay {
  color: #e67e22;
  background: #fef9e7;
  border: 1px solid #f9e4b7;
}

/* ── Grid ──────────────────────────────────────────────────── */
.grid {
  position: relative;
  padding: var(--cell-gap);
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), 1fr);
  grid-gap: var(--cell-gap);
  border: 1px solid var(--color-border);
  width: var(--grid-width);
  animation: board-in 0.25s ease;
}

.board-hidden {
  display: none;
}

@keyframes board-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#ocean-grid {
  cursor: pointer;
}

.grid div {
  background-color: var(--color-sea);
  border: 1px solid var(--color-border);
  height: var(--cell-size);
  width: var(--cell-size);
}

/* ── Estados de célula ─────────────────────────────────────── */
.explosion {
  z-index: 999;
  background-image: url('../img/explosion.png');
}

.water {
  z-index: 999;
  background-image: url('../img/water.png');
}

/* ── Botões ────────────────────────────────────────────────── */
button {
  margin-top: 10px;
  padding: 5px 10px;
  font-size: 16px;
}

/* ── Sprites horizontais ───────────────────────────────────── */
/* Posições são coordenadas fixas de spritesheet e não usam variáveis */
.sprite-h {
  background-image: url('../img/battleships-h.png');
}

.sprite-h.cruzader-h {
  background-position: -32px 3px;
}

.sprite-h.aircraft-h {
  background-position: -8px -47px;
}

.sprite-h.frigate-h {
  background-position: -28px -114px;
}

.sprite-h.submarine-h {
  background-position: -175px -74px;
}

/* ── Sprites verticais ─────────────────────────────────────── */
.sprite-v {
  background-image: url('../img/battleships-v.png');
}

.sprite-v.cruzader-v {
  background-position: 4px 190px;
}

.sprite-v.aircraft-v {
  background-position: -48px 170px;
}

.sprite-v.frigate-v {
  background-position: -113px 189px;
}

.sprite-v.submarine-v {
  background-position: -74px 310px;
}

/* ── Chat ──────────────────────────────────────────────────── */
#chat-panel {
  flex-direction: column;
  width: 200px;
  align-self: stretch;
  border: 1px solid var(--color-border);
  background: #fff;
  font-size: 0.82em;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg {
  max-width: 90%;
  padding: 4px 7px;
  border-radius: 8px;
  word-break: break-word;
  line-height: 1.3;
}

.msg-me {
  align-self: flex-end;
  background: #d1f0d1;
  text-align: right;
}

.msg-opp {
  align-self: flex-start;
  background: #e8e8e8;
}

#chat-input-row {
  display: flex;
  border-top: 1px solid var(--color-border);
}

#chat-input {
  flex: 1;
  padding: 5px;
  border: none;
  outline: none;
  font-size: 0.95em;
  min-width: 0;
}

#chat-send {
  margin: 0;
  padding: 5px 8px;
  font-size: 0.85em;
  border: none;
  border-left: 1px solid var(--color-border);
  background: var(--color-sea);
  cursor: pointer;
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: var(--color-modal-bg);
}

.modal-content {
  background-color: #fefefe;
  margin: 15% auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
  max-width: var(--modal-max-width);
  text-align: center;
}

.close {
  color: var(--color-close-btn);
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}
