/* ========================================================== chess cabinet
   Fixed art direction: a tournament board in wood and cream. It ignores the
   active world on purpose - piece recognition matters more than theming.
   ===================================================================== */
.cs {
  --board: min(78vw, 56vh, 520px);
  --sq: calc(var(--board) / 8);
  --light: #efe0c3;
  --dark: #8f6a4a;
  --frame: #3a2a1c;
  --white-piece: #f7f1e4;
  --white-line: #2a2420;
  --black-piece: #2d2824;
  --black-line: #8d8278;
  --pick: #ffcc4d;
  --go: rgba(60, 170, 90, .9);
  --danger: #e0533f;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.5rem, 1.6vh, 0.9rem);
  width: 100%;
}

.cs__layout {
  display: flex;
  gap: clamp(0.6rem, 1.6vw, 1.2rem);
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

/* ============================================================== eval bar */
.cs__eval {
  width: 14px;
  height: var(--board);
  border-radius: 7px;
  overflow: hidden;
  background: var(--black-piece);
  border: 1px solid rgba(0, 0, 0, .5);
  box-shadow: inset 0 0 6px rgba(0, 0, 0, .6);
  flex: none;
  position: relative;
}
.cs__eval[hidden] { display: none; }
.cs__eval-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 50%;
  background: linear-gradient(0deg, var(--white-piece), #fffdf6);
  transition: height .45s var(--ease-out);
}
.cs__eval-mid {
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: rgba(255, 60, 60, .7);
}

/* ================================================================= board */
.cs__frame {
  position: relative;
  padding: clamp(7px, 1.4vw, 13px);
  padding-left: clamp(16px, 2.6vw, 24px);
  padding-bottom: clamp(16px, 2.6vw, 24px);
  border-radius: 6px;
  background: linear-gradient(160deg, #5b4126, var(--frame) 60%, #4a3420);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .12),
    inset 0 -3px 8px rgba(0, 0, 0, .6),
    0 24px 56px -24px rgba(0, 0, 0, .95);
}

.cs__board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: var(--board);
  height: var(--board);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .6);
}

.cs__sq {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  background: var(--light);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.cs__sq--dark { background: var(--dark); }
.cs__sq:disabled { cursor: default; }
.cs__sq:focus-visible { outline: 3px solid var(--pick); outline-offset: -3px; z-index: 5; }

/* coordinates live on the frame, not the squares */
.cs__coords {
  position: absolute;
  font-family: var(--mono);
  font-size: clamp(7px, 1.2vw, 10px);
  color: rgba(255, 240, 210, .6);
  letter-spacing: .04em;
  pointer-events: none;
}
.cs__coords--files {
  left: clamp(16px, 2.6vw, 24px);
  right: clamp(7px, 1.4vw, 13px);
  bottom: 4px;
  display: flex;
  justify-content: space-around;
}
.cs__coords--ranks {
  top: clamp(7px, 1.4vw, 13px);
  bottom: clamp(16px, 2.6vw, 24px);
  left: 4px;
  width: clamp(10px, 1.6vw, 14px);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}

/* ---- highlights */
.cs__sq.is-last::before {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255, 204, 77, .32);
}
.cs__sq.is-from::before {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255, 204, 77, .45);
  box-shadow: inset 0 0 0 3px var(--pick);
}
.cs__sq.is-check::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(224, 83, 63, .85) 0%, rgba(224, 83, 63, .35) 45%, transparent 72%);
  animation: cs-alarm 1.1s ease-in-out infinite;
  pointer-events: none;
}
@keyframes cs-alarm { 50% { opacity: .45; } }

.cs__dot {
  position: absolute;
  width: 26%; height: 26%;
  border-radius: 50%;
  background: var(--go);
  pointer-events: none;
  animation: cs-pop .2s var(--ease-spring);
}
.cs__ring {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 4px solid var(--go);
  pointer-events: none;
  animation: cs-pop .2s var(--ease-spring);
}
@keyframes cs-pop { from { transform: scale(.3); opacity: 0; } }

