/*
 * Chess Factory — game stylesheet.
 * Two colors. Light: #FEEFE8. Dark: #282623. Everything else is a tint of
 * the dark over the light. Minimal, high-contrast.
 */

:root {
  --light: #FEEFE8;
  --dark: #282623;
  --tint-06: rgba(40, 38, 35, 0.06);
  --tint-14: rgba(40, 38, 35, 0.14);
  --tint-30: rgba(40, 38, 35, 0.30);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--light);
  color: var(--dark);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

::selection {
  background: var(--dark);
  color: var(--light);
}

a {
  color: var(--dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover {
  background: var(--dark);
  color: var(--light);
  text-decoration: none;
}

/* ---- Chrome ---- */

.site-header,
.site-footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.site-header {
  border-bottom: 2px solid var(--dark);
}

.site-footer {
  border-top: 2px solid var(--dark);
  margin-top: auto;
  font-size: 12px;
}

.site-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 0;
}

.version-tag {
  font-size: 12px;
  letter-spacing: 0.08em;
  border: 1px solid var(--dark);
  padding: 0.1rem 0.5rem;
}

/* ---- Layout ---- */

.game {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 2rem;
  padding: 2rem 1.25rem;
}

/* ---- Board ---- */

.board-wrap {
  flex: 0 1 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(88vw, 72vh, 560px);
  aspect-ratio: 1;
  border: 2px solid var(--dark);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.square--light {
  background: var(--light);
}

.square--dark {
  background: var(--tint-14);
}

.coord {
  position: absolute;
  font-size: 9px;
  letter-spacing: 0.05em;
  opacity: 0.65;
  pointer-events: none;
}

.coord--file {
  right: 3px;
  bottom: 1px;
}

.coord--rank {
  left: 3px;
  top: 1px;
}

/* ---- Pieces ---- */

.piece {
  display: block;
  width: var(--piece-scale, 64%);
  height: var(--piece-scale, 64%);
  pointer-events: none;
}

.piece[data-type="k"] {
  --piece-scale: 90%;
}

.piece[data-type="q"] {
  --piece-scale: 80%;
}

.piece[data-type="r"],
.piece[data-type="b"],
.piece[data-type="n"] {
  --piece-scale: 70%;
}

.piece[data-type="p"] {
  --piece-scale: 55%;
}

.piece svg {
  display: block;
  width: 100%;
  height: 100%;
}

.piece--b {
  color: var(--dark);
}

/* Light pieces are the light color with a dark outline. The outline is
   drawn with stacked drop-shadows so it traces the silhouette of compound
   glyphs (king, queen, knight) rather than their constituent shapes. */
.piece--w {
  color: var(--light);
  filter:
    drop-shadow(1.5px 0 0 var(--dark))
    drop-shadow(-1.5px 0 0 var(--dark))
    drop-shadow(0 1.5px 0 var(--dark))
    drop-shadow(0 -1.5px 0 var(--dark));
}

.piece--ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.piece--ghost svg {
  width: var(--piece-scale, 64%);
  height: var(--piece-scale, 64%);
}

/* ---- Square states ---- */

.square--selected {
  box-shadow: inset 0 0 0 3px var(--dark);
}

.square--last {
  box-shadow: inset 0 0 0 2px var(--tint-30);
}

.square--selected.square--last {
  box-shadow: inset 0 0 0 3px var(--dark);
}

.square--check {
  background-image: repeating-linear-gradient(
    45deg,
    transparent 0 6px,
    var(--tint-30) 6px 8px
  );
}

.square--target::after {
  content: "";
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: var(--dark);
  opacity: 0.55;
  position: absolute;
}

.square--capture::after {
  content: "";
  position: absolute;
  inset: 6%;
  border: 3px solid var(--dark);
  border-radius: 50%;
  opacity: 0.75;
}

.square--drag-source .piece {
  opacity: 0.25;
}

/* ---- Promotion dialog ---- */

.promo {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(254, 239, 232, 0.88);
}

.promo__box {
  background: var(--light);
  border: 2px solid var(--dark);
  padding: 1rem;
}

.promo__title {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  margin-bottom: 0.75rem;
}

.promo__row {
  display: flex;
  gap: 0.5rem;
}

.promo__choice {
  width: 56px;
  height: 56px;
  padding: 8px;
  background: var(--light);
  border: 1px solid var(--dark);
  cursor: pointer;
}

.promo__choice:hover {
  background: var(--tint-14);
}

.promo__choice .piece {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---- Panel ---- */

.panel {
  flex: 0 1 260px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.version-summary {
  border: 1px solid var(--dark);
  background: var(--tint-06);
  padding: 0.7rem 0.8rem;
  font-size: 12px;
}

.version-summary__title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 0.5rem;
}

.version-summary__row {
  margin: 0 0 0.4rem;
}

.version-summary__row:last-child {
  margin-bottom: 0;
}

.version-summary__label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status {
  border: 2px solid var(--dark);
  padding: 0.6rem 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 12px;
}

.status--over {
  background: var(--dark);
  color: var(--light);
}

.movelist {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--dark);
}

.movelist:empty {
  display: none;
}

.movelist__row {
  display: grid;
  grid-template-columns: 2.5rem 1fr 1fr;
  gap: 0.25rem;
  padding: 0.15rem 0.6rem;
}

.movelist__row:nth-child(odd) {
  background: var(--tint-06);
}

.movelist__num {
  opacity: 0.6;
}

.movelist__ply--last {
  background: var(--dark);
  color: var(--light);
  padding: 0 0.3rem;
  justify-self: start;
}

.captured {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 1.5rem;
}

.captured__row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 18px;
}

.captured__row .piece {
  width: 18px;
  height: 18px;
}

.controls {
  display: flex;
  gap: 0.5rem;
}

button.control {
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--light);
  color: var(--dark);
  border: 2px solid var(--dark);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

button.control:hover {
  background: var(--dark);
  color: var(--light);
}

button.control:disabled {
  opacity: 0.35;
  cursor: default;
}

button.control:disabled:hover {
  background: var(--light);
  color: var(--dark);
}

@media (max-width: 720px) {
  .game {
    padding: 1rem;
    gap: 1.25rem;
  }

  .panel {
    flex-basis: 100%;
  }
}
