/* ---------- base ---------- */
*,*::before,*::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(ellipse at top, #2b2f3a, #14171f 70%);
  color: #e6e8ec;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

#app {
  display: grid;
  grid-template-columns: minmax(320px, 78vmin) 320px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 880px) {
  #app {
    grid-template-columns: 1fr;
    padding-top: 65px;
    padding-bottom: 65px;
  }
  #sidebar {
    width: 100%;
    max-width: 100%;
  }
  #clock-top {
    position: fixed;
    top: 24px;
    left: 24px;
    right: 24px;
    z-index: 100;
    margin: 0;
  }
  #clock-bot {
    position: fixed;
    bottom: 24px;
    left: 24px;
    right: 24px;
    z-index: 100;
    margin: 0;
  }
}

/* ---------- board ---------- */
#board-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 8px;
  box-shadow:
    0 30px 60px rgba(0,0,0,0.55),
    0 0 0 12px #4a3526,
    0 0 0 13px #2a1c12;
  background: #4a3526;
  padding: 0;
  overflow: hidden;
}
#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;  /* allow pointer-capture drag on touch devices */
}
.sq {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.sq.light { background: linear-gradient(160deg, #f4dcb1 0%, #e6c896 100%); }
.sq.dark  { background: linear-gradient(160deg, #b58863 0%, #8d633f 100%); }
.sq .coord {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0.6;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px;  top: 1px;    }
.sq.light .coord { color: #8d633f; }
.sq.dark  .coord { color: #f4dcb1; }

.sq.last { box-shadow: inset 0 0 0 999px rgba(255,225,80,0.28); }
.sq.sel  { box-shadow: inset 0 0 0 999px rgba(120,200,120,0.35); }
.sq.check { box-shadow: inset 0 0 24px 6px rgba(220,40,40,0.6); }

.sq .dot {
  position: absolute;
  width: 28%;
  height: 28%;
  background: rgba(40,40,40,0.32);
  border-radius: 50%;
  pointer-events: none;
}
.sq .ring {
  position: absolute;
  inset: 6%;
  border: 4px solid rgba(40,40,40,0.32);
  border-radius: 50%;
  pointer-events: none;
}

.piece {
  width: 92%;
  height: 92%;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
  transition: transform 120ms ease;
}
.sq.dragging .piece { opacity: 0.4; }
.piece.lift { transform: scale(1.08); }

/* ---------- sidebar ---------- */
#sidebar {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 12px;
  height: 78vmin;
  min-height: 480px;
  background: #1c2029;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.45);
}
#title { display: flex; align-items: center; justify-content: space-between; }
#title h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; }
#new-game {
  background: #3a6df0;
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
#new-game:hover { background: #4d80ff; }

.clock {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
  background: #262b36;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #2f3543;
}
.clock .who { font-size: 12px; color: #9aa3b3; text-transform: uppercase; letter-spacing: 1px; }
.clock .time { font-size: 26px; font-weight: 600; }
.clock.active { border-color: #3a6df0; box-shadow: 0 0 0 2px rgba(58,109,240,0.2); }
.clock.low .time { color: #ff6363; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.status {
  font-size: 13px;
  color: #9aa3b3;
  min-height: 18px;
  text-align: center;
}
.status.check { color: #ffb46b; font-weight: 600; }
.status.thinking::after { content: "…"; animation: dots 1.2s steps(4,end) infinite; }
.status.opening { color: #888; font-size: 0.9em; font-style: italic; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

#moves-wrap {
  background: #262b36;
  border-radius: 8px;
  overflow-y: auto;
  border: 1px solid #2f3543;
}
#moves { width: 100%; border-collapse: collapse; font-size: 14px; }
#moves td {
  padding: 4px 10px;
  font-variant-numeric: tabular-nums;
}
#moves td.num { color: #6c7384; width: 32px; }
#moves td.ply { cursor: default; }
#moves tr:nth-child(odd) { background: rgba(255,255,255,0.02); }
#moves td.current { background: rgba(58,109,240,0.25); border-radius: 4px; }

/* ---------- promotion picker ---------- */
#promotion {
  position: absolute;
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  background: #f4dcb1;
  border: 2px solid #4a3526;
  border-radius: 6px;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
#promotion.hidden { display: none; }
#promotion .opt { width: 100%; aspect-ratio: 1/1; cursor: pointer; }
#promotion .opt:hover { background: rgba(58,109,240,0.25); }
#promotion .opt svg { width: 100%; height: 100%; }

/* ---------- drag ghost ---------- */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.55));
  transform: scale(1.08);
}

/* ---------- colour picker ---------- */
.color-field { padding: 8px 12px 10px !important; }
.color-pick {
  display: flex;
  gap: 10px;
  padding: 4px 0 0;
}
/* hide the actual radio buttons but keep them in the form */
.color-pick input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  pointer-events: none;
}
.color-tile {
  flex: 1;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 2px solid #3a3f50;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
  user-select: none;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.1s;
  padding: 0;
}
.color-tile:hover { transform: scale(1.07); }
.color-tile.white-tile { background: #f0d9b5; color: #1c1c1c; }
.color-tile.black-tile { background: #1c1c1c; color: #e8e8e8; }
.color-tile.split-tile {
  background: linear-gradient(135deg, #f0d9b5 50%, #1c1c1c 50%);
}
/* highlight the chosen option */
.color-pick input[type="radio"]:checked + .color-tile {
  border-color: #3a6df0;
  box-shadow: 0 0 0 2px rgba(58,109,240,0.4);
}

/* ---------- dialogs ---------- */
dialog {
  background: #1c2029;
  color: #e6e8ec;
  border: 1px solid #2f3543;
  border-radius: 12px;
  padding: 22px 26px;
  min-width: 300px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.7);
}
dialog::backdrop { background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 14px; font-size: 20px; }
dialog fieldset { border: 1px solid #2f3543; border-radius: 8px; margin: 0 0 12px; padding: 10px 12px; }
dialog legend { font-size: 12px; color: #9aa3b3; padding: 0 6px; text-transform: uppercase; letter-spacing: 1px; }
dialog label { display: block; padding: 4px 0; cursor: pointer; }
dialog menu { display: flex; justify-content: flex-end; padding: 0; margin: 8px 0 0; }
dialog button {
  background: #3a6df0;
  color: white;
  border: 0;
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
dialog button:hover { background: #4d80ff; }
