:root {
  --bg: #040404;
  --panel: #0b1113;
  --primary: #119da4;
  --secondary: #0c7489;
  --accent: #13505B;
  --light: #d7d9ce;
  --muted: rgba(215, 217, 206, .62);
  --grid: rgba(215, 217, 206, .14);
  --hit: #ff4d4d;
  --miss: #4da6ff;
  --ship: rgba(17, 157, 164, .55);
  --danger: #ff6868;
  --sonar: #f7d774;
  --sonar-detected: #ffe28a;
  --valid: rgba(17, 157, 164, .32);
  --invalid: rgba(255, 77, 77, .24);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(17, 157, 164, .18), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(19, 80, 91, .26), transparent 30rem),
    var(--bg);
  color: var(--light);
}

button, input { font: inherit; }

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.app.shake { animation: screenShake .22s ease-in-out; }
.app.big-shake { animation: screenShakeBig .36s ease-in-out; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.brand { display: flex; flex-direction: column; gap: 4px; }

.brand h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: -.05em;
  line-height: 1;
}

.brand span, .small-note { color: var(--muted); font-size: 14px; }

.player-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(215, 217, 206, .06);
  border: 1px solid rgba(215, 217, 206, .12);
  border-radius: 999px;
  padding: 8px 12px;
  white-space: nowrap;
}

.player-pill input, .text-input {
  border: 1px solid rgba(215, 217, 206, .14);
  outline: none;
  color: var(--light);
  background: rgba(0, 0, 0, .18);
  border-radius: 12px;
  padding: 10px 12px;
}

.player-pill input {
  width: 170px;
  border: none;
  background: transparent;
  padding: 0;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, rgba(16, 27, 30, .88), rgba(6, 10, 11, .92));
  border: 1px solid rgba(215, 217, 206, .12);
  border-radius: var(--radius);
  box-shadow: 0 20px 70px rgba(0, 0, 0, .34);
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid rgba(215, 217, 206, .09);
}

.panel-title {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.status {
  color: var(--light);
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 800;
  letter-spacing: -.04em;
  margin: 0;
}

.substatus {
  color: var(--muted);
  margin: 6px 0 0;
  font-size: 13px;
}

.boards {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 18px;
  padding: 18px;
}

.board-wrap h2 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
  width: 100%;
  aspect-ratio: 1;
  padding: 8px;
  border-radius: 16px;
  background: rgba(0, 0, 0, .22);
  border: 1px solid rgba(215, 217, 206, .10);
}

.cell {
  border: 1px solid var(--grid);
  background: rgba(215, 217, 206, .035);
  border-radius: 7px;
  cursor: default;
  position: relative;
  transition: transform .1s ease, background .1s ease, border-color .1s ease, box-shadow .1s ease;
}

.target-grid .cell:not(.shot),
.target-grid.sonar-mode .cell,
.placement-grid .cell {
  cursor: pointer;
}

.target-grid .cell:not(.shot):hover,
.target-grid.sonar-mode .cell:hover,
.placement-grid .cell:hover {
  transform: translateY(-1px);
  background: rgba(17, 157, 164, .16);
  border-color: rgba(17, 157, 164, .72);
  box-shadow: 0 0 18px rgba(17, 157, 164, .22);
}

.target-grid.sonar-mode .cell:hover {
  background: rgba(247, 215, 116, .14);
  border-color: rgba(247, 215, 116, .72);
  box-shadow: 0 0 20px rgba(247, 215, 116, .22);
}

.cell.ship {
  background: var(--ship);
  border-color: rgba(17, 157, 164, .9);
}

.cell.ghost-valid {
  background: var(--valid);
  border-color: rgba(17, 157, 164, .9);
  box-shadow: 0 0 14px rgba(17, 157, 164, .18);
}

.cell.ghost-invalid {
  background: var(--invalid);
  border-color: rgba(255, 77, 77, .82);
  box-shadow: 0 0 14px rgba(255, 77, 77, .16);
}

.cell.hit {
  background: rgba(255, 77, 77, .2);
  border-color: rgba(255, 77, 77, .95);
}

.cell.hit::after {
  content: "";
  position: absolute;
  inset: 28%;
  border-radius: 999px;
  background: var(--hit);
  box-shadow: 0 0 16px rgba(255, 77, 77, .7);
  animation: pop .18s ease-out;
}

.cell.miss {
  background: rgba(77, 166, 255, .12);
  border-color: rgba(77, 166, 255, .72);
}

.cell.miss::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 999px;
  border: 2px solid var(--miss);
  opacity: .9;
  animation: ripple .28s ease-out;
}

.cell.sunk {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .16), 0 0 16px rgba(255, 77, 77, .2);
}

.cell.sonar-highlight {
  background: rgba(247, 215, 116, .16);
  border-color: rgba(247, 215, 116, .72);
  animation: sonarPulse .9s ease-out 2;
}

.cell.sonar-detected {
  background: rgba(255, 226, 138, .28);
  border-color: rgba(255, 226, 138, .95);
  box-shadow: 0 0 18px rgba(255, 226, 138, .35);
}

.cell.sonar-detected::before {
  content: "";
  position: absolute;
  inset: 30%;
  border-radius: 999px;
  background: var(--sonar-detected);
  box-shadow: 0 0 16px rgba(255, 226, 138, .75);
}

.side { display: flex; flex-direction: column; gap: 18px; }
.card { padding: 16px; }
.actions { display: grid; gap: 10px; }
.divider { width: 100%; border: 0; border-top: 1px solid rgba(215, 217, 206, .1); }

.btn {
  border: 1px solid rgba(215, 217, 206, .16);
  background: rgba(215, 217, 206, .06);
  color: var(--light);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .1s ease, background .1s ease, border-color .1s ease, opacity .1s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(17, 157, 164, .55);
  background: rgba(17, 157, 164, .11);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .44;
}

.btn.primary {
  background: linear-gradient(180deg, var(--primary), var(--secondary));
  color: #001315;
  border-color: rgba(17, 157, 164, .95);
}

.btn.sonar {
  border-color: rgba(247, 215, 116, .38);
  color: #fff0b6;
}

.btn.danger {
  border-color: rgba(255, 104, 104, .34);
  color: #ffd7d7;
}

.stat-list, .ship-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stat-list li, .ship-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  border-bottom: 1px solid rgba(215, 217, 206, .08);
  padding-bottom: 8px;
}

.stat-list strong, .ship-list strong { color: var(--light); }
.ship-list li.current strong { color: var(--sonar); }
.ship-list li.placed { opacity: .45; }

.log {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow: auto;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  padding-right: 4px;
}

.log-entry {
  padding: 8px 10px;
  background: rgba(215, 217, 206, .045);
  border-radius: 10px;
}

@keyframes pop {
  from { transform: scale(.4); opacity: .4; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes ripple {
  from { transform: scale(.4); opacity: 1; }
  to { transform: scale(1.5); opacity: .35; }
}

@keyframes sonarPulse {
  0% { box-shadow: 0 0 0 rgba(247, 215, 116, 0); }
  45% { box-shadow: 0 0 22px rgba(247, 215, 116, .4); }
  100% { box-shadow: 0 0 0 rgba(247, 215, 116, 0); }
}

@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 2px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-2px, -2px); }
  80% { transform: translate(2px, 1px); }
}

@keyframes screenShakeBig {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-6px, 3px); }
  30% { transform: translate(6px, -2px); }
  45% { transform: translate(-4px, -4px); }
  60% { transform: translate(4px, 3px); }
  75% { transform: translate(-2px, 2px); }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .boards { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .player-pill { width: 100%; }
  .player-pill input { width: 100%; }
}
