/* GOATCOIN Arcade - Chess board (Gate 2A).
 *
 * Palette only: the same tokens the four cabinets use. No image asset, no webfont, no canvas:
 * the board is a real 8x8 grid of buttons so every square is focusable and named.
 */

/* The stage shrinks to fit its contents, so the surface states its own width: without this the
 * board sizes itself from the toolbar instead of from the stage. --board lives here so the toolbar,
 * the board and the status line all share one measure. */
.chess-surface {
  /* Same budget the 2048 board uses (--game-h minus its action row), so the two cabinets show
   * boards of the same size on the same screen. */
  --board: min(100%, calc(var(--game-h) - 64px), 640px);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  position: relative; width: 100%;
}

.chess-toolbar { width: var(--board); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
/* Both toolbar items keep their line: the label is short but letter-spaced, and on a 300 px board
 * it would otherwise break into three lines. */
.chess-toolbar > * { flex: 0 0 auto; white-space: nowrap; }

/* site.css turns every .btn into width:100% at <=430 px. In this row that stretched "Flip board" to
 * the toolbar's whole width and, because the row cannot wrap, pushed it 164 px past the cabinet.
 * Keep the button at its own width and let the two items stack when the board is too narrow for both.
 */
.chess-toolbar { flex-wrap: wrap; row-gap: 8px; }
.chess-toolbar > .btn { width: auto; }

.chess-turn {
  font-size: 11px; font-weight: 850; letter-spacing: .16em; text-transform: uppercase;
  color: var(--green);
}

/* The wrapper gives the promotion chooser something to sit on: it is positioned against the board,
 * not against the stage, so it appears over the last rank wherever the cabinet is on screen. */
.chess-board-wrap { position: relative; width: var(--board); max-width: 100%; }

.chess-board {
  width: 100%; aspect-ratio: 1 / 1;
  container-type: inline-size;
  margin: 0 auto;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border: 2px solid #354761; border-radius: 10px; overflow: hidden; background: #08182b;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}

/* The gate's own status paragraph sits inside this sidepanel. Its address is one unbreakable
 * 42-character token, so it needs a break opportunity and a little air before GAME. */
#arcade-gate-status, .arcade-gate-status {
  overflow-wrap: anywhere; word-break: break-word; margin: 0 0 10px;
  font-size: 12px; line-height: 1.6; color: var(--muted);
}

/* One square. Gate 5.2: pieces are locally hosted SVG files, not font glyphs. Each file carries
 * its own fill and outline (white: ivory on dark navy; black: charcoal on silver), so the board no
 * longer depends on a platform symbol font or on -webkit-text-stroke - the two things that made a
 * black piece read as near-white on a dark square. The geometry is identical for both colours and
 * scales from the 243 px mobile board to the 612 px desktop board. */
.cq {
  appearance: none; -webkit-appearance: none;
  border: 0; padding: 0; margin: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  line-height: 1; cursor: pointer;
}

/* The piece itself. Absolute so the square's background, the last-move tint and the legal-move
 * ring stay independent of it, and pointer-events:none so the square keeps the gesture. The class
 * is colour+type in ONE token (wk, bb, ...): separate .w/.b plus .b-for-bishop classes would let
 * ".pc.b.b" match every black piece, because repeating a class in a compound selector is a no-op. */
.pc {
  position: absolute; left: 4%; top: 4%; width: 92%; height: 92%;
  pointer-events: none;
  background-repeat: no-repeat; background-position: center; background-size: contain;
  filter: drop-shadow(0 1px 1.5px rgba(1, 9, 17, .45));
}
.pc.wk { background-image: url(pieces/white_king.svg); }
.pc.wq { background-image: url(pieces/white_queen.svg); }
.pc.wr { background-image: url(pieces/white_rook.svg); }
.pc.wb { background-image: url(pieces/white_bishop.svg); }
.pc.wn { background-image: url(pieces/white_knight.svg); }
.pc.wp { background-image: url(pieces/white_pawn.svg); }
.pc.bk { background-image: url(pieces/black_king.svg); }
.pc.bq { background-image: url(pieces/black_queen.svg); }
.pc.br { background-image: url(pieces/black_rook.svg); }
.pc.bb { background-image: url(pieces/black_bishop.svg); }
.pc.bn { background-image: url(pieces/black_knight.svg); }
.pc.bp { background-image: url(pieces/black_pawn.svg); }

/* Board squares, Option C: measured so that every piece/square combination clears ~2.6:1 while the
 * two square colours still separate from each other at 2.16:1. Cream #F7F4E8 on #7692BA = 2.89:1,
 * on #3E5C80 = 6.25:1; charcoal #161717 on #7692BA = 5.64:1, on #3E5C80 = 2.61:1. */
.cq.light { background-color: #7692ba; }
.cq.dark  { background-color: #3e5c80; }

.cq.last { background-image: linear-gradient(rgba(216, 182, 117, .30), rgba(216, 182, 117, .30)); }
.cq.sel { box-shadow: inset 0 0 0 3px var(--green); }
/* Check indicator: no single amber clears 3:1 against both squares (#7692BA needs a dark mark,
 * #3E5C80 a bright one), so the ring is two-tone — a dark amber edge that reads on the light square
 * and a pale amber band that reads on the dark one. Selection, target and last-move are unchanged. */
.cq.check { box-shadow: inset 0 0 0 2px #4a2500, inset 0 0 0 4px #ffd98a; }

/* Legal destination: a dot on an empty square, a ring on an occupied one. */
.cq.target::after {
  content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%;
  background: rgba(181, 247, 121, .85);
}
.cq.target.occ::after {
  width: 78%; height: 78%; background: transparent;
  border: 3px solid rgba(181, 247, 121, .9);
}

.cq:focus-visible { outline: 3px solid var(--green); outline-offset: -3px; z-index: 2; }

.chess-status { width: var(--board); max-width: 100%; margin: 0; min-height: 20px; color: var(--muted); font-size: 13px; text-align: center; }
.chess-status strong { color: var(--white); }

/* Promotion chooser: four buttons over the board, never a modal dialog. */
.chess-promo {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 10px; background: rgba(6, 22, 45, .96);
  border: 1px solid #354761; border-radius: 10px;
}
.chess-promo[hidden] { display: none; }
.chess-promo button {
  appearance: none; border: 1px solid #4c6685; border-radius: 8px; background-color: #102a49;
  cursor: pointer; padding: 0; height: 64px;
  background-repeat: no-repeat; background-position: center; background-size: 54%;
}
.chess-promo.w [data-piece="q"] { background-image: url(pieces/white_queen.svg); }
.chess-promo.w [data-piece="r"] { background-image: url(pieces/white_rook.svg); }
.chess-promo.w [data-piece="b"] { background-image: url(pieces/white_bishop.svg); }
.chess-promo.w [data-piece="n"] { background-image: url(pieces/white_knight.svg); }
.chess-promo.b [data-piece="q"] { background-image: url(pieces/black_queen.svg); }
.chess-promo.b [data-piece="r"] { background-image: url(pieces/black_rook.svg); }
.chess-promo.b [data-piece="b"] { background-image: url(pieces/black_bishop.svg); }
.chess-promo.b [data-piece="n"] { background-image: url(pieces/black_knight.svg); }

/* Gate 5.2: centred result panel. It floats over the board - the finished position stays visible
 * behind translucent navy - and never replaces or clears the board or the move list. */
.chess-result {
  position: absolute; inset: 0; z-index: 4;
  display: flex; align-items: center; justify-content: center;
  padding: 14px; text-align: center;
  background: rgba(6, 22, 45, .55);
  border-radius: 12px;
}
.chess-result[hidden] { display: none; }
.chess-result-card {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  max-width: 100%; padding: 20px 22px;
  background: rgba(8, 26, 52, .94);
  border: 1px solid rgba(181, 247, 121, .28);
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
}
.chess-result-kicker { margin: 0; font-size: 10.5px; letter-spacing: .22em; color: #8fa1b8; }
.chess-result-title {
  margin: 4px 0 0; font-size: clamp(21px, 4.4vw, 38px); line-height: 1.08;
  font-weight: 800; letter-spacing: .01em; color: var(--green); text-transform: uppercase;
}
.chess-result-reason { margin: 0; font-size: 13px; line-height: 1.35; color: #cdd7e5; }
.chess-result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
.chess-result-actions .btn { min-width: 118px; }
@media (max-width: 420px) {
  .chess-result { padding: 8px; }
  .chess-result-card { padding: 14px 12px; }
  .chess-result-actions { flex-direction: column; align-items: stretch; width: 100%; max-width: 190px; }
}
.chess-promo button:hover { border-color: var(--green); }
.chess-promo button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.chess-moves {
  list-style: none; margin: 12px 0 0; padding: 0;
  max-height: 232px; overflow: auto;
  font-size: 13px; color: var(--muted);
}
.chess-moves li {
  display: flex; gap: 8px; padding: 3px 0; border-bottom: 1px solid #1b2f47;
}
.chess-moveno { width: 30px; color: #7d8ea3; }
.chess-moves b { color: var(--white); font-weight: 600; }
.chess-moves b.chess-black { color: var(--blue); }

/* The shared hero is a three-column line: title, one sentence, level note. Chess has the shortest
 * title on the site, so the sentence is squeezed into a narrow middle column and wraps mid-phrase.
 * This page drops it below the layout breakpoint instead; the sentence is repeated in the panel. */
@media (max-width: 760px) {
  .game-hero .hero-line > p { display: none; }
  /* --board stays as defined on .chess-surface: one measure for the toolbar, the board and the
   * status line. Redefining it on .chess-board here would make the board narrower than the toolbar. */
  .chess-moves { max-height: 150px; }
}
/* Gate 5: game setup (mode, difficulty, colour). Same palette tokens as the rest of the cabinet -
 * no new colour, no image. Buttons keep their own width here: site.css makes every .btn full width
 * at <=430 px, which would stack the three difficulty buttons into three rows on a phone. */
.chess-setup { margin: 0 0 16px; }
.chess-setup-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
.chess-setup-row:last-child { margin-bottom: 0; }
.chess-setup-row[hidden] { display: none; }
.chess-setup .btn {
  width: auto; flex: 1 1 auto; min-height: 40px; padding: 0 12px;
  font-size: 11px; letter-spacing: .04em;
}
.chess-setup .btn[aria-pressed="true"] {
  border-color: var(--green); color: var(--white);
  box-shadow: inset 0 0 0 1px var(--green);
}
