/* Battleship — tokens from /assets/base.css */

:root {
  --cell: 38px;
  --gap: 2px;
  --water: rgba(30, 60, 120, 0.25);
  --water-hover: rgba(60, 100, 180, 0.4);
  --ship-fill: rgba(138, 124, 255, 0.35);
  --ship-border: var(--accent);
  --hit: #ff5d7a;
  --miss: rgba(255, 255, 255, 0.15);
  --sunk: #ff3a5c;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app {
  width: 100%;
  max-width: 640px;
  padding: 0 16px;
}

/* Header */
.top {
  text-align: center;
  padding: 28px 0 4px;
}
.top h1 {
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Screens */
.screen { margin-bottom: 24px; }
.hidden { display: none !important; }

/* Mode select */
.mode-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 0;
}
.mode-sub {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 15px;
}
.mode-buttons {
  display: flex;
  gap: 14px;
}
.mode-btn {
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-md);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn.primary:hover { opacity: 0.9; }
.btn.primary:disabled { opacity: 0.4; pointer-events: none; }
.btn.ghost {
  background: transparent;
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--surface-hover); }

/* AI / local options */
.ai-options {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 24px;
  animation: result-pop 0.3s ease-out;
}
.option-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.option-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.option-pills { display: flex; gap: 6px; }
.btn.pill {
  padding: 6px 16px;
  font-size: 13px;
  border-radius: var(--radius-pill);
}
.btn.pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.option-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.option-check input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
}
.option-hint {
  font-size: 12px;
  color: var(--muted);
}

/* Phase labels */
.phase-label {
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 2px;
}
.place-hint, .battle-sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.shot-label {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  margin-top: -10px;
}

/* Ship picker */
.ship-picker {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.ship-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ship-chip:hover { background: var(--surface-hover); }
.ship-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.ship-chip.placed { opacity: 0.4; pointer-events: none; }

/* On touch devices, let placed ships be tappable to reposition */
@media (pointer: coarse) {
  .cell.ship { cursor: grab; }
  .ship-chip.placed { pointer-events: auto; cursor: pointer; }
}
.ship-chip .dot-row { display: flex; gap: 2px; }
.ship-chip .dot {
  width: 8px; height: 8px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.5;
}
.ship-chip.active .dot { opacity: 1; }

/* Grid area */
.grid-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.grid-labels-top {
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  gap: var(--gap);
  margin-left: calc(22px + var(--gap));
  margin-bottom: 2px;
}
.grid-labels-top span {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.grid-with-rows { display: flex; }
.grid-labels-side {
  display: grid;
  grid-template-rows: repeat(10, var(--cell));
  gap: var(--gap);
  width: 22px;
  margin-right: var(--gap);
}
.grid-labels-side span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-template-rows: repeat(10, var(--cell));
  gap: var(--gap);
  border-radius: var(--radius-md);
  padding: 4px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  touch-action: none; /* prevent scroll/zoom while dragging ships */
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: 4px;
  background: var(--water);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
  position: relative;
}
.cell:hover:not(.hit):not(.miss):not(.sunk) {
  background: var(--water-hover);
  transform: scale(1.05);
}

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

/* Placement preview */
.cell.preview {
  background: rgba(138, 124, 255, 0.3);
  border-color: var(--accent);
}
.cell.preview-invalid {
  background: rgba(255, 93, 122, 0.2);
  border-color: var(--hit);
}

/* Hit */
.cell.hit {
  background: rgba(255, 93, 122, 0.3);
  border-color: var(--hit);
  cursor: default;
}
.cell.hit::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hit);
  font-size: 16px;
  font-weight: 700;
}

/* Miss */
.cell.miss {
  background: var(--miss);
  cursor: default;
}
.cell.miss::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transform: translate(-50%, -50%);
  opacity: 0.6;
}

/* Sunk */
.cell.sunk {
  background: rgba(255, 58, 92, 0.3);
  border-color: var(--sunk);
  cursor: default;
}
.cell.sunk::after { color: var(--sunk); }

/* Disabled grid */
.grid.disabled .cell { pointer-events: none; cursor: default; }

/* Crosshair on attack grid */
.battle-grid .cell:not(.hit):not(.miss):not(.sunk) {
  cursor: crosshair;
}

/* --- Animations --- */

