/* Battleship — layout & visuals */
:root {
  --bg: #050a14;
  --panel-a: rgba(17, 32, 56, .88);
  --panel-b: rgba(9, 18, 34, .92);
  --line: rgba(125, 211, 252, .16);
  --line-strong: rgba(125, 211, 252, .4);
  --text: #e6f0ff;
  --muted: #7e95b8;
  --cyan: #38bdf8;
  --green: #4ade80;
  --red: #f87171;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 650px at 12% -8%, rgba(56, 189, 248, .16), transparent 62%),
    radial-gradient(900px 600px at 108% 12%, rgba(99, 102, 241, .13), transparent 60%),
    radial-gradient(900px 700px at 50% 118%, rgba(13, 148, 136, .14), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.app { max-width: 1180px; margin: 0 auto; padding-bottom: 44px; }

/* ------------------------------------------------------------- Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px clamp(10px, 3vw, 26px) 12px;
}

h1 {
  margin: 0;
  font-size: clamp(1.15rem, 3.4vw, 1.6rem);
  font-weight: 800;
  letter-spacing: .38em;
  text-indent: .38em;
  text-transform: uppercase;
  background: linear-gradient(92deg, #7dd3fc 0%, #e0f2fe 45%, #38bdf8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(56, 189, 248, .35));
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

button { font: inherit; color: inherit; }

.ghost-btn,
.placement-actions button,
.icon-btn {
  border: 1px solid var(--line);
  background: rgba(12, 26, 46, .72);
  border-radius: 11px;
  padding: 8px 14px;
  font-size: .8rem;
  letter-spacing: .05em;
  cursor: pointer;
  transition: background .16s, border-color .16s, transform .16s, box-shadow .16s;
}

.ghost-btn:hover,
.placement-actions button:not(:disabled):hover,
.icon-btn:hover {
  background: rgba(28, 54, 88, .9);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.ghost-btn:active,
.placement-actions button:not(:disabled):active,
.icon-btn:active { transform: translateY(0); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 11px;
  color: #9ec9f0;
}

.icon-btn .sound-x { display: none; }
.icon-btn.muted .sound-waves { display: none; }
.icon-btn.muted .sound-x { display: inline; }

.primary {
  background: linear-gradient(180deg, #0ea5e9, #0369a1);
  border-color: var(--cyan);
  color: #f0f9ff;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(14, 165, 233, .35);
}

.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #38bdf8, #0284c7);
  box-shadow: 0 10px 26px rgba(56, 189, 248, .45);
}

.primary:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }

.primary.big {
  width: 100%;
  padding: 12px 30px;
  font-size: .95rem;
  border-radius: 13px;
}

.primary.ready { animation: readyPulse 1.8s ease-in-out infinite; }

@keyframes readyPulse {
  0%, 100% { box-shadow: 0 8px 22px rgba(14, 165, 233, .35); }
  50% { box-shadow: 0 8px 32px rgba(56, 189, 248, .8); }
}

/* ----------------------------------------------------------- Status pill */

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(92%, 680px);
  margin: 0 auto 14px;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(15, 30, 53, .92), rgba(8, 17, 32, .92));
  box-shadow: 0 12px 34px rgba(0, 0, 0, .4);
  font-size: .88rem;
  text-align: center;
}

.turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #64748b;
  flex: 0 0 auto;
}

.turn-dot[data-who="player"] {
  background: var(--green);
  box-shadow: 0 0 10px rgba(74, 222, 128, .8);
  animation: dotPulse 1.6s ease-in-out infinite;
}

.turn-dot[data-who="cpu"] {
  background: var(--red);
  box-shadow: 0 0 10px rgba(248, 113, 113, .8);
  animation: dotPulse 1.6s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: .72; }
}

/* ---------------------------------------------------------------- Panels */

.boards {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(16px, 2.6vw, 32px);
  padding: 0 clamp(10px, 3vw, 26px);
}

.panel {
  flex: 1 1 340px;
  max-width: 490px;
  padding: 14px 14px 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-a), var(--panel-b));
  box-shadow: 0 22px 55px rgba(0, 0, 0, .5);
  transition: border-color .25s, box-shadow .25s;
}

.panel h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 4px 12px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--muted);
}

.fleet-count {
  color: #bae6fd;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: none;
  white-space: nowrap;
}

.panel.active {
  border-color: rgba(74, 222, 128, .5);
  box-shadow: 0 22px 55px rgba(0, 0, 0, .5), 0 0 0 1px rgba(74, 222, 128, .25), 0 0 46px rgba(74, 222, 128, .14);
}

#cpuPanel.active {
  border-color: rgba(248, 113, 113, .5);
  box-shadow: 0 22px 55px rgba(0, 0, 0, .5), 0 0 0 1px rgba(248, 113, 113, .28), 0 0 46px rgba(248, 113, 113, .15);
}

/* ------------------------------------------------------------ Board grid */