/* ================================================================ pieces */
.cp {
  width: 86%;
  height: 86%;
  display: block;
  pointer-events: none;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .45));
  transition: transform .18s var(--ease-out);
}
.cp--white path, .cp--white circle { fill: var(--white-piece); stroke: var(--white-line); stroke-width: 2.4; stroke-linejoin: round; }
.cp--black path, .cp--black circle { fill: var(--black-piece); stroke: var(--black-line); stroke-width: 2.4; stroke-linejoin: round; }
/* the shading details inside bishop and knight keep their own fill */
.cp [opacity] { stroke: none; }

.cs__sq:not(:disabled):hover .cp.is-mine { transform: translateY(-2px) scale(1.04); }
.cs__piece-anim { transition: transform .2s var(--ease-out); }

/* a piece being dragged follows the pointer */
.cs__drag {
  position: fixed;
  z-index: 60;
  width: var(--sq);
  height: var(--sq);
  margin-left: calc(var(--sq) / -2);
  margin-top: calc(var(--sq) / -2);
  pointer-events: none;
  display: grid;
  place-items: center;
}
.cs__drag .cp { width: 94%; height: 94%; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .6)); }

/* ===================================================== promotion picker */
.cs__promo {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(10, 8, 6, .72);
  backdrop-filter: blur(3px);
}
.cs__promo-row {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-radius: 8px;
  background: linear-gradient(160deg, #5b4126, #3a2a1c);
  box-shadow: 0 16px 40px -16px #000;
}
.cs__promo-btn {
  width: calc(var(--sq) * 0.92);
  height: calc(var(--sq) * 0.92);
  display: grid;
  place-items: center;
  border: 2px solid transparent;
  border-radius: 5px;
  background: var(--light);
  cursor: pointer;
}
.cs__promo-btn:hover, .cs__promo-btn:focus-visible {
  border-color: var(--pick);
  outline: none;
  background: #fff6dd;
}

/* ================================================================= aside */
.cs__aside {
  width: min(228px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cs__clocks { display: flex; gap: 0.4rem; }
.cs__clock {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .35);
  border: 1px solid var(--mist);
  font-family: var(--mono);
  text-align: center;
}
.cs__clock-label { display: block; font-size: 0.52rem; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-faint); }
.cs__clock-time { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.cs__clock.is-active { border-color: rgba(var(--accent-rgb), .6); box-shadow: 0 0 16px -6px rgba(var(--accent-rgb), .6); }
.cs__clock.is-low .cs__clock-time { color: var(--danger); }

.cs__taken {
  display: flex;
  gap: 2px;
  min-height: 18px;
  flex-wrap: wrap;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--mist);
}
.cs__taken .cp { width: 16px; height: 16px; filter: none; }
.cs__taken-score { margin-left: auto; font-family: var(--mono); font-size: 0.7rem; color: var(--ink-dim); }

.cs__moves {
  flex: 1;
  max-height: 270px;
  overflow-y: auto;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--mist);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.65;
  scrollbar-width: thin;
}
.cs__move-row { display: flex; gap: 0.35rem; }
.cs__move-no { color: var(--ink-faint); min-width: 1.9em; text-align: right; }
.cs__move {
  flex: 1;
  padding: 0 0.25rem;
  border-radius: 3px;
  cursor: pointer;
  color: var(--ink);
  background: none;
  border: 0;
  font: inherit;
  text-align: left;
}
.cs__move:hover { background: rgba(255, 255, 255, .08); }
.cs__move.is-current { background: rgba(255, 204, 77, .22); color: #fff; }

.cs__engine {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: .04em;
  color: var(--ink-faint);
  min-height: 1.1em;
  text-align: center;
}

@media (max-width: 820px) {
  .cs { --board: min(92vw, 50vh, 460px); }
  .cs__aside { width: min(100%, 460px); }
  .cs__moves { max-height: 110px; }
  .cs__eval { width: var(--board); height: 12px; }
  .cs__eval-fill { left: 0; top: 0; bottom: 0; width: 50%; height: auto; right: auto;
    background: linear-gradient(90deg, var(--white-piece), #fffdf6); transition: width .45s var(--ease-out); }
  .cs__eval-mid { left: 50%; top: 0; bottom: 0; width: 1px; height: auto; right: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .cp, .cs__dot, .cs__ring { animation: none; transition: none; }
  .cs__sq.is-check::after { animation: none; }
}
