/* Ship Battle: Ocean of Softwares */
.sb {
  --sea-950: #041222;
  --sea-900: #061a2e;
  --sea-800: #0b2447;
  --sea-700: #12335f;
  --sea-600: #1c4483;
  --teal: #5fd4c4;
  --accent: #f2b134;
  --hit: #ff5a5f;
  --miss: #9fc0ea;
  --text: #e8eef8;
  --muted: #9fb0ca;
  --line: rgba(159, 192, 234, 0.16);
  width: 100%;
  max-width: 1060px;
  margin: 18px auto;
  padding: 20px 22px 22px;
  color: var(--text);
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(95, 212, 196, 0.12), transparent 60%),
    radial-gradient(900px 500px at 110% 120%, rgba(242, 177, 52, 0.08), transparent 60%),
    linear-gradient(160deg, var(--sea-800), var(--sea-900) 65%, var(--sea-950));
  border-radius: 22px;
  box-shadow: 0 20px 50px rgba(4, 18, 34, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  line-height: 1.5;
  box-sizing: border-box;
}
.sb *, .sb *::before, .sb *::after { box-sizing: border-box; }
.sb button { font: inherit; }
.sb button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Header */
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sb-title { display: flex; align-items: center; gap: 12px; }
.sb-title img { width: 42px; height: 42px; }
.sb-title h1 { margin: 0; font-size: clamp(24px, 3.4vw, 32px); letter-spacing: -0.3px; color: #fff; line-height: 1.1; }
.sb-title p { margin: 2px 0 0; color: var(--muted); font-size: 14.5px; }
.sb-tools { display: flex; gap: 8px; }
.sb-icon {
  width: 40px; height: 40px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--text); font-size: 17px;
}
.sb-icon:hover { border-color: var(--teal); }