@keyframes hit-flash {
  0%   { background: rgba(255, 93, 122, 0.8); transform: scale(1.2); }
  50%  { background: rgba(255, 93, 122, 0.5); }
  100% { background: rgba(255, 93, 122, 0.3); transform: scale(1); }
}
.cell.hit-anim { animation: hit-flash 0.5s ease-out; }

@keyframes miss-splash {
  0%   { transform: scale(0); opacity: 0; }
  50%  { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(1); opacity: 0.6; }
}
.cell.miss-anim::after { animation: miss-splash 0.4s ease-out; }

@keyframes sunk-shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-3px); }
  40%  { transform: translateX(3px); }
  60%  { transform: translateX(-2px); }
  80%  { transform: translateX(2px); }
}
.cell.sunk-anim { animation: sunk-shake 0.5s ease-out; }

@keyframes result-pop {
  0%   { opacity: 0; transform: scale(0.7) translateY(10px); }
  60%  { transform: scale(1.05) translateY(0); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Water ripple */
@keyframes water-ripple {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.6; }
}
.cell.water-idle {
  animation: water-ripple 3s ease-in-out infinite;
}
.cell.water-idle:nth-child(3n)   { animation-delay: 0s; }
.cell.water-idle:nth-child(3n+1) { animation-delay: 1s; }
.cell.water-idle:nth-child(3n+2) { animation-delay: 2s; }

/* Shot result overlay */
.shot-result {
  text-align: center;
  margin-top: 20px;
  animation: result-pop 0.4s ease-out;
}
.shot-result-icon {
  font-size: 36px;
  margin-bottom: 4px;
  line-height: 1;
}
.shot-result-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.shot-result-text.miss-text { color: var(--muted); }
.shot-result-text.hit-text  { color: var(--hit); }
.shot-result-text.sunk-text { color: var(--sunk); }

/* Battle actions */
.battle-actions {
  display: flex;
  justify-content: center;
  margin-top: 16px;
  animation: result-pop 0.3s ease-out 0.2s both;
}

/* Place actions */
.place-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

/* Fleet status */
.fleet-status {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.fleet-ship {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  transition: opacity 0.3s, border-color 0.3s;
}
.fleet-ship.sunk {
  text-decoration: line-through;
  opacity: 0.35;
  border-color: var(--sunk);
}

/* Minimap */
.minimap-area {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.grid-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
}
.minimap-grid {
  --mini: 16px;
  display: grid;
  grid-template-columns: repeat(10, var(--mini));
  grid-template-rows: repeat(10, var(--mini));
  gap: 1px;
  border-radius: var(--radius-md);
  padding: 3px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
}
.mini-cell {
  width: var(--mini);
  height: var(--mini);
  border-radius: 2px;
  background: var(--water);
  position: relative;
}
.mini-cell.ship { background: var(--ship-fill); border: 1px solid var(--ship-border); }
.mini-cell.hit  { background: rgba(255, 93, 122, 0.4); }
.mini-cell.hit::after {
  content: "✕"; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--hit); font-size: 9px; font-weight: 700;
}
.mini-cell.miss { background: var(--miss); }
.mini-cell.sunk { background: rgba(255, 58, 92, 0.35); border-color: var(--sunk); }

/* Handoff screen */
.handoff-card {
  text-align: center;
  padding: 80px 20px;
}
.handoff-text {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}
.handoff-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 32px;
  min-height: 20px;
}
.handoff-btn {
  padding: 14px 36px;
  font-size: 16px;
}

/* Game over */
.game-over-card {
  text-align: center;
  padding: 60px 20px;
  animation: result-pop 0.5s ease-out;
}
.winner-title {
  font-size: 36px;
  margin-bottom: 8px;
}
.winner-sub {
  color: var(--muted);
  margin-bottom: 8px;
}
.winner-stats {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 28px;
}
.winner-stats strong {
  color: var(--text);
  font-weight: 600;
}
.game-over-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* Mobile */
@media (max-width: 520px) {
  :root { --cell: 30px; }
  .minimap-grid { --mini: 13px; }
  .mode-btn { padding: 12px 24px; font-size: 15px; }
  .handoff-text { font-size: 18px; }
}
@media (max-width: 400px) {
  :root { --cell: 26px; }
  .minimap-grid { --mini: 11px; }
}
