/*
 * Board (<hokito-board>, web/src/ui/board.js) and status line
 * (<hokito-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
 */

hokito-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 {
  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);
}

/* 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;
}

.board__controls {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-2);
}

/* Status line: standing text plus a polite live message. */
hokito-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;
}
