/* Dark Waters: the sonar plots, the marks, the vessels. Layout rules for the
   deployment and battle screens. Shared HUD pieces are in hud.css. */

.plot {
  --lab: 18px;
  display: grid;
  grid-template-columns: var(--lab) minmax(0, 1fr);
  grid-template-rows: var(--lab) auto;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
}
.plot .corner { grid-area: 1 / 1; }
.plot .cols, .plot .rows {
  display: grid;
  font: 500 10px/1 var(--mono);
  color: var(--ink-faint);
}
.plot .cols { grid-template-columns: repeat(10, 1fr); align-items: center; text-align: center; }
.plot .rows { grid-template-rows: repeat(10, 1fr); align-items: center; text-align: center; }

.water {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  aspect-ratio: 1;
  border: 1px solid var(--line-strong);
  background:
    radial-gradient(circle at 50% 50%, rgba(var(--sea-rgb), 0.09), transparent 72%),
    var(--sea);
  overflow: hidden;
}
/* range rings: the sonar plot */
.water::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-radial-gradient(circle at 50% 50%, transparent 0 calc(12% - 1px), rgba(var(--sea-rgb), 0.12) calc(12% - 1px) 12%),
    linear-gradient(rgba(var(--sea-rgb), 0.12), rgba(var(--sea-rgb), 0.12)) 50% 0 / 1px 100% no-repeat,
    linear-gradient(rgba(var(--sea-rgb), 0.12), rgba(var(--sea-rgb), 0.12)) 0 50% / 100% 1px no-repeat;
}
.water .sweep {
  position: absolute;
  inset: -21%;
  pointer-events: none;
  background: conic-gradient(from 0deg, rgba(var(--sea-rgb), 0.16), transparent 40deg, transparent);
  border-radius: 50%;
  animation: sweep 5s linear infinite;
}
.water.dim .sweep { display: none; }

.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;
  cursor: default;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}
button.cell { cursor: crosshair; }
button.cell:disabled { cursor: default; }
button.cell:hover:not(:disabled) { background: rgba(var(--sea-rgb), 0.1); }

/* ---- marks: a miss is a ring, a hit is a cross. Shape first, colour second. */

.mk { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 3; }
.mk.miss::before {
  content: "";
  width: 34%;
  height: 34%;
  border: 2px solid var(--slate);
  border-radius: 50%;
  opacity: 0.85;
}
.mk.miss.fresh::after {
  content: "";
  position: absolute;
  width: 34%;
  height: 34%;
  border: 2px solid #8b97ad;
  border-radius: 50%;
  animation: ripple 1.6s ease-out forwards;
}
@keyframes ripple {
  from { transform: scale(0.6); opacity: 1; }
  to { transform: scale(3.2); opacity: 0; }
}
.mk.hit { background: radial-gradient(circle, rgba(230, 57, 70, 0.55) 0 30%, rgba(230, 57, 70, 0.12) 31% 62%, transparent 64%); }
.mk.hit::before, .mk.hit::after {
  content: "";
  position: absolute;
  width: 62%;
  height: 3px;
  background: #ff5a66;
  border-radius: 1px;
  transform: rotate(45deg);
  box-shadow: 0 0 6px rgba(230, 57, 70, 0.9);
}
.mk.hit::after { transform: rotate(-45deg); }
.mk.hit .blip {
  position: absolute;
  inset: 18%;
  border: 2px solid var(--hit);
  border-radius: 50%;
  animation: blip 2.4s ease-out infinite;
}
.mk.hit.fresh { animation: flare 0.7s ease-out; }
.mk.hit.fresh .blip { animation: blip 0.9s ease-out 3, blip 2.4s ease-out 2.7s infinite; }
@keyframes blip {
  from { transform: scale(0.4); opacity: 1; }
  to { transform: scale(1.9); opacity: 0; }
}
@keyframes flare {
  0% { background-color: rgba(255, 120, 120, 0.95); }
  100% { background-color: transparent; }
}
.mk.hit.dead .blip { display: none; }

