/* ⚓ Battleships — Classroom Edition */

:root {
  --bg1: #041a33;
  --bg2: #0b3f6e;
  --card: rgba(255, 255, 255, 0.07);
  --card-line: rgba(255, 255, 255, 0.14);
  --text: #eef6ff;
  --muted: #9cb7d6;
  --sea1: #1f86c7;
  --sea2: #176aa3;
  --grid: rgba(255, 255, 255, 0.13);
  --ship1: #dfe6ee;
  --ship2: #8796a6;
  --accent: #ffcc33;
  --good: #36d27f;
  --bad: #ff5a5f;
  --warn: #ffb020;
  --hit: #ff6a3d;
  --radius: 16px;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background-color: var(--bg1);
  background-image: radial-gradient(ellipse 120% 80% at 50% 0%, var(--bg2), var(--bg1) 70%);
  background-attachment: fixed;
  padding-bottom: 60px;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0 0 10px; }
h3 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 6px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.noscript { text-align: center; padding: 40px; font-size: 1.2rem; }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  color: #1b1300;
  background: linear-gradient(180deg, #ffd95a, var(--accent));
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 #b8860b, 0 6px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.07); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #b8860b, 0 3px 8px rgba(0, 0, 0, 0.25); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.big { font-size: 1.15rem; padding: 13px 26px; }
.btn.small { font-size: 0.85rem; padding: 7px 13px; }
.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 1px var(--card-line);
}
.btn.ghost:active:not(:disabled) { box-shadow: inset 0 0 0 1px var(--card-line); }

.link {
  font: inherit;
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.back-link {
  display: block;
  width: max-content;
  margin: 18px auto 0;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
}
.back-link:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }

/* ---------- Cards & screens ---------- */

.screen { padding: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(6px);
}

.hero {
  max-width: 460px;
  margin: 6vh auto 0;
  text-align: center;
}
.logo {
  font-size: 64px;
  display: inline-block;
  animation: bob 3s ease-in-out infinite;
}
.hero h1 {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  letter-spacing: 0.06em;
  font-weight: 900;
  text-shadow: 0 4px 0 #0a2c4f, 0 8px 18px rgba(0, 0, 0, 0.4);
  margin-bottom: 4px;
}
.tagline { color: var(--accent); font-style: italic; margin: 0 0 22px; min-height: 1.3em; }

#join-form label { display: block; font-weight: 700; margin-bottom: 8px; }
.name-row { display: flex; gap: 8px; margin-bottom: 14px; }
.name-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.1rem;
  padding: 11px 14px;
  border-radius: 12px;
  border: 2px solid var(--card-line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}
.name-row input:focus { border-color: var(--accent); outline: none; }
.name-row .btn { font-size: 1.3rem; padding: 6px 14px; }

