/* Battleships — own styles, theme variables only. Root class: .bs */

/* a little more room for two grids side by side; below 992 px the shared layout stacks as usual */
@media (min-width: 992px) {
  .gm-layout.bs-layout {
    grid-template-columns: minmax(0, 760px) minmax(260px, 1fr);
  }
}

.bs {
  width: 100%;
  container-type: inline-size;
}

.bs-boards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

@container (min-width: 640px) {
  .bs-boards { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* while shooting, the target grid comes first in the stacked (phone) layout */
@container (max-width: 639.9px) {
  .bs.is-play .bs-target { order: -1; }
}

.bs-board { min-width: 0; }

.bs-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 14px;
  margin: 0 0 8px;
  font: 500 1.05rem/1.2 var(--gm-display, "Fraunces", Georgia, serif);
  letter-spacing: -0.01em;
  color: var(--gm-text, #f2eee6);
}

.bs-title small {
  font: 600 0.66rem/1.2 var(--gm-body, "DM Sans", system-ui, sans-serif);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gm-muted, rgba(242, 238, 230, 0.66));
  white-space: nowrap;
}

.bs-grid-wrap {
  position: relative;
  width: 100%;
  max-width: 400px;
}

.bs-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 1px;
  padding: 1px;
  box-sizing: border-box;
  width: 100%;
  background: var(--gm-line, rgba(255, 255, 255, 0.09));
  border: 1px solid var(--gm-board-edge, rgba(0, 0, 0, 0.45));
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.bs-cell {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: block;
  aspect-ratio: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  background: var(--gm-surface, #1b2740);
  transition: background 0.12s ease;
}

.bs-cell:hover { background: var(--gm-surface-2, #22304a); }
.bs-cell:disabled { cursor: default; }
.bs-cell:disabled:hover { background: var(--gm-surface, #1b2740); }

.bs-cell:focus-visible {
  outline: 3px solid var(--gm-accent-bright, #e0584a);
  outline-offset: -3px;
  z-index: 2;
}

.bs-cell.is-miss { background: var(--gm-bg-2, #131c2b); }
.bs-cell.is-miss:hover { background: var(--gm-bg-2, #131c2b); }
.bs-cell.is-hit { background: var(--gm-accent-soft, rgba(192, 57, 43, 0.3)); }
.bs-cell.is-hit:hover { background: var(--gm-accent-soft, rgba(192, 57, 43, 0.3)); }
.bs-cell.is-preview { background: var(--gm-accent-soft, rgba(192, 57, 43, 0.3)); }
.bs-cell.is-preview-bad { background: var(--gm-bg-2, #131c2b); box-shadow: inset 0 0 0 2px var(--gm-accent-bright, #e0584a); }
.bs-cell.is-sel { box-shadow: inset 0 0 0 2px var(--gm-accent-bright, #e0584a); }

/* ship bodies, hit crosses and miss dots are drawn once per grid in an SVG overlay */
.bs-marks {
  position: absolute;
  inset: 2px;
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  pointer-events: none;
  overflow: visible;
}

.bs-ship {
  fill: var(--gm-sq-dark, #6b3a44);
  stroke: var(--gm-board-edge, rgba(0, 0, 0, 0.45));
  stroke-width: 0.05;
}

.bs-ship.is-sunk {
  fill: var(--gm-bg-2, #131c2b);
  stroke: var(--gm-accent-bright, #e0584a);
  stroke-width: 0.1;
}

.bs-outline {
  fill: none;
  stroke: var(--gm-accent-bright, #e0584a);
  stroke-width: 0.12;
  stroke-dasharray: 0.3 0.14;
}

.bs-miss {
  fill: var(--gm-muted, rgba(242, 238, 230, 0.66));
}

.bs-hit {
  fill: none;
  stroke: var(--gm-accent-bright, #e0584a);
  stroke-width: 0.14;
  stroke-linecap: round;
}

.bs-ship.is-sunk ~ .bs-hit,
.bs-hit.is-sunk {
  stroke: var(--gm-text, #f2eee6);
}

/* small fleet strips under each grid */
.bs-fleet {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 10px 0 0;
  min-height: 14px;
}

.bs-icon {
  position: relative;
  display: inline-block;
  height: 12px;
  width: calc(var(--len, 3) * 12px);
  border-radius: 6px;
  background: var(--gm-sq-dark, #6b3a44);
  box-shadow: inset 0 0 0 1px var(--gm-board-edge, rgba(0, 0, 0, 0.45));
  vertical-align: middle;
}

.bs-icon.is-sunk {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--gm-muted, rgba(242, 238, 230, 0.66));
  opacity: 0.55;
}

.bs-icon.is-sunk::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--gm-accent-bright, #e0584a);
  transform: rotate(-8deg);
}

/* set-up: tray + buttons (hidden while shooting) */
.bs-setup {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--gm-line, rgba(255, 255, 255, 0.09));
  border-radius: var(--gm-radius, 12px);
  background: var(--gm-surface, #1b2740);
}

.bs:not(.is-setup) .bs-setup { display: none; }

.bs-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bs-ship-btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--gm-line-2, rgba(255, 255, 255, 0.16));
  background: var(--gm-bg-2, #131c2b);
  color: var(--gm-text, #f2eee6);
  font: 500 0.86rem/1.2 var(--gm-body, "DM Sans", system-ui, sans-serif);
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.bs-ship-btn:hover { border-color: var(--gm-accent-bright, #e0584a); }

.bs-ship-btn[aria-pressed="true"] {
  border-color: var(--gm-accent, #c0392b);
  box-shadow: 0 0 0 3px var(--gm-accent-soft, rgba(192, 57, 43, 0.3));
}

.bs-ship-btn.is-placed { opacity: 0.5; }
.bs-ship-btn.is-placed[aria-pressed="true"] { opacity: 1; }

.bs-ship-btn:focus-visible {
  outline: 3px solid var(--gm-accent-bright, #e0584a);
  outline-offset: 2px;
}

.bs-setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.bs-setup-actions .gm-btn,
.gm-actions .gm-btn,
.gm-seg button {
  min-height: 44px;
  touch-action: manipulation;
}

#gm-battleships .gm-status { margin-top: 16px; }

#bs-level { border-radius: 16px; }

@media (max-width: 480px) {
  .bs-boards { gap: 16px; }
  /* bleed a few pixels into the page gutter so every square stays at 32 px or more on a 360 px phone */
  .bs-grid-wrap { width: auto; max-width: none; margin: 0 -5px; }
  .bs-setup { padding: 12px; }
  .bs-ship-btn { padding: 6px 10px; gap: 8px; font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .bs-cell, .bs-ship-btn { transition: none; }
}
