/* Chess — Parlour Games */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  margin-bottom: 16px;
}
.control-group {
  display: inline-flex;
  align-items: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow);
  gap: 2px;
}
.opt-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 0 10px 0 8px;
  font-weight: 600;
}
.opt {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 600 13px 'Inter', sans-serif;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 32px;
  transition: background 160ms ease, color 160ms ease;
}
.opt:hover { color: var(--ink); }
.opt.is-active {
  background: var(--accent);
  color: var(--accent-soft);
}

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 20px;
  align-items: start;
}
@media (max-width: 820px) {
  .play {
    grid-template-columns: 1fr;
  }
}

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.board {
  width: min(100%, 600px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--accent);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-lift);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  position: relative;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI Symbol', 'Apple Symbols', 'Noto Sans Symbols2', 'DejaVu Sans', sans-serif;
  font-size: clamp(22px, 6.4vw, 52px);
  line-height: 1;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--ink);
}
.sq.light { background: #efe1bf; }
.sq.dark  { background: #b08a5a; }
.sq.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.sq.last-move { background: rgba(244, 227, 178, 0.85); }
.sq.last-move.dark { background: rgba(176, 138, 90, 0.95); box-shadow: inset 0 0 0 2px rgba(244, 227, 178, 0.55); }
.sq.check { background: #e6736a !important; box-shadow: inset 0 0 0 3px var(--danger); animation: chess-check-pulse 900ms ease-out infinite alternate; }
@keyframes chess-check-pulse {
  from { box-shadow: inset 0 0 0 3px var(--danger); }
  to   { box-shadow: inset 0 0 0 3px var(--danger), 0 0 0 4px rgba(192, 57, 43, 0.25); }
}

/* Last-move highlight fades in softly */
@keyframes chess-last-move-in {
  from { background: transparent; }
}
.sq.last-move { animation: chess-last-move-in 240ms ease-out; }

/* Piece appearing in its new square (via re-render after move) */
@keyframes chess-piece-in {
  from { transform: scale(0.85); opacity: 0.4; }
  to   { transform: scale(1); opacity: 1; }
}
.sq.last-move .piece { animation: chess-piece-in 200ms ease-out; }

@media (prefers-reduced-motion: reduce) {
  .sq.check, .sq.last-move, .sq.last-move .piece { animation: none; }
}

.piece {
  pointer-events: none;
  line-height: 1;
  display: block;
  text-shadow: 0 1px 0 rgba(255,255,255,0.08);
  font-weight: 400;
}
.piece.w {
  color: #fbf6ea;
  text-shadow: 0 1px 0 #1c2a3a, 1px 0 0 #1c2a3a, -1px 0 0 #1c2a3a, 0 -1px 0 #1c2a3a, 1px 1px 0 #1c2a3a, -1px -1px 0 #1c2a3a, 1px -1px 0 #1c2a3a, -1px 1px 0 #1c2a3a;
}
.piece.b {
  color: #1c2a3a;
  text-shadow: 0 1px 0 rgba(251,246,234,0.5);
}

.sq .hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.sq .hint[hidden] { display: none; }
.sq .hint::after {
  content: '';
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(31, 58, 95, 0.32);
}
.sq.has-piece .hint::after {
  width: 86%;
  height: 86%;
  background: transparent;
  border: 4px solid rgba(31, 58, 95, 0.35);
  box-sizing: border-box;
}

.sq .coord {
  position: absolute;
  font: 600 10px 'Inter', sans-serif;
  color: rgba(28, 42, 58, 0.5);
  pointer-events: none;
}
.sq.dark .coord { color: rgba(251, 246, 234, 0.75); }
.sq .coord.file { right: 4px; bottom: 2px; }
.sq .coord.rank { left: 4px; top: 2px; }

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.captured {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cap-row {
  min-height: 28px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 22px;
  line-height: 1;
  letter-spacing: 1px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}
.cap-row .w { color: #fbf6ea; text-shadow: 0 0 0 #1c2a3a, 1px 0 0 #1c2a3a, -1px 0 0 #1c2a3a, 0 1px 0 #1c2a3a, 0 -1px 0 #1c2a3a; }
.cap-row .b { color: #1c2a3a; }

.moves-panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 120px;
  max-height: 360px;
  overflow-y: auto;
}
.moves-head {
  font: 700 12px 'Inter', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 6px;
}
.moves-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--ink);
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 2px 10px;
}
.moves-list .ply-num {
  color: var(--muted);
  font-weight: 600;
}
.moves-list .ply {
  font-variant-numeric: tabular-nums;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 42, 58, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.overlay[hidden] { display: none; }
.overlay-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  text-align: center;
  box-shadow: var(--shadow-lift);
  max-width: 360px;
  width: 100%;
}
.overlay-card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 24px;
  margin: 0 0 4px;
}
.overlay-sub {
  color: var(--ink-soft);
  margin: 0 0 16px;
  font-size: 14px;
}
.overlay-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.promote-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.promote-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-2);
  width: 56px;
  height: 56px;
  border-radius: 10px;
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, transform 150ms ease;
}
.promote-btn:hover {
  background: var(--accent-soft);
  transform: translateY(-2px);
}

/* Aside info */
.aside-info { margin-top: 22px; }
.aside-info details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.aside-info summary {
  cursor: pointer;
  font: 700 14px 'Inter', sans-serif;
  color: var(--ink);
}
.aside-info .help-body {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}
.aside-info .help-body p { margin: 0 0 8px; }
.aside-info .help-body ul { margin: 0; padding-left: 18px; }
.aside-info .help-body li { margin: 4px 0; }

/* Fullscreen — fill the play container */
body[data-fullscreen="true"] .play {
  height: 100%;
  grid-template-rows: 1fr;
}
body[data-fullscreen="true"] .board {
  width: min(100%, 92vh);
}

@media (max-width: 480px) {
  .play { padding: 12px; gap: 12px; }
  .opt { padding: 6px 10px; font-size: 12px; }
  .side-panel { flex-direction: column; }
  .moves-panel { max-height: 220px; }
}
