:root {
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #16202a;
  --muted: #5b6b7a;
  --border: #d7dee6;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;

  --water: #cfe8fb;
  --water-deep: #8fc7ee;
  --hit: #ef4444;
  --miss: #94a3b8;
  --sunk: #7f1d1d;
  --hover: #fde68a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --card-bg: #17212c;
    --text: #e7edf3;
    --muted: #93a4b3;
    --border: #263542;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;

    --water: #12314a;
    --water-deep: #0d2438;
    --hit: #f87171;
    --miss: #64748b;
    --sunk: #fca5a5;
    --hover: #fbbf24;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.user-tag {
  background: var(--primary);
  color: white;
  padding: .25rem .75rem;
  border-radius: 999px;
  font-size: .85rem;
}

main#app { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
.screen.hidden { display: none; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card.center { text-align: center; }
h2 { margin-top: 0; }
h3 { margin: 0 0 .5rem; }
.muted { color: var(--muted); font-size: .9rem; }
.hidden { display: none !important; }

input[type=text] {
  padding: .6rem .8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  width: 100%;
  max-width: 260px;
  margin-right: .5rem;
}

button {
  padding: .6rem 1.1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  font-size: .95rem;
}
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
button.primary:hover { background: var(--primary-hover); }
button.danger { border-color: var(--hit); color: var(--hit); }
button.danger:hover { background: var(--hit); color: white; }
button:disabled { opacity: .5; cursor: not-allowed; }

.lobby-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.lobby-list { list-style: none; padding: 0; margin: 1rem 0; display: flex; flex-direction: column; gap: .5rem; }
.lobby-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--border); }

.placement-actions { display: flex; gap: .75rem; margin-top: 1rem; }

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, 32px);
  grid-template-rows: repeat(10, 32px);
  gap: 2px;
  background: var(--water-deep);
  padding: 4px;
  border-radius: 8px;
  width: max-content;
  touch-action: none;
}
.cell {
  width: 32px; height: 32px;
  background: var(--water);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  z-index: 2;
  font-size: .85rem;
  font-weight: bold;
  color: white;
}
.cell.ship { background: transparent; }
.cell.miss::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--miss);
}
.cell.hit { background: var(--hit); }
.cell.hit::after { content: "✕"; }
.cell.sunk { background: var(--sunk); }
.cell.sunk::after { content: "☠"; }

.board.my-turn .cell:not(.hit):not(.miss):hover {
  background: var(--hover);
  cursor: crosshair;
}

/* Casco del barco: imagen dibujada por encima del agua y por debajo de las
   marcas de impacto/fallo, para que el daño se vea sobre el barco. */
.ship-hull {
  position: absolute;
  z-index: 1;
  pointer-events: none;
}
.ship-hull-img {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .4));
}

.boards-layout { display: flex; gap: 2rem; flex-wrap: wrap; }

.game-status { display: flex; flex-direction: column; gap: .6rem; }
.game-status-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }

.turn-indicator {
  font-weight: 600;
  font-size: 1rem;
  text-align: center;
  border-radius: 8px;
  padding: 0;
  transition: padding .2s ease, font-size .2s ease, background-color .2s ease, color .2s ease;
}
.turn-indicator.active {
  font-size: 1.5rem;
  font-weight: 800;
  color: white;
  background: var(--primary);
  padding: .6rem;
  animation: turn-pulse 1.4s ease-in-out infinite;
}
@keyframes turn-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}
@media (prefers-reduced-motion: reduce) {
  .turn-indicator.active { animation: none; }
}
