/* Battleship Styles */

:root {
  --cell-size: 36px;
  --grid-gap: 2px;
  --water: #0d1b2a;
  --water-alt: #1b2838;
  --ship-color: #4a90d9;
  --hit: #e94560;
  --miss: #7f8c9b;
  --sink: #c0392b;
  --bg-game: #0f0f1a;
  --bg-card: #1a1a2e;
  --border: #2a2a4a;
  --text: #eee;
  --text-dim: #a0a0b8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-game);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-header {
  width: 100%;
  background: var(--bg-card);
  border-bottom: 2px solid var(--hit);
  padding: 16px 20px;
}

.game-header .container {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-header h1 { font-size: 1.4rem; }
.game-header .back-link { color: var(--text-dim); text-decoration: none; font-size: 0.9rem; }
.game-header .back-link:hover { color: var(--hit); }

.game-container {
  max-width: 800px;
  width: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Mode selector */
.mode-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  width: 100%;
}

.mode-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn:hover { border-color: #4ecca3; color: #4ecca3; }
.mode-btn.active { border-color: var(--hit); background: rgba(233,69,96,0.1); color: var(--hit); }

/* Status */
.status {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding: 10px 24px;
  border-radius: 10px;
  background: var(--bg-card);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* Setup Phase */
.setup-phase {
  width: 100%;
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.setup-info {
  flex: 0 0 200px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ship-pool-label { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }

.ship-pool {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ship-in-pool {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  opacity: 1;
  transition: all 0.3s;
}

.ship-in-pool.placed { opacity: 0.3; text-decoration: line-through; }

.ship-in-pool .ship-blocks { display: flex; gap: 3px; }
.ship-in-pool .ship-blocks span {
  width: 14px; height: 14px; border-radius: 3px;
  background: var(--ship-color);
}

.setup-controls { display: flex; flex-direction: column; gap: 8px; }

.board-wrapper { flex: 1; }

.board-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-align: center;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Board Grid */
.board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size));
  gap: var(--grid-gap);
  background: var(--border);
  padding: var(--grid-gap);
  border-radius: 8px;
  margin: 0 auto;
  width: fit-content;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--water);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.cell:hover:not(.ship):not(.hit):not(.miss):not(.sunk) {
  background: var(--water-alt);
}

/* Ship cells (on player board) */
.cell.ship { background: var(--ship-color); }

/* Hover placement ghost */
.cell.valid-ghost { background: rgba(74,144,217,0.4); }
.cell.invalid-ghost { background: rgba(233,69,96,0.3); }

/* Shot markers */
.cell.hit {
  background: var(--hit);
  animation: hitPulse 0.4s ease;
}
.cell.hit::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: white;
}

.cell.miss {
  background: transparent;
}
.cell.miss::after {
  content: '•';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--miss);
}

.cell.sunk {
  background: var(--sink);
  animation: sinkFlash 0.5s ease;
}
.cell.sunk::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: white;
}

/* Battle Phase */
.battle-phase {
  width: 100%;
}

.boards-container {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.board-section { text-align: center; }

/* Enemy board hover only on unknown cells */
.cell.enemy:not(.hit):not(.miss):not(.sunk):hover {
  background: var(--water-alt);
  box-shadow: inset 0 0 8px rgba(233,69,96,0.3);
}

/* Scoreboard */
.scoreboard {
  display: flex;
  gap: 16px;
  margin: 16px 0;
  width: 100%;
}

.score-item {
  flex: 1;
  text-align: center;
  padding: 10px;
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.score-item .label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 4px; }
.score-item .value { font-size: 1.4rem; font-weight: 700; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-icon { font-size: 3rem; margin-bottom: 12px; }
.modal-title { font-size: 1.5rem; margin-bottom: 8px; }
.modal-text { color: var(--text-dim); margin-bottom: 20px; }

/* Buttons */
.btn {
  padding: 10px 20px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.btn-primary { background: var(--hit); color: white; border-color: var(--hit); }
.btn-primary:hover { background: #ff6b81; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-secondary { background: transparent; color: var(--text-dim); }
.btn-secondary:hover { border-color: var(--hit); color: var(--hit); }

/* Instructions */
.instructions {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  line-height: 1.7;
}
.instruction-step { color: var(--text-dim); }
.instruction-step strong { color: var(--text); }

/* Board row: status left, grid right */
.board-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: flex-start;
}

/* Ship status panel — sidebar */
.ship-status {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 110px;
  max-width: 130px;
  padding-top: 2px;
}

.ship-status-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 0.65rem;
  line-height: 1.3;
  transition: all 0.3s;
  white-space: nowrap;
}

.ship-status-item.sunk {
  opacity: 0.5;
  text-decoration: line-through;
  border-color: var(--sink, #c0392b);
}

.ship-status-item .ship-name {
  flex: 1;
  color: var(--text);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ship-status-item .ship-cells {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.ship-status-item .ship-cells span {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--water);
  border: 1px solid var(--border);
}

.ship-status-item .ship-cells span.intact { background: var(--ship-color, #4a90d9); }
.ship-status-item .ship-cells span.hit { background: var(--hit, #e94560); }
.ship-status-item .ship-cells span.sunk { background: var(--sink, #c0392b); }
.ship-status-item .ship-cells span.unknown { background: transparent; border-color: transparent; }

/* Utility */
.hidden { display: none !important; }

/* Footer */
.game-footer { text-align: center; padding: 20px; color: #555; font-size: 0.8rem; width: 100%; }

/* Animations */
@keyframes hitPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes sinkFlash {
  0% { background: var(--hit); }
  50% { background: var(--sink); transform: scale(1.1); }
  100% { background: var(--sink); }
}

/* Responsive */
@media (max-width: 700px) {
  :root { --cell-size: 30px; }
  .setup-phase { flex-direction: column; }
  .setup-info { flex: none; width: 100%; flex-direction: row; flex-wrap: wrap; }
  .ship-pool { flex-direction: row; flex-wrap: wrap; }
  .boards-container { flex-direction: column; align-items: center; }
}
@media (max-width: 420px) {
  :root { --cell-size: 26px; }
}
