/* ── Defence placement ──────────────────────────────────────────────── */

.screen--place { align-items: stretch; }

.place {
  display: flex;
  flex-direction: column;
  gap: clamp(7px, 1.3vh, 12px);
  flex: 1;
  min-height: 0;
  background: var(--bg);
  padding:
    calc(var(--sat) + 14px)
    calc(var(--sar) + 14px)
    calc(var(--sab) + 12px)
    calc(var(--sal) + 14px);
}

.place__bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 34px;
  flex: none;
}

.place__actions, .who { align-content: center; }

.timer {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-btn);
  font-size: clamp(13px, 3.7vw, 15px);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: color .2s ease, background-color .2s ease;
}

.timer svg { width: 15px; height: 15px; }
.timer.is-low { color: var(--c-red-ink); }
.timer.is-low svg { animation: joining-pulse 1s ease-in-out infinite; }

/* ── The board ──────────────────────────────────────────────────────── */

.place__board {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;   /* lets the board fit itself to this box */
}

.board {
  --gutter: clamp(16px, 4.6vw, 24px);
  display: grid;
  grid-template-columns: var(--gutter) 1fr;
  grid-template-rows: var(--gutter) 1fr;
  gap: 3px;
  aspect-ratio: 1;
  /* fallback first, then: the largest square this box can hold */
  width: 100%;
  max-height: 100%;
  width: min(100cqw, 100cqh);
  animation: board-land .55s cubic-bezier(.56, 0, .35, .98) both;
}

/* lands out of the curtain's zoom */
@keyframes board-land {
  from { transform: scale(1.2); opacity: .4; }
  to { transform: none; opacity: 1; }
}

.board__files,
.board__ranks {
  display: grid;
  place-items: center;
  font-size: clamp(9px, 2.7vw, 13px);
  font-weight: 750;
  color: var(--ink);
}

.board__files {
  grid-area: 1 / 2;
  grid-template-columns: repeat(var(--n), 1fr);
}

.board__ranks {
  grid-area: 2 / 1;
  grid-template-rows: repeat(var(--n), 1fr);
}

