/* ---------- Warrior figures, 3D board and the Ink (engraving) theme ---------- */

/* Colours shared by every theme; each theme below sets the two team colours. */
:root {
  --mt: #cfd6e0;      /* metal */
  --sk: #f4c7a1;      /* skin */
  --wd: #9a6436;      /* wood */
  --gd: #ffc93c;      /* gold */
  --hair: #6b3f1f;
  --fur: #fffaf0;
  --boot: #3b2a20;
  --ink: #1c1330;     /* outlines */
  --shade: rgba(0, 0, 0, 0.16);
}
body[data-theme='battle'] { --w-tm: #2347a0; --w-td: #c9a13b; --w-hs: #cfc6b8; --b-tm: #8a1616; --b-td: #1c1c1e; --b-hs: #3a2618; }
body[data-theme='candy'] { --w-tm: #ffb703; --w-td: #fb5607; --w-hs: #fff1e6; --b-tm: #9d4edd; --b-td: #3c096c; --b-hs: #5a3a31; }
body[data-theme='neon']  { --w-tm: #00e0a4; --w-td: #00796b; --w-hs: #e6fff7; --b-tm: #ff2e7e; --b-td: #7a0036; --b-hs: #3d2a3a; --ink: #0d0b1f; }
body[data-theme='ocean'] { --w-tm: #5ad1f5; --w-td: #1769aa; --w-hs: #f4f8fb; --b-tm: #ff8f3f; --b-td: #a83800; --b-hs: #6b4426; }
body[data-theme='royal'] { --w-tm: #fbf3dc; --w-td: #c99a2e; --w-hs: #f7f3ea; --b-tm: #3d5afe; --b-td: #14206e; --b-hs: #2e2a2a; }

/* Ink: black-and-white pen hatching, like an old engraving. */
body[data-theme='ink'] {
  --w-tm: url(#ink-l); --w-td: url(#ink-m); --w-hs: #fff;
  --b-tm: url(#ink-d); --b-td: #2a2a2a; --b-hs: url(#ink-m);
  --mt: url(#ink-h); --sk: #fff; --wd: #fff; --gd: #fff; --hair: url(#ink-m); --fur: #fff; --boot: #111;
  --ink: #0b0b0b; --shade: url(#ink-s);
  --gem-k: #111; --gem-q: #111; --gem-r: #111; --gem-b: #111; --gem-n: #111; --gem-p: #fff;
  --w-hi: #ffffff; --w-lo: #d4d4d4; --w-line: #111;
  --b-hi: #5a5a5a; --b-lo: #111; --b-line: #000;
  --light: #ddd6c6;
  --dark: repeating-linear-gradient(45deg, #b9b1a0 0 3px, #6e675a 3px 4.2px);
  --board-edge: #0b0b0b;
  --accent: #e8e2d0;
}
body[data-theme='ink'] .sq .coord { color: #111 !important; background: #f6f3ea; padding: 0 2px; border-radius: 3px; }

/* Figure parts */
.figp.w { --tm: var(--w-tm); --td: var(--w-td); --hs: var(--w-hs); }
.figp.b { --tm: var(--b-tm); --td: var(--b-td); --hs: var(--b-hs); }
.figp[data-t='p'] { --gem: var(--gem-p); }
.figp[data-t='n'] { --gem: var(--gem-n); }
.figp[data-t='b'] { --gem: var(--gem-b); }
.figp[data-t='r'] { --gem: var(--gem-r); }
.figp[data-t='q'] { --gem: var(--gem-q); }
.figp[data-t='k'] { --gem: var(--gem-k); }
.figp .fig * { stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.f-tm { fill: var(--tm); }
.f-td { fill: var(--td); }
.f-hs { fill: var(--hs); }
.f-mt { fill: var(--mt); }
.f-sk { fill: var(--sk); }
.f-wd { fill: var(--wd); }
.f-gd { fill: var(--gd); }
.f-hair { fill: var(--hair); }
.f-fur { fill: var(--fur); }
.f-boot { fill: var(--boot); }
.f-gem { fill: var(--gem); }
.figp .fig .f-gs { fill: rgba(0, 0, 0, 0.3); stroke: none; }
.figp .fig .f-shade { fill: var(--shade); stroke: none; }
.figp .fig .f-eye { fill: var(--ink); stroke: none; }
.figp .fig .f-line { fill: none; stroke-width: 1.2; }
.figp .fig .f-crook { fill: none; stroke: var(--gd); stroke-width: 4.5; }
body[data-theme='ink'] .figp .fig .f-crook { stroke: #111; stroke-width: 4; }

/* Figures on the board stand on their square and are taller than it. */
.board { overflow: visible; border-radius: 6px; }
.board-wrap { margin-top: calc(var(--sq) * 0.35); }
.sq .piece { pointer-events: auto; }
.sq .piece.victim { pointer-events: none; }
.sq .piece.figp { position: absolute; left: 4%; bottom: 5%; width: 92%; height: 138%; }
.sq.mine:hover .piece { transform: none; filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.95)) drop-shadow(0 4px 3px rgba(0, 0, 0, 0.35)); }

/* They're alive: breathe while idle, bounce when picked up. */
.figp .fig { transform-origin: 50% 96%; animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { transform: translateY(-1.5%) scaleY(1.025); } }
.sq.sel .figp .fig { animation: ready 0.42s ease-in-out infinite alternate; }
@keyframes ready { to { transform: translateY(-7%); } }
.rubble-pile .fig, .log .fig, .drag-ghost .fig, .promo-choices .fig { animation: none !important; }

/* ---------- 3D board ---------- */
/* Real 3D board (Three.js canvas) */
.board3d { position: absolute; inset: calc(var(--sq) * -0.35) calc(var(--sq) * -0.5) calc(var(--sq) * -0.25); }
.board3d canvas { display: block; outline: none; }
body.view3d .board-wrap { margin-top: calc(var(--sq) * 0.45); margin-bottom: calc(var(--sq) * 0.3); }
body.view3d .layout { column-gap: calc(var(--sq) * 0.8); }

/* ---------- Figures elsewhere ---------- */
.drag-ghost.figp { width: var(--sq); height: calc(var(--sq) * 1.5); transform: translate(-50%, -85%) scale(1.1); }
.rubble-pile .piece.figp { width: 34px; height: 50px; margin: -4px 4px; }
.rubble-pile .piece.figp::after { display: none; }
.log .piece.figp { width: 28px; height: 40px; }
.brand-pieces .piece.figp { width: 52px; height: 78px; }
.promo-choices .piece.figp { width: 46px; height: 68px; }

/* New rubble arrives after the fallen piece has been knocked down. */
.rubble-pile .piece.fresh { animation-delay: 0.55s; animation-fill-mode: backwards; }

/* Rendered 3D figure pictures (log, rubble, flat board) */
.piece img.fig { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-drag: none; }
.figp.real { filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35)); }
.log .piece.figp.real { width: 30px; height: 45px; }
.rubble-pile .piece.figp.real { width: 40px; height: 60px; margin: -8px 2px; filter: grayscale(0.35) brightness(0.85) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.5)); }
.brand-pieces .piece.figp.real { width: 60px; height: 90px; }

/* Narrow screens: keep the 3D canvas inside the page (no sideways scrolling). */
html, body { overflow-x: hidden; }
@media (max-width: 760px) {
  .board3d { inset: calc(var(--sq) * -0.45) 0 calc(var(--sq) * -0.05); }
  body.view3d .board-wrap { margin-top: calc(var(--sq) * 0.5); margin-bottom: calc(var(--sq) * 0.1); }
}

/* Ink theme: outline each army so black pieces show on dark squares and white on light. */
body[data-theme='ink'] .sq .figp.b, body[data-theme='ink'] .rubble .figp.b, body[data-theme='ink'] .log .figp.b {
  filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 2px rgba(255, 255, 255, 0.85)) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4));
}
body[data-theme='ink'] .sq .figp.w, body[data-theme='ink'] .rubble .figp.w, body[data-theme='ink'] .log .figp.w {
  filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.8)) drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4));
}

