/* ================= Chess UI ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --light: #f0d9b5;
  --dark: #b58863;
  --accent: #7c5cff;
  --bg1: #12121c;
  --bg2: #1c1c2e;
}

body {
  min-height: 100vh;
  background: radial-gradient(circle at 20% 0%, #26264a 0%, var(--bg1) 55%),
              linear-gradient(160deg, var(--bg1), var(--bg2));
  color: #f2f2f7;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px;
}

/* ---------- Animated logo (Animista focus-in-contract-bck) ---------- */
.header { text-align: center; margin-bottom: 14px; }

.logo {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(48px, 9vw, 84px);
  font-weight: 700;
  text-transform: lowercase;
  background: linear-gradient(180deg, #fff7dd 0%, #ffd76e 55%, #e0a63a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 10px 30px rgba(255, 200, 80, 0.25);
  cursor: pointer;
  -webkit-perspective: 600px;
  perspective: 600px;
  animation: focus-in-contract-bck 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@-webkit-keyframes focus-in-contract-bck {
  0% {
    letter-spacing: 1em;
    -webkit-transform: translateZ(300px);
            transform: translateZ(300px);
    -webkit-filter: blur(12px);
            filter: blur(12px);
    opacity: 0;
  }
  100% {
    -webkit-transform: translateZ(12px);
            transform: translateZ(12px);
    -webkit-filter: blur(0);
            filter: blur(0);
    opacity: 1;
  }
}
@keyframes focus-in-contract-bck {
  0% {
    letter-spacing: 1em;
    -webkit-transform: translateZ(300px);
            transform: translateZ(300px);
    -webkit-filter: blur(12px);
            filter: blur(12px);
    opacity: 0;
  }
  100% {
    -webkit-transform: translateZ(12px);
            transform: translateZ(12px);
    -webkit-filter: blur(0);
            filter: blur(0);
    opacity: 1;
  }
}

.subtitle {
  margin-top: 6px;
  color: #9a9ab5;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  font-size: 12px;
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  max-width: 1040px;
}

.board-wrap { display: flex; flex-direction: column; gap: 10px; }

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 14px;
  border-radius: 10px;
}
.eval {
  font-family: ui-monospace, monospace;
  color: #8affc1;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 13px;
}

/* ---------- Board ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(88vw, 560px);
  height: min(88vw, 560px);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 0 0 4px #2c2c44;
  user-select: none;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.cell.light { background: var(--light); }
.cell.dark { background: var(--dark); }
.cell.last { box-shadow: inset 0 0 0 999px rgba(255, 240, 90, 0.28); }
.cell.sel { box-shadow: inset 0 0 0 999px rgba(124, 92, 255, 0.45); }
.cell.check { box-shadow: inset 0 0 0 999px rgba(255, 60, 60, 0.5); }

.cell.hl::after {
  content: "";
  position: absolute;
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: rgba(20, 20, 40, 0.35);
  z-index: 2;
}
.cell.hl.empty::after { background: rgba(20, 20, 40, 0.28); }
.cell.hl:not(.empty)::after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 5px solid rgba(20, 20, 40, 0.35);
}

.piece {
  font-size: min(9.2vw, 56px);
  line-height: 1;
  z-index: 1;
  transition: transform 0.12s;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35));
}
.cell:hover .piece { transform: scale(1.07); }
.piece.w { color: #fffdf7; -webkit-text-stroke: 1.4px #1d1d22; }
.piece.b { color: #23232b; -webkit-text-stroke: 1.2px #000; }

.cell.pop .piece { animation: pop 0.3s ease; }
@keyframes pop {
  0% { transform: scale(0.5); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.coord {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  opacity: 0.55;
  pointer-events: none;
}
.coord.file { right: 3px; bottom: 2px; }
.coord.rank { left: 3px; top: 2px; }
.cell.light .coord { color: var(--dark); }
.cell.dark .coord { color: var(--light); }

/* ---------- Controls ---------- */
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn {
  background: linear-gradient(180deg, var(--accent), #5a3fe0);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(92, 63, 224, 0.4);
  transition: transform 0.1s, filter 0.15s;
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.07);
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.level-label {
  font-size: 13px;
  color: #b9b9cf;
  display: flex;
  align-items: center;
  gap: 6px;
}
.select {
  background: #23233a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- Side panel ---------- */
.panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: #9a9ab5;
}
.moves {
  max-height: 260px;
  overflow-y: auto;
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 60px;
}
.pair { display: flex; gap: 8px; }
.num { color: #77778f; width: 26px; }
.mv { color: #e8e8f2; min-width: 52px; }
.mv.ai { color: #b9a7ff; }

.captured { display: flex; flex-direction: column; gap: 4px; font-size: 18px; }
.cap-row { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; min-height: 24px; }
.cap-label { font-size: 11px; color: #8888a3; margin-right: 6px; text-transform: uppercase; }

.hint {
  font-size: 12px;
  line-height: 1.5;
  color: #9292ab;
  background: rgba(255, 255, 255, 0.04);
  border-left: 3px solid var(--accent);
  padding: 8px 10px;
  border-radius: 0 8px 8px 0;
}
.hint b { color: #cfcfe4; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 16, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-box {
  background: linear-gradient(180deg, #262642, #1b1b30);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 30px 40px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: focus-in-contract-bck 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}
.modal-emoji { font-size: 64px; margin-bottom: 8px; }
.modal-title { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.modal-sub { color: #9a9ab5; font-size: 14px; margin-bottom: 18px; }

@media (max-width: 760px) {
  .panel { width: min(88vw, 560px); }
}