.board-frame {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  grid-template-rows: 18px minmax(0, 1fr);
  gap: 5px;
}

.col-labels,
.row-labels {
  display: grid;
  color: var(--muted);
  font-size: .6rem;
  font-weight: 600;
  user-select: none;
}

.col-labels {
  grid-template-columns: repeat(10, minmax(0, 1fr));
  text-align: center;
  align-items: center;
}

.row-labels {
  grid-template-rows: repeat(10, minmax(0, 1fr));
  text-align: center;
  align-items: center;
}

.grid-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(165deg, #0e3457 0%, #0a2540 45%, #071b30 100%);
  box-shadow: inset 0 0 0 1px rgba(125, 211, 252, .22), inset 0 0 70px rgba(2, 8, 20, .85);
}

.grid-wrap::before {
  content: "";
  position: absolute;
  inset: -40%;
  z-index: 0;
  background: repeating-linear-gradient(115deg, rgba(125, 211, 252, .045) 0 2px, transparent 2px 16px);
  animation: drift 22s linear infinite;
}

@keyframes drift { to { transform: translate3d(-48px, -48px, 0); } }

.ships-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.grid {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
}

.cell {
  position: relative;
  border: 1px solid rgba(125, 211, 252, .10);
  transition: background .15s;
}

@media (hover: hover) {
  .grid.armed { cursor: crosshair; }
  .grid.armed .cell:hover { background: rgba(125, 211, 252, .14); }
}

/* -------------------------------------------------------- Shot markers */

.cell.miss::after {
  content: "";
  position: absolute;
  inset: 31%;
  border-radius: 50%;
  background: #dbeafe;
  box-shadow: 0 0 8px rgba(191, 219, 254, .9);
  animation: pop .3s ease-out;
}

.cell.miss::before {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 2px solid rgba(191, 219, 254, .55);
  animation: ripple .6s ease-out forwards;
}

.cell.hit::after {
  content: "";
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff7c2, #fbbf24 32%, #f97316 58%, #dc2626 80%, #7f1d1d);
  box-shadow: 0 0 16px rgba(249, 115, 22, .9);
  animation: boom .4s cubic-bezier(.2, 1.35, .4, 1);
}

.cell.hit::before {
  content: "";
  position: absolute;
  inset: -10%;
  background: radial-gradient(circle, rgba(251, 146, 60, .55), transparent 68%);
  animation: flash .7s ease-out forwards;
}

.cell.hit.sunk::after {
  filter: saturate(.55) brightness(.72);
  box-shadow: 0 0 10px rgba(120, 40, 10, .7);
}

@keyframes pop {
  0% { transform: scale(.2); opacity: 0; }
  65% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes ripple {
  0% { transform: scale(.35); opacity: .95; }
  100% { transform: scale(1.6); opacity: 0; }
}

@keyframes boom {
  0% { transform: scale(.15); opacity: 0; }
  55% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.cell.preview-ok {
  background: rgba(74, 222, 128, .4);
  box-shadow: inset 0 0 0 2px rgba(74, 222, 128, .85);
}

.cell.preview-bad {
  background: rgba(248, 113, 113, .35);
  box-shadow: inset 0 0 0 2px rgba(248, 113, 113, .8);
}

/* --------------------------------------------------------------- Ships */

.ship {
  position: absolute;
  border-radius: 5px;
  overflow: hidden;
  background: linear-gradient(180deg, #cfdcee, #93a8c2 46%, #64788f);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .4), inset 0 -5px 9px rgba(0, 0, 0, .28), 0 3px 9px rgba(0, 0, 0, .45);
}

.ship::before {
  content: "";
  position: absolute;
  inset: 20% 9%;
  border-radius: 3px;
  opacity: .75;
  background: repeating-linear-gradient(90deg, rgba(13, 32, 54, .4) 0 2px, transparent 2px 7px);
}

.ship.vertical::before {
  background: repeating-linear-gradient(0deg, rgba(13, 32, 54, .4) 0 2px, transparent 2px 7px);
}

.ship::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, .24), transparent 20%, transparent 80%, rgba(0, 0, 0, .24));
}

.ship.vertical::after {
  background: linear-gradient(180deg, rgba(0, 0, 0, .24), transparent 20%, transparent 80%, rgba(0, 0, 0, .24));
}

