/* =========================================================================
   chess page -- extends styles.css tokens
   ========================================================================= */

:root {
  --sq-light:   #f0e8da;
  --sq-dark:    #d4bfa2;
  --sq-sel:     rgba(249, 115, 22, .45);
  --sq-last:    rgba(249, 115, 22, .22);
  --sq-check:   rgba(220, 60, 40, .50);
  --pc-white:   #faf6ef;
  --pc-black:   #221c17;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sq-light: #3d342b;
    --sq-dark:  #27201a;
    --sq-sel:   rgba(249, 115, 22, .50);
    --sq-last:  rgba(249, 115, 22, .25);
    --pc-white: #f2ece3;
    --pc-black: #15100c;
  }
}

/* ---- layout ------------------------------------------------------------- */
.chess-layout {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(260px, 340px);
  gap: 28px;
  align-items: start;
  justify-content: center;
}

@media (max-width: 900px) {
  .chess-layout { grid-template-columns: minmax(0, 1fr); }
  .side-col { max-width: 560px; width: 100%; margin: 0 auto; }
}

.board-col { display: flex; flex-direction: column; align-items: center; }

/* ---- board -------------------------------------------------------------- */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(92vw, 560px);
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(28px, 8.4vw, 52px);
  line-height: 1;
  cursor: default;
  font-family: 'Segoe UI Symbol', 'Noto Sans Symbols 2', var(--mono);
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }
.sq.clickable { cursor: pointer; }

.sq.last::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--sq-last);
  pointer-events: none;
}
.sq.sel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--sq-sel);
  pointer-events: none;
}
.sq.check::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--sq-check);
  pointer-events: none;
}

/* legal-move markers */
.sq.tgt::after {
  content: '';
  position: absolute;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(249, 115, 22, .55);
  pointer-events: none;
}
.sq.tgt.cap::after {
  width: 86%;
  background: transparent;
  border: 3px solid rgba(249, 115, 22, .65);
}

/* coordinates on the board edge */
.sq .coord {
  position: absolute;
  font-family: var(--mono);
  font-size: .58rem;
  font-weight: 500;
  opacity: .55;
  pointer-events: none;
}
.sq .coord.file { right: 4px; bottom: 2px; }
.sq .coord.rank { left: 4px; top: 3px; }

/* old WebViews (iOS <= 14, Chrome < 88) lack aspect-ratio -- without this the
   board collapses to zero height. 11.5vw*8 = 92vw and 70px*8 = 560px mirror
   the board's width: min(92vw, 560px), so squares stay square. */
@supports not (aspect-ratio: 1) {
  .sq { height: 11.5vw; max-height: 70px; }
  .sq.tgt::after { height: 26%; }
  .sq.tgt.cap::after { height: 86%; }
}

.piece { position: relative; z-index: 1; pointer-events: none; }
.piece.pw { color: var(--pc-white); text-shadow: 0 1px 1px rgba(0,0,0,.55), 0 0 3px rgba(0,0,0,.30); }
.piece.pb { color: var(--pc-black); text-shadow: 0 1px 1px rgba(255,255,255,.22); }

/* ---- player strips / status --------------------------------------------- */
.player-strip {
  width: min(92vw, 560px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  font-size: .82rem;
  color: var(--text-mid);
  min-height: 34px;
}
.player-strip .who { font-weight: 700; color: var(--text); }
.player-strip .side-tag {
  font-size: .66rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  color: var(--text-faint);
}
.player-strip .turn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 0 3px var(--glow);
  flex: none;
  opacity: 0;
}
.player-strip.to-move .turn-dot { opacity: 1; animation: blink 1.6s steps(1) infinite; }

.chess-status {
  width: min(92vw, 560px);
  margin: 10px 0 0;
  font-size: .8rem;
  color: var(--comment);
  text-align: left;
  min-height: 1.4em;
}

/* ---- banner / panels ----------------------------------------------------- */
.chess-banner {
  max-width: 560px;
  margin: 0 auto 22px;
  padding: 10px 14px;
  font-size: .82rem;
  color: var(--orange-deep);
  background: color-mix(in srgb, var(--orange) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--orange) 35%, transparent);
  border-radius: var(--radius);
}
@media (prefers-color-scheme: dark) { .chess-banner { color: var(--orange-lit); } }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 16px;
}

.panel-title { margin: 0 0 12px; font-size: .8rem; color: var(--comment); }
.panel-note  { margin: 10px 0 0; font-size: .74rem; color: var(--comment); }

.field-label {
  display: block;
  font-size: .74rem;
  color: var(--text-mid);
  margin-bottom: 5px;
}
.field {
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 12px;
  font: inherit;
  font-size: .88rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.field:focus { outline: 2px solid var(--orange); outline-offset: 1px; border-color: transparent; }

.btn-block { width: 100%; justify-content: center; }

.btn-danger:hover { border-color: #c0392b; color: #c0392b; }
.btn-danger:hover::before, .btn-danger:hover::after { color: #c0392b; }

.panel-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---- move list ----------------------------------------------------------- */
.move-list {
  margin: 0;
  padding: 0 0 0 6px;
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  font-size: .84rem;
  line-height: 1.9;
}
.move-list li { display: flex; gap: 12px; }
.move-list .num { color: var(--text-faint); width: 2.4em; flex: none; text-align: right; }
.move-list .mv  { width: 4.6em; }
.move-list .mv.latest { color: var(--orange-deep); font-weight: 700; }
@media (prefers-color-scheme: dark) { .move-list .mv.latest { color: var(--orange-lit); } }
.move-list:empty::after { content: '// no moves yet'; color: var(--comment); font-size: .78rem; }

/* ---- archive ------------------------------------------------------------- */
.archive-list { margin: 0; padding: 0; list-style: none; font-size: .8rem; }
.archive-list li { border-top: 1px solid var(--border-soft); }
.archive-list li:first-child { border-top: 0; }

.archive-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 2px;
  font: inherit;
  font-size: .8rem;
  color: var(--text);
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
}
.archive-head:hover { color: var(--orange-deep); }
@media (prefers-color-scheme: dark) { .archive-head:hover { color: var(--orange-lit); } }
.archive-head .res { margin-left: auto; color: var(--text-faint); flex: none; }

.archive-sans {
  padding: 0 2px 10px;
  color: var(--comment);
  font-size: .74rem;
  line-height: 1.7;
  word-break: break-word;
}

/* ---- promotion overlay ---------------------------------------------------- */
.promo-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
}
.promo-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 18px 22px;
}
.promo-choices { display: flex; gap: 10px; }
.promo-choices button {
  font-size: 2.2rem;
  line-height: 1;
  padding: 10px 14px;
  color: var(--text);
  background: var(--bg-tint);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Segoe UI Symbol', 'Noto Sans Symbols 2', var(--mono);
}
.promo-choices button:hover { border-color: var(--orange); color: var(--orange-deep); }

/* ---- toast ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 120;
  max-width: min(92vw, 480px);
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: .82rem;
  color: #fff;
  background: #2b241e;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