.error { color: #ff9a9d; min-height: 1.2em; margin: 12px 0 0; font-weight: 700; }

.howto { text-align: left; margin-top: 14px; color: var(--muted); }
.howto summary { cursor: pointer; font-weight: 700; color: var(--text); }
.howto ol { padding-left: 20px; line-height: 1.5; }

/* ---------- Lobby ---------- */

.lobby { max-width: 560px; margin: 4vh auto 0; text-align: center; }
.welcome-line { margin: 0 0 18px; }
.lobby h3 { margin-top: 24px; text-align: left; }

.waiting { list-style: none; padding: 0; margin: 0 0 14px; text-align: left; }
.waiting li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 8px;
  animation: pop 0.25s ease-out;
}
.waiting li .who { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.waiting li.empty { display: block; color: var(--muted); font-style: italic; background: none; border: 2px dashed var(--card-line); }

/* ---------- Game header ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  max-width: 1000px;
  margin: 0 auto;
}
.versus { font-size: 1.15rem; font-weight: 800; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.versus .me { color: var(--accent); }
.versus .vs { color: var(--muted); font-size: 0.85rem; font-style: italic; }
.tools { display: flex; align-items: center; gap: 8px; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.quiet { background: var(--warn); animation: blink 1s infinite; }
.dot.left { background: #555; }

.banner {
  max-width: 1000px;
  margin: 12px auto;
  padding: 12px 18px;
  border-radius: 14px;
  text-align: center;
  font-weight: 800;
  font-size: 1.1rem;
  background: var(--card);
  border: 1px solid var(--card-line);
  min-height: 1.3em;
  transition: background 0.2s;
}
.banner.go { background: linear-gradient(90deg, #1c9b57, var(--good)); color: #03220f; border-color: transparent; animation: pulse 1.6s ease-in-out infinite; }
.banner.hit { background: linear-gradient(90deg, #d63d16, var(--hit)); border-color: transparent; }
.banner.ouch { background: linear-gradient(90deg, #8c1d2a, #c0392b); border-color: transparent; }
.banner.miss { background: linear-gradient(90deg, #135b8c, #2a8bc9); border-color: transparent; }
.banner.good { background: linear-gradient(90deg, #b8860b, var(--accent)); color: #241a00; border-color: transparent; }
.banner.bad { background: linear-gradient(90deg, #5b2333, #7d2f45); border-color: transparent; }

.claim {
  max-width: 1000px;
  margin: 0 auto 12px;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(255, 176, 32, 0.15);
  border: 1px solid var(--warn);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- Game over ---------- */

.over { max-width: 620px; margin: 0 auto 16px; text-align: center; padding: 18px 22px; }
.over.won { border-color: var(--accent); box-shadow: 0 0 40px rgba(255, 204, 51, 0.25); }
.over-emoji { font-size: 60px; line-height: 1; animation: bounce 1s ease-in-out infinite; }
.over h2 { font-size: 2rem; font-weight: 900; margin: 6px 0; letter-spacing: 0.05em; }
.over.won h2 { color: var(--accent); }
.over p { margin: 6px 0; }
.over-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ---------- Layout ---------- */

.layout {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 18px 32px;
  max-width: 1000px;
  margin: 0 auto;
}
.board-wrap { display: flex; flex-direction: column; align-items: center; }
.side { width: min(300px, 100%); }
.dock { width: min(300px, 100%); display: flex; flex-direction: column; gap: 12px; }

/* ---------- Boards ---------- */

.board {
  --cell: 30px;
  display: grid;
  grid-template-columns: repeat(11, var(--cell));
  grid-template-rows: repeat(11, var(--cell));
  gap: 2px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.board.big { --cell: min(36px, calc((100vw - 48px) / 11.4), calc((100vh - 200px) / 11.4)); }
.board.small { --cell: min(24px, calc((100vw - 48px) / 11.4)); }
#place-board.big { --cell: min(38px, calc((100vw - 48px) / 11.4)); }

.label {
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * 0.42);
  font-weight: 800;
  color: var(--muted);
}

.cell {
  position: relative;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--sea1), var(--sea2));
  box-shadow: inset 0 0 0 1px var(--grid);
  transition: background 0.15s;
}
.cell::before,
.cell::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * 0.62);
  line-height: 1;
  pointer-events: none;
}

