* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

:root {
  --sea: #bfe3f2;
  --sea-deep: #9fd4ea;
  --card: #ffffff;
  --ink: #2b3a4a;
  --accent: #ff8fab;
  --accent-dark: #e05780;
  --ok: #43aa8b;
  --cell: clamp(26px, 8.2vw, 42px);
}

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #d8f0fa 0%, var(--sea) 45%, #a5d8ee 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
}

header { text-align: center; margin: 8px 0 4px; }
h1 { font-size: clamp(1.4rem, 5vw, 2.2rem); text-shadow: 2px 2px 0 #fff; }
.tagline { color: #5b7286; font-size: .95rem; margin-top: 2px; }

main { width: 100%; max-width: 900px; display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 10px; }

.card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 6px 18px rgba(43, 58, 74, .15);
  padding: 20px;
  width: 100%;
  max-width: 520px;
}

.card-inner { background: #f4f9fc; border-radius: 12px; padding: 14px 16px; margin-top: 18px; }
.rules h3 { margin-bottom: 8px; }
.rules ul { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }

label { display: block; font-weight: bold; margin-bottom: 6px; }

input[type=text] {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 2px solid var(--sea-deep);
  border-radius: 10px;
  margin-bottom: 12px;
}
input[type=text]:focus { outline: none; border-color: var(--accent); }

button {
  font: inherit;
  font-weight: bold;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--sea-deep);
  border-radius: 12px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform .08s, background .15s;
}
button:hover:not(:disabled) { transform: translateY(-2px); }
button:disabled { opacity: .45; cursor: not-allowed; }

button.big {
  display: block;
  width: 100%;
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
  font-size: 1.15rem;
  padding: 12px;
  border-radius: 14px;
}
button.big:hover:not(:disabled) { background: var(--accent-dark); }

.invite {
  background: #fff3cd;
  border: 2px dashed #e0b74f;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  text-align: center;
}

.error { color: #c0392b; margin-top: 10px; font-weight: bold; }
.hint { font-size: .85rem; color: #5b7286; margin-top: 10px; }

/* share bar */
.share { text-align: center; }
.share-row { display: flex; gap: 8px; margin: 10px 0; }
.share-row input { flex: 1; margin: 0; font-size: .85rem; }
.waiting { color: #5b7286; font-size: .9rem; }

.dots::after { content: ''; animation: dots 1.5s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* grids */
.grid-holder { display: inline-block; position: relative; }

/* cheese-throwing mouse */
.mouse {
  position: absolute;
  top: -4px;
  left: -6px;
  font-size: 1.5rem;
  z-index: 5;
  transform: scaleX(-1);
  filter: drop-shadow(1px 2px 1px rgba(43,58,74,.3));
}
.mouse.throwing { animation: mousethrow .45s ease-out; }
@keyframes mousethrow {
  0%   { transform: scaleX(-1) rotate(0deg); }
  30%  { transform: scaleX(-1) rotate(-25deg) translateY(-4px); }
  60%  { transform: scaleX(-1) rotate(15deg) scale(1.15); }
  100% { transform: scaleX(-1) rotate(0deg); }
}
.cheese {
  position: absolute;
  z-index: 70;
  font-size: 1.5rem;
  pointer-events: none;
  filter: drop-shadow(1px 2px 2px rgba(43,58,74,.35));
}
.cheese-pop {
  position: absolute;
  z-index: 70;
  font-size: 1.3rem;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: cheesepop .35s ease-out forwards;
}
@keyframes cheesepop {
  0%   { opacity: 1; transform: translate(-50%,-50%) scale(.5); }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.8); }
}
.grid {
  display: grid;
  grid-template-columns: calc(var(--cell) * .7) repeat(10, var(--cell));
  user-select: none;
  -webkit-user-select: none;
}
.glabel {
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell) * .38);
  font-weight: bold; color: #4a6b80;
  height: var(--cell);
}
.glabel.corner { height: calc(var(--cell) * .7); }
.grid .glabel.col { height: calc(var(--cell) * .7); }

.cell {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid rgba(74, 107, 128, .35);
  background: linear-gradient(180deg, #d4ecf7, var(--sea-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * .62);
  line-height: 1;
  position: relative;
  cursor: default;
}
.cell.clickable { cursor: pointer; }
.cell.clickable:hover { filter: brightness(1.12); }

.cell.cat-pikk  { background: #ffe8a3; }
.cell.cat-nyan  { background: linear-gradient(135deg, #ffd1dc, #d3c1f5, #bfe6ff); }
.cell.cat-pahur { background: #ddd0bd; }
.cell.cat-kiisu { background: #ffd6e8; }

.cell.preview-ok  { background: #b8e6c9 !important; }
.cell.preview-bad { background: #f5b7b1 !important; }

.cell.hit  { background: #ffb499 !important; }
.cell.sunkcell { background: #f1948a !important; }
.cell.miss .splash { opacity: .8; font-size: calc(var(--cell) * .42); }

/* placement layout */
#screen-place { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
#screen-place h2 { text-shadow: 1px 1px 0 #fff; }
.place-wrap { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: flex-start; }
.place-side { display: flex; flex-direction: column; gap: 10px; min-width: 230px; max-width: 300px; }

.fleet { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.fleet li {
  background: var(--card);
  border: 2px solid var(--sea-deep);
  border-radius: 10px;
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .95rem;
}
.fleet li.selected { border-color: var(--accent-dark); background: #ffeef4; }
.fleet li.done { opacity: .5; text-decoration: line-through; cursor: default; }
.fleet .cnt { font-weight: bold; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row button { flex: 1; white-space: nowrap; font-size: .85rem; }

/* battle */
#screen-battle { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.banner {
  font-size: 1.15rem; font-weight: bold; text-align: center;
  background: var(--card); border-radius: 14px; padding: 10px 22px;
  box-shadow: 0 4px 12px rgba(43,58,74,.15);
}
.banner.your-turn { background: #d5f5e3; border: 2px solid var(--ok); }
.banner.their-turn { background: #fdebd0; border: 2px solid #e0b74f; }

.battle-wrap { display: flex; flex-wrap: wrap; gap: 22px; justify-content: center; }
.board-block { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.board-block h3 { text-shadow: 1px 1px 0 #fff; font-size: 1rem; }

.score-card {
  padding: 14px 20px;
  max-width: 640px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 14px 30px;
  justify-content: space-around;
  font-size: .85rem;
}
.score-side { flex: 1 1 240px; min-width: 220px; max-width: 300px; }
.score-side h4 { font-size: .9rem; margin-bottom: 4px; }
.score-side h4 b { color: var(--accent-dark); }
.score-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 1px 0; }
.score-row.allgone span:first-child { text-decoration: line-through; opacity: .55; }
.pip { margin-left: 2px; }
.pip.down { filter: grayscale(1); opacity: .5; }

.log {
  max-width: 640px; max-height: 160px; overflow-y: auto;
  font-size: .85rem; padding: 12px 16px;
  display: flex; flex-direction: column-reverse; gap: 3px;
}

/* overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(43, 58, 74, .55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.overlay-box { text-align: center; max-width: 420px; }
.end-emoji { font-size: 4rem; animation: bounce 1s infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-12px); } }
.overlay-box h2 { margin: 10px 0 6px; }
.overlay-box p { margin-bottom: 16px; }

.confetti-cat {
  position: fixed; top: -10vh; z-index: 60; pointer-events: none;
  animation: fall linear forwards;
  font-size: 2rem;
}
@keyframes fall { to { transform: translateY(115vh) rotate(360deg); } }

/* toasts */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 40; align-items: center; }
.toast {
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 8px 18px; font-size: .95rem;
  animation: toastin .2s ease-out, toastout .4s ease-in 2.4s forwards;
  white-space: nowrap;
}
@keyframes toastin { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastout { to { opacity: 0; transform: translateY(10px); } }

footer { margin: 24px 0 10px; color: #5b7286; font-size: .8rem; text-align: center; }

@media (max-width: 720px) {
  .battle-wrap { gap: 14px; }
  :root { --cell: clamp(24px, 8.6vw, 36px); }
}