/* the 1px gap IS the grid line, so the rules stay hairline-thin */
.board__play {
  grid-area: 2 / 2;
  position: relative;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.board__grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: 1px;
  padding: 1px;
  border: 2.5px solid var(--tone);
  border-radius: 7px;
  background: rgba(130, 150, 180, .4);
  background: color-mix(in srgb, var(--tone) 38%, #fff);
  overflow: hidden;
  touch-action: none;   /* dragging a unit must not scroll the screen */
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: #f6fafe;
  background: color-mix(in srgb, var(--tone) 7%, #fff);
  transition: background-color .12s ease;
}

.cell--ok { background: color-mix(in srgb, var(--tone) 45%, #fff); }
.cell--bad { background: #fbd5da; }

.cell--taken { background: var(--tone); }
.cell--mine { background: color-mix(in srgb, var(--tone) 62%, var(--ink)); }

/* the icon lives in every square from the start and is simply re-pointed */
.cell__icon {
  display: none;
  width: 62%;
  height: 62%;
  color: #fff;
}

.cell--taken .cell__icon { display: block; }

.cell--reject { animation: cell-reject .32s ease; }

@keyframes cell-reject {
  0%, 100% { background: #f6fafe; }
  40% { background: #f4a3ae; }
}

/* ── Rotation arrows on each placed unit ────────────────────────────── */

.board__arrows {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* out of the way while a unit is being dragged across the board */
.board__play.is-holding .board__arrows { opacity: .25; }

.rot {
  position: absolute;
  display: grid;
  place-items: center;
  width: clamp(21px, 5.6vw, 26px);
  height: clamp(21px, 5.6vw, 26px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  translate: -50% -50%;
  background: var(--surface);
  color: var(--tone);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .14), 0 3px 8px rgba(17, 24, 39, .16);
  pointer-events: auto;
  touch-action: manipulation;
  transition: transform .14s cubic-bezier(.2, .8, .3, 1), background-color .14s ease,
    color .14s ease;
}

.rot svg { width: 68%; height: 68%; }
.rot:active { transform: scale(.88); }

@media (hover: hover) {
  .rot:hover { background: var(--ink); color: var(--ink-inverse); transform: scale(1.08); }
}

/* ── Who you are ────────────────────────────────────────────────────── */

.who {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  flex: none;
  margin: 0;
  padding: 7px 16px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tone) 12%, #fff);
  font-size: clamp(13px, 3.8vw, 16px);
  font-weight: 780;
  letter-spacing: -.01em;
  color: color-mix(in srgb, var(--tone) 72%, var(--ink));
}

.who__dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--tone);
}

/* ── Your Defence tray ──────────────────────────────────────────────── */

.tray { flex: none; }

.tray__title {
  margin: 0 0 6px;
  text-align: center;
  font-size: clamp(13px, 3.7vw, 16px);
  font-weight: 780;
  letter-spacing: -.01em;
  color: color-mix(in srgb, var(--tone) 70%, var(--ink));
}

.tray__units {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 2px;
}

.unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  padding: 7px 4px;
  border: 2px solid transparent;
  border-radius: 13px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 5px 14px rgba(17, 24, 39, .07);
  touch-action: none;   /* a drag off this card must not pan the page */
  transition: border-color .15s ease, transform .15s cubic-bezier(.2, .8, .3, 1),
    opacity .15s ease;
}

.unit__name {
  font-size: clamp(10px, 2.9vw, 12px);
  font-weight: 700;
  color: color-mix(in srgb, var(--tone) 68%, var(--ink));
  white-space: nowrap;
}

.unit__row { display: flex; align-items: center; gap: 5px; }

.unit__shape {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  color: var(--tone);
}

.unit__shape svg { width: clamp(10px, 3vw, 13px); height: auto; }

.unit__count {
  font-size: clamp(10px, 2.9vw, 12px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.unit.is-selected {
  border-color: var(--tone);
  transform: translateY(-2px);
}

.unit.is-empty { opacity: .38; }
.unit.is-nudge { animation: nudge .3s ease; }
.unit:active { transform: scale(.97); }

/* ── Actions ────────────────────────────────────────────────────────── */

.place__actions {
  display: flex;
  justify-content: center;
  gap: 9px;
  flex: none;
  min-height: clamp(46px, 6.4vh, 54px);
}

.place__actions .action {
  width: auto;
  min-width: 160px;
  margin-top: 0;
  min-height: clamp(46px, 6.4vh, 54px);
}

.place__actions .action:disabled { opacity: .45; }
.place__actions .action:disabled:hover { background: var(--surface); color: var(--ink); }

.badge--done {
  --tone: var(--c-green);
  align-self: center;
  padding: 10px 20px;
  font-size: clamp(13px, 3.7vw, 15px);
}

/* ── Wide screens: the tray becomes a side panel, as in the design ─── */

@media (min-width: 760px) {
  .place {
    display: grid;
    grid-template-columns: 1fr clamp(190px, 24vw, 250px);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "bar   tray"
      "board tray"
      "who   tray"
      "acts  tray";
    gap: 14px 18px;
    /* stretch, or the board's size container would have no height to read */
    align-items: stretch;
  }

  .place__bar { grid-area: bar; }
  .place__board { grid-area: board; }
  .who { grid-area: who; justify-self: center; }
  .place__actions { grid-area: acts; }

  .tray {
    grid-area: tray;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 12px;
    border: 2px solid var(--tone);
    border-radius: var(--radius-card);
    background: var(--surface);
    overflow-y: auto;
  }

  .tray__title { font-size: 17px; }

  .tray__units {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .unit {
    width: 100%;
    box-shadow: none;
    border-bottom: 1px solid var(--line);
    border-radius: 10px;
  }

  .unit:last-child { border-bottom: 0; }
}
