/* Sea Battle – only what's specific to this game.
   Header, difficulty, score and status come from /css/style.css. */

:root {
  --bs-ship: #5b6372;
  --bs-hit: #ff8a7a;
}

:root[data-theme="light"] {
  --bs-ship: #9aa3b2;
  --bs-hit: #d9483b;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bs-ship: #9aa3b2;
    --bs-hit: #d9483b;
  }
}

.bs-heading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  margin-bottom: -8px;
  text-align: center;
}

/* ---------- Stages ---------- */

.bs-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.bs-placer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(100%, 400px);
}

.bs-hint {
  min-height: 21px;
  text-align: center;
}

.bs-hint[data-tone="warn"] {
  color: var(--warn);
}

/* Battle: side by side on wide screens, stacked (theirs first) on phones */
.bs-seas {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
  width: min(100%, 860px);
}

@media (min-width: 720px) {
  .bs-seas {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.bs-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* The holders sit in a centred column, so they need their own width;
   without one they shrink to nothing and take the sea with them. */
.bs-side > div {
  display: flex;
  justify-content: center;
  width: 100%;
}

.bs-side-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--text-muted);
}

/* On phones your own sea can be a little smaller */
@media (max-width: 719px) {
  .bs-side.is-home .bs-sea-wrap {
    width: min(100%, 300px);
  }
}

/* ---------- A sea ---------- */

.bs-sea-wrap {
  width: min(100%, 400px);
}

.bs-sea {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: 3px;
  aspect-ratio: 1;
  padding: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  touch-action: manipulation;
}

/* Their sea while it's your shot: a faint green edge says "fire here" */
.bs-sea.is-live {
  border-color: var(--accent);
}

.bs-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: var(--inset);
  color: var(--text);
}

.bs-cell:disabled {
  cursor: default;
}

.bs-cell:not(:disabled) {
  cursor: pointer;
}

.bs-sea.is-live .bs-cell:not(:disabled):hover {
  background: var(--accent-soft);
}

.bs-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 2;
}

/* Ships: one rounded hull drawn across their squares */
.bs-cell.is-ship::before {
  content: "";
  position: absolute;
  inset: 5px;
  background: var(--bs-ship);
  border-radius: 4px;
}

.bs-cell.is-h.is-start::before { right: -3px; border-radius: 999px 3px 3px 999px; }
.bs-cell.is-h.is-mid::before   { left: -3px; right: -3px; border-radius: 0; }
.bs-cell.is-h.is-end::before   { left: -3px; border-radius: 3px 999px 999px 3px; }
.bs-cell.is-v.is-start::before { bottom: -3px; border-radius: 999px 999px 3px 3px; }
.bs-cell.is-v.is-mid::before   { top: -3px; bottom: -3px; border-radius: 0; }
.bs-cell.is-v.is-end::before   { top: -3px; border-radius: 3px 3px 999px 999px; }

.bs-cell.is-selected::before {
  background: var(--accent);
}

/* A solid, dimmer colour (not opacity: the hull pieces overlap,
   and see-through pieces would show seams) */
.bs-cell.is-sunk::before {
  background: color-mix(in srgb, var(--bs-ship) 45%, var(--inset));
}

/* Preview while moving a ship */
.bs-cell.is-ghost-ok {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}

.bs-cell.is-ghost-bad {
  box-shadow: inset 0 0 0 2px var(--danger);
}

/* ---------- Shots ---------- */

.bs-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.bs-mark::after {
  content: "";
  display: block;
}

/* Miss: a small ripple */
.bs-cell.is-miss .bs-mark::after {
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--text-faint);
}

/* Hit: a bright burst */
.bs-cell.is-hit .bs-mark::after {
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: var(--bs-hit);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bs-hit) 30%, transparent);
  animation: bs-hit 220ms ease-out;
}

.bs-cell.is-hit:not(.is-ship) {
  background: color-mix(in srgb, var(--bs-hit) 14%, var(--inset));
}

.bs-cell.is-sunk.is-hit .bs-mark::after {
  width: 34%;
  height: 34%;
  box-shadow: none;
  animation: none;
}

/* The newest shot on each sea */
.bs-cell.is-last {
  box-shadow: inset 0 0 0 2px var(--text);
}

/* The newest miss: a splash ring */
.bs-cell.is-last.is-miss .bs-mark::after {
  animation: bs-splash 600ms ease-out;
}

@keyframes bs-splash {
  from {
    transform: scale(0.3);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--text-faint) 70%, transparent);
  }
  to {
    transform: scale(1);
    box-shadow: 0 0 0 16px transparent;
  }
}

/* The newest hit: a bigger bang */
.bs-cell.is-last.is-hit:not(.is-sunk) .bs-mark::after {
  animation: bs-hit 220ms ease-out, bs-bang 600ms ease-out;
}

@keyframes bs-bang {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bs-hit) 70%, transparent); }
  to   { box-shadow: 0 0 0 18px transparent; }
}

@keyframes bs-hit {
  from { transform: scale(0.3); }
  to   { transform: scale(1); }
}

/* ---------- Fleet list ---------- */

.bs-fleet {
  width: min(100%, 400px);
}

.bs-fleet-title {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.bs-fleet ul {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.bs-fleet li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.bs-pips {
  display: inline-flex;
  gap: 2px;
}

.bs-pips i {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--bs-ship);
}

.bs-fleet li.is-sunk {
  color: var(--text-faint);
  text-decoration: line-through;
}

.bs-fleet li.is-sunk .bs-pips i {
  background: var(--bs-hit);
  opacity: 0.6;
}

@media (prefers-reduced-motion: reduce) {
  .bs-cell.is-miss .bs-mark::after,
  .bs-cell.is-hit .bs-mark::after {
    animation: none;
  }
}

/* Phone held sideways: fit the screen height (see css/style.css) */
@media (orientation: landscape) and (max-height: 540px) {
  .bs-place {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    width: var(--play-w);
  }
  .bs-placer {
    width: min(400px, calc(var(--play-h) - 30px));
  }
  .bs-place .game-actions {
    flex-direction: column;
  }
  .bs-seas {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    width: var(--play-w);
  }
  .bs-seas .bs-sea-wrap,
  .bs-side.is-home .bs-sea-wrap {
    width: min(100%, calc(var(--play-h) - 34px));
  }
}
