/* Themes: every colour lives in a variable; <html data-theme="…"> (set by theme.js) swaps the set.
   Night is the default. To add a theme, copy a [data-theme] block and add its name to theme.js. */
:root {
  color-scheme: dark;
  --bg: #0f1424; --glow: #2b3a6b; --panel: #182038; --field: #0b1020;
  --text: #e8ecf8; --muted: #95a1c4; --accent: #ffcc4d; --on-accent: #241c00; --line: #ffffff44;
  --scrim: #0f1424a8; --danger: #d9483b;
  /* battleships */
  --water: #1663a6; --water-hover: #3a8fd8; --water-frame: #0a355e; --miss: #cfe6ff; --near: #0b3b66;
  --hull-1: #fff; --hull-2: #a9bacb; --hull-edge: #33475e; --hit: #e0533d; --sunk: #5c1c16; --sunk-mark: #ff9d8c;
  /* checkers */
  --sq-light: #ecd4ad; --sq-dark: #8b5a36; --sq-last: #a8783f; --wood: #4a2c17;
  /* connect four */
  --c4-board: #1d4fb8; --c4-hole: #0f1424; --p0: #e5383b; --p1: #ffcc4d;
  /* backgammon */
  --felt: #1f5c3f; --pt-a: #ecd4ad; --pt-b: #9b3b2e;
}
[data-theme="bubblegum"] {
  color-scheme: light;
  --bg: #ffc6de; --glow: #fff0f6; --panel: #fff5f9; --field: #ffe3ef;
  --text: #4a1233; --muted: #a24d79; --accent: #ff3d8b; --on-accent: #fff; --line: #4a123344;
  --scrim: #ffc6deb0; --danger: #e0335a;
  --water: #1fa8a0; --water-hover: #3cc4bc; --water-frame: #14807a; --miss: #e3fbf8; --near: #0d5f5a;
  --hull-1: #fff59d; --hull-2: #ffc400; --hull-edge: #a87700; --hit: #ff3d8b; --sunk: #8a0f45; --sunk-mark: #ffb3d1;
  --sq-light: #ffe3ef; --sq-dark: #e86aa6; --sq-last: #f48fbf; --wood: #b83275;
  --c4-board: #ff5fa2; --c4-hole: #ffe3ef; --p0: #0f8f88; --p1: #ffd60a;
  --felt: #f49ac1; --pt-a: #fff0f6; --pt-b: #0f8f88;
}
[data-theme="daylight"] {
  color-scheme: light;
  --bg: #eef2f8; --glow: #fff; --panel: #fff; --field: #eef2f8;
  --text: #1d2433; --muted: #5b6780; --accent: #2563eb; --on-accent: #fff; --line: #1d243344;
  --scrim: #eef2f8b8; --danger: #dc2626;
  --water: #9cc9f5; --water-hover: #b9dafa; --water-frame: #5d9ad6; --miss: #1e4f85; --near: #6c9fd4;
  --hull-1: #6b7a90; --hull-2: #2f3b4e; --hull-edge: #161d29; --hit: #ef4444; --sunk: #7f1d1d; --sunk-mark: #fecaca;
  --sq-light: #f3e5c8; --sq-dark: #b07a4f; --sq-last: #c8955f; --wood: #6b4423;
  --c4-board: #2563eb; --c4-hole: #eef2f8; --p0: #ef4444; --p1: #facc15;
  --felt: #2f7d5b; --pt-a: #f3e5c8; --pt-b: #b0413e;
}

