/* Game Table: soft pastel, calm, rounded. Original artwork, all drawn in CSS/SVG. */
@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --ink: #3d3553;
  --ink-soft: #736b8a;
  --cream: #fffaf6;
  --card: #fffaf6;
  --line: rgba(61, 53, 83, 0.08);
  --coral: #ff8f7a;
  --coral-deep: #ef6f5b;
  --butter: #ffd37a;
  --mint: #8fdcb5;
  --lilac: #b9a4f0;
  --sky: #8ec5ff;
  --sea-hi: #a8e3e0;
  --sea: #7fcad0;
  --sea-deep: #5aa9bf;
  --shadow-soft: 0 18px 40px -22px rgba(73, 52, 110, 0.45), 0 2px 6px rgba(73, 52, 110, 0.06);
  --shadow-pop: 0 10px 0 -2px rgba(73, 52, 110, 0.12), 0 22px 40px -18px rgba(73, 52, 110, 0.5);
  --radius: 26px;
  --top-h: 64px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #fde9e1 0%, #f3e3f4 38%, #e3e6fb 68%, #dcf2ee 100%);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- background sky ---------- */
.sky { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; opacity: 0.55; }
.b1 { width: 46vw; height: 46vw; left: -10vw; top: -14vw; background: radial-gradient(circle, #ffd6c9 0%, transparent 68%); }
.b2 { width: 50vw; height: 50vw; right: -14vw; top: 10vh; background: radial-gradient(circle, #d6cdfa 0%, transparent 66%); }
.b3 { width: 44vw; height: 44vw; left: 22vw; bottom: -26vw; background: radial-gradient(circle, #c9efe4 0%, transparent 66%); }
.isle { position: absolute; width: 120px; opacity: 0.8; animation: drift 14s ease-in-out infinite alternate; }
.i1 { left: 5vw; bottom: 9vh; }
.i2 { right: 6vw; top: 14vh; width: 90px; animation-duration: 18s; animation-delay: -6s; }
@keyframes drift { from { transform: translateY(0); } to { transform: translateY(-14px); } }

/* ---------- top bar ---------- */
.top {
  height: var(--top-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 22px; letter-spacing: 0.2px; }
.brand-mark { width: 40px; height: 40px; filter: drop-shadow(0 4px 6px rgba(160, 100, 120, 0.25)); }
.top-mid { flex: 1; display: flex; justify-content: center; }
.top-right { display: flex; gap: 10px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 16px; border: 0; cursor: pointer;
  background: var(--cream); box-shadow: var(--shadow-soft);
  display: grid; place-items: center; transition: transform 0.2s var(--ease-spring);
}
.icon-btn:active { transform: scale(0.92); }
.i-sound { width: 24px; height: 24px; background: var(--ink-soft);
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 9h4l5-4v14l-5-4H4z" fill="black"/><path d="M17 8l5 8M22 8l-5 8" stroke="black" stroke-width="2" stroke-linecap="round"/></svg>') center/contain no-repeat;
          mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 9h4l5-4v14l-5-4H4z" fill="black"/><path d="M17 8l5 8M22 8l-5 8" stroke="black" stroke-width="2" stroke-linecap="round"/></svg>') center/contain no-repeat; }
.icon-btn[aria-pressed="true"] .i-sound { background: var(--coral-deep);
  -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 9h4l5-4v14l-5-4H4z" fill="black"/><path d="M16 9a4 4 0 0 1 0 6M19 6a8 8 0 0 1 0 12" stroke="black" stroke-width="2" fill="none" stroke-linecap="round"/></svg>');
          mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 9h4l5-4v14l-5-4H4z" fill="black"/><path d="M16 9a4 4 0 0 1 0 6M19 6a8 8 0 0 1 0 12" stroke="black" stroke-width="2" fill="none" stroke-linecap="round"/></svg>'); }

.code-chip {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 18px; border-radius: 999px; background: var(--cream); box-shadow: var(--shadow-soft);
  font-size: 18px; color: var(--ink-soft);
}
.code-chip b { color: var(--ink); font-weight: 600; letter-spacing: 1.5px; font-size: 20px; }
.code-chip .score { background: #f3ecfb; border-radius: 999px; padding: 4px 12px; font-size: 16px; color: var(--ink); }

/* ---------- generic ---------- */
main { min-height: calc(100vh - var(--top-h)); outline: none; }
.btn {
  border: 0; cursor: pointer; border-radius: 20px; padding: 0 26px; min-height: 60px;
  font-size: 21px; font-weight: 600; color: #fff;
  background: linear-gradient(180deg, #ffa08c, var(--coral-deep));
  box-shadow: 0 6px 0 #d45a48, 0 16px 26px -12px rgba(212, 90, 72, 0.7);
  transition: transform 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #d45a48, 0 8px 16px -10px rgba(212, 90, 72, 0.7); }
.btn.soft { background: var(--cream); color: var(--ink); box-shadow: 0 6px 0 #e4dbe9, 0 16px 26px -14px rgba(73, 52, 110, 0.45); }
.btn.soft:active { box-shadow: 0 2px 0 #e4dbe9; }
.btn.mint { background: linear-gradient(180deg, #a6e8c6, #6fcf9f); box-shadow: 0 6px 0 #53b083, 0 16px 26px -12px rgba(83, 176, 131, 0.7); color: #1f4a37; }
.btn.lilac { background: linear-gradient(180deg, #cbbaf7, #9f86ea); box-shadow: 0 6px 0 #8069cf, 0 16px 26px -12px rgba(128, 105, 207, 0.7); }
.btn.small { min-height: 50px; font-size: 18px; padding: 0 18px; border-radius: 16px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-soft); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 140%);
  background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 18px; font-size: 18px;
  transition: transform 0.35s var(--ease-spring); z-index: 50; max-width: 80vw; text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- lobby ---------- */
.lobby { max-width: 1180px; margin: 0 auto; padding: 18px 28px 40px; text-align: center; }
.hero h1 { font-size: 58px; margin: 6px 0 4px; font-weight: 600; letter-spacing: -0.5px; }
.hero p { font-size: 22px; color: var(--ink-soft); margin: 0 0 30px; }
.games { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; }
.game-card {
  border: 0; text-align: left; cursor: pointer; padding: 0; overflow: hidden; position: relative;
  background: var(--card); border-radius: 30px; box-shadow: var(--shadow-pop);
  transition: transform 0.35s var(--ease-spring);
}
.game-card:hover { transform: translateY(-6px) rotate(-0.4deg); }
.game-card:active { transform: scale(0.97); }
.game-card .art { height: 230px; display: grid; place-items: center; }
.game-card .info { padding: 18px 24px 24px; }
.game-card h2 { margin: 0 0 6px; font-size: 30px; font-weight: 600; }
.game-card p { margin: 0; color: var(--ink-soft); font-size: 18px; line-height: 1.35; }
.game-card.soon { cursor: default; }
.game-card.soon:hover { transform: none; }
.game-card.soon .art { filter: saturate(0.6); opacity: 0.8; }
.ribbon { position: absolute; top: 18px; right: 18px; background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 15px; color: var(--ink-soft); box-shadow: var(--shadow-soft); }
.ribbon.live { background: var(--mint); color: #1f4a37; }
.art.sea { background: linear-gradient(180deg, #c7ecf0, #8fd0d6); }
.art.chess { background: linear-gradient(180deg, #f9e3d3, #ecc8b4); }
.art.words { background: linear-gradient(180deg, #f6edc9, #ebd9a0); }
.art svg { width: 78%; height: 88%; overflow: visible; }
.bob { animation: bob 3.2s ease-in-out infinite; transform-origin: 50% 80%; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-1.2deg); } 50% { transform: translateY(-5px) rotate(1.2deg); } }
.wave { animation: wave 4s ease-in-out infinite alternate; }
@keyframes wave { from { transform: translateX(-8px); } to { transform: translateX(8px); } }

/* ---------- modal / setup sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(61, 53, 83, 0.28); display: grid; place-items: center; z-index: 30; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: min(760px, calc(100% - 24px)); padding: 30px 34px 34px; text-align: center; animation: rise 0.45s var(--ease-spring); }
@keyframes rise { from { transform: translateY(40px) scale(0.96); opacity: 0; } }
.sheet h2 { margin: 0 0 6px; font-size: 34px; font-weight: 600; }
.sheet p.sub { margin: 0 0 22px; color: var(--ink-soft); font-size: 19px; }
.players { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
.player-pick {
  border: 3px solid transparent; background: #f8f1f6; border-radius: 22px; padding: 12px 6px 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 18px;
  transition: transform 0.25s var(--ease-spring), border-color 0.2s;
}
.player-pick .face { font-size: 42px; width: 66px; height: 66px; border-radius: 50%; display: grid; place-items: center; }
.player-pick[aria-pressed="true"] { border-color: var(--coral); background: #fff; transform: translateY(-4px); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.choices .btn { width: 100%; }
.choices .full { grid-column: 1 / -1; }
.join-row { display: flex; gap: 12px; margin-top: 6px; }
.code-input {
  flex: 1; min-height: 64px; border-radius: 20px; border: 3px solid #eadff0; background: #fff;
  font: inherit; font-size: 28px; text-align: center; letter-spacing: 3px; text-transform: uppercase; color: var(--ink);
  outline: none; user-select: text;
}
.code-input:focus { border-color: var(--lilac); }
.link-btn { background: none; border: 0; color: var(--ink-soft); font-size: 17px; cursor: pointer; margin-top: 16px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- room layout ---------- */
.room {
  height: calc(100vh - var(--top-h));
  min-height: 600px;
  display: grid; grid-template-columns: 360px 1fr; gap: 22px;
  padding: 4px 26px 20px;
  max-width: 1400px; margin: 0 auto;
}
.side { display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.stage { display: flex; flex-direction: column; align-items: center; min-height: 0; gap: 12px; }

/* opponent / friend card */
.friend { padding: 16px 18px; display: flex; gap: 14px; align-items: center; position: relative; }
.friend .avatar { width: 92px; height: 92px; flex: none; }
.friend .who { min-width: 0; }
.friend .name { font-size: 25px; font-weight: 600; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend .status { font-size: 16px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #cfc6d9; }
.dot.on { background: #5fcf95; box-shadow: 0 0 0 4px rgba(95, 207, 149, 0.2); }

.bubble {
  position: relative; margin-top: -4px; background: #fff; border-radius: 22px; padding: 14px 18px;
  font-size: 20px; line-height: 1.3; box-shadow: var(--shadow-soft); min-height: 56px;
  transform-origin: 30px 0; animation: pop 0.5s var(--ease-spring);
  overflow-wrap: anywhere;
}
.bubble::before { content: ""; position: absolute; top: -10px; left: 40px; width: 22px; height: 22px; background: #fff; transform: rotate(45deg); border-radius: 4px; }
.bubble.hidden { visibility: hidden; animation: none; }
.bubble.quiet { color: var(--ink-soft); font-size: 17px; }
.bubble:not(.quiet) { cursor: pointer; }
@keyframes pop { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* avatars */
.avatar svg { width: 100%; height: 100%; overflow: visible; }
.avatar .eyes { animation: blink 5s infinite; transform-origin: 50% 46%; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
.avatar .antenna { animation: sway 3s ease-in-out infinite alternate; transform-origin: 50% 26%; }
@keyframes sway { from { transform: rotate(-8deg); } to { transform: rotate(8deg); } }
.avatar.thinking .pupils { animation: look 2.4s ease-in-out infinite; }
@keyframes look { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-4px); } 70% { transform: translateX(4px); } }
.avatar.talking .mouth { animation: talk 0.28s ease-in-out infinite alternate; transform-origin: 50% 66%; }
@keyframes talk { from { transform: scaleY(1); } to { transform: scaleY(1.9); } }
.avatar .body { animation: breathe 4s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.025, 0.98); } }
.avatar.empty { opacity: 0.45; filter: grayscale(0.6); }
.human-face { width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center; font-size: 52px; }

/* turn banner */
.banner {
  min-height: 58px; padding: 10px 28px; border-radius: 999px; background: var(--cream); box-shadow: var(--shadow-soft);
  font-size: 23px; font-weight: 500; display: flex; align-items: center; gap: 12px;
  transition: background 0.3s, transform 0.4s var(--ease-spring);
}
.banner.go { background: linear-gradient(180deg, #fff6d9, #ffe7a8); transform: scale(1.04); }
.banner .dots i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); margin: 0 2px; animation: dots 1.2s infinite; }
.banner .dots i:nth-child(2) { animation-delay: 0.15s; } .banner .dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dots { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-6px); opacity: 1; } }

/* ---------- boards ---------- */
.board-wrap { perspective: 1400px; }
.board {
  --cell: 50px; --gap: 4px;
  position: relative; padding: 14px 16px 16px 14px; border-radius: 30px;
  background: linear-gradient(160deg, #fdf7f1, #f2e6ee);
  box-shadow: 0 14px 0 -2px #e3cfdc, 0 30px 50px -24px rgba(73, 52, 110, 0.55);
  transform: rotateX(9deg); transform-origin: 50% 100%;
}
.board.small { --cell: 25px; --gap: 2px; padding: 10px 12px 12px 10px; border-radius: 22px; transform: none; box-shadow: 0 8px 0 -2px #e3cfdc, 0 20px 34px -22px rgba(73, 52, 110, 0.5); }
.board .grid-area { display: grid; grid-template-columns: 22px auto; grid-template-rows: 22px auto; gap: 4px; }
.board.small .grid-area { grid-template-columns: 14px auto; grid-template-rows: 14px auto; gap: 2px; }
.col-labels, .row-labels { display: grid; gap: var(--gap); color: var(--ink-soft); font-size: 15px; font-weight: 500; }
.board.small .col-labels, .board.small .row-labels { font-size: 10px; }
.col-labels { grid-template-columns: repeat(10, var(--cell)); grid-column: 2; text-align: center; align-items: end; }
.row-labels { grid-template-rows: repeat(10, var(--cell)); grid-row: 2; align-items: center; text-align: center; }
.sea {
  position: relative; grid-column: 2; grid-row: 2;
  display: grid; grid-template-columns: repeat(10, var(--cell)); grid-template-rows: repeat(10, var(--cell)); gap: var(--gap);
  padding: 0; border-radius: 18px; overflow: hidden;
}
.board.small .sea { border-radius: 10px; }
.sea::before {
  /* one shimmering light layer for the whole sea: cheap on low-end GPUs */
  content: ""; position: absolute; inset: -40%; z-index: 1; pointer-events: none;
  background: repeating-linear-gradient(115deg, transparent 0 46px, rgba(255, 255, 255, 0.12) 46px 60px, transparent 60px 120px);
  animation: shimmer 9s linear infinite;
}
@keyframes shimmer { from { transform: translateX(-60px); } to { transform: translateX(60px); } }
.cell {
  position: relative; border: 0; padding: 0; margin: 0; border-radius: 10px; cursor: default;
  background: linear-gradient(180deg, var(--sea-hi), var(--sea));
  box-shadow: inset 0 -3px 0 rgba(40, 110, 130, 0.18);
  transition: transform 0.18s var(--ease-out), background 0.2s;
}
.board.small .cell { border-radius: 5px; box-shadow: inset 0 -2px 0 rgba(40, 110, 130, 0.16); }
.cell.shot { background: linear-gradient(180deg, #9bd6d8, #74bfc8); }
.armed .cell:not(.shot) { cursor: crosshair; }
.armed .cell:not(.shot):hover { transform: translateY(-3px); background: linear-gradient(180deg, #c3f0ea, #95d9d6); }
.armed .cell:not(.shot):active { transform: scale(0.92); }
.cell.aim::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; border: 3px dashed #fff; animation: spin 1.2s linear infinite; z-index: 3; }
@keyframes spin { to { transform: rotate(360deg); } }
.cell:focus-visible { outline: 3px solid var(--lilac); outline-offset: 2px; z-index: 4; }

/* ships layer */
.ships { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.ship { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.ship .hull { width: 100%; height: 100%; animation: bob 3.4s ease-in-out infinite; }
.ship svg { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 4px 3px rgba(30, 80, 100, 0.25)); }
.ship.sunk svg { filter: grayscale(0.55) brightness(0.92) drop-shadow(0 2px 2px rgba(30, 80, 100, 0.2)); opacity: 0.8; }
.ship.sunk .hull { animation: sink 1.6s var(--ease-out) forwards; }
@keyframes sink { 0% { transform: translateY(-6px) rotate(0); } 60% { transform: translateY(3px) rotate(4deg); } 100% { transform: translateY(2px) rotate(3deg); } }
.ship.ghost { opacity: 0.55; }
.ship.ghost.bad svg { filter: sepia(1) hue-rotate(-40deg) saturate(3); opacity: 0.6; }
.ship.lifted .hull { animation: none; transform: translateY(-6px) scale(1.04); }
.ship.reveal { opacity: 0.5; }

/* pegs (hit/miss markers) live in cells, above ships */
.peg { position: absolute; inset: 0; display: grid; place-items: center; z-index: 5; pointer-events: none; }
.peg.miss::before { content: ""; width: 30%; height: 30%; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.35); }
.peg.hit::before {
  content: ""; width: 46%; height: 46%; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd0a8, var(--coral) 45%, var(--coral-deep));
  box-shadow: 0 0 0 4px rgba(255, 143, 122, 0.35), 0 3px 6px rgba(160, 60, 40, 0.35);
}
.peg.sunk::before { background: radial-gradient(circle at 35% 35%, #c8bcd8, #8f84a6 60%, #6d6385); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35); }
.peg.fresh::before { animation: pegIn 0.6s var(--ease-spring); }
@keyframes pegIn { 0% { transform: scale(0); } 100% { transform: scale(1); } }
/* splash: ring + droplets */
.splash { position: absolute; inset: -20%; z-index: 6; pointer-events: none; }
.splash i { position: absolute; left: 50%; top: 50%; border-radius: 50%; }
.splash .ring { width: 30%; height: 30%; margin: -15% 0 0 -15%; border: 3px solid #fff; animation: ring 0.9s var(--ease-out) forwards; }
.splash .drop { width: 12%; height: 12%; margin: -6% 0 0 -6%; background: #fff; animation: drop 0.8s var(--ease-out) forwards; }
.splash .drop:nth-child(2) { --dx: -28px; --dy: -26px; } .splash .drop:nth-child(3) { --dx: 26px; --dy: -30px; }
.splash .drop:nth-child(4) { --dx: -10px; --dy: -38px; } .splash .drop:nth-child(5) { --dx: 14px; --dy: -20px; }
@keyframes ring { from { transform: scale(0.3); opacity: 1; } to { transform: scale(3); opacity: 0; } }
@keyframes drop { 0% { transform: translate(0, 0); opacity: 1; } 60% { transform: translate(var(--dx), var(--dy)); opacity: 1; } 100% { transform: translate(calc(var(--dx) * 1.3), calc(var(--dy) * -0.2)); opacity: 0; } }
/* boom: soft starburst */
.boom { position: absolute; inset: -40%; z-index: 6; pointer-events: none; }
.boom i { position: absolute; left: 50%; top: 50%; width: 22%; height: 22%; margin: -11% 0 0 -11%; border-radius: 50%; background: var(--butter); animation: burst 0.7s var(--ease-out) forwards; }
.boom i:nth-child(1) { --dx: 0; --dy: -34px; } .boom i:nth-child(2) { --dx: 30px; --dy: -12px; } .boom i:nth-child(3) { --dx: 20px; --dy: 26px; }
.boom i:nth-child(4) { --dx: -20px; --dy: 26px; } .boom i:nth-child(5) { --dx: -30px; --dy: -12px; }
.boom b { position: absolute; left: 50%; top: 50%; width: 50%; height: 50%; margin: -25% 0 0 -25%; border-radius: 50%; background: radial-gradient(circle, #fff3c4, rgba(255, 180, 120, 0) 70%); animation: flash 0.6s ease-out forwards; }
@keyframes burst { 0% { transform: translate(0, 0) scale(1.2); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; } }
@keyframes flash { 0% { transform: scale(0.4); opacity: 1; } 100% { transform: scale(2.4); opacity: 0; } }
.bubbles { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.bubbles i { position: absolute; bottom: 20%; width: 8px; height: 8px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.85); animation: rise-b 1.8s ease-out forwards; }
@keyframes rise-b { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-50px); opacity: 0; } }
.shake { animation: shake 0.45s ease; }
@keyframes shake { 0%, 100% { transform: rotateX(9deg) translateX(0); } 25% { transform: rotateX(9deg) translateX(-5px); } 75% { transform: rotateX(9deg) translateX(5px); } }

.board-title { font-size: 18px; color: var(--ink-soft); margin: 0 0 8px 6px; display: flex; justify-content: space-between; align-items: center; }
.board-title b { color: var(--ink); font-weight: 600; }

/* fleet tally */
.tally { display: flex; flex-wrap: wrap; gap: 6px; }
.tally span { font-size: 14px; padding: 4px 10px; border-radius: 999px; background: #eef7f6; color: #2f6b72; }
.tally span.gone { background: #f1ebf3; color: #a79db5; text-decoration: line-through; }
.mine { padding: 16px 18px 18px; }

/* placement tray */
.tray { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.tray h3 { margin: 0; font-size: 24px; font-weight: 600; }
.tray p { margin: 0; color: var(--ink-soft); font-size: 17px; line-height: 1.35; }
.tray .row { display: flex; gap: 12px; }
.tray .row .btn { flex: 1; }
.ship-list { display: flex; flex-direction: column; gap: 8px; }
.ship-pick {
  border: 3px solid transparent; border-radius: 18px; background: #f6f0f6; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 12px; padding: 6px 12px; min-height: 52px; font-size: 18px;
  transition: transform 0.2s var(--ease-spring), border-color 0.2s;
}
.ship-pick .mini { height: 26px; flex: none; }
.ship-pick[aria-pressed="true"] { border-color: var(--coral); background: #fff; transform: translateX(4px); }
.ship-pick.placed { opacity: 0.6; }

/* waiting card overlays */
.overlay {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center;
  background: rgba(255, 250, 246, 0.55); border-radius: 30px;
}
.overlay .card { padding: 28px 34px; text-align: center; max-width: 460px; animation: rise 0.5s var(--ease-spring); }
.overlay h2 { margin: 0 0 8px; font-size: 30px; font-weight: 600; }
.overlay p { margin: 0 0 14px; font-size: 19px; color: var(--ink-soft); line-height: 1.4; }
.big-code { font-size: 46px; font-weight: 600; letter-spacing: 4px; color: var(--ink); background: #f6f0fa; border-radius: 20px; padding: 10px 22px; display: inline-block; margin: 6px 0 14px; }
.overlay .btn + .btn { margin-left: 12px; }

/* finish */
.finish h2 { font-size: 40px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 16px; border-radius: 4px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ship placement on the grid, driven by --r/--c/--n custom properties */
.ship {
  left: calc(var(--c) * (var(--cell) + var(--gap)));
  top: calc(var(--r) * (var(--cell) + var(--gap)));
  width: calc(var(--n) * var(--cell) + (var(--n) - 1) * var(--gap));
  height: var(--cell);
  padding: 2px;
}
.ship.down { transform: translateX(var(--cell)) rotate(90deg); }
.board.small.shake { animation: shakeflat 0.45s ease; }
@keyframes shakeflat { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.ship-pick .mini svg { width: 100%; height: 100%; }
.game-card { display: flex; flex-direction: column; justify-content: flex-start; }
.game-card .art { width: 100%; flex: none; }
.ribbon { z-index: 2; }
.art.sea svg { width: 100%; height: 100%; }
.toast { transform: translate(-50%, 220%); visibility: hidden; }
.toast.show { visibility: visible; }
.bubble.hidden { display: none; }
.tray { padding: 16px 18px; gap: 10px; }
.tray p { font-size: 16px; }
.ship-list { gap: 6px; }
.ship-pick { min-height: 46px; padding: 4px 12px; }
.join-row .btn { width: auto; min-width: 200px; }
.ship { padding: 1px; }
.ship.lifted svg { filter: drop-shadow(0 0 5px #fff) drop-shadow(0 10px 6px rgba(30, 80, 100, 0.3)); }

/* finish card "peek" so the child can look at the final board */
.peek-btn { display: none; }
.overlay.peek { background: transparent; pointer-events: none; align-items: end; padding-bottom: 14px; }
.overlay.peek .card { display: none; }
.overlay.peek .peek-btn { display: inline-flex; pointer-events: auto; }
.overlay.peek .peek-btn.btn { width: auto; min-height: 46px; box-shadow: var(--shadow-soft); }

/* ---------- chess ---------- */
.cboard {
  --sq: clamp(34px, min((100cqi - 90px) / 8, (100vh - 290px) / 8), 78px);
  position: relative; padding: 14px 16px 12px 12px; border-radius: 30px;
  background: linear-gradient(160deg, #fdf7f1, #f2e6ee);
  box-shadow: 0 14px 0 -2px #e3cfdc, 0 30px 50px -24px rgba(73, 52, 110, 0.55);
  transform: rotateX(9deg); transform-origin: 50% 100%;
}
.c-grid { display: grid; grid-template-columns: 22px auto; grid-template-rows: auto 22px; gap: 4px; }
.c-ranks { display: grid; grid-template-rows: repeat(8, var(--sq)); align-items: center; text-align: center; color: var(--ink-soft); font-size: 15px; font-weight: 500; }
.c-files { grid-column: 2; display: grid; grid-template-columns: repeat(8, var(--sq)); text-align: center; color: var(--ink-soft); font-size: 15px; font-weight: 500; align-items: center; }
.c-squares {
  position: relative; display: grid; grid-template-columns: repeat(8, var(--sq)); grid-template-rows: repeat(8, var(--sq));
  border-radius: 18px; overflow: hidden; box-shadow: inset 0 0 0 2px rgba(61, 53, 83, 0.06);
}
.sq { border: 0; padding: 0; margin: 0; position: relative; background: #fbf1e6; cursor: default; }
.sq.dark { background: #cfbfe8; }
.sq.last { background-image: linear-gradient(rgba(255, 205, 110, 0.5), rgba(255, 205, 110, 0.5)); }
.sq.sel { background-image: linear-gradient(rgba(255, 205, 110, 0.75), rgba(255, 205, 110, 0.75)); }
.sq.check { background-image: radial-gradient(circle, rgba(255, 120, 100, 0.9) 0%, rgba(255, 120, 100, 0.35) 45%, transparent 70%); }
.sq.target::after { content: ""; position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; margin: -14% 0 0 -14%; border-radius: 50%; background: rgba(61, 53, 83, 0.26); z-index: 3; animation: pegIn 0.3s var(--ease-spring); }
.sq.capture::after { content: ""; position: absolute; inset: 7%; border-radius: 50%; border: 5px solid rgba(239, 111, 91, 0.75); z-index: 3; animation: pegIn 0.3s var(--ease-spring); }
.cboard.armed .sq.can, .cboard.armed .sq.target, .cboard.armed .sq.capture { cursor: pointer; }
.cboard.armed .sq.can:hover { filter: brightness(1.05); }
.sq:focus-visible { outline: 3px solid var(--coral); outline-offset: -3px; z-index: 4; }
.c-pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.piece { position: absolute; left: calc(var(--x) * var(--sq)); top: calc(var(--y) * var(--sq)); width: var(--sq); height: var(--sq); transition: transform 0.45s var(--ease-out); }
.piece svg { width: 100%; height: 100%; display: block; overflow: visible; transition: transform 0.25s var(--ease-spring); }
.piece.lifted svg { transform: translateY(-9%) scale(1.08); }
.piece.taken { animation: taken 0.6s var(--ease-out) forwards; z-index: 1; }
@keyframes taken { to { transform: translateY(-25%) scale(0.3); opacity: 0; } }
.pc .shadow { fill: rgba(61, 53, 83, 0.16); }
.pw .body, .pw .base { fill: #fffaf3; stroke: #c9ad9f; stroke-width: 3; stroke-linejoin: round; }
.pb .body, .pb .base { fill: #5d4b7d; stroke: #3b2e53; stroke-width: 3; stroke-linejoin: round; }
.pw .eye { fill: #6d5a7f; stroke: none; }
.pb .eye { fill: #fffaf3; stroke: none; }
.pc .cut { fill: none; stroke-width: 4; stroke-linecap: round; }
.pw .cut { stroke: #c9ad9f; }
.pb .cut { stroke: #9a87c0; }
.pc .shine { fill: none; stroke: rgba(255, 255, 255, 0.7); stroke-width: 4; stroke-linecap: round; }
.pb .shine { stroke: rgba(255, 255, 255, 0.22); }

.chess-info { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.cap-row { display: grid; grid-template-columns: 108px 1fr auto; align-items: center; gap: 8px; min-height: 32px; }
.cap-label { font-size: 16px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caps { display: flex; flex-wrap: wrap; flex: 1; align-items: center; }
.cap { width: 26px; height: 26px; margin-right: -7px; }
.cap svg { width: 100%; height: 100%; }
.caps .none, .move-list .none { color: #b0a7bf; font-size: 15px; }
.lead { font-weight: 600; color: #2f8a63; font-size: 17px; }
.moves-title { font-weight: 600; font-size: 18px; margin-top: 6px; }
.move-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; font-size: 17px; }
.move-list li b { color: var(--ink-soft); font-weight: 500; }
.move-list li span { display: inline-block; min-width: 3.2em; }
.chess-info .link-btn { align-self: flex-start; margin-top: 6px; }
.promo-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.promo-pick { width: 78px; height: 78px; border-radius: 20px; border: 3px solid transparent; background: #f6f0f6; cursor: pointer; padding: 6px; transition: transform 0.2s var(--ease-spring); }
.promo-pick:hover { transform: translateY(-3px); border-color: var(--butter); }
.promo-pick svg { width: 100%; height: 100%; }

/* ---------- responsive ---------- */
/* Fluid boards: desktop sizes the cells from whichever of width or height runs out first. */
/* Cells size from the container width (cqi), not 100vw, so scrollbars never cause clipping. */
.room, .stage { container-type: inline-size; }
.stage { width: 100%; }
.board { --cell: clamp(26px, min((100cqi - 100px) / 10, (100vh - 274px) / 10), 64px); }
.board.small { --cell: clamp(20px, (100vh - 520px) / 10, 25px); }
.games { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.art.doodle { background: linear-gradient(180deg, #e8f4ff, #d3e6fb); }
.game-card .art { height: clamp(150px, 26vw, 230px); }

@media (max-height: 740px) and (min-width: 1100px) {
  .friend .avatar { width: 76px; height: 76px; }
}

/* Tablet and phone: one column. Friend, bubble, banner, their sea, then your sea. */
@media (max-width: 1099px) {
  .room { display: flex; flex-direction: column; align-items: stretch; height: auto; min-height: 0;
    max-width: 760px; gap: 14px; padding: 4px 16px 28px; }
  .side, .stage { display: contents; }
  .friend { order: 1; }
  .bubble { order: 2; }
  .banner { order: 3; align-self: center; text-align: center; justify-content: center; font-size: clamp(17px, 4.4vw, 23px); padding: 10px 20px; }
  .board-wrap { order: 4; align-self: center; max-width: 100%; }
  .side-main { order: 5; }
  .board { --cell: clamp(22px, (100cqi - 96px) / 10, 56px); transform: none; }
  .board.shake { animation: shakeflat 0.45s ease; }
  .board.small { --cell: clamp(18px, (100cqi - 104px) / 10, 34px); }
  .mine { display: flex; flex-direction: column; align-items: center; }
  .mine .board-title { align-self: stretch; }
  .ship-list { flex-direction: row; flex-wrap: wrap; }
  .ship-pick { flex: 1 1 150px; }
  .overlay { border-radius: 20px; }
}

/* Phone */
@media (max-width: 620px) {
  .top { padding: 0 12px; gap: 8px; }
  .brand span { display: none; }
  .code-chip { font-size: 15px; padding: 6px 8px 6px 14px; gap: 8px; }
  .code-chip b { font-size: 17px; letter-spacing: 1px; }
  .lobby { padding: 8px 14px 30px; }
  .hero h1 { font-size: 38px; }
  .hero p { font-size: 18px; margin-bottom: 20px; }
  .games { gap: 18px; }
  .game-card h2 { font-size: 26px; }
  .room { padding: 2px 10px 24px; gap: 12px; }
  .board { --gap: 3px; --cell: clamp(20px, (100cqi - 68px) / 10, 40px); padding: 8px 10px 10px 8px; border-radius: 20px;
    box-shadow: 0 8px 0 -2px #e3cfdc, 0 20px 34px -22px rgba(73, 52, 110, 0.5); }
  .board .grid-area { grid-template-columns: 16px auto; grid-template-rows: 16px auto; gap: 3px; }
  .col-labels, .row-labels { font-size: 12px; }
  .cell { border-radius: 7px; }
  .sea { border-radius: 12px; }
  .friend { padding: 12px 14px; }
  .friend .avatar { width: 64px; height: 64px; }
  .friend .name { font-size: 21px; }
  .bubble { font-size: 18px; padding: 12px 16px; min-height: 0; }
  .tray { padding: 14px; }
  .ship-pick { flex: 1 1 130px; font-size: 16px; }
  .ship-pick .mini { height: 20px; }
  .overlay .card { padding: 20px 18px; width: min(460px, 92%); }
  .overlay h2 { font-size: 24px; }
  .overlay p { font-size: 16px; }
  .finish h2 { font-size: 30px; }
  .big-code { font-size: clamp(26px, 9vw, 40px); letter-spacing: 2px; padding: 8px 14px; }
  .overlay .btn + .btn { margin-left: 0; margin-top: 12px; }
  .overlay .btn { width: 100%; }
  .sheet { padding: 22px 16px 22px; max-height: 92vh; overflow-y: auto; }
  .sheet h2 { font-size: 26px; }
  .sheet p.sub { font-size: 17px; margin-bottom: 14px; }
  .players { gap: 8px; margin-bottom: 18px; }
  .player-pick { font-size: 14px; padding: 8px 2px; border-radius: 18px; }
  .player-pick .face { width: 50px; height: 50px; font-size: 32px; }
  .choices { grid-template-columns: 1fr; gap: 14px; }
  .join-row { flex-wrap: wrap; }
  .join-row .code-input { min-width: 0; flex: 1 1 100%; }
  .join-row .btn { flex: 1 1 100%; min-width: 0; }
  .isle { display: none; }
}
@media (max-width: 420px) {
  .code-chip .score { display: none; }
}

/* chess responsive */
@media (max-width: 1099px) {
  .cboard { --sq: clamp(30px, (100cqi - 64px) / 8, 74px); transform: none; }
  .chess-info { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
  .chess-info .moves-title, .chess-info .move-list, .chess-info .link-btn { grid-column: 1 / -1; }
  .chess-info .cap-row { grid-column: span 1; }
}
@media (max-width: 620px) {
  .cboard { --sq: clamp(28px, (100cqi - 46px) / 8, 60px); padding: 8px 10px 8px 6px; border-radius: 20px;
    box-shadow: 0 8px 0 -2px #e3cfdc, 0 20px 34px -22px rgba(73, 52, 110, 0.5); }
  .c-grid { grid-template-columns: 14px auto; grid-template-rows: auto 16px; gap: 3px; }
  .c-ranks, .c-files { font-size: 12px; }
  .c-squares { border-radius: 12px; }
  .chess-info { grid-template-columns: 1fr; }
  .cap-label { font-size: 15px; }
  .cap-row { grid-template-columns: 96px 1fr auto; }
  .promo-pick { width: 64px; height: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