/* Ships */
.cell.ship {
  background: linear-gradient(180deg, var(--ship1), var(--ship2));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  border-radius: 3px;
}
.cell.ship.h.bow { border-radius: 45% 3px 3px 45%; }
.cell.ship.h.stern { border-radius: 3px 25% 25% 3px; }
.cell.ship.v.bow { border-radius: 45% 45% 3px 3px; }
.cell.ship.v.stern { border-radius: 3px 3px 25% 25%; }
.cell.ship.h.bow.stern, .cell.ship.v.bow.stern { border-radius: 40%; }
.cell[data-icon]::before { content: attr(data-icon); }
.cell.ship.revealed:not(.sunk) { background: linear-gradient(180deg, #f3d9a4, #b3925a); opacity: 0.9; }

/* Shots */
.cell.miss::after {
  content: "";
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 15%, rgba(255, 255, 255, 0.18) 16% 27%, transparent 28%);
}
.cell.hit { background: linear-gradient(180deg, #ff9a5a, #c5361b); }
.cell.ship.hit { background: linear-gradient(180deg, #ffb37a, #c5361b); }
.cell.hit::after { content: "🔥"; animation: flicker 0.9s ease-in-out infinite alternate; }
.cell.sunk { background: linear-gradient(180deg, #4b3a3a, #231818) !important; }
.cell.sunk::after { content: "💀"; animation: none; font-size: calc(var(--cell) * 0.5); }
.cell.sunk::before { opacity: 0.35; }

/* Placement preview */
.cell.pv-ok { background: linear-gradient(180deg, #5fe39e, #23a862); box-shadow: inset 0 0 0 2px #b9ffd8; }
.cell.pv-bad { background: linear-gradient(180deg, #ff7a7e, #c9343a); box-shadow: inset 0 0 0 2px #ffc9cb; }
#place-board .cell { cursor: pointer; }

/* Your turn: aim! */
.board.armed .cell.open { cursor: crosshair; }
.board.armed .cell.open:hover { background: linear-gradient(135deg, #3aa3e6, #2183c4); box-shadow: inset 0 0 0 2px var(--accent); }
.board.armed .cell.open:hover::after { content: "🎯"; }
.board.armed { filter: drop-shadow(0 0 14px rgba(255, 204, 51, 0.35)); }
.board.dim { opacity: 0.75; filter: saturate(0.75); }

/* Effects */
.fx { position: absolute; pointer-events: none; z-index: 3; }
.fx.boom {
  inset: -60%;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0, #ffe066 20%, #ff7b00 42%, rgba(255, 60, 0, 0) 68%);
  animation: boom 0.65s ease-out forwards;
}
.fx.splash {
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  animation: splash 0.75s ease-out forwards;
}
.shake { animation: shake 0.5s; }

/* ---------- Shipyard (placement) ---------- */

.dock-list { list-style: none; padding: 0; margin: 0; }
.dock-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  margin-bottom: 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  cursor: pointer;
}
.dock-list li:hover { background: rgba(255, 255, 255, 0.11); }
.dock-list li.selected { border-color: var(--accent); background: rgba(255, 204, 51, 0.12); }
.dock-list li.placed { opacity: 0.6; }
.dock-list .icon { font-size: 1.3rem; }
.dock-list .name { flex: 1; font-weight: 700; }
.dock-list .pips, .fleet-status .pips { color: var(--ship2); letter-spacing: 1px; font-size: 0.75rem; }
.dock-list .tick { color: var(--good); width: 1em; }
.dock-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Battle side panel ---------- */

.fleet-status { list-style: none; padding: 0; margin: 0 0 8px; }
.fleet-status li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.fleet-status .name { flex: 1; }
.fleet-status li.sunk .name { text-decoration: line-through; color: var(--muted); }
.fleet-status li.sunk .icon { filter: grayscale(1); opacity: 0.5; }
.fleet-status .tag { font-size: 0.7rem; font-weight: 800; background: var(--bad); color: #fff; padding: 2px 6px; border-radius: 6px; }

.log {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.9rem;
}
.log li { padding: 6px 8px; border-radius: 8px; margin-bottom: 4px; background: rgba(255, 255, 255, 0.05); animation: pop 0.25s ease-out; }
.log li.hit { background: rgba(255, 106, 61, 0.18); }
.log li.ouch { background: rgba(192, 57, 43, 0.25); }
.log li.good { background: rgba(255, 204, 51, 0.2); }
.log .coord { display: inline-block; font-weight: 800; font-size: 0.75rem; padding: 1px 6px; border-radius: 6px; margin-right: 6px; }
.log .coord.me { background: var(--accent); color: #231a00; }
.log .coord.opp { background: #c0392b; color: #fff; }

.taunt-bar { margin-top: 12px; width: 100%; max-width: 440px; text-align: center; }
.taunts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; animation: pop 0.2s ease-out; }
.chip.toggle { font-size: 0.9rem; padding: 7px 14px; }
.chip.toggle.open { background: rgba(255, 204, 51, 0.18); border-color: var(--accent); }
.chip {
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-line);
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
}
.chip:hover { background: rgba(255, 255, 255, 0.16); }
.chip:active { transform: scale(0.96); }

/* ---------- Pop-ups ---------- */

.bubble {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: #fff;
  color: #10233a;
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 1.05rem;
  max-width: calc(100vw - 32px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 30px;
  border: 10px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
}
.bubble.pop { animation: pop 0.3s ease-out; }

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 60;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  background: #10233a;
  border: 1px solid var(--card-line);
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: pop 0.25s ease-out;
  transition: opacity 0.4s, transform 0.4s;
  text-align: center;
}
.toast.warn { border-color: var(--warn); }
.toast.bad { border-color: var(--bad); }
.toast.good { border-color: var(--good); }
.toast.me { border-color: var(--accent); color: var(--accent); }
.toast.out { opacity: 0; transform: translateY(10px); }

.net {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 60;
  background: #5b2333;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  animation: blink 1.2s infinite;
}

.rain { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.rain span { position: absolute; top: -50px; animation-name: fall; animation-timing-function: linear; animation-fill-mode: forwards; }
.rain.up span { top: auto; bottom: -50px; animation-name: rise; }

/* Decorative waves along the bottom */
.waves {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 46px;
  pointer-events: none;
  z-index: -1;
  opacity: 0.35;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='46' viewBox='0 0 120 46'%3E%3Cpath d='M0 20 Q30 0 60 20 T120 20 V46 H0 Z' fill='%231f86c7'/%3E%3C/svg%3E") repeat-x;
  background-size: 120px 46px;
  animation: waves 8s linear infinite;
}

/* ---------- Animations ---------- */

@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(54, 210, 127, 0.5); } 50% { box-shadow: 0 0 0 8px rgba(54, 210, 127, 0); } }
@keyframes blink { 50% { opacity: 0.4; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes flicker { from { transform: scale(0.9) rotate(-4deg); } to { transform: scale(1.08) rotate(4deg); } }
@keyframes boom { from { transform: scale(0.2); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
@keyframes splash { from { transform: scale(0.2); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }
@keyframes fall { to { transform: translateY(115vh) rotate(540deg); } }
@keyframes rise { to { transform: translateY(-115vh) rotate(-30deg); } }
@keyframes waves { from { background-position-x: 0; } to { background-position-x: 120px; } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  .screen { padding: 12px; }
  .card { padding: 18px; }
  .banner { font-size: 1rem; }
  .side, .dock { width: 100%; }
  .side .board.small { margin: 0 auto; }
}