/* target picked, not yet fired: crosshairs */
.cell.sel::before {
  content: "";
  position: absolute;
  inset: 12%;
  z-index: 4;
  border: 2px solid var(--amber);
  border-radius: 50%;
  background:
    linear-gradient(var(--amber), var(--amber)) 50% 0 / 2px 30% no-repeat,
    linear-gradient(var(--amber), var(--amber)) 50% 100% / 2px 30% no-repeat,
    linear-gradient(var(--amber), var(--amber)) 0 50% / 30% 2px no-repeat,
    linear-gradient(var(--amber), var(--amber)) 100% 50% / 30% 2px no-repeat;
}
.side-0 .cell.sel::before { border-color: var(--teal); }

/* sonar ping sector: hatched, with the answer in the status line */
.cell.sector { background: repeating-linear-gradient(45deg, rgba(92, 103, 125, 0.32) 0 3px, transparent 3px 7px); }
.cell.sector.contact { background: repeating-linear-gradient(45deg, rgba(255, 159, 28, 0.38) 0 3px, transparent 3px 7px); }
.pinging button.cell:not(:disabled):hover { background: rgba(255, 159, 28, 0.2); }

/* deployment preview */
.cell.ghost-ok { background: rgba(46, 196, 182, 0.25); outline: 1px dashed var(--teal); outline-offset: -3px; }
.cell.ghost-bad { background: repeating-linear-gradient(45deg, rgba(230, 57, 70, 0.4) 0 3px, transparent 3px 7px); }
.side-1 .cell.ghost-ok { background: rgba(255, 159, 28, 0.22); outline-color: var(--amber); }

/* ---- vessels */

.fleet-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.ship { position: absolute; padding: 0.5%; }
.ship .vessel { width: 100%; height: 100%; display: block; overflow: visible; }
.vessel * { vector-effect: non-scaling-stroke; }
.vessel path, .vessel rect, .vessel circle { stroke: var(--side, var(--teal)); stroke-width: 1.6; fill: none; }
.vessel > path:first-child, .vessel > g > path:first-child { fill: color-mix(in srgb, var(--side, var(--teal)) 20%, transparent); }
.vessel .detail { stroke-width: 1.1; opacity: 0.85; }
.vessel .detail-fill { fill: var(--side, var(--teal)); }
.ship.sunk { --side: var(--hit); }
.ship.sunk .vessel > path:first-child, .ship.sunk .vessel > g > path:first-child { fill: none; stroke-dasharray: 4 3; }
.ship.sunk.fresh { animation: reveal 1.2s ease-out; }
@keyframes reveal { from { opacity: 0; filter: drop-shadow(0 0 8px var(--hit)); } }
.ship.hidden-reveal { opacity: 0.55; }
.ship.picked { opacity: 0.4; }

/* ---- screens */

