/* Chess — board, pieces (pixel art in retro, glyphs in modern), move list */
.ch-msg { margin: 0 0 12px; }
.ch-msg[data-t="w"] { color: var(--a2); }
.ch-msg[data-t="b"] { color: var(--a1); }

.ch-layout { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 18px; align-items: start; }
@media (max-width: 720px) { .ch-layout { grid-template-columns: 1fr; } }

.ch-board-wrap { position: relative; max-width: 560px; width: 100%; margin: 0 auto; }
.ch-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.ch-sq {
  --light: #eedcb8;
  --dark: #b4875f;
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  margin: 0;
  aspect-ratio: 1;
  min-width: 0;
  cursor: pointer;
  font: inherit;
  container-type: size;
  -webkit-tap-highlight-color: transparent;
}
.ch-sq.light { background: var(--light); }
.ch-sq.dark { background: var(--dark); }
.ch-sq.last::before, .ch-sq.sel::before { content: ""; position: absolute; inset: 0; background: rgba(255, 214, 64, .45); }
.ch-sq.sel::before { background: rgba(108, 92, 231, .45); }
.ch-sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(239, 60, 80, .95) 0, rgba(239, 60, 80, .55) 45%, transparent 75%); }
.ch-sq.mated .ch-pc { transform: rotate(90deg); transition: transform .4s; }
.ch-sq.dot::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(20, 20, 40, .28); pointer-events: none; }
.ch-sq.cap::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(20, 20, 40, .3); pointer-events: none; }
.ch-sq:focus-visible { outline: 3px solid var(--a3); outline-offset: -3px; z-index: 2; }
@media (hover: hover) { .ch-sq:hover::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .45); } }

.ch-rank, .ch-file { position: absolute; font: 700 11px/1 var(--font-body); pointer-events: none; opacity: .75; }
.ch-rank { top: 3px; left: 4px; }
.ch-file { bottom: 3px; right: 4px; }
.ch-sq.light .ch-rank, .ch-sq.light .ch-file { color: var(--dark); }
.ch-sq.dark .ch-rank, .ch-sq.dark .ch-file { color: var(--light); }

