/* Battleship — storybook seaside: sky header, living sea board, sandy deck. */

:root {
  --ink: #1b3a5b;
  --ink-soft: #3a5a7c;
  --sky1: #cdefff;
  --sky2: #eaf8ff;
  --sea1: #4fb3e8;
  --sea2: #2e8fcb;
  --sea-deep: #1e6fa8;
  --foam: #f4fbff;
  --sand1: #f6dfa4;
  --sand2: #efcb7f;
  --coral: #f2653f;
  --coral-dark: #d24a27;
  --sun: #ffc94d;
  --ok: #2fa46a;
  --ok-dark: #1f7d4e;
  --hull: #5a6b7c;
  --display: "Fredoka", "Comic Sans MS", system-ui, sans-serif;
  --body: "Nunito", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background: linear-gradient(to bottom, var(--sky1), var(--sky2) 45%, #d8f1fd);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Header (sky) ---------- */

.sky {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.6rem 1rem 0.4rem;
}

.brand { display: flex; align-items: center; gap: 0.5rem; }

.brand-anchor { width: 2rem; height: 2rem; color: var(--coral); }

.brand h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
}

.status-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--foam);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.05rem;
}

.fleet-chip svg { width: 1.6rem; height: 1.2rem; }
.fleet-boat { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.fleet-boat.sunk { opacity: 0.35; }
.fleet-boat-len { font-size: 0.6rem; font-weight: 800; color: var(--ink-soft); margin-top: 0.05rem; }
.shot-chip svg { width: 1.1rem; height: 1.1rem; }

.grownup-btn {
  font-family: var(--body);
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: transparent;
  border: 2px dashed var(--ink-soft);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  opacity: 0.7;
}
.grownup-btn:hover { opacity: 1; }

/* ---------- Main / screens ---------- */

#main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0.4rem 0.6rem 1rem;
  width: 100%;
}

/* During play, lock the page to the viewport so the FIRE deck never
   needs scrolling; the board scales down to the space that remains. */
body.phase-play { height: 100dvh; overflow: hidden; }
body.phase-play #main { padding-bottom: 0.2rem; }
body.phase-play #screen-play { flex: 1; min-height: 0; }
body.phase-play #screen-play .board-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 40rem;
}
body.phase-play #screen-play .board-wrap svg {
  width: 100%;
  height: 100%;
}

.screen { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.screen[hidden] { display: none; }

.card {
  background: var(--foam);
  border: 3px solid var(--ink);
  border-radius: 1.2rem;
  box-shadow: 0 6px 0 rgba(27, 58, 91, 0.18);
  padding: 1rem 1.3rem;
}

/* ---------- Welcome ---------- */

.welcome-card { text-align: center; max-width: 22rem; margin-top: 8vh; }
.welcome-card h2 { font-family: var(--display); margin: 0.4rem 0 0.2rem; }
.welcome-card p { margin: 0 0 1rem; font-weight: 700; color: var(--ink-soft); }
.welcome-boat { width: 8rem; }

/* ---------- Setup ---------- */

#screen-setup { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-start; }

.setup-panel { max-width: 20rem; }
.setup-panel h2 { font-family: var(--display); margin: 0 0 0.6rem; font-size: 1.3rem; }

.steppers { display: flex; gap: 1rem; flex-wrap: wrap; }

.stepper-label { font-weight: 800; font-size: 0.95rem; display: block; margin-bottom: 0.25rem; }
.stepper-label small { color: var(--ink-soft); font-weight: 700; }

.stepper-ctrl { display: flex; align-items: center; gap: 0.4rem; }

.step-btn {
  width: 2.4rem; height: 2.4rem;
  font-family: var(--display);
  font-size: 1.4rem; font-weight: 700;
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 0.8rem;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(27,58,91,0.25);
}
.step-btn:active { transform: translateY(2px); box-shadow: none; }

.step-val {
  font-family: var(--display);
  font-size: 1.5rem; font-weight: 700;
  min-width: 2ch; text-align: center;
}

.setup-hint { font-weight: 700; color: var(--ink-soft); font-size: 0.9rem; }

.fleet-summary { display: flex; flex-wrap: wrap; gap: 0.4rem; min-height: 1.8rem; }
.fleet-pill {
  font-family: var(--display); font-weight: 600; font-size: 0.9rem;
  border: 2px solid var(--ink); border-radius: 999px;
  padding: 0.1rem 0.6rem; background: #fff;
}

.setup-error { color: var(--coral-dark); font-weight: 800; margin: 0.4rem 0 0; }

.setup-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; }

.big-btn {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2rem;
  padding: 0.55rem 1.6rem;
  border-radius: 1rem;
  border: 3px solid var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(27,58,91,0.25);
  color: #fff;
}
.big-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.big-btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }

.ok-btn { background: var(--ok); }
.ok-btn:hover:not(:disabled) { background: var(--ok-dark); }
.clear-btn { background: var(--ink-soft); }

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

.board-wrap {
  width: 100%;
  max-width: min(92vw, 62vh, 40rem);
  margin: 0 auto;
}

.board-wrap svg { width: 100%; height: auto; display: block; }