/* Buttons */
.sb-btn {
  border-radius: 11px; padding: 9px 16px; font-weight: 700; font-size: 14.5px; cursor: pointer;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.sb-btn:hover { border-color: var(--teal); }
.sb-btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1300; }
.sb-btn.primary:hover { background: #ffc451; }
.sb-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.sb-btn.small { padding: 7px 12px; font-size: 13.5px; }

/* Setup panel */
.sb-setup {
  display: grid; grid-template-columns: auto 1fr; gap: 12px 18px; align-items: center;
  padding: 14px 16px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 16px; background: rgba(4, 18, 34, 0.35);
}
.sb-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 700; }
.sb-seg { justify-self: start; display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); }
.sb-seg button {
  border: 0; border-radius: 9px; padding: 7px 14px; cursor: pointer; font-weight: 700; font-size: 14px;
  background: transparent; color: var(--muted);
}
.sb-seg button small { display: block; font-weight: 500; font-size: 11px; opacity: 0.85; }
.sb-seg button.active { background: var(--teal); color: #05222a; }
.sb-dock { display: flex; flex-wrap: wrap; gap: 8px; }
.dock-ship {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 7px 11px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--text);
}
.dock-ship .pips { display: inline-flex; gap: 2px; }
.dock-ship .pips i { width: 9px; height: 9px; border-radius: 2px; background: #a9b6c8; }
.dock-ship.placed { opacity: 0.6; }
.dock-ship.placed .pips i { background: var(--teal); }
.dock-ship.active { opacity: 1; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(242, 177, 52, 0.25); }
.sb-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.sb-actions .spacer { flex: 1; }

/* Message */
.sb-msg {
  margin: 0 0 14px; padding: 10px 14px; border-radius: 12px; min-height: 44px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); font-weight: 600; font-size: 15px;
}
.sb-msg.good { border-color: rgba(95, 212, 196, 0.6); color: #c8fff6; }
.sb-msg.bad { border-color: rgba(255, 90, 95, 0.6); color: #ffd3d4; }
.sb-msg.warn { border-color: rgba(242, 177, 52, 0.7); color: #ffe7b5; }

/* Boards */
.sb-boards { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.sb-board {
  padding: 14px; border-radius: 18px; border: 1px solid var(--line); background: rgba(4, 18, 34, 0.4);
  transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.sb-board.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(242, 177, 52, 0.18); }
.sb-board-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; margin-bottom: 10px; }
.sb-board-head h2 { margin: 0; font-size: 17px; color: #fff; letter-spacing: 0.2px; }
.sb-board-head h2 span { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 6px; }
.sb-fleet { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.fl-ship { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.fl-ship b { font-weight: 600; }
.fl-ship .pips { display: inline-flex; gap: 2px; }
.fl-ship .pips i { width: 7px; height: 7px; border-radius: 2px; background: var(--teal); }
.fl-ship .pips i.x { background: var(--hit); }
.fl-ship.sunk { text-decoration: line-through; opacity: 0.6; }

.sb-frame { max-width: 440px; margin: 0 auto; display: grid; grid-template-columns: 20px 1fr; grid-template-rows: 20px auto; gap: 4px; }
.sb-cols { grid-column: 2; display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.sb-rows { grid-row: 2; display: grid; grid-template-rows: repeat(10, 1fr); gap: 3px; }
.sb-cols span, .sb-rows span { display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.sb-grid {
  grid-column: 2; grid-row: 2;
  display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(10, 1fr); gap: 3px;
  aspect-ratio: 1 / 1; width: 100%;
  padding: 3px; border-radius: 10px;
  background:
    repeating-linear-gradient(120deg, rgba(95, 212, 196, 0.05) 0 12px, transparent 12px 26px),
    linear-gradient(180deg, #0e2d55, #0a2141);
}
.sb .cell {
  position: relative; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 4px;
  background: rgba(28, 68, 131, 0.55); cursor: pointer; transition: background 0.12s;
}
.sb .cell:hover { background: rgba(61, 118, 201, 0.7); }

/* Ships */
.sb .cell.ship { background: linear-gradient(180deg, #b7c3d3, #7d8ea8); }
.sb .cell.ship.v { background: linear-gradient(90deg, #b7c3d3, #7d8ea8); }
.sb .cell.ship.h.start { border-radius: 45% 4px 4px 45%; }
.sb .cell.ship.h.end { border-radius: 4px 45% 45% 4px; }
.sb .cell.ship.v.start { border-radius: 45% 45% 4px 4px; }
.sb .cell.ship.v.end { border-radius: 4px 4px 45% 45%; }
.sb .cell.ship.selected { background: linear-gradient(180deg, #ffd27a, #f2b134); }
.sb .cell.ship.sunk { background: linear-gradient(180deg, #6b2a35, #45161f); box-shadow: inset 0 0 0 1px rgba(255, 90, 95, 0.55); }
.sb .cell.pv { background: rgba(95, 212, 196, 0.6) !important; }
.sb .cell.pv-bad { background: rgba(255, 90, 95, 0.55) !important; }

/* Shots */
.sb .cell.miss::after {
  content: ""; position: absolute; inset: 32%; border-radius: 50%;
  background: var(--miss); opacity: 0.85; animation: sb-splash 0.35s ease-out;
}
.sb .cell.hit::after {
  content: ""; position: absolute; inset: 14%; border-radius: 50%;
  background: radial-gradient(circle, #fff3c4 0 18%, #ffb347 32%, var(--hit) 58%, rgba(255, 90, 95, 0) 74%);
  animation: sb-boom 0.4s ease-out;
}
.sb .cell.hit.sunk::after { background: radial-gradient(circle, #ffb3b5 0 20%, var(--hit) 45%, rgba(255, 90, 95, 0) 72%); }
.sb .cell.flash { box-shadow: 0 0 0 2px var(--accent); }
@keyframes sb-splash { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 0.85; } }
@keyframes sb-boom { 0% { transform: scale(0.2); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* Interaction by phase */
.sb #myGrid .cell { cursor: default; }
.sb.is-setup #myGrid .cell { cursor: pointer; }
.sb #myGrid .cell:not(.ship):hover { background: rgba(28, 68, 131, 0.55); }
.sb.is-setup #myGrid .cell:not(.ship):hover { background: rgba(61, 118, 201, 0.7); }
.sb #enemyGrid .cell.done { cursor: default; }
.sb #enemyGrid .cell.done:not(.ship):hover { background: rgba(28, 68, 131, 0.55); }
.sb #enemyGrid .cell:not(.done):hover { background: rgba(242, 177, 52, 0.35); box-shadow: inset 0 0 0 2px var(--accent); }
.sb.is-setup #enemyBoard { opacity: 0.45; }
.sb.is-setup #enemyBoard .sb-grid { pointer-events: none; }
.sb-wait { display: none; margin: 8px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.sb.is-setup .sb-wait { display: block; }
.sb:not(.is-setup) .sb-setup { display: none; }
.sb #newBtn { display: none; }
.sb:not(.is-setup) #newBtn { display: inline-flex; }

/* Stats */
.sb-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.sb-stat { text-align: center; padding: 9px 6px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); }
.sb-stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; color: #fff; line-height: 1.2; }
.sb-stat span { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }

/* Modal */
.sb-modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(4, 18, 34, 0.7); backdrop-filter: blur(3px);
}
.sb-modal.hidden { display: none; }
.sb-modal-card {
  width: 100%; max-width: 420px; text-align: center; padding: 26px 22px 22px; border-radius: 20px;
  background: linear-gradient(160deg, var(--sea-700), var(--sea-900)); border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45); animation: sb-pop 0.22s ease-out;
}
.sb-modal-card h2 { margin: 0; font-size: 30px; color: #fff; }
.sb-modal.won .sb-modal-card h2 { color: var(--accent); }
.sb-modal-card p { margin: 6px 0 14px; color: var(--muted); }
.sb-modal-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
.sb-best { min-height: 1.4em; font-weight: 700; color: var(--teal) !important; }
.sb-modal-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
@keyframes sb-pop { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }

/* Phones and small tablets */
@media (max-width: 820px) {
  .sb { margin: 8px auto; padding: 14px 12px 16px; border-radius: 16px; }
  .sb-boards { grid-template-columns: 1fr; gap: 14px; }
  .sb.is-battle #enemyBoard, .sb.is-over #enemyBoard { order: -1; }
  .sb.is-setup #enemyBoard { display: none; }
  .sb-setup { grid-template-columns: 1fr; gap: 8px; padding: 12px; }
  .sb-actions { justify-content: stretch; }
  .sb-actions .sb-btn { flex: 1 1 auto; justify-content: center; }
  .sb-actions .spacer { display: none; }
  .sb-board { padding: 10px; }
  .sb-msg { position: sticky; top: 0; z-index: 5; background: #0e2a4f; font-size: 14px; box-shadow: 0 6px 16px rgba(4, 18, 34, 0.45); }
  .sb-frame { grid-template-columns: 16px 1fr; grid-template-rows: 16px auto; gap: 3px; }
  .sb-grid, .sb-cols, .sb-rows { gap: 2px; }
  .sb-grid { padding: 2px; }
  .sb-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .sb-title img { width: 34px; height: 34px; }
  .sb-title p { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .sb *, .sb *::before, .sb *::after { animation: none !important; transition: none !important; }
}
