/*
 * Board (<monolith-board>, web/src/ui/board.js) and status line
 * (<monolith-status-line>, web/src/ui/status-line.js). Tokens only (tokens.css).
 *
 * Size: as wide as its container up to 560 px, always square; at 360 px wide
 * screens the squares stay above the 44 px touch target (FR-021).
 * No state is shown by colour alone (NFR-008):
 *   selected origin      thick dark frame
 *   legal landing square dashed inner frame
 *   last move            corner triangle
 *   Black / White pawn   solid disc / light disc with a double ring (CSS shapes)
 *   stack                offset disc behind the top pawn and an 'x4' badge
 */

monolith-board,
.board {
  display: block;
  width: min(100%, 560px);
  min-width: 0;
}

.board__frame {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr);
  grid-template-rows: auto 1.25rem;
  gap: var(--space-1);
}

.board__ranks,
.board__files {
  display: grid;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1;
  text-align: center;
  user-select: none;
}

.board__ranks {
  grid-template-rows: repeat(6, 1fr);
  align-items: center;
}

.board__files {
  grid-column: 2;
  grid-template-columns: repeat(6, 1fr);
  align-items: center;
}

.board__grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, minmax(var(--touch-target), 1fr));
  aspect-ratio: 1;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  /* Tap to select, tap to move: no double-tap zoom, no hover-only cues. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--board-square-light);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.square[data-shade="dark"] {
  background: var(--board-square-dark);
}

.square:focus-visible {
  z-index: 2;
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: calc(-1 * var(--focus-ring-width));
}

/* Selected origin: highlight plus a thick frame. */
.square[data-selected] {
  background: var(--board-square-highlight);
  box-shadow: inset 0 0 0 4px var(--pawn-white-stroke);
}

/* Legal landing square: dashed inner frame in the target colour. */
.square[data-target]::after {
  content: "";
  position: absolute;
  inset: 6%;
  border: 3px dashed var(--board-square-target);
  border-radius: var(--radius-round);
  pointer-events: none;
}

/* Last move: a corner triangle on its start and landing squares. */
.square[data-last]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 30%;
  height: 30%;
  background: var(--board-square-highlight);
  clip-path: polygon(0 0, 100% 0, 0 100%);
  box-shadow: inset 2px 2px 0 var(--pawn-white-stroke);
  pointer-events: none;
}

/*
 * Pawns (CSS shapes). Black: solid disc with a thin light rim. White: light
 * disc with a dark rim and a second inner ring. A stack adds an offset disc
 * behind the top pawn. The value is a numeral scaled to the square.
 */
.square {
  container-type: inline-size;
}

.piece {
  position: absolute;
  inset: 13% 15% 15% 13%;
  pointer-events: none;
}

.pawn,
.piece__under {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-round);
}

.piece__under {
  transform: translate(10%, 12%);
}

.pawn {
  display: grid;
  place-items: center;
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-size: 34cqi;
  font-weight: 700;
  line-height: 1;
}

.pawn--black {
  border: 2px solid var(--pawn-black-stroke);
  background: var(--pawn-black-fill);
  color: var(--pawn-black-stroke);
}

.pawn--white {
  border: 3px solid var(--pawn-white-stroke);
  background: var(--pawn-white-fill);
  color: var(--pawn-white-stroke);
}

.pawn.pawn--white {
  box-shadow:
    inset 0 0 0 3px var(--pawn-white-fill),
    inset 0 0 0 5px var(--pawn-white-stroke);
}

/*
 * The slide of a single step (board-motion.js): a copy of the moved pawn on
 * top of the squares, outside the layout and the pointer's way; the real
 * pawn waits hidden on its landing square until the copy arrives.
 */
.board__motion {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  will-change: transform;
  container-type: inline-size;
}

.square[data-arriving] .pawn {
  visibility: hidden;
}

/* Stack height badge: 'x4'. */
.square__height {
  position: absolute;
  right: 4%;
  bottom: 4%;
  padding: 0 0.25em;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.3;
  pointer-events: none;
}

/* Status line: standing text plus a polite live message. */
monolith-status-line,
.status-line {
  display: grid;
  gap: var(--space-1);
  min-height: calc(2 * var(--line-height) * 1em);
}

.status-line__state {
  font-weight: 600;
}

.status-line__message[data-kind="error"] {
  color: var(--color-danger);
  font-weight: 600;
}

.status-line__message[data-kind="result"] {
  font-weight: 700;
}

/*
 * Board controls (<board-controls>, web/src/ui/board-controls.js), directly
 * under the board. First line: the arrows (secondary icon buttons with a CSS
 * chevron) around the position counter, centred. Second line, wrapping:
 * 'Start from here on' (secondary), Undo (the one primary of the board
 * column, shown only while it can act) and Flip board (secondary, with a
 * decorative turn glyph). Every control keeps the 44 px target and nothing
 * shares a line with the arrows, so no control can overlap another.
 */
board-controls,
.board-controls {
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  width: min(100%, 560px);
  min-width: 0;
}

.board-controls__flip {
  white-space: nowrap;
}

.board-controls__flip::before {
  content: "\21C5" / "";
  font-size: var(--text-lg);
  line-height: 1;
}

.board-controls__steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

.board-controls__arrow {
  width: calc(1.5 * var(--touch-target));
}

.board-controls__chevron {
  display: block;
  width: 0.65rem;
  height: 0.65rem;
  border-top: 3px solid currentColor;
  border-right: 3px solid currentColor;
  transform: translateX(-0.15rem) rotate(45deg);
}

.board-controls__arrow--previous .board-controls__chevron {
  transform: translateX(0.15rem) rotate(-135deg);
}

.board-controls__position {
  min-width: 7ch;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.board-controls__edit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.board-controls__hint {
  flex-basis: 100%;
  margin: 0;
  text-align: center;
}
