/* ===== Two-player chess — clean, elegant ===== */
:root {
  /* as large as the screen allows: full width on phones, capped on desktop,
     leaving room for the compact top turn-bar and bottom arrows */
  --board: min(96vw, calc(100dvh - 118px), 760px);
  --sq: calc(var(--board) / 8);
  --light: #ffffff;
  --dark:  #eff0f1;
  --green: #58cc02;
  --green-d: #46a302;
  --ink: #3c3c3c;
  --muted: #9aa0a6;
  --trail: rgba(106, 130, 170, 0.30); /* last-move trail: soft slate blue */
  --ease: cubic-bezier(0.22, 0.8, 0.2, 1);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Nunito", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #fff;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
.stage {
  position: relative;
  width: var(--board);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.6vh, 14px);
}

/* ---- HUD ---- */
.hud { display: flex; align-items: center; justify-content: center; min-height: 26px; }
.turn {
  display: inline-flex; align-items: center; gap: clamp(4px, 1vw, 9px);
  font-weight: 800; font-size: clamp(9.5px, 2.4vw, 15px);
  padding: clamp(3px, 0.8vw, 7px) clamp(7px, 2vw, 15px); border-radius: 999px;
  background: #f6f7f8; color: var(--muted);
  transition: background .25s var(--ease), color .25s var(--ease), box-shadow .25s var(--ease);
}
.turn.you {
  color: var(--green-d); background: #eefbe3;
  box-shadow: 0 0 0 2px rgba(88,204,2,.18) inset;
}
.turn.over { color: var(--ink); background: #f1f2f4; }
.dot {
  width: clamp(5px, 1.3vw, 10px); height: clamp(5px, 1.3vw, 10px); border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 2px rgba(0,0,0,.06) inset;
  transition: background .25s var(--ease);
}
.dot.w { background: #fff; box-shadow: 0 0 0 1.5px #d2d6da inset; }
.dot.b { background: #4a4a4a; }
.turn.you .dot { box-shadow: 0 0 0 2px rgba(88,204,2,.35); }

/* ---- board ---- */
.board-wrap { position: relative; width: var(--board); height: var(--board); }
.board {
  position: relative;
  width: var(--board); height: var(--board);
  border-radius: 9px; overflow: hidden;
  box-shadow: 0 14px 36px -20px rgba(40, 60, 30, 0.32);
  user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.squares {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}
.square { position: relative; }
.square.light { background: var(--light); }
.square.dark  { background: var(--dark); }

/* check — soft red glow on the king's square */
.square.check::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(255,72,66,0.28), rgba(255,72,66,0) 68%);
}

.pieces { position: absolute; inset: 0; pointer-events: none; }
/* Position is left/top (set in JS as % of the board); the resting transform is `none`.
   No will-change -> no permanent compositor layer to sub-pixel-snap/drift on iOS.
   transform is only ever a transient scale (grow) or translate (FLIP move). */
.piece {
  position: absolute; top: 0; left: 0;
  width: var(--sq); height: var(--sq);
  background-repeat: no-repeat; background-position: center 46%; background-size: 84% 84%;
  transform-origin: center 50%;
}

/* move hints */
.hint {
  position: absolute; pointer-events: none;
  width: var(--sq); height: var(--sq);
  display: grid; place-items: center;
  opacity: 0; transition: opacity .16s var(--ease);
}
.hint.show { opacity: 1; }
.hint .dot-h { width: 26%; height: 26%; border-radius: 50%; background: rgba(60,70,50,0.18); }

/* ---- bottom nav ---- */
.hud-bottom { gap: 26px; }
.nav {
  display: grid; place-items: center; padding: 0;
  width: 40px; height: 40px; border-radius: 13px;
  border: 2px solid #e7e9ec; border-bottom-width: 4px; background: #fff;
  color: #7b8089; cursor: pointer;
  transition: transform .06s ease, background .15s, color .15s, opacity .15s;
}
.nav svg { display: block; width: 19px; height: 19px; }
.nav:hover:not(:disabled) { background: #f6f7f8; color: var(--ink); }
.nav:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.nav:disabled { opacity: .38; cursor: default; }

/* "ready for next game" button (shown in the bottom bar after game-over) */
.rematch-btn {
  font-family: inherit; font-weight: 800; font-size: 14px; color: #fff;
  background: var(--green); border: none; border-bottom: 3px solid var(--green-d);
  border-radius: 13px; height: 40px; padding: 0 18px; cursor: pointer; white-space: nowrap;
  transition: transform .06s ease, background .15s, opacity .2s;
}
.rematch-btn:active { transform: translateY(2px); border-bottom-width: 1px; }
.rematch-btn.waiting { background: #eef0f2; color: var(--muted); border-bottom-color: #dfe2e5; }

/* ---- admin menu (p=1) ---- */
.admin { position: absolute; top: 0; right: 0; z-index: 70; }
.menu-btn {
  display: grid; place-items: center; padding: 0;
  width: clamp(26px, 6.6vw, 36px); height: clamp(26px, 6.6vw, 36px); border-radius: clamp(9px, 2.4vw, 12px);
  border: 2px solid #e7e9ec; border-bottom-width: 3px; background: #fff;
  color: #9aa0a6; cursor: pointer;
  transition: transform .06s ease, background .15s, color .15s;
}
.menu-btn svg { display: block; width: clamp(14px, 3.6vw, 20px); height: clamp(14px, 3.6vw, 20px); }
.menu-btn:hover { background: #f6f7f8; color: var(--ink); }
.menu-btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 168px;
  background: #fff; border-radius: 16px; padding: 7px;
  box-shadow: 0 18px 44px -18px rgba(40, 60, 30, 0.42), 0 2px 0 rgba(0, 0, 0, 0.03), 0 0 0 1px rgba(0,0,0,.04);
  transform-origin: top right; animation: menuIn 0.16s var(--ease);
}
@keyframes menuIn { from { opacity: 0; transform: scale(0.93) translateY(-6px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 11px 14px; border: none; background: none; border-radius: 11px;
  font-family: inherit; font-weight: 800; font-size: 15px; color: var(--ink);
  cursor: pointer; text-align: left; transition: background .14s ease, color .14s ease;
}
.menu-item svg { color: var(--muted); transition: color .14s ease; }
.menu-item:hover { background: #eefbe3; color: var(--green-d); }
.menu-item:hover svg { color: var(--green-d); }

/* transient toast (e.g. a move that failed to send) */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 200;
  background: #3c3c3c; color: #fff; font-weight: 800; font-size: 13.5px;
  padding: 11px 18px; border-radius: 14px; max-width: 82vw; text-align: center;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.2s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%); } }

/* ---- overlay (ready / game over) ---- */
.overlay {
  position: absolute; inset: 0; border-radius: 9px;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  display: grid; place-items: center;
  z-index: 50;
  animation: fadein .25s var(--ease);
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.card {
  width: min(86%, 360px);
  background: #fff; border-radius: 22px;
  box-shadow: 0 24px 60px -24px rgba(40,60,30,.45), 0 2px 0 rgba(0,0,0,.03);
  padding: 26px 24px; text-align: center;
}
.card h2 { margin: 0 0 6px; font-size: 22px; font-weight: 900; color: var(--ink); }
.card p { margin: 0 0 18px; color: var(--muted); font-weight: 700; font-size: 14px; line-height: 1.5; }
.seats { display: flex; gap: 10px; justify-content: center; margin: 0 0 20px; }
.seat {
  flex: 1; max-width: 130px; padding: 12px 8px; border-radius: 14px;
  background: #f6f7f8; font-weight: 800; font-size: 13px; color: var(--muted);
  transition: background .2s, color .2s, box-shadow .2s;
}
.seat .who { font-size: 14px; color: var(--ink); margin-bottom: 4px; }
.seat.ready { background: #eefbe3; color: var(--green-d); box-shadow: 0 0 0 2px rgba(88,204,2,.2) inset; }
.seat.me { outline: 2px dashed rgba(88,204,2,.4); outline-offset: 2px; }
.seat .st { font-size: 12px; }

.btn {
  font-family: inherit; font-weight: 900; font-size: 16px; color: #fff;
  background: var(--green); border: none; border-bottom: 4px solid var(--green-d);
  border-radius: 16px; padding: 13px 22px; cursor: pointer; width: 100%;
  transition: transform .06s ease, background .15s, opacity .2s;
}
.btn:hover { background: #5bd406; }
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.ghost { background: #fff; color: var(--green-d); border: 2px solid #e7e9ec; border-bottom-width: 4px; }

/* seat chooser (shown when the URL has no /1 or /2) */
.choose-title { margin: 2px 0 18px; font-weight: 900; font-size: 18px; color: var(--ink); text-align: center; }
.choose-row { display: flex; gap: 12px; }
.choose-row .btn { width: auto; flex: 1; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* ---- promotion picker ---- */
.promo {
  position: absolute; inset: 0; z-index: 60;
  background: rgba(255,255,255,0.55); backdrop-filter: blur(4px);
  display: grid; place-items: center;
  animation: fadein .18s var(--ease);
}
.promo .row {
  display: flex; gap: 12px; padding: 14px;
  background: #fff; border-radius: 20px;
  box-shadow: 0 24px 60px -24px rgba(40,60,30,.5);
}
.promo .opt {
  width: var(--sq); height: var(--sq); max-width: 84px; max-height: 84px;
  border-radius: 14px; cursor: pointer; background: #f6f7f8;
  background-repeat: no-repeat; background-position: center; background-size: 78%;
  transition: transform .12s var(--ease), background-color .15s;
}
.promo .opt:hover { transform: translateY(-3px) scale(1.04); background-color: #eefbe3; }