.deploy { display: grid; gap: 14px; }
@media (min-width: 860px) {
  .deploy { grid-template-columns: minmax(0, 520px) minmax(260px, 1fr); align-items: start; justify-content: center; }
}
.roster { display: grid; gap: 6px; }
.vessel-pick {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(var(--raise-rgb), 0.6);
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.vessel-pick[aria-pressed="true"] { border-color: var(--side, var(--teal)); background: color-mix(in srgb, var(--side, var(--teal)) 14%, transparent); }
.vessel-pick .sil { height: 16px; }
.vessel-pick .sil .vessel { height: 100%; width: auto; max-width: 64px; }
.vessel-pick b { font: 700 15px/1.1 var(--head); letter-spacing: 0.1em; display: block; }
.vessel-pick small { font: 400 11px/1.2 var(--mono); color: var(--ink-faint); }
.vessel-pick .state { font: 600 11px/1 var(--mono); letter-spacing: 0.1em; color: var(--ink-faint); }
.vessel-pick.placed .state { color: var(--side, var(--teal)); }

.battle { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .battle { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
}
.theatre { display: grid; gap: 10px; align-content: start; }
.theatre header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.theatre header .label b { color: var(--side); }
.theatre.own .plot { max-width: 380px; justify-self: center; }
@media (min-width: 900px) { .theatre.own .plot { max-width: none; } }
.large-tap .theatre.own .plot { max-width: 300px; }
.fire-row { display: flex; gap: 8px; }
.fire-row .btn { flex: 1; }
.fire-row .btn.primary { flex: 2; }

.tally { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 600 11px/1.2 var(--mono);
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.tag i { font-style: normal; color: var(--ink-faint); }
.tag.down { border-color: rgba(230, 57, 70, 0.6); color: #ff8088; text-decoration: line-through; text-decoration-thickness: 2px; }
.tag.down::after { content: var(--down-word); text-decoration: none; display: inline-block; font-size: 9px; padding: 1px 4px; background: var(--hit); color: #fff; border-radius: 2px; }

.log {
  font: 400 12px/1.5 var(--mono);
  color: var(--ink-faint);
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 7.5em;
  overflow: hidden;
}
.log li:first-child { color: var(--ink-dim); }

/* ---- a vessel going down: the card over the plot it went down in */

.sunk-card {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 6;
  transform: translate(-50%, -50%);
  width: min(78%, 300px);
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 12px 14px 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.55);
  text-align: center;
  pointer-events: none;
  animation: stamp 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  transition: opacity 0.4s ease-in;
}
.sunk-card.gone { opacity: 0; }
.sunk-card::before {
  /* the flash behind the card as it lands */
  content: "";
  position: absolute;
  inset: -40%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 140, 120, 0.55), rgba(230, 57, 70, 0.2) 40%, transparent 70%);
  animation: burst 0.9s ease-out both;
}
.sunk-card .kicker { font: 600 11px/1.2 var(--mono); letter-spacing: 0.18em; color: #ff8088; }
.sunk-card.ours .kicker { color: var(--ink); }
.sunk-card .sil { --side: var(--hit); height: 22px; width: calc(var(--n) * 24px); margin: 6px 0 2px; }
.sunk-card .sil .vessel { width: 100%; height: 100%; display: block; overflow: visible; }
.sunk-card .sil .vessel > path:first-child { fill: rgba(230, 57, 70, 0.18); stroke-dasharray: 4 3; }
.sunk-card b { font: 700 clamp(22px, 7vw, 30px)/1 var(--head); letter-spacing: 0.14em; color: #ff5a66; text-shadow: 0 0 12px rgba(230, 57, 70, 0.7); }
.sunk-card small { font: 400 11px/1.2 var(--mono); color: var(--ink-dim); letter-spacing: 0.08em; }
.sunk-card .left { margin-top: 6px; font: 600 11px/1.2 var(--mono); letter-spacing: 0.1em; color: var(--ink-dim); border-top: 1px solid var(--line); padding-top: 6px; width: 100%; }
@keyframes stamp {
  from { transform: translate(-50%, -50%) scale(1.7) rotate(-4deg); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
}
@keyframes burst {
  from { transform: scale(0.2); opacity: 1; }
  to { transform: scale(1.3); opacity: 0; }
}

/* ---- deployment: turning */

.deploy .btn .dir { display: inline-block; min-width: 1em; font-family: var(--mono); }
.deploy-hint { margin: 0; line-height: 1.5; }
.hint-fine { display: none; }
@media (hover: hover) and (pointer: fine) { .hint-fine { display: inline; } }

/* Painted plates (common/plates.js): the plot's surface, and the vessels.
   A painted vessel glows in its side's colour; sunk, it fades and its
   drawn outline comes back dashed, so sunk is still a shape. */
body.has-board-dark-waters .water { background: var(--plate-board-dark-waters) center / cover, var(--sea); }
.vessel.has-plate { filter: drop-shadow(0 0 1.5px var(--side, var(--teal))); }
.vessel .plate-hull { display: none; }
.ship.sunk .vessel .plate { opacity: 0.3; }
.ship.sunk .vessel .plate-hull, .sunk-card .vessel .plate-hull { display: inline; }
.ship.sunk .vessel .plate-hull > path:first-child, .sunk-card .vessel .plate-hull > path:first-child { fill: none; stroke-dasharray: 4 3; }
.sunk-card .vessel.has-plate .plate { opacity: 0.45; }
