:root {
  --game-width: 886px;
  --bg: #0b1020;
  --card: #151b2e;
  --card2: #101729;
  --line: #2b3554;
  --text: #eef3ff;
  --muted: #9aa8c7;
  --accent: #77b7ff;
  --good: #70e0a2;
  --bad: #ff6b7a;
  --warn: #ffd166;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 0%, #1d2b53, var(--bg) 42%);
}
.wrap {
  width: min(1600px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
  display: grid;
  gap: 16px;
  justify-items: center;
}
.hero {
  position: relative;
  width: 100%;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 12px;
  margin-bottom: 2px;
}
h1 { margin: 0; font-size: clamp(30px, 5vw, 54px); letter-spacing: -0.05em; text-align: center; }
h2 { margin: 0 0 12px; font-size: 20px; }
p { margin: 0; }
.card { background: color-mix(in srgb, var(--card) 88%, transparent); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: 0 18px 40px rgba(0,0,0,.22); }
.hidden { display: none !important; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
button, input {
  border: 1px solid #3b86d9;
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
}
button {
  cursor: pointer;
  color: #06111f;
  background: linear-gradient(#9dd0ff, var(--accent));
  font-weight: 700;
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { color: var(--text); background: transparent; border-color: var(--line); }
button.danger { border-color: #6b2b3a; }
input { min-width: 160px; background: var(--card2); color: var(--text); border-color: var(--line); text-transform: uppercase; }
.muted { color: var(--muted); }
.lobby { width: min(680px, 100%); }
.game { width: 100%; display: grid; gap: 16px; justify-items: center; }
.topbar { width: min(var(--game-width), 100%); display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.roomline { color: var(--muted); margin-bottom: 6px; }
.status { font-size: 18px; font-weight: 800; }
.sharebox { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.setup { width: min(var(--game-width), 100%); display: grid; gap: 10px; justify-items: center; text-align: center; }
.shipline { color: var(--muted); }
.boards {
  width: min(var(--game-width), 100%);
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 18px;
  align-items: start;
  justify-content: center;
}
.boardCard {
  width: max-content;
  overflow: visible;
  display: grid;
  justify-items: center;
}
.board {
  display: grid;
  grid-template-columns: repeat(10, 36px);
  grid-template-rows: repeat(10, 36px);
  gap: 4px;
  user-select: none;
  touch-action: manipulation;
}
.cell {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid #263557;
  background: #0d1730;
  color: var(--text);
  font-weight: 900;
  font-size: 18px;
  line-height: 1;
  text-align: center;
  cursor: pointer;
}
.cell:hover { outline: 2px solid rgba(119,183,255,.55); }
.cell.ship { background: #2a6fb3; border-color: #7abfff; }
.cell.preview { background: rgba(112,224,162,.35); border-color: var(--good); }
.cell.badPreview { background: rgba(255,107,122,.28); border-color: var(--bad); }
.cell.hit { background: #7c2330; border-color: var(--bad); }
.cell.miss { background: #25314c; color: #b7c4e4; }
.cell.dead { background: #2c1017; border-color: #ff9aa5; }
.cell.hit,
.cell.dead {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
  font-size: 20px;
  line-height: 1;
}
.cell .emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  line-height: 1;
  text-align: center;
}
.cell.disabled { cursor: default; opacity: .86; }
.cell.blocked {
  background: #172139;
  border-color: #2b3554;
  color: #667594;
  cursor: not-allowed;
  opacity: .58;
}
.cell.shotAnim {
  animation: shotPulse .55s cubic-bezier(.2,.8,.2,1);
}
.cell.shotAnim .emoji {
  animation: emojiPop .55s cubic-bezier(.2,.8,.2,1);
}
.board.turnMuted {
  filter: grayscale(1);
  opacity: .55;
}
.board.turnMuted .cell {
  cursor: default;
}
@keyframes shotPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(255,255,255,0); }
  35% { transform: scale(1.12); box-shadow: 0 0 0 5px rgba(255,255,255,.16); }
  100% { transform: scale(1); box-shadow: 0 0 0 rgba(255,255,255,0); }
}
@keyframes emojiPop {
  0% { transform: scale(.5); opacity: .4; }
  45% { transform: scale(1.28); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.legend { width: min(var(--game-width), 100%); display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 16px; height: 16px; display: inline-block; border-radius: 4px; }
.legend .ship { background: #2a6fb3; }
.legend .hit { background: #7c2330; }
.legend .miss { background: #25314c; }
.legend .dead { background: #2c1017; border: 1px solid #ff9aa5; }
@media (max-width: 820px) {
  .hero, .topbar { align-items: stretch; }
  .topbar { flex-direction: column; }
  .topbar, .setup, .boards, .legend { width: 100%; }
  .boards { grid-template-columns: 1fr; justify-items: center; }
  .board { grid-template-columns: repeat(10, minmax(25px, 1fr)); grid-template-rows: repeat(10, minmax(25px, 1fr)); gap: 3px; }
  .cell { width: 100%; aspect-ratio: 1; height: auto; border-radius: 6px; }
}

.shipStats {
  width: min(var(--game-width), 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  color: var(--muted);
  text-align: center;
}
.statPill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 128px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(16, 23, 41, .72);
  font-weight: 700;
}
.statPill b {
  color: var(--text);
  font-size: 18px;
}
.boardCard {
  position: relative;
}
.endEffect {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
  border-radius: 18px;
}
.endEffect span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  animation-delay: var(--delay);
  animation-duration: var(--dur);
  animation-iteration-count: infinite;
  animation-timing-function: cubic-bezier(.16,.9,.24,1);
}
.fireworks span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 16%, #ffd166 17% 38%, #ff6b7a 39% 62%, transparent 63%);
  box-shadow: 0 0 14px rgba(255, 209, 102, .9);
  animation-name: fireworkBurst;
}
.rain span {
  width: 2px;
  height: 18px;
  border-radius: 99px;
  background: linear-gradient(to bottom, transparent, rgba(157, 208, 255, .9));
  top: -24px;
  animation-name: rainFall;
  animation-timing-function: linear;
}
@keyframes fireworkBurst {
  0% { transform: translate(0,0) scale(.15); opacity: 0; }
  12% { opacity: 1; }
  62% { transform: translate(var(--dx), var(--dy)) scale(1.35); opacity: .95; }
  100% { transform: translate(calc(var(--dx) * 1.45), calc(var(--dy) * 1.45 + 20px)) scale(.35); opacity: 0; }
}
@keyframes rainFall {
  0% { transform: translateY(-32px) rotate(10deg); opacity: 0; }
  8% { opacity: .85; }
  100% { transform: translateY(var(--fall)) rotate(10deg); opacity: 0; }
}

@media (max-width: 820px) {
  .shipStats { width: 100%; }
}
