/* Fog Line: the field, the reefs, the tokens, the fight card. A plotting
   table seen from above in the theme's ground, with a bank of fog across
   the middle rows: not a board from any box, no plastic stands, no flags
   on pegs. Shared HUD pieces are in hud.css.

   Colour is never the only cue: a unit is its glyph (and its number), a
   side is its insignia, a reef is hatched rock, a cell a unit can step to
   carries a dot, one it can attack a crosshair ring, and the unit picked a
   white frame. */

.field {
  --lab: 16px;
  display: grid;
  grid-template-columns: var(--lab) minmax(0, 1fr);
  grid-template-rows: var(--lab) auto;
  width: 100%;
  max-width: max(300px, calc(100dvh - 224px));
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}
.field .corner { grid-area: 1 / 1; }
.field .cols, .field .rows {
  display: grid;
  font: 600 10px/1 var(--mono);
  color: var(--ink-faint);
}
.field .cols { grid-template-columns: repeat(8, 1fr); align-items: center; text-align: center; }
.field .rows { grid-template-rows: repeat(8, 1fr); align-items: center; text-align: center; }

.ground {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  border: 1px solid var(--line-strong);
  background: var(--sea);
  overflow: hidden;
}
/* the fog: a slow bank across the middle of the field, under the units */
.ground::before {
  content: "";
  position: absolute;
  inset: 0 -50%;
  pointer-events: none;
  z-index: 1;
  background:
    radial-gradient(ellipse 30% 14% at 30% 47%, rgba(205, 215, 230, 0.12), transparent 70%),
    radial-gradient(ellipse 26% 12% at 70% 55%, rgba(205, 215, 230, 0.1), transparent 70%),
    linear-gradient(to bottom, transparent 22%, rgba(190, 205, 225, 0.07) 38%, rgba(190, 205, 225, 0.09) 50%, rgba(190, 205, 225, 0.07) 62%, transparent 78%);
  animation: fl-fog 40s ease-in-out infinite alternate;
}
@keyframes fl-fog { from { transform: translateX(-12%); } to { transform: translateX(12%); } }

.ground .cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  cursor: default;
}
.ground button.cell { cursor: pointer; }
.ground button.cell:hover { background-color: rgba(var(--sea-rgb), 0.12); }

/* home rows: each side's ground, faintly in its colour */
.side-0 .cell.home-own, .side-1 .cell.home-enemy { background-color: rgba(46, 196, 182, 0.07); }
.side-1 .cell.home-own, .side-0 .cell.home-enemy { background-color: rgba(255, 159, 28, 0.06); }
.deploy .cell.home-enemy { background-image: repeating-linear-gradient(-45deg, rgba(128, 145, 166, 0.08) 0 2px, transparent 2px 9px); }
.deploy .cell.swap:hover { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35); }

/* a reef: hatched rock, raised, plainly not ground */
.ground .cell.reef {
  z-index: 2;
  background:
    repeating-linear-gradient(135deg, rgba(140, 152, 172, 0.5) 0 3px, rgba(92, 103, 125, 0.2) 3px 8px),
    #1b2330;
  box-shadow: inset 0 0 0 1px rgba(160, 172, 190, 0.55), inset 0 -4px 0 rgba(0, 0, 0, 0.35);
}

/* ---- tokens ---- */

.tok {
  position: relative;
  z-index: 2;
  display: block;
  width: 88%;
  aspect-ratio: 1;
}
/* the token's own colours (frame, glyph, insignia, marks) are in hud.css,
   shared with the lobby's scene */
