/* =============================================================================
 * board.css — classical marble board, pieces, highlights, arrows, overlays,
 * eval bar and the reaction (GIF) layer.
 * ========================================================================== */

/* --- Frame & board ------------------------------------------------------- */
#board-frame {
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1 / 1;
  padding: 24px;
  background: linear-gradient(145deg, #23272e 0%, #111317 50%, #1c2026 100%);
  border: 2px solid #363c46;
  border-radius: 0.85rem;
  box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.9), inset 0 1px 2px rgba(255, 255, 255, 0.15), inset 0 0 24px rgba(0, 0, 0, 0.85);
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#board-container {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 3px solid #0b0c0e;
  border-radius: 0.25rem;
  box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.25), inset 0 0 15px rgba(0, 0, 0, 0.75);
  position: relative;
  overflow: hidden;
  background-color: #111;
  touch-action: none;
  container-type: size;
}

.frame-coord-ranks, .frame-coord-files {
  position: absolute;
  display: flex;
  justify-content: space-around;
  align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  color: #94a3b8;
  pointer-events: none;
}
.frame-coord-ranks { top: 27px; bottom: 27px; width: 24px; flex-direction: column; }
.frame-coord-ranks.left { left: 0; }
.frame-coord-ranks.right { right: 0; }
.frame-coord-files { left: 27px; right: 27px; height: 24px; flex-direction: row; }
.frame-coord-files.top { top: 0; }
.frame-coord-files.bottom { bottom: 0; }

/* --- Squares -------------------------------------------------------------- */
.square {
  position: relative;
  cursor: pointer;
  transition: filter 0.12s ease;
}

/* Carrara white marble */
.light-square {
  background-color: #f3f4f6;
  background-image:
    linear-gradient(125deg, rgba(255, 255, 255, 0.92) 0%, rgba(226, 230, 235, 0.6) 35%, rgba(252, 253, 254, 0.95) 55%, rgba(209, 215, 222, 0.75) 100%),
    radial-gradient(ellipse at 20% 80%, rgba(160, 170, 185, 0.22) 0%, transparent 60%),
    linear-gradient(35deg, transparent 44%, rgba(180, 188, 198, 0.35) 47%, rgba(180, 188, 198, 0.1) 50%, transparent 54%);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.06), inset 0 1px 1px rgba(255, 255, 255, 0.8);
}

/* Nero Marquina black marble */
.dark-square {
  background-color: #1e2229;
  background-image:
    linear-gradient(135deg, #323842 0%, #1a1e24 38%, #282d36 62%, #13161b 100%),
    radial-gradient(ellipse at 75% 25%, rgba(255, 255, 255, 0.06) 0%, transparent 55%),
    linear-gradient(155deg, transparent 46%, rgba(255, 255, 255, 0.07) 48%, transparent 51%);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.65), inset 0 1px 1px rgba(255, 255, 255, 0.06);
}

@media (hover: hover) { .square:hover { filter: brightness(1.06); } }

/* One highlight per square, chosen by priority in board-view.js. */
.square::before { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.hl-last::before { background-color: rgba(59, 130, 246, 0.32); box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.45); }
.hl-selected::before { background: rgba(234, 179, 8, 0.42); box-shadow: inset 0 0 0 3px rgba(250, 204, 21, 0.85); }
.hl-check::before {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.88) 15%, rgba(185, 28, 28, 0.65) 65%, rgba(127, 29, 29, 0.2) 100%);
  box-shadow: inset 0 0 12px rgba(254, 202, 202, 0.7);
  animation: checkPulse 1.4s infinite ease-in-out;
}
@keyframes checkPulse { 0%, 100% { opacity: 0.95; } 50% { opacity: 0.65; } }
.hl-red::before { background-color: rgba(239, 68, 68, 0.48); box-shadow: inset 0 0 0 3px rgba(248, 113, 113, 0.85); }
.hl-amber::before { background-color: rgba(245, 158, 11, 0.48); box-shadow: inset 0 0 0 3px rgba(251, 191, 36, 0.85); }
.hl-green::before { background-color: rgba(34, 197, 94, 0.42); box-shadow: inset 0 0 0 3px rgba(74, 222, 128, 0.85); }
.hl-blue::before { background-color: rgba(59, 130, 246, 0.42); box-shadow: inset 0 0 0 3px rgba(96, 165, 250, 0.85); }
.hl-premove::before { background-color: rgba(14, 165, 233, 0.44); box-shadow: inset 0 0 0 3px rgba(56, 189, 248, 0.9); }
.hl-premove-sel::before { background-color: rgba(6, 182, 212, 0.35); box-shadow: inset 0 0 0 3px rgba(34, 211, 238, 0.85); }
.drag-over { filter: brightness(1.15); }

/* Legal-move markers */
.valid-move-indicator::after {
  content: '';
  position: absolute;
  left: 37%; top: 37%;
  width: 26%; height: 26%;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.85) 0%, rgba(5, 150, 105, 0.75) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  z-index: 12;
  pointer-events: none;
}
.valid-capture-indicator::after {
  content: '';
  position: absolute;
  left: 7%; top: 7%;
  width: 86%; height: 86%;
  box-sizing: border-box;
  border: 5px solid rgba(239, 68, 68, 0.75);
  border-radius: 50%;
  z-index: 12;
  pointer-events: none;
}

