/* ══════════════════════════════════════════════════════════════════════
   CHESS — easter egg modal (js/chess/modal.js)

   Built on the site's tokens (--bg, --fg, --border, --r …) so it follows the
   light/dark theme automatically. Chrome mirrors the booking modal: same
   backdrop blur, radius, shadow, easing, z-index layer, and the same
   "display toggled from JS" rule so a closed modal can never leave an
   invisible layer over the page (see the note above .booking-modal-backdrop).
══════════════════════════════════════════════════════════════════════ */

/* Piece font: a 2.8 KB subset (U+2654–265F only) of Noto Sans Symbols 2, SIL OFL 1.1
   (assets/fonts/OFL-noto-sans-symbols-2.txt). Self-hosted so every platform draws
   the same glyphs; system fonts are the fallback. U+FE0E is appended in JS so ♟
   never turns into a colour emoji. */
@font-face {
  font-family: 'Chess Noto';
  src: url('../assets/fonts/noto-sans-symbols-2-chess.woff2') format('woff2');
  font-display: swap;
  unicode-range: U+2654-265F, U+FE0E;
}

.chess-modal,
.cp-ghost {
  --chess-font: 'Chess Noto', 'Noto Sans Symbols 2', 'Segoe UI Symbol', 'Apple Symbols', 'DejaVu Sans', 'FreeSerif', serif;
  /* light theme board */
  --sq-l: #ece9e2;
  --sq-d: #c8c4b9;
  --pc-w: #ffffff;       --pc-w-line: #1c1c1c;
  --pc-b: #1a1a1a;       --pc-b-line: transparent;
  --hint: rgba(15, 15, 15, .26);
  --hl-last: rgba(217, 84, 31, .30);
  --hl-sel:  rgba(217, 84, 31, .48);
  --warn: #c2410c;
}
body.dark .chess-modal,
body.dark .cp-ghost {
  --sq-l: #3d3d3b;
  --sq-d: #262625;
  --pc-w: #f6f6f2;      --pc-w-line: #060606;
  --pc-b: #0b0b0b;      --pc-b-line: rgba(255, 255, 255, .58);
  --hint: rgba(255, 255, 255, .30);
  --warn: #fb923c;
}
@media (prefers-color-scheme: dark) {
  body:not(.light) .chess-modal,
  body:not(.light) .cp-ghost {
    --sq-l: #3d3d3b;
    --sq-d: #262625;
    --pc-w: #f6f6f2;    --pc-w-line: #060606;
    --pc-b: #0b0b0b;    --pc-b-line: rgba(255, 255, 255, .58);
    --hint: rgba(255, 255, 255, .30);
    --warn: #fb923c;
  }
}

html.chess-open { overflow: hidden; }

/* ── Shell (same pattern as .booking-modal) ── */
.chess-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .28);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 8500;
  opacity: 0; pointer-events: none;
  transition: opacity .24s var(--ease-out);
}
.chess-backdrop.open { opacity: 1; pointer-events: auto; }

.chess-modal {
  display: none;
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.96);
  width: calc(100% - 32px);
  max-width: 940px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  background: var(--bg);
  border: 1px solid var(--border-s);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .18);
  z-index: 8600;
  flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: transform .32s var(--ease-out), opacity .24s var(--ease-out);
  overflow: hidden;
  font-family: var(--sans);
  color: var(--fg);
}
.chess-modal.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.chess-modal:focus { outline: none; }

.chess-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chess-title { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.chess-sub { margin-top: 2px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .04em; color: var(--fg-3); }
.chess-close {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-3); cursor: pointer; background: none; border: none;
  transition: background var(--t), color var(--t);
}
.chess-close:hover { background: var(--bg-hover); color: var(--fg); }

/* ── Layout ── */
.chess-body {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 20px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  grid-template-areas:
    "board status"
    "board controls"
    "board settings"
    "board moves";
  grid-template-rows: auto auto auto 1fr;
  gap: 14px 24px;
  align-items: start;
}
.chess-status      { grid-area: status; }
.chess-board-col   { grid-area: board; }
.chess-controls    { grid-area: controls; }
.chess-settings    { grid-area: settings; }
.chess-moves       { grid-area: moves; min-height: 0; }

/* ── Status ── */
.chess-status {
  padding: 13px 15px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  transition: border-color var(--t);
}
.chess-status-main { font-size: 15px; font-weight: 600; letter-spacing: -.015em; line-height: 1.3; }
.chess-status-sub { margin-top: 3px; font-size: 12.5px; line-height: 1.5; color: var(--fg-2); }
.chess-status-sub:empty { display: none; }
.chess-modal[data-tone="check"] .chess-status-main { color: var(--warn); }
.chess-modal[data-tone="end"] .chess-status { border-color: var(--border-s); }
.chess-modal[data-tone="busy"] .chess-status-main { color: var(--fg-2); }
.chess-claimbar {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  font-size: 12.5px; color: var(--fg-2);
}
.chess-claimbtns { display: flex; gap: 6px; }