.tok-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.tok.late .tok-svg { opacity: 0.6; } /* shown only at the end: the survivors nobody had seen */
.tok .rk {
  position: absolute;
  top: -3%;
  right: -3%;
  min-width: 1.25em;
  padding: 1px 2px;
  border-radius: 3px;
  background: var(--c);
  color: #06101a;
  font: 700 clamp(8px, 2vw, 11px)/1 var(--mono); /* the colour reads first; the number is the check */
  text-align: center;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.tok.arrive { animation: fl-arrive 0.32s ease-out both; }
/* a token is 88% of its cell, so one cell is 1/0.88 of the token */
@keyframes fl-arrive { from { transform: translate(calc(var(--dx) * 113.6%), calc(var(--dy) * 113.6%)); } }

/* ---- picking and targets ---- */

.ground .cell.sel::after {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: 3;
  border: 3px solid #fff;
  border-radius: 3px;
  box-shadow: 0 0 0 2px var(--side), 0 0 16px var(--side);
  pointer-events: none;
}
/* a cell the picked unit can move to: a dot */
.ground .cell.tgt.move::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--side);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.45), 0 0 10px var(--side);
  pointer-events: none;
}
/* an enemy it can attack: a crosshair ring over the token */
.ground .cell.tgt.attack::after {
  content: "";
  position: absolute;
  inset: 4%;
  z-index: 3;
  border: 3px solid #ff5a66;
  border-radius: 50%;
  background:
    linear-gradient(#ff5a66, #ff5a66) 50% 0 / 3px 22% no-repeat,
    linear-gradient(#ff5a66, #ff5a66) 50% 100% / 3px 22% no-repeat,
    linear-gradient(#ff5a66, #ff5a66) 0 50% / 22% 3px no-repeat,
    linear-gradient(#ff5a66, #ff5a66) 100% 50% / 22% 3px no-repeat;
  box-shadow: 0 0 10px rgba(230, 57, 70, 0.8);
  pointer-events: none;
  animation: fl-lock 1.2s ease-in-out infinite alternate;
}
@keyframes fl-lock { to { transform: scale(0.9); } }
.ground .cell.tgt { background-color: rgba(255, 255, 255, 0.05); }

/* the last move: a dashed arrow in the mover's colour */
.last-move {
  --c: var(--p0);
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
  opacity: 0.9;
}
.last-move.p1 { --c: var(--p1); }
.last-move .lm-line { fill: none; stroke: var(--c); stroke-width: 0.075; stroke-dasharray: 0.16 0.1; stroke-linecap: round; filter: drop-shadow(0 0 0.04px #000); }
.last-move .lm-head { fill: var(--c); stroke: #06101a; stroke-width: 0.02; }
.last-move .lm-from { fill: none; stroke: var(--c); stroke-width: 0.06; }

/* ---- a fight: both units, a cross over whichever fell ---- */

.fight-card {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 6;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 10px;
  border: 2px solid var(--hit);
  border-radius: var(--radius);
  background: var(--top-bg);
  box-shadow: 0 0 0 1px rgba(230, 57, 70, 0.35), 0 0 28px rgba(230, 57, 70, 0.5);
  pointer-events: none;
  animation: fl-stamp 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  transition: opacity 0.4s ease-in;
}
.fight-card.taken { border-color: #fff; box-shadow: 0 0 28px rgba(255, 255, 255, 0.45); }
.fight-card.gone { opacity: 0; }
.fight-card figure { margin: 0; display: grid; justify-items: center; gap: 6px; width: clamp(76px, 24vw, 104px); }
.fight-card .tok { width: clamp(52px, 16vw, 72px); }
.fight-card .tok .rk { font-size: 14px; }
.fight-card figcaption { text-align: center; }
.fight-card figcaption b { display: block; font: 700 14px/1.1 var(--head); letter-spacing: 0.08em; }
.fight-card figcaption small { display: block; font: 600 10px/1.2 var(--mono); letter-spacing: 0.12em; color: var(--c); }
.fight-card figure.p0 { --c: var(--p0); }
.fight-card figure.p1 { --c: var(--p1); }
.fight-card .clash { width: 24px; height: 24px; flex: none; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; animation: fl-spark 0.5s ease-out 0.15s both; }
.fight-card .fell .tok-svg { opacity: 0.45; }
.fight-card .fell .tok::before, .fight-card .fell .tok::after {
  content: "";
  position: absolute;
  left: 2%;
  right: 2%;
  top: calc(50% - 3px);
  height: 6px;
  border-radius: 2px;
  background: #ff5a66;
  box-shadow: 0 0 8px rgba(230, 57, 70, 0.9);
  transform: rotate(45deg);
  animation: fl-strike 0.35s ease-out 0.45s both;
}
.fight-card .fell .tok::after { transform: rotate(-45deg); }
.fight-card .fell figcaption b { text-decoration: line-through; text-decoration-color: #ff5a66; text-decoration-thickness: 2px; }
@keyframes fl-stamp {
  from { transform: translate(-50%, -50%) scale(1.6) rotate(-3deg); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
}
@keyframes fl-spark { from { transform: scale(0.2) rotate(-45deg); opacity: 0; } }
@keyframes fl-strike { from { opacity: 0; scale: 1.6; } }

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

.fl.deploy, .fl.battle { display: grid; gap: 14px; }
@media (min-width: 900px) {
  .fl.deploy, .fl.battle { grid-template-columns: minmax(0, 600px) minmax(260px, 360px); align-items: start; justify-content: center; }
}
.fl .theatre { display: grid; gap: 10px; align-content: start; }
.fl .theatre header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.fl .theatre header .label b { color: var(--side); }
.fl .btn-row .btn.primary { flex: 2 1 auto; }

/* the key: every unit in its colour (--u, art.js UNIT_COLOURS), its rank,
   how many, what it beats and does; in a battle how many are left */
.legend { display: grid; gap: 6px; }
@media (min-width: 560px) and (max-width: 899px) { .legend { grid-template-columns: 1fr 1fr; } }
.legend-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 5px 8px 5px 6px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--u, var(--line));
  border-radius: var(--radius);
  background: linear-gradient(90deg, color-mix(in srgb, var(--u, transparent) 16%, transparent), transparent 70%), rgba(var(--raise-rgb), 0.5);
}
.legend-row .tok { width: 36px; }
.legend-row .tok .rk { font-size: 9px; }
.legend-row b { display: block; font: 700 15px/1.1 var(--head); letter-spacing: 0.08em; color: var(--u, inherit); }
.legend-row small { display: block; font: 400 11px/1.3 var(--mono); color: var(--ink-faint); }
.legend-left { display: block; margin-top: 2px; font: 700 11px/1.3 var(--mono); color: var(--ink-faint); }
.legend-left b { display: inline; font: inherit; }
.legend-left b.p0 { color: var(--p0); }
.legend-left b.p1 { color: var(--p1); }
.legend-pic { width: 44px; aspect-ratio: 1; }
.legend-pic .tok-svg { width: 100%; height: 100%; display: block; }
.key > summary { cursor: pointer; padding: 4px 0; }
.key[open] > summary { margin-bottom: 6px; }

/* the side panel: the last move, both sides' losses, the log */
.side-panel { gap: 12px; }
.last-line { margin: 0; }
.last-line b { color: var(--side); }
.losses { display: grid; gap: 6px; }
.losses .label b { color: var(--side); }
.loss-row { display: flex; flex-wrap: wrap; gap: 6px; }
.loss {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px 2px 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.06em;
  color: var(--ink-dim);
}
.loss i { font-style: normal; color: var(--ink-faint); }
.tok.mini { width: 22px; }
.fl .log {
  font: 400 12px/1.5 var(--mono);
  color: var(--ink-faint);
  margin: 0;
  padding: 0;
  list-style: none;
}
.fl .log li:first-child { color: var(--ink-dim); }

.reduce-motion .ground::before { animation: none; transform: none; }

/* Painted plates (common/plates.js): the field's surface. */
body.has-board-fog-line .ground { background: var(--plate-board-fog-line) center / cover, var(--sea); }

/* the fight card shows each unit's picture, lit in its colour */
.fight-card .tok { filter: drop-shadow(0 0 7px var(--u, transparent)); }
.fight-card figcaption b { color: var(--u, inherit); }