.hdr-btn { cursor: pointer; }
.hdr-btn rect {
  fill: var(--foam);
  stroke: var(--ink);
  stroke-width: 3;
  transition: fill 120ms;
}
.hdr-btn text {
  font-family: var(--display);
  font-weight: 700;
  fill: var(--ink);
  pointer-events: none;
}
.hdr-btn:hover rect { fill: #fff3d6; }
.hdr-btn.selected rect { fill: var(--sun); }
.hdr-btn:focus-visible rect { stroke: var(--coral); stroke-width: 5; }
.hdr-btn.static { cursor: default; }
.hdr-btn.static rect { fill: rgba(244, 251, 255, 0.65); }

.beam { pointer-events: none; }

.target-ring {
  animation: spin 5s linear infinite;
  transform-origin: center;
  transform-box: fill-box;
}

@keyframes spin { to { transform: rotate(360deg); } }

.cell-wave { animation: bob 3.2s ease-in-out infinite; }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2.5px); }
}

.shot-icon.fresh { animation: pop 400ms cubic-bezier(0.2, 1.6, 0.4, 1); transform-origin: center; transform-box: fill-box; }

@keyframes pop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* Top-down reveal: the wreck looms up from the deep, then settles. */
.ship-reveal { animation: sink-in 1100ms ease-out; transform-origin: center; transform-box: fill-box; }

@keyframes sink-in {
  0% { opacity: 0; transform: scale(1.18); }
  55% { opacity: 1; transform: scale(0.98); }
  80% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.paint-cell { cursor: pointer; }

/* ---------- Deck (sand footer) ---------- */

.deck { color: var(--sand1); margin-top: auto; }
.deck[hidden] { display: none; }

.deck-wave { display: block; width: 100%; height: 1.2rem; }

.deck-inner {
  background: linear-gradient(to bottom, var(--sand1), var(--sand2));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 0.5rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
}

.readout {
  font-family: var(--display);
  font-weight: 700;
  font-size: 2.6rem;
  min-width: 4.2ch;
  text-align: center;
  background: var(--foam);
  border: 3px solid var(--ink);
  border-radius: 1rem;
  padding: 0.1rem 0.8rem;
  line-height: 1.2;
}
.readout .readout-letter { color: var(--sea-deep); }
.readout .readout-number { color: var(--coral-dark); }
.readout.wiggle { animation: wiggle 400ms ease-in-out; }

@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-4deg); }
  75% { transform: rotate(4deg); }
}

.fire-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--display);
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 0.05em;
  color: #fff;
  background: linear-gradient(to bottom, var(--coral), var(--coral-dark));
  border: 4px solid var(--ink);
  border-radius: 1.4rem;
  padding: 0.5rem 1.8rem;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(27,58,91,0.3);
}
.fire-btn svg { width: 1.8rem; height: 1.8rem; color: var(--sun); }
.fire-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: none; }
.fire-btn:disabled { filter: grayscale(0.9); opacity: 0.5; cursor: default; box-shadow: none; }

/* ---------- PIN modal ---------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(27, 58, 91, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
}
.modal[hidden] { display: none; }

.modal-card { position: relative; text-align: center; padding: 1.2rem 1.6rem; }
.modal-card h2 { font-family: var(--display); margin: 0 0 0.6rem; font-size: 1.2rem; }

.modal-close {
  position: absolute; top: 0.4rem; right: 0.6rem;
  background: none; border: none; font-size: 1.2rem;
  color: var(--ink-soft); cursor: pointer; font-weight: 800;
}

.pin-dots { display: flex; justify-content: center; gap: 0.6rem; margin-bottom: 0.8rem; }
.pin-dots i {
  width: 0.9rem; height: 0.9rem; border-radius: 50%;
  border: 3px solid var(--ink); background: transparent;
}
.pin-dots i.filled { background: var(--ink); }
.pin-dots.shake { animation: wiggle 300ms ease-in-out 2; }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 3.4rem);
  gap: 0.5rem;
  justify-content: center;
}
.pin-pad button {
  font-family: var(--display);
  font-size: 1.4rem; font-weight: 600;
  height: 3.1rem;
  border: 3px solid var(--ink);
  border-radius: 0.9rem;
  background: var(--foam);
  color: var(--ink);
  cursor: pointer;
}
.pin-pad button:active { background: var(--sun); }

/* ---------- Victory ---------- */

.victory {
  position: fixed; inset: 0;
  background: rgba(15, 40, 70, 0.15);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
.victory[hidden] { display: none; }

.victory-card {
  text-align: center; z-index: 2; padding: 1.6rem 2.2rem;
  background: rgba(0, 0, 0, 0.25);
  border-color: var(--foam);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}
.victory-card h2 {
  font-family: var(--display);
  font-size: 2rem; margin: 0 0 0.4rem;
  color: var(--sun);
}
.victory-card p { font-weight: 800; font-size: 1.1rem; margin: 0 0 1rem; color: #fff; }
.victory-card .ok-btn { color: #fff; border-color: var(--foam); }

.fireworks { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.fireworks svg { position: absolute; width: 10rem; height: 10rem; }
.fw-burst { animation: burst 1.6s ease-out infinite; transform-origin: center; }
.fw-burst line { stroke-linecap: round; }

@keyframes burst {
  0% { transform: scale(0.1); opacity: 0; }
  15% { opacity: 1; }
  70% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.25); opacity: 0; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .cell-wave, .fw-burst, .shot-icon.fresh, .ship-reveal,
  .target-ring, .readout.wiggle, .pin-dots.shake { animation: none; }
}

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

@media (max-width: 480px) {
  .brand h1 { font-size: 1.2rem; }
  .readout { font-size: 2rem; }
  .fire-btn { font-size: 1.5rem; padding: 0.45rem 1.2rem; }
  #screen-setup { flex-direction: column; align-items: center; }
}