/* ── Board column ── */
.chess-board-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chess-board-wrap {
  position: relative; width: 100%;
  max-width: min(100%, 640px, calc(100vh - 230px));
  max-width: min(100%, 640px, calc(100dvh - 230px));
  margin: 0 auto;
}
.chess-player {
  width: 100%;
  max-width: min(100%, 640px, calc(100vh - 230px));
  max-width: min(100%, 640px, calc(100dvh - 230px));
  margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 24px; font-size: 12.5px; color: var(--fg-2);
}
.chess-who { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; color: var(--fg); }
.chess-dot { width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--border-s); flex-shrink: 0; }
.chess-dot-w { background: #fff; }
.chess-dot-b { background: #141414; border-color: rgba(128, 128, 128, .5); }
.chess-caps { display: inline-flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; min-width: 0; line-height: 1; }
.cap { font-family: var(--chess-font); font-size: 15px; margin-left: -3px; }
.cap.cp-w { color: var(--pc-w); -webkit-text-stroke: .6px var(--pc-w-line); paint-order: stroke fill; }
.cap.cp-b { color: var(--pc-b); -webkit-text-stroke: .5px var(--pc-b-line); paint-order: stroke fill; }
.chess-adv { margin-left: 8px; font-family: var(--mono); font-size: 11px; color: var(--fg-3); }
.chess-dots { display: inline-flex; gap: 3px; margin-left: 6px; color: var(--fg-3); }
.chess-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: chessDot 1.1s ease-in-out infinite; }
.chess-dots i:nth-child(2) { animation-delay: .15s; }
.chess-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes chessDot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* ── Board ── */
.chess-board {
  display: flex; flex-direction: column;
  width: 100%; aspect-ratio: 1 / 1;
  container-type: inline-size;
  border: 1px solid var(--border-s);
  border-radius: 8px; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cq-row { display: flex; flex: 1; min-height: 0; }
.cq {
  position: relative; flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: default;
}
.cq.is-light { background: var(--sq-l); }
.cq.is-dark  { background: var(--sq-d); }
.cq::before { content: ''; position: absolute; inset: 0; pointer-events: none; }
.cq.is-last::before  { background: var(--hl-last); }
.cq.is-sel::before   { background: var(--hl-sel); }
.cq.is-check::before { background: radial-gradient(circle at 50% 50%, rgba(220, 38, 38, .85) 0, rgba(220, 38, 38, .45) 42%, rgba(220, 38, 38, 0) 74%); }
.cq.is-target::after {
  content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: var(--hint); pointer-events: none; z-index: 2;
}
.cq.is-capture::after {
  content: ''; position: absolute; inset: 5%; border-radius: 50%;
  border: max(3px, 0.9cqw) solid var(--hint); pointer-events: none; z-index: 2;
}
.cq.is-own { cursor: grab; }
.cq.is-target, .cq.is-capture { cursor: pointer; }
.cq:focus-visible { outline: 2px solid var(--fg); outline-offset: -3px; z-index: 3; }

.cc { position: absolute; font-family: var(--mono); font-size: 10px; line-height: 1; font-weight: 500; pointer-events: none; z-index: 1; }
.cc-r { top: 4px; left: 5px; }
.cc-f { bottom: 4px; right: 5px; }
.is-light .cc { color: var(--sq-d); }
.is-dark  .cc { color: var(--sq-l); }
@container (min-width: 480px) { .cc { font-size: 11px; } }

/* ── Pieces ── */
.cp {
  position: relative; z-index: 1;
  font-family: var(--chess-font);
  font-size: clamp(24px, 8.4vw, 54px);
  font-size: 9.6cqw;
  line-height: 1; font-weight: 400;
  pointer-events: none;
  text-align: center;
}
.cp-w { color: var(--pc-w); -webkit-text-stroke: 1.1px var(--pc-w-line); paint-order: stroke fill; }
.cp-b { color: var(--pc-b); -webkit-text-stroke: .9px var(--pc-b-line); paint-order: stroke fill; }
.cp.is-lifted { opacity: .22; }
.cp-ghost {
  position: fixed; left: 0; top: 0; z-index: 9000; pointer-events: none;
  text-align: center; will-change: transform;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .35));
  transform-origin: center;
}

