/* Chess — Cozy Alpaca Studio (shell UI + pieces; board chrome from Board Template) */
:root {
  --cream: #f7f1e8;
  --ink: #3d3429;
  --soft: #8b7355;
  --piece-white: #f5e6c8;
  --piece-white-rim: #c4a574;
  --piece-black: #4a3728;
  --piece-black-rim: #2c2118;
  --accent: #c4785a;
  --panel: #fffaf3;
  --shadow: rgba(61, 52, 41, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  flex-direction: column;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #f0e6d6 0%, #e4d5c0 50%, #d9cbb8 100%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0 0 2rem;
}

.app { width: 100%; max-width: 700px; align-self: center; margin-top: 1.25rem; padding: 0 1rem; }

.header { text-align: center; margin-bottom: 0.75rem; position: relative; }
.header h1 {
  font-weight: 600;
  font-size: 1.75rem;
  letter-spacing: 0.02em;
}
.tagline { font-size: 0.85rem; color: var(--soft); margin-top: 0.15rem; }


.mute-btn {
  position: absolute;
  top: 0;
  right: 0;
  appearance: none;
  border: none;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow);
  z-index: 2;
  min-width: 3.6rem;
}
.mute-btn:hover { filter: brightness(1.03); }
.mute-btn.is-muted {
  background: #e8dcc8;
  color: var(--soft);
  box-shadow: inset 0 0 0 1px rgba(61, 52, 41, 0.12);
}


.is-hidden { display: none !important; }

.side-select {
  background: var(--panel);
  border-radius: 12px;
  padding: 1.25rem 1rem 1.35rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 2px 8px var(--shadow);
  text-align: center;
}
.side-select-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.side-select-note {
  font-size: 0.8rem;
  color: var(--soft);
  line-height: 1.4;
  margin-bottom: 1rem;
}
.side-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
}
.side-btn { min-width: 5.5rem; }
.side-btn[data-side="w"] {
  background: var(--piece-white);
  color: var(--ink);
  border: 1px solid var(--piece-white-rim);
}
.side-btn[data-side="b"] {
  background: var(--piece-black);
  color: #f5e6c8;
}
.side-btn[data-side="random"] {
  background: var(--accent);
  color: #fff;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--panel);
  border-radius: 12px;
  padding: 0.65rem 0.9rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.status { font-size: 0.95rem; font-weight: 500; flex: 1; }

.btn {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 4px var(--shadow);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }

#board-host { width: 100%; }

/* Piece shell — sprite-ready via data-piece / PIECE_ASSETS */
.chess-piece {
  width: 82%;
  height: 82%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: transform 0.12s ease;
  user-select: none;
}
.chess-piece:hover { transform: scale(1.06); }
.chess-piece.white .chess-glyph {
  color: #fff8e8;
  text-shadow:
    0 0 2px #5a4a30,
    0 1px 2px rgba(0, 0, 0, 0.45),
    1px 1px 0 rgba(90, 70, 40, 0.55);
}
.chess-piece.black .chess-glyph {
  color: #2a2018;
  text-shadow:
    0 0 2px #f5e6c8,
    0 1px 1px rgba(255, 255, 255, 0.35);
}
.chess-glyph {
  font-size: clamp(1.35rem, 7vw, 2.35rem);
  line-height: 1;
  pointer-events: none;
}
.chess-piece.has-sprite .chess-glyph { display: none; }
.chess-piece img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.chess-piece.has-sprite-bg .chess-glyph { display: none; }

.promo-picker {
  margin-top: 0.75rem;
  background: var(--panel);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 2px 8px var(--shadow);
  text-align: center;
}
.promo-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.promo-buttons {
  display: flex;
  gap: 0.45rem;
  justify-content: center;
  flex-wrap: wrap;
}
.promo-btn {
  min-width: 3rem;
  font-size: 1.35rem;
  padding: 0.35rem 0.55rem;
  background: #e8dcc8;
  color: var(--ink);
}

.hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--soft);
  margin-top: 0.85rem;
  line-height: 1.4;
}

@media (max-width: 400px) {
  .header h1 { font-size: 1.4rem; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-actions { width: 100%; justify-content: flex-end; }
  .side-buttons { flex-direction: column; align-items: stretch; }
}

/* Difficulty 1–10 (slice 3: editable on setup only; locked during play) */
.difficulty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin: 0.15rem auto 0.35rem;
  max-width: 22rem;
}
.diff-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}
.diff-slider {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.diff-value {
  font-size: 0.95rem;
  font-weight: 700;
  min-width: 1.4rem;
  text-align: center;
  color: var(--accent);
}
.diff-hint {
  font-size: 0.72rem;
  color: var(--soft);
  margin-bottom: 0.85rem;
  line-height: 1.35;
}
.diff-locked {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--soft);
  background: var(--panel);
  border-radius: 12px;
  padding: 0.4rem 0.9rem;
  margin: 0 0 0.85rem;
  box-shadow: 0 2px 8px var(--shadow);
}
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
}
.btn-secondary {
  background: #8b7355;
}

/* —— UX polish (Chess-local; Board Template untouched) —— */

/* Capture / claim destinations: solid yellow wash (Checkers must-jump yellow family, held solid — not flickering).
   Empty legal moves keep Board Template hl-move yellow circle. */