/* Pile of bodies in the fallen-pieces panels */
.rubble-pile.heap { position: relative; display: block; min-height: 170px; flex: 1; overflow: hidden; }
.rubble-pile.heap::before {
  content: '';
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: -6px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(90, 20, 20, 0.45), rgba(0, 0, 0, 0.35) 55%, transparent 72%);
}
.corpse {
  position: absolute;
  width: 52%;
  aspect-ratio: 2 / 1;
  transform: rotate(var(--tilt)) scaleX(var(--flip));
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.6));
}
.corpse img { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-drag: none; }
.corpse.fresh { animation: corpse-drop 0.75s cubic-bezier(0.3, 1.35, 0.5, 1) 0.5s backwards; }
@keyframes corpse-drop {
  from { transform: translateY(-170px) rotate(calc(var(--tilt) - 50deg)) scaleX(var(--flip)); opacity: 0; }
  60% { opacity: 1; }
}
body[data-theme='ink'] .corpse.b { filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 2px rgba(255, 255, 255, 0.8)) drop-shadow(0 4px 3px rgba(0, 0, 0, 0.5)); }
body[data-theme='ink'] .corpse.w { filter: drop-shadow(0 0 1px #000) drop-shadow(0 4px 3px rgba(0, 0, 0, 0.5)); }
@media (max-width: 1100px) { .rubble-pile.heap { min-height: 130px; } }

/* Phones: let the menus wrap onto two lines and shrink a little */
@media (max-width: 760px) {
  .topbar-right { flex-wrap: wrap; justify-content: center; gap: 6px; }
  .topbar-right select { font-size: 13px; padding: 6px 8px; max-width: 46vw; }
  .topbar-right .btn.icon { padding: 5px 9px; }
  .status { font-size: 15px; padding: 6px 12px; }
  .board3d canvas { touch-action: pan-y; }
}
html { -webkit-text-size-adjust: 100%; }
button, select, .sq, .board3d { touch-action: manipulation; }