:root { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 50% -10%, var(--glow), var(--bg) 60%) fixed; }
main { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
h1, h2, h3 { margin: 0; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* top bar with the theme picker */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-bottom: 20px; }
.bar a { color: var(--muted); text-decoration: none; }
.bar a:hover { color: var(--text); }
.bar h1 { font-size: 1.6rem; }
.theme { font: inherit; font-size: .9rem; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }

/* home */
.home { text-align: center; }
.home h1 { font-size: clamp(2.2rem, 7vw, 3.6rem); margin-top: 4vh; letter-spacing: -0.02em; }
.sub { color: var(--muted); margin: 10px 0 40px; font-size: 1.1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; text-align: left; }
.card {
  display: block; color: inherit; text-decoration: none; background: var(--panel);
  border-radius: 18px; overflow: hidden; box-shadow: 0 10px 30px #0005; transition: transform .2s, box-shadow .2s;
}
.card:hover, .card:focus-visible { transform: translateY(-6px); box-shadow: 0 18px 40px #0008; }
.card h2 { margin: 18px 20px 6px; }
.card p { margin: 0 20px 22px; color: var(--muted); line-height: 1.45; }
.art { height: 180px; display: flex; align-items: center; justify-content: center; gap: 16px; font-size: 84px; }
.art.sea {
  background:
    linear-gradient(#fff1 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, #fff1 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(160deg, var(--water), var(--water-frame));
}
.art.wood { background: repeating-conic-gradient(var(--sq-dark) 0 25%, var(--sq-light) 0 50%) 0 0 / 60px 60px; }
.art .pc { width: 72px; font-size: 40px; }
.art.c4 { background: radial-gradient(circle, var(--c4-hole) 13px, transparent 14px) 0 0 / 40px 40px, var(--c4-board); }
.art.c4 i { width: 64px; aspect-ratio: 1; border-radius: 50%; }
.art.felt {
  background:
    linear-gradient(to bottom right, transparent 49.5%, var(--felt) 50%) 0 0 / 30px 90px repeat-x,
    linear-gradient(to bottom left, transparent 49.5%, var(--felt) 50%) 15px 0 / 30px 90px repeat-x,
    repeating-linear-gradient(90deg, var(--pt-a) 0 15px, var(--pt-b) 15px 30px) 0 0 / 60px 90px repeat-x,
    var(--felt);
}

/* game pages */
#status { font-size: 1.15rem; min-height: 1.5em; text-align: center; margin: 12px 0 18px; }
.invite {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px;
  background: var(--panel); border: 1px dashed var(--accent); border-radius: 12px; padding: 14px;
}
.invite input {
  flex: 1 1 260px; min-width: 0; padding: 10px 12px; border: 0; border-radius: 8px;
  background: var(--field); color: var(--text); font: inherit;
}
.btn { background: var(--accent); color: var(--on-accent); border: 0; border-radius: 8px; padding: 10px 18px; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 2px var(--line); }
.center { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 18px 0; }
.toast {
  position: fixed; bottom: 24px; left: 50%; translate: -50%; padding: 10px 18px; border-radius: 10px;
  background: var(--danger); color: #fff; box-shadow: 0 6px 20px #0008;
}
/* the Ready cover over a board */
.board-wrap { position: relative; width: min(100%, 560px); margin: 0 auto; }
.overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 12px;
  border-radius: 6px; background: var(--scrim); backdrop-filter: blur(2px);
}
.overlay p { margin: 0; font-size: 1.25rem; }
.btn.big { font-size: 1.5rem; padding: 14px 48px; border-radius: 12px; box-shadow: 0 10px 30px #0008; }

/* checkers (the .pc pieces are reused by backgammon) */
.checkers {
  display: grid; grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  width: 100%; aspect-ratio: 1; font-size: min(5.5vw, 36px);
  border: 10px solid var(--wood); border-radius: 6px; box-shadow: 0 14px 40px #0008;
}
.sq { border: 0; padding: 0; display: grid; place-items: center; cursor: default; }
.light { background: var(--sq-light); }
.dark { background: var(--sq-dark); }
.sq.last { background: var(--sq-last); }
.sq.can, .sq.target { cursor: pointer; }
.sq.can .pc { outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }
.sq.sel { box-shadow: inset 0 0 0 4px var(--accent); }
.sq.target::after { content: ""; width: 30%; aspect-ratio: 1; border-radius: 50%; background: color-mix(in srgb, var(--accent) 85%, transparent); }
.pc { width: 78%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 700; }
.pc.w { background: radial-gradient(circle at 35% 30%, #fff, #d6d0c2); box-shadow: 0 3px 0 #9d968a, 0 5px 8px #0006; color: #4a4030; }
.pc.b { background: radial-gradient(circle at 35% 30%, #4a4a4a, #111); box-shadow: 0 3px 0 #000, 0 5px 8px #0006; color: #eee; }
.pc.king::after { content: "♛"; color: #d4a017; line-height: 1; }

/* battleships */
.seas { display: flex; flex-wrap: wrap; justify-content: center; gap: 28px; }
.seas section { width: min(100%, 450px); }
.seas h3 { text-align: center; color: var(--muted); font-weight: 500; margin-bottom: 10px; }
.side { display: flex; align-items: center; gap: 12px; }
.side .grid { flex: 1; min-width: 0; }
/* ships left: one row per size, crossed out once sunk */
.roster { display: flex; flex-direction: column; gap: 9px; }
.roster div { display: flex; gap: 5px; }
.mini { position: relative; width: calc(var(--n) * 14px); height: 13px; border-radius: 7px; background: linear-gradient(var(--hull-1), var(--hull-2)); }
.mini.sunk { background: var(--sunk); }
.mini.sunk::after { content: ""; position: absolute; left: -3px; right: -3px; top: 5.5px; height: 2px; background: var(--sunk-mark); rotate: -14deg; }
@media (max-width: 600px) {
  .side { flex-direction: column; }
  .side .grid { width: 100%; flex: none; }
  .roster { order: -1; flex-flow: row wrap; justify-content: center; gap: 6px 14px; }
}
.grid {
  display: grid; grid-template: repeat(10, 1fr) / repeat(10, 1fr); gap: 2px; aspect-ratio: 1;
  padding: 3px; border-radius: 10px; background: var(--water-frame); transition: box-shadow .2s; user-select: none;
}
.grid.active { box-shadow: 0 0 0 3px var(--accent), 0 0 30px color-mix(in srgb, var(--accent) 35%, transparent); }
.cell { border: 0; padding: 0; border-radius: 3px; background: var(--water); color: #fff; display: grid; place-items: center; font-size: min(4vw, 20px); }
.cell:disabled { cursor: default; }
.grid.active .cell:enabled { cursor: crosshair; }
.grid.active .cell:enabled:hover { background: var(--water-hover); }
.cell.miss::after { content: ""; width: 22%; aspect-ratio: 1; border-radius: 50%; background: var(--miss); opacity: .75; }
.cell.near { background: var(--near); } /* water ruled out by a sunk ship next to it, never fired at */
.cell.hit::after, .cell.sunk::after { content: "✕"; }
/* ships: hulls lit from one side, cells joined into one rounded shape */
.cell.ship { background: linear-gradient(var(--hull-1), var(--hull-2)); box-shadow: inset 0 -3px var(--hull-edge); }
.cell.ship.v { background: linear-gradient(90deg, var(--hull-1), var(--hull-2)); box-shadow: inset -3px 0 var(--hull-edge); }
.cell.ship.solo { background: radial-gradient(circle at 35% 30%, var(--hull-1), var(--hull-2)); box-shadow: inset -2px -3px var(--hull-edge); }
.cell.hit { background: var(--hit); }
.cell.sunk { background: var(--sunk); color: var(--sunk-mark); }
.cell.h:not(.stern) { margin-right: -3px; } /* reach over the 2px gap with 1px to spare, no seams */
.cell.v:not(.stern) { margin-bottom: -3px; }
.cell.h, .cell.v { border-radius: 0; }
.cell.h.bow { border-radius: 50% 0 0 50%; }
.cell.h.stern { border-radius: 0 50% 50% 0; }
.cell.v.bow { border-radius: 50% 50% 0 0; }
.cell.v.stern { border-radius: 0 0 50% 50%; }
.cell.solo { border-radius: 35%; }
.placing .cell.ship { cursor: grab; touch-action: none; }
.cell.ship.dragging { background: var(--accent); box-shadow: none; }
.cell.ship.dragging.bad { background: var(--hit); }

/* connect four: 7 column buttons of 6 holes each */
.c4 { display: flex; gap: 6px; padding: 10px; border-radius: 16px; background: var(--c4-board); box-shadow: 0 14px 40px #0008; overflow: hidden; }
.col { flex: 1; display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; background: none; border-radius: 999px; cursor: default; }
.c4.mine .col:enabled { cursor: pointer; }
.c4.mine .col:enabled:hover { background: #ffffff2a; }
.hole { width: 100%; aspect-ratio: 1; border-radius: 50%; background: var(--c4-hole); box-shadow: inset 0 3px 6px #0006; }
.p0 { background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--p0), #fff 35%), var(--p0)); }
.p1 { background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--p1), #fff 35%), var(--p1)); }
.hole.win { box-shadow: inset 0 0 0 5px #fffc, 0 0 14px #fff8; }
.hole.drop { animation: drop .45s cubic-bezier(.5, 0, 1, 1); }
@keyframes drop { from { translate: 0 calc(-115% * var(--fall)); } }
.legend { text-align: center; color: var(--muted); display: flex; justify-content: center; align-items: center; gap: 8px; }
.legend i { width: 18px; aspect-ratio: 1; border-radius: 50%; display: inline-block; }
.legend .me { color: var(--text); font-weight: 700; }
.pick { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

/* backgammon: 12 points per row, bar in the middle, borne-off tray on the right */
.board-wrap.wide { width: min(100%, 700px); }
.bgb {
  display: grid; grid-template-columns: repeat(6, 1fr) .8fr repeat(6, 1fr) 1fr; grid-template-rows: 1fr 1fr;
  gap: 0 2px; aspect-ratio: 13 / 10; padding: 8px; font-size: min(2.6vw, 17px);
  background: var(--felt); border: 10px solid var(--wood); border-radius: 8px; box-shadow: 0 14px 40px #0008; user-select: none;
}
.pt { position: relative; border: 0; padding: 0; background: none; display: flex; flex-direction: column; align-items: center; cursor: default; min-width: 0; }
.pt.low { flex-direction: column-reverse; }
.pt::before { content: ""; position: absolute; inset: 0 0 10% 0; clip-path: polygon(0 0, 100% 0, 50% 100%); background: var(--pt-a); }
.pt.low::before { inset: 10% 0 0 0; clip-path: polygon(0 100%, 100% 100%, 50% 0); }
.pt.alt::before { background: var(--pt-b); }
.pt.last::before { filter: brightness(1.25) saturate(1.2); }
.pt .pc, .rail .pc { position: relative; width: 84%; flex: none; }
.pt.can, .pt.target, .rail.can, .rail.target { cursor: pointer; }
.pt.can .pc:last-child, .rail.can > div:last-child .pc:last-child { outline: 3px solid color-mix(in srgb, var(--accent) 75%, transparent); outline-offset: 1px; }
.pt.sel .pc:last-child, .rail.sel > div:last-child .pc:last-child { outline: 4px solid var(--accent); }
.pt.target::after { content: ""; position: absolute; left: 32%; width: 36%; aspect-ratio: 1; border-radius: 50%; background: var(--accent); top: 62%; }
.pt.low.target::after { top: auto; bottom: 62%; }
.rail { grid-row: 1 / 3; border: 0; padding: 6px 0; background: var(--wood); display: flex; flex-direction: column; justify-content: space-between; align-items: center; gap: 4px; border-radius: 4px; color: var(--sq-light); }
.rail > div { display: flex; flex-direction: column; align-items: center; width: 100%; }
.rail.off { background: color-mix(in srgb, var(--wood) 70%, #000); font-weight: 700; }
.rail.off.target { outline: 3px dashed var(--accent); outline-offset: -3px; }
/* phones: use the whole width, thinner frame, no gaps, a squarer board, checkers filling their point */
@media (max-width: 600px) {
  .board-wrap.wide { width: calc(100% + 16px); margin-inline: -8px; }
  .bgb { grid-template-columns: repeat(6, 1fr) .8fr repeat(6, 1fr) .8fr; gap: 0; padding: 3px; border-width: 5px; aspect-ratio: 1; font-size: 3.6vw; }
  .pt .pc, .rail .pc { width: 100%; }
}
.dice { display: flex; gap: 8px; font-size: 52px; line-height: 1; min-height: 52px; }
.dice span.used { opacity: .25; }

/* ---- effects (fx.js) ---- */
.sound { font-size: 1.05rem; line-height: 1; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.moving { position: relative; z-index: 6; }
/* battleships: a hit flashes and bursts, a miss ripples */
.cell.boom { position: relative; z-index: 2; animation: boom .75s ease-out; }
@keyframes boom {
  0% { transform: scale(1.7); filter: brightness(2.4) saturate(1.5); box-shadow: 0 0 0 3px #ffd166, 0 0 26px 14px #ff7b00; }
  45% { transform: scale(1.15); box-shadow: 0 0 0 1px #ff9f1c, 0 0 18px 8px #ff4d0080; }
  100% { transform: none; filter: none; box-shadow: none; }
}
.cell.splash { animation: splash .7s ease-out; }
@keyframes splash { from { box-shadow: 0 0 0 0 var(--miss); } to { box-shadow: 0 0 0 16px transparent; } }
/* checkers: jumped pieces shrink away once the jumping piece has passed */
.pc.poof { grid-area: 1 / 1; animation: poof .45s ease-in var(--d, 0s) forwards; }
@keyframes poof { to { transform: scale(.2) rotate(90deg); opacity: 0; } }
/* connect four: the winning line pulses */
.hole.win { animation: glow .9s ease-in-out infinite alternate; }
@keyframes glow { to { box-shadow: inset 0 0 0 5px #fff, 0 0 22px 6px #fffa; } }
/* backgammon: dice tumble in */
.dice span.tumble { display: inline-block; animation: tumble .55s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes tumble { from { transform: translateY(-40px) rotate(-260deg) scale(.6); } }

/* game-over card */
.announce { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: var(--scrim); backdrop-filter: blur(3px); animation: fade .25s; }
.announce .card { width: min(100%, 420px); text-align: center; padding: 28px 24px 8px; border-radius: 22px; background: var(--panel); box-shadow: 0 24px 60px #0009; animation: pop .55s cubic-bezier(.2, 1.5, .4, 1); }
.announce.lose .card { animation: pop .55s cubic-bezier(.2, 1.5, .4, 1), shake .5s .55s; }
.announce .emoji { font-size: 84px; line-height: 1; animation: hop 1s ease-in-out infinite alternate; }
.announce.lose .emoji { animation: droop 1.6s ease-in-out infinite alternate; }
.announce h2 { font-size: 2.2rem; margin: 10px 0 6px; }
.announce.win h2 { color: var(--accent); }
.announce p { color: var(--muted); margin: 0; line-height: 1.45; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
@keyframes shake { 25% { transform: translateX(-10px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
@keyframes hop { to { transform: translateY(-12px) rotate(6deg); } }
@keyframes droop { to { transform: rotate(-12deg) translateY(6px); } }
.confetti { position: fixed; inset: 0; z-index: 60; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 15px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(var(--spin)); } }

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