/* ── Promotion chooser ── */
.chess-promo {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(0, 0, 0, .42);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  border-radius: 8px;
}
.chess-promo[hidden] { display: none; }
.chess-promo-title { font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: #fff; }
.chess-promo-row {
  display: flex; gap: 8px; padding: 10px;
  background: var(--bg); border: 1px solid var(--border-s); border-radius: var(--r);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}
.chess-promo-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: clamp(54px, 14vw, 76px); padding: 8px 4px 6px;
  background: var(--sq-l); border: 1px solid var(--border); border-radius: var(--r-sm);
  cursor: pointer; color: var(--fg);
  transition: background var(--t), border-color var(--t), transform var(--t);
}
.chess-promo-btn .cp { font-size: clamp(30px, 8vw, 46px); pointer-events: none; }
.chess-promo-btn:hover, .chess-promo-btn:focus-visible { border-color: var(--fg); transform: translateY(-1px); outline: none; }
.chess-promo-name { font-size: 10.5px; color: var(--fg-2); text-transform: capitalize; }
.chess-promo-cancel {
  font-size: 12px; color: #fff; background: none; border: none; cursor: pointer;
  padding: 4px 8px; border-radius: var(--r-sm); text-decoration: underline; text-underline-offset: 3px;
}
.chess-promo-cancel:focus-visible { outline: 2px solid #fff; }

/* ── Buttons ── */
.chess-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.chess-btn {
  height: 34px; padding: 0 10px;
  font-family: inherit; font-size: 12.5px; font-weight: 500; letter-spacing: -.005em;
  color: var(--fg); background: transparent;
  border: 1px solid var(--border-s); border-radius: var(--r-sm);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), color var(--t) var(--ease), opacity var(--t);
}
.chess-btn:hover:not(:disabled) { background: var(--bg-hover); }
.chess-btn:focus-visible, .chess-segbtn:focus-visible, .chess-close:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.chess-btn:disabled { opacity: .38; cursor: not-allowed; }
.chess-btn--solid { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chess-btn--solid:hover:not(:disabled) { background: var(--fg); opacity: .85; }
.chess-btn.is-armed { color: var(--warn); border-color: var(--warn); }

/* ── Settings ── */
.chess-settings { display: flex; flex-direction: column; gap: 12px; }
.chess-label { font-family: var(--mono); font-size: 10px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3); margin-bottom: 6px; }
.chess-seg { display: flex; border: 1px solid var(--border-s); border-radius: var(--r-sm); overflow: hidden; }
.chess-segbtn {
  flex: 1; min-width: 0; height: 32px; padding: 0 4px;
  font-family: inherit; font-size: 12px; font-weight: 500; color: var(--fg-2);
  background: transparent; border: none; border-left: 1px solid var(--border); cursor: pointer;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.chess-segbtn:first-child { border-left: none; }
.chess-segbtn:hover:not(.is-on) { background: var(--bg-hover); color: var(--fg); }
.chess-segbtn.is-on { background: var(--fg); color: var(--bg); }
.chess-segbtn:focus-visible { outline-offset: -2px; }
.chess-hint { margin-top: 6px; font-size: 11.5px; color: var(--fg-3); }
.chess-hint[hidden], .chess-claimbar[hidden] { display: none; }

/* ── Move list ── */
.chess-movelist {
  list-style: none; margin: 0; padding: 4px 0;
  max-height: 188px; overflow-y: auto;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px; scrollbar-width: thin;
}
.chess-movelist li { display: grid; grid-template-columns: 30px 1fr 1fr; align-items: center; padding: 1px 0; }
.chess-movelist .mn { color: var(--fg-3); padding-left: 4px; }
.chess-movelist .mv { padding: 2px 6px; border-radius: 4px; color: var(--fg); }
.chess-movelist .mv.is-now { background: var(--bg-hover); font-weight: 600; }
.chess-movelist .empty { display: block; padding: 8px 4px; color: var(--fg-3); }

.chess-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Tablet / phone ── */
@media (max-width: 760px) {
  .chess-modal {
    width: 100%; max-width: none; height: 100%; max-height: none;
    top: 0; left: 0; border: none; border-radius: 0;
    transform: translateY(14px);
  }
  .chess-modal.open { transform: none; }
  .chess-head { padding: 12px 16px 10px; padding-top: max(12px, env(safe-area-inset-top)); }
  .chess-body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "status" "board" "controls" "settings" "moves";
    grid-template-rows: none;
    padding: 12px 14px calc(18px + env(safe-area-inset-bottom));
    gap: 12px;
  }
  .chess-board-wrap, .chess-player { max-width: 100%; }
  .chess-status { padding: 10px 12px; }
  .chess-status-main { font-size: 14px; }
  .chess-movelist { max-height: 130px; }
  .cc { font-size: 9px; }
  .cc-r { top: 2px; left: 3px; }
  .cc-f { bottom: 2px; right: 3px; }
}
@media (max-width: 380px) {
  .chess-btn { font-size: 12px; padding: 0 6px; }
  .chess-segbtn { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .chess-modal, .chess-backdrop, .chess-btn, .chess-segbtn, .chess-promo-btn { transition: none; }
  .chess-dots i { animation: none; opacity: .6; }
}