.cas-square.hl-jump {
  box-shadow: inset 0 0 0 3px rgba(255, 196, 90, 0.85);
  background-image: linear-gradient(rgba(255, 210, 120, 0.42), rgba(255, 210, 120, 0.42));
}
/* Soft optional dot on wash; wash is the required capture signal under the piece */
.cas-square.hl-jump::after {
  width: 18%;
  height: 18%;
  background: rgba(255, 196, 90, 0.5);
  box-shadow: none;
}

/* Player king in check — soft washed-out red (not vivid), held solid */
.cas-square.check-warn {
  box-shadow: inset 0 0 0 3px rgba(190, 100, 90, 0.5);
  background-image: linear-gradient(rgba(210, 120, 110, 0.36), rgba(210, 120, 110, 0.36));
}
/* Flash gently when a non-king piece with zero legal moves is selected while in check */
.cas-square.check-warn-flash {
  animation: check-warn-pulse 0.95s ease-in-out infinite;
}
@keyframes check-warn-pulse {
  0%, 100% {
    box-shadow: inset 0 0 0 3px rgba(190, 100, 90, 0.55);
    background-image: linear-gradient(rgba(210, 120, 110, 0.4), rgba(210, 120, 110, 0.4));
  }
  50% {
    box-shadow: inset 0 0 0 2px rgba(190, 100, 90, 0.22);
    background-image: linear-gradient(rgba(210, 120, 110, 0.14), rgba(210, 120, 110, 0.14));
  }
}


/* Enemy last-move teaching cue (AI only): from=dark blue, to=sky blue; castling paints king+rook (4 tiles); held until next AI move */
.cas-square.last-from {
  box-shadow: inset 0 0 0 3px rgba(40, 75, 130, 0.78);
  background-image: linear-gradient(rgba(30, 60, 110, 0.44), rgba(30, 60, 110, 0.44));
}
.cas-square.last-to {
  box-shadow: inset 0 0 0 3px rgba(110, 190, 235, 0.88);
  background-image: linear-gradient(rgba(135, 205, 245, 0.48), rgba(135, 205, 245, 0.48));
}

/* Capture yellow + check red beat last-move blues when overlapping */
.cas-square.hl-jump {
  box-shadow: inset 0 0 0 3px rgba(255, 196, 90, 0.85);
  background-image: linear-gradient(rgba(255, 210, 120, 0.42), rgba(255, 210, 120, 0.42));
}
.cas-square.check-warn {
  box-shadow: inset 0 0 0 3px rgba(190, 100, 90, 0.5);
  background-image: linear-gradient(rgba(210, 120, 110, 0.36), rgba(210, 120, 110, 0.36));
}

/* —— Stats panel (mirror Sudoku 6.1; columns Totals + difficulty 1–10) —— */
.stats-btn {
  position: absolute;
  top: 0;
  left: 0;
  appearance: none;
  border: none;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow);
  z-index: 2;
  min-width: 3.6rem;
}
.stats-btn:hover { filter: brightness(1.03); }
.stats-btn.is-open {
  background: #e8dcc8;
  box-shadow: inset 0 0 0 1px rgba(61, 52, 41, 0.12);
}

.stats-panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 0.85rem 0.95rem 0.95rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 2px 8px var(--shadow);
}
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.stats-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.stats-close {
  padding: 0.28rem 0.7rem;
  font-size: 0.78rem;
}
.stats-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}
.stats-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  background: #f0e6d6;
  border-radius: 8px;
  padding: 0.28rem 0.55rem;
  font-size: 0.8rem;
  box-shadow: inset 0 0 0 1px rgba(61, 52, 41, 0.06);
}
.stats-k {
  color: var(--soft);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stats-v {
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stats-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.35rem;
}
.stats-table {
  width: 100%;
  min-width: 36rem;
  border-collapse: collapse;
  font-size: 0.72rem;
}
.stats-table th,
.stats-table td {
  text-align: right;
  padding: 0.28rem 0.32rem;
  border-bottom: 1px solid rgba(61, 52, 41, 0.08);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stats-table thead th {
  color: var(--soft);
  font-weight: 600;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stats-table tbody th {
  text-align: left;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: 0;
}
.stats-table thead th:first-child {
  text-align: left;
}
.stats-note {
  font-size: 0.72rem;
  color: var(--soft);
  line-height: 1.35;
  margin-top: 0.25rem;
}

.diff-locked-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  background: var(--panel);
  border-radius: 12px;
  padding: 0.4rem 0.9rem;
  margin: 0 0 0.85rem;
  box-shadow: 0 2px 8px var(--shadow);
}
.diff-locked-row .diff-locked {
  background: transparent;
  box-shadow: none;
  margin: 0;
  padding: 0;
}
.match-timer {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 2.6rem;
  text-align: center;
  opacity: 0.85;
}

/* Studio bar — match First Fleece / Meadow Takeover */
#studio-bar {
  position: relative;
  z-index: 20;
  align-self: stretch;
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: #1c2619;
  color: #c9d4b8;
  font-family: Nunito, system-ui, sans-serif;
  font-size: 0.92rem;
  box-sizing: border-box;
  margin: 0;
}
#studio-bar a {
  color: #f7efe3;
  font-weight: 700;
  text-decoration: none;
  margin-right: 0.45rem;
}
#studio-bar a:hover { text-decoration: underline; }