.ship.sunk {
  background: linear-gradient(180deg, #64707f, #414a58 45%, #272d36);
  box-shadow: inset 0 0 0 1px rgba(255, 130, 80, .4), inset 0 0 20px rgba(0, 0, 0, .75);
}

#cpuShips .ship { background: linear-gradient(180deg, #e7c0a8, #bd7f5e 46%, #7d4a33); }
#cpuShips .ship.sunk { background: linear-gradient(180deg, #5a626e, #3a4149 45%, #23282f); }

.ship.revealed {
  animation: revealShip .55s cubic-bezier(.2, 1.2, .4, 1) backwards;
}

@keyframes revealShip {
  0% { opacity: 0; transform: scale(.8); }
  100% { opacity: 1; transform: scale(1); }
}

/* ------------------------------------------------------------ Ship dock */

.dock {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 13px;
  min-height: 54px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(12, 26, 46, .7);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .14s, border-color .16s, box-shadow .16s, background .16s;
}

.chip:hover { border-color: var(--line-strong); transform: translateY(-2px); }

.chip.selected {
  border-color: var(--cyan);
  background: rgba(14, 116, 144, .4);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 20px rgba(56, 189, 248, .4);
}

.chip.placed { opacity: .42; cursor: default; transform: none; }
.chip.placed:hover { transform: none; border-color: var(--line); }
.chip.placed .chip-label strong { text-decoration: line-through; }

.chip-graphic { display: flex; gap: 2px; pointer-events: none; }

.chip-graphic i {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: linear-gradient(180deg, #cfdcee, #7e93ad);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}

.chip.selected .chip-graphic i { background: linear-gradient(180deg, #bae6fd, #0ea5e9); }

.chip-label {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  text-align: left;
  pointer-events: none;
}

.chip-label strong { font-size: .7rem; font-weight: 600; color: #dbeafe; letter-spacing: .02em; }
.chip-label em { font-style: normal; font-size: .6rem; color: var(--muted); }

.chip.placed::after {
  content: "\2713";
  color: var(--green);
  font-size: .8rem;
  font-weight: 700;
  margin-left: 2px;
}

.placement-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

/* ----------------------------------------------------------- Drag ghost */

.drag-ghost {
  position: fixed;
  z-index: 70;
  display: none;
  pointer-events: none;
  border-radius: 5px;
  opacity: .9;
  background: linear-gradient(180deg, rgba(125, 211, 252, .92), rgba(56, 189, 248, .62));
  box-shadow: 0 0 0 2px rgba(125, 211, 252, .55), 0 14px 34px rgba(0, 0, 0, .55);
  transition: left .06s linear, top .06s linear;
}

.drag-ghost.visible { display: block; }
.drag-ghost.snapped { transition: none; }

.drag-ghost.bad {
  background: linear-gradient(180deg, rgba(248, 113, 113, .92), rgba(220, 38, 38, .62));
  box-shadow: 0 0 0 2px rgba(248, 113, 113, .6), 0 14px 34px rgba(0, 0, 0, .55);
}

/* ---------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 90;
  transform: translate(-50%, -24px);
  opacity: 0;
  pointer-events: none;
  max-width: min(90vw, 480px);
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 20, 38, .96);
  color: #e0f2fe;
  font-size: .88rem;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
  transition: opacity .25s, transform .25s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------------------------------------------- Overlay */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(3, 8, 18, .74);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.overlay-card {
  width: min(94vw, 430px);
  padding: 30px 26px 26px;
  border-radius: 22px;
  border: 1px solid var(--line-strong);
  text-align: center;
  background: linear-gradient(180deg, rgba(21, 40, 70, .98), rgba(8, 17, 32, .99));
  box-shadow: 0 40px 90px rgba(0, 0, 0, .75);
  animation: cardIn .45s cubic-bezier(.2, 1.3, .4, 1);
}

@keyframes cardIn {
  0% { opacity: 0; transform: translateY(26px) scale(.94); }
  100% { opacity: 1; transform: none; }
}

.overlay-title {
  margin-bottom: 8px;
  font-size: clamp(1.7rem, 6vw, 2.2rem);
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.overlay-title.win { color: var(--green); text-shadow: 0 0 30px rgba(74, 222, 128, .65); }
.overlay-title.lose { color: var(--red); text-shadow: 0 0 30px rgba(248, 113, 113, .6); }

.overlay-sub { margin: 0 0 18px; color: var(--muted); font-size: .9rem; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}

.stat {
  padding: 11px 10px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(12, 26, 46, .72);
}

.stat span {
  display: block;
  margin-bottom: 4px;
  font-size: .58rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat strong { font-size: 1.08rem; color: #e0f2fe; }

/* --------------------------------------------------------------- Shake */

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

.panel.shake { animation: shake .42s ease-in-out; }

/* ----------------------------------------------------------- Responsive */

@media (max-width: 900px) {
  .boards { flex-direction: column; align-items: center; }
  .panel { flex: 0 0 auto; width: min(94vw, 500px); max-width: none; }
}

@media (max-width: 430px) {
  .topbar { padding: 14px 12px 10px; }
  h1 { letter-spacing: .24em; text-indent: .24em; }
  .panel { padding: 12px 11px 14px; border-radius: 16px; }
  .status { font-size: .8rem; padding: 10px 14px; }
  .chip { padding: 6px 9px; gap: 6px; }
  .chip-graphic i { width: 8px; height: 8px; }
  .chip-label strong { font-size: .64rem; }
  .chip-label em { font-size: .56rem; }
  .placement-actions button, .ghost-btn { padding: 8px 11px; font-size: .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