/* pieces */
.ch-pc { position: relative; z-index: 1; width: 100%; height: 100%; display: grid; place-items: center; pointer-events: none; }
.ch-pc svg { display: none; width: 78%; height: 78%; shape-rendering: crispEdges; }
.ch-pc i {
  font-style: normal;
  font-size: min(9.2vw, 54px);
  font-size: 82cqh;
  line-height: 1;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Arial Unicode MS", serif;
}
.ch-pc.w i { color: #fff; text-shadow: 0 0 1px #000, 0 1px 1px #000, 1px 0 1px #000, -1px 0 1px #000, 0 -1px 1px #000, 0 2px 3px rgba(0,0,0,.35); }
.ch-pc.b i { color: #1d1b26; text-shadow: 0 0 1px rgba(255,255,255,.4), 0 2px 3px rgba(0,0,0,.35); }
.ch-ghost { position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(0,0,0,.35)); }
.ch-ghost i { font-size: min(11vw, 64px); }

/* captured pieces */
.ch-cap { min-height: 26px; display: flex; flex-wrap: wrap; align-items: center; gap: 0; padding: 4px 2px; }
.ch-cap .ch-pc { width: 20px; height: 22px; margin-right: -4px; }
.ch-cap .ch-pc i { font-size: 18px; }
.ch-cap .ch-pc svg { width: 100%; height: 100%; }
.ch-cap em { font-style: normal; margin-left: 10px; color: var(--dim); font-size: 14px; }

/* promotion picker */
.ch-promo { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 4, 12, .55); z-index: 5; border-radius: var(--radius-sm); }
.ch-promo[hidden] { display: none; }
.ch-promo-box { padding: 14px 16px; text-align: center; }
.ch-promo-box p { margin: 0 0 10px; }
.ch-promo-box div { display: flex; gap: 8px; }
.ch-promo-btn { width: 60px; height: 60px; display: grid; place-items: center; border: var(--border); border-radius: var(--radius-sm); background: #eedcb8; cursor: pointer; padding: 4px; }
.ch-promo-btn:hover, .ch-promo-btn:focus-visible { background: #ffd23f; }

/* move list */
.ch-side { border: var(--border); border-radius: var(--radius); background: var(--panel-2); padding: 12px; }
.ch-h { font-size: 13px; margin: 0 0 8px; font-family: var(--font-display); color: var(--dim); letter-spacing: .04em; }
.ch-moves { list-style: none; counter-reset: mv; margin: 0; padding: 0; max-height: 420px; overflow: auto; font-variant-numeric: tabular-nums; }
.ch-moves li { counter-increment: mv; display: grid; grid-template-columns: 30px 1fr 1fr; gap: 4px; padding: 3px 4px; border-radius: 4px; }
.ch-moves li::before { content: counter(mv) "."; color: var(--dim); }
.ch-moves li:nth-child(odd) { background: rgba(127, 127, 127, .08); }
.ch-moves li.empty { display: block; color: var(--dim); background: none; }
.ch-moves li.empty::before { content: none; }
@media (max-width: 720px) {
  .ch-side { padding: 10px; }
  .ch-moves { max-height: 140px; display: flex; flex-wrap: wrap; gap: 2px 10px; }
  .ch-moves li { display: flex; gap: 6px; background: none !important; padding: 0; }
}

/* ---------- retro look ---------- */
[data-theme="retro"] .ch-board { border: 4px solid #000; border-radius: 0; box-shadow: 0 0 0 3px var(--a5), 8px 8px 0 #000, 0 0 40px rgba(155, 92, 255, .35); }
[data-theme="retro"] .ch-sq { --light: #3a2d6b; --dark: #1b1338; }
[data-theme="retro"] .ch-pc svg { display: block; }
[data-theme="retro"] .ch-pc i { display: none; }
[data-theme="retro"] .ch-pc.w svg { fill: var(--a2); filter: drop-shadow(1px 0 0 #000) drop-shadow(-1px 0 0 #000) drop-shadow(0 1px 0 #000) drop-shadow(0 -1px 0 #000) drop-shadow(0 0 6px rgba(53, 242, 224, .55)); }
[data-theme="retro"] .ch-pc.b svg { fill: var(--a1); filter: drop-shadow(1px 0 0 #000) drop-shadow(-1px 0 0 #000) drop-shadow(0 1px 0 #000) drop-shadow(0 -1px 0 #000) drop-shadow(0 0 6px rgba(255, 46, 154, .55)); }
[data-theme="retro"] .ch-sq.last::before { background: rgba(255, 210, 63, .28); }
[data-theme="retro"] .ch-sq.sel::before { background: rgba(124, 255, 79, .35); }
[data-theme="retro"] .ch-sq.dot::after { background: var(--a4); border-radius: 0; width: 22%; height: 22%; box-shadow: 0 0 8px var(--a4); }
[data-theme="retro"] .ch-sq.cap::after { border-radius: 0; border: 4px dashed var(--a4); inset: 6%; }
[data-theme="retro"] .ch-rank, [data-theme="retro"] .ch-file { font: 8px/1 var(--font-display); color: rgba(255, 255, 255, .45) !important; }
[data-theme="retro"] .ch-promo-btn { background: #1b1338; border-radius: 0; }
[data-theme="retro"] .ch-promo-btn:hover, [data-theme="retro"] .ch-promo-btn:focus-visible { background: #3a2d6b; }
[data-theme="retro"] .ch-cap .ch-pc { width: 18px; height: 18px; margin-right: 0; }
[data-theme="retro"] .ch-side { border-radius: 0; }
[data-theme="retro"] .ch-moves { font-size: 18px; }
[data-theme="retro"] .ch-h { font-size: 10px; }