/* --- Pieces (cburnett SVG set, GPLv2+ — see README) ------------------------ */
.piece {
  position: absolute;
  inset: 0;
  z-index: 10;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.45));
  pointer-events: none;
}
.piece.empty { display: none; }
.piece.drag-origin { opacity: 0.28; }
.piece.anim { z-index: 25; }

.wK { background-image: url('../img/pieces/wK.svg'); }
.wQ { background-image: url('../img/pieces/wQ.svg'); }
.wR { background-image: url('../img/pieces/wR.svg'); }
.wB { background-image: url('../img/pieces/wB.svg'); }
.wN { background-image: url('../img/pieces/wN.svg'); }
.wP { background-image: url('../img/pieces/wP.svg'); }
.bK { background-image: url('../img/pieces/bK.svg'); }
.bQ { background-image: url('../img/pieces/bQ.svg'); }
.bR { background-image: url('../img/pieces/bR.svg'); }
.bB { background-image: url('../img/pieces/bB.svg'); }
.bN { background-image: url('../img/pieces/bN.svg'); }
.bP { background-image: url('../img/pieces/bP.svg'); }

.drag-ghost {
  position: fixed;
  left: 0; top: 0;
  pointer-events: none;
  z-index: 300;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  filter: drop-shadow(0 10px 8px rgba(0, 0, 0, 0.55));
  transform: translate(-50%, -50%) scale(1.1);
}

/* --- Arrow overlay ---------------------------------------------------------- */
#board-svg-overlay { z-index: 20; }
#board-svg-overlay polygon { fill-opacity: 0.8; }
#board-svg-overlay polygon.preview { fill-opacity: 0.55; }
#board-svg-overlay polygon.hint { fill-opacity: 0.9; stroke: rgba(255, 255, 255, 0.85); stroke-width: 3; stroke-dasharray: 10 7; }

/* --- Board overlays ------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(10, 12, 16, 0.88);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 40;
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.overlay.visible { opacity: 1; pointer-events: auto; }

.promo-choice {
  width: 64px; height: 64px;
  border-radius: 12px;
  background-color: #1f2937;
  background-size: 82% 82%;
  background-position: center;
  background-repeat: no-repeat;
  border: 1px solid #374151;
  transition: transform 0.12s ease, border-color 0.12s ease, background-color 0.12s ease;
}
.promo-choice:hover, .promo-choice:focus-visible { transform: translateY(-2px); border-color: #f59e0b; background-color: #273244; outline: none; }

#view-banner { z-index: 30; }

/* --- Eval bar --------------------------------------------------------------- */
#eval-bar-container {
  width: 26px;
  background-color: #14171d;
  border: 2px solid #363c46;
  border-radius: 0.6rem;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7), inset 0 0 6px rgba(0, 0, 0, 0.8);
  flex-shrink: 0;
}
#eval-bar-container.flipped { flex-direction: column-reverse; }
#eval-bar-container.eval-off { display: none; }
#eval-bar-white-fill { width: 100%; background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%); transition: height 0.38s cubic-bezier(0.22, 1, 0.36, 1); }
#eval-bar-black-fill { width: 100%; flex: 1; background: linear-gradient(180deg, #1e2229 0%, #0f1217 100%); }
#eval-bar-text { position: absolute; left: 0; right: 0; text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 9px; font-weight: 800; z-index: 20; pointer-events: none; }
#eval-bar-text.at-bottom { bottom: 6px; }
#eval-bar-text.at-top { top: 6px; }
#eval-bar-text.on-white { color: #111827; }
#eval-bar-text.on-black { color: #e5e7eb; }

/* --- Reaction layer (GIF / WebP) -------------------------------------------- */
#reaction-layer {
  position: absolute;
  inset: 0;
  z-index: 45; /* above the game-over card so a final checkmate reaction is visible */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.22s ease, transform 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}
#reaction-layer.visible { opacity: 1; transform: scale(1); }
.reaction-card { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 64%; }
#reaction-img {
  width: 100%;
  max-width: 100%;
  max-height: 60cqh;
  object-fit: contain;
  border-radius: 14px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.65);
  background: #000;
}
#reaction-layer[data-kind="bad"] #reaction-img { border-color: #f87171; }
#reaction-layer[data-kind="great"] #reaction-img { border-color: #fbbf24; }
#reaction-label {
  font-weight: 800;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
#reaction-layer[data-kind="bad"] #reaction-label { background: #7f1d1d; color: #fee2e2; border: 1px solid #f87171; }
#reaction-layer[data-kind="great"] #reaction-label { background: #78350f; color: #fef3c7; border: 1px solid #fbbf24; }
#reaction-label[hidden] { display: none; }

/* Status pills in the frame border (top / bottom coordinate strips) */
.frame-pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  height: 19px;
  line-height: 17px;
  padding: 0 10px;
  border-width: 1px;
  border-style: solid;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}
.frame-pill.top { top: 2px; }
.frame-pill.bottom { bottom: 2px; }
.frame-pill.hidden { display: none; }
