/* ============================================================================
   CHESZ — Passe esthétique premium
   Hérite du kit-design.css (tokens, palette sémantique, animations).
   Adapte pour jeu d'échecs : plateau, pièces, micro-interactions premium.
   ============================================================================ */

:root {
  /* --- PALETTE SPÉCIFIQUE À CHESZ (plateau + thème) --- */
  /* Plateau d'échecs : couleurs harmonisées pour identité premium et lisibilité WCAG AA+ */
  --chess-light: #d4c5a0;      /* case claire (beige chaud) */
  --chess-dark: #7a6f56;       /* case sombre (taupe riche) */
  --chess-light-alt: #f5e8d0;  /* alt clair (très chaud pour light mode) */
  --chess-dark-alt: #c4b59d;   /* alt sombre (gris chaud) */

  /* Surlignages et états du plateau */
  --chess-sel: rgba(56, 224, 139, 0.35);           /* sélection case (vert lumineux) */
  --chess-last: rgba(212, 175, 55, 0.35);          /* dernier coup (or premium) */
  --chess-sel-glow: rgba(56, 224, 139, 0.25);      /* glow sélection */
  --chess-last-glow: rgba(212, 175, 55, 0.25);     /* glow dernier coup */
  --chess-check: rgba(255, 91, 87, 0.7);           /* alerte échec (rouge chaud) */
  --chess-check-glow: rgba(255, 91, 87, 0.3);      /* glow échec */
  --chess-dot: rgba(212, 175, 55, 0.4);            /* point déplacement possible */

  /* Glows de pièces premium */
  --chess-piece-glow-white: 0 0 20px rgba(251, 246, 238, 0.18), 0 0 40px rgba(212, 175, 55, 0.12);
  --chess-piece-glow-black: 0 0 20px rgba(33, 27, 24, 0.25), 0 0 40px rgba(56, 224, 139, 0.08);

  /* Premium glows sémantiques */
  --glow-gold-soft: rgba(212, 175, 55, 0.15);
  --glow-gold-mid: rgba(212, 175, 55, 0.25);
  --glow-gold-bright: rgba(212, 175, 55, 0.35);
  --glow-green-soft: rgba(56, 224, 139, 0.12);
  --glow-green-mid: rgba(56, 224, 139, 0.2);
  --glow-green-bright: rgba(56, 224, 139, 0.35);
}

/* --- RESET & STYLES GLOBAUX --- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: linear-gradient(135deg, #0e1219 0%, #1a2029 50%, #0e1219 100%);
  color: var(--cb-text-primary);
  font-family: var(--cb-font-family);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: max(calc(8px + var(--cb-safe-top, 0)), 8px) 10px max(calc(24px + var(--cb-safe-bottom, 0)), 10px) 10px;
  gap: 10px;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
  font-weight: 400;
  line-height: 1.35;
}

/* --- TOPBAR & BRAND --- */
.topbar {
  width: min(520px, 100%);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.05em;
  font-weight: 800;
  color: var(--cb-text-primary);
  text-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    0 0 16px var(--glow-gold-soft),
    0 0 32px var(--glow-green-soft);
  transition: text-shadow var(--cb-duration-normal) var(--cb-easing-ease-out);
}

.brand .tag {
  color: var(--cb-text-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  font: inherit;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--cb-text-primary);
  cursor: pointer;
  border: 1px solid var(--cb-border-medium);
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--cb-radius-sm);
  padding: 8px 12px;
  white-space: nowrap;
  transition: all var(--cb-duration-fast) var(--cb-easing-in-out);
  box-shadow:
    0 0 8px var(--glow-green-soft),
    var(--cb-shadow-inset);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow:
    0 0 20px var(--glow-green-mid),
    0 0 12px rgba(56, 224, 139, 0.25),
    var(--cb-shadow-inset);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn:focus {
  outline: var(--cb-focus-ring);
  outline-offset: 2px;
  box-shadow:
    var(--cb-focus-shadow),
    0 0 16px var(--glow-gold-mid),
    var(--cb-shadow-inset);
}

.icon-btn.pri {
  color: var(--cb-text-on-accent);
  background: linear-gradient(180deg, #f5a623, var(--cb-accent));
  border: 0;
  box-shadow:
    0 0 20px var(--glow-gold-mid),
    0 4px 14px rgba(212, 175, 55, 0.3),
    var(--cb-shadow-inset);
  transition: all var(--cb-duration-fast) var(--cb-easing-in-out);
}

.icon-btn.pri:hover {
  box-shadow:
    0 0 32px var(--glow-gold-bright),
    0 0 24px rgba(212, 175, 55, 0.5),
    0 6px 18px rgba(212, 175, 55, 0.4);
  transform: translateY(-2px);
}

.icon-btn.pri:active {
  transform: translateY(-1px);
}

/* --- ANIMATIONS FONDAMENTALES --- */
@keyframes fadeInScale {
  0% { opacity: 0; transform: scale(0.94); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes slideUp {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes shimmer {
  0% { background-position: -1000px 0; }
  100% { background-position: 1000px 0; }
}

@keyframes moveIn {
  0% { opacity: 0; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1); }
}

/* --- ÉCRAN MENU --- */
#screen-menu {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  margin-top: 3vh;
  animation: fadeInScale 0.3s var(--cb-easing-in-out);
}

#screen-menu.hide {
  display: none;
}

.hero {
  text-align: center;
}

.hero .logo {
  font-size: clamp(2.4rem, 12vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--cb-text-primary);
  text-shadow:
    0 4px 16px rgba(0, 0, 0, 0.5),
    0 0 24px var(--glow-gold-soft),
    0 0 48px var(--glow-green-soft);
  transition: text-shadow var(--cb-duration-slow) var(--cb-easing-ease-out);
}

.hero .sub {
  color: var(--cb-text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 4px;
}

.hero .glyphs {
  font-size: clamp(2rem, 9vw, 2.8rem);
  letter-spacing: 0.08em;
  margin-top: 10px;
  color: var(--cb-accent);
  text-shadow:
    0 2px 6px rgba(0, 0, 0, 0.4),
    0 0 16px var(--glow-gold-mid),
    0 0 32px var(--glow-gold-soft);
  animation: pulse 2.4s ease-in-out infinite;
  filter: drop-shadow(0 0 8px var(--glow-gold-soft));
}

.menu-card {
  width: 100%;
  background: var(--cb-glass-bg);
  backdrop-filter: var(--cb-glass-blur);
  border: 1px solid var(--cb-border-medium);
  border-radius: var(--cb-radius-lg);
  padding: 16px;
  box-shadow:
    0 0 40px var(--glow-green-mid),
    0 0 20px var(--glow-gold-soft),
    var(--cb-shadow-lg),
    var(--cb-shadow-inset);
  animation: slideUp var(--cb-duration-slow) var(--cb-easing-bounce);
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
}

.menu-card:hover {
  box-shadow:
    0 0 48px var(--glow-green-bright),
    0 0 28px var(--glow-gold-soft),
    var(--cb-shadow-xl),
    var(--cb-shadow-inset);
}

.menu-card h2 {
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--cb-text-primary);
}

.menu-card .hint {
  margin: 0 0 12px;
  color: var(--cb-text-secondary);
  font-size: 0.8rem;
}

.diffs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.diff-chip {
  flex: 1;
  font: inherit;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--cb-text-primary);
  cursor: pointer;
  border: 1px solid var(--cb-border-medium);
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--cb-radius-md);
  padding: 11px 6px;
  text-align: center;
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
  box-shadow: 0 0 12px var(--glow-green-soft);
}

.diff-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 20px var(--glow-green-mid);
}

.diff-chip.on {
  border-color: var(--cb-accent);
  background: rgba(212, 175, 55, 0.16);
  color: var(--cb-accent);
  box-shadow:
    0 0 24px var(--glow-gold-mid),
    0 0 0 1px var(--cb-accent);
}

.diff-chip:active {
  transform: scale(0.97);
}

.big-btn {
  width: 100%;
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  border: 0;
  border-radius: var(--cb-radius-md);
  padding: 15px;
  color: var(--cb-text-on-accent);
  background: linear-gradient(180deg, #f5a623, var(--cb-accent));
  box-shadow:
    0 0 32px var(--glow-gold-mid),
    0 0 24px rgba(212, 175, 55, 0.25),
    var(--cb-shadow-md);
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
}

.big-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 48px var(--glow-gold-bright),
    0 0 40px rgba(212, 175, 55, 0.4),
    var(--cb-shadow-lg);
}

.big-btn:active {
  transform: translateY(0);
}

.big-btn:focus {
  outline: var(--cb-focus-ring);
  outline-offset: 2px;
  box-shadow:
    var(--cb-focus-shadow),
    0 0 40px var(--glow-gold-bright),
    var(--cb-shadow-lg);
}

.big-btn.alt {
  color: var(--cb-text-primary);
  background: var(--cb-glass-bg);
  border: 1px solid var(--cb-border-medium);
  box-shadow:
    0 0 28px var(--glow-green-soft),
    0 0 20px rgba(56, 224, 139, 0.12),
    var(--cb-shadow-md),
    var(--cb-shadow-inset);
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
}

.big-btn.alt:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow:
    0 0 40px var(--glow-green-mid),
    0 0 32px rgba(56, 224, 139, 0.25),
    var(--cb-shadow-lg),
    var(--cb-shadow-inset);
  transform: translateY(-1px);
}

/* --- ÉCRAN JEU --- */
#screen-game {
  width: min(520px, 100%);
  display: none;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  animation: fadeInScale 0.3s var(--cb-easing-in-out);
}

#screen-game.show {
  display: flex;
}

.players {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pl {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--cb-glass-bg);
  border: 1px solid var(--cb-border-medium);
  border-radius: var(--cb-radius-md);
  padding: 8px 12px;
  min-width: 0;
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
  box-shadow:
    0 0 20px var(--glow-green-soft),
    0 0 16px rgba(56, 224, 139, 0.08),
    var(--cb-shadow-inset);
}

.pl:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow:
    0 0 32px var(--glow-green-mid),
    0 0 24px rgba(56, 224, 139, 0.15),
    var(--cb-shadow-inset);
  transform: translateY(-1px);
}

.pl .disc {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow:
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    inset 0 1px 2px rgba(255, 255, 255, 0.15);
}

.pl.white .disc {
  background: radial-gradient(circle at 35% 30%, #ffffff, #e6dcc9 60%, #c9bda2);
}

.pl.black .disc {
  background: radial-gradient(circle at 35% 30%, #4a423b, #231d19 60%, #120e0c);
}

.pl .nm {
  font-weight: 800;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.pl .chk {
  display: none;
  font-size: 0.72rem;
  font-weight: 800;
  color: #ffffff;
  background: var(--cb-danger);
  border: 0;
  border-radius: var(--cb-radius-xs);
  padding: 3px 8px;
}

.pl.in-check .chk {
  display: inline-block;
  animation: pulse 0.6s ease-in-out infinite;
  box-shadow: 0 0 12px rgba(255, 91, 87, 0.4);
}

.pl.active {
  border-color: var(--cb-accent);
  background: rgba(212, 175, 55, 0.12);
  box-shadow:
    0 0 32px var(--glow-gold-mid),
    0 0 24px rgba(212, 175, 55, 0.35),
    0 0 0 1px var(--cb-accent),
    var(--cb-shadow-inset);
}

#status {
  min-height: 1.2em;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--cb-text-primary);
  text-align: center;
  min-height: 1.4em;
  animation: fadeIn 0.2s var(--cb-easing-in-out);
}

#online-banner {
  display: none;
  width: 100%;
  background: var(--cb-glass-bg);
  border: 1px solid var(--cb-accent);
  border-radius: var(--cb-radius-md);
  padding: 10px 13px;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  box-shadow:
    0 0 32px var(--glow-gold-mid),
    0 0 0 1px var(--cb-accent),
    var(--cb-shadow-md);
}

#online-banner.show {
  display: flex;
  animation: slideUp 0.3s var(--cb-easing-bounce);
}

#online-banner .code {
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: 0.05em;
  color: var(--cb-accent);
  font-variant-numeric: tabular-nums;
}

#online-banner .lbl {
  color: var(--cb-text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
}

/* --- PLATEAU D'ÉCHECS --- */
.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(94vw, 460px);
  aspect-ratio: 1;
  --cell: calc(min(94vw, 460px) / 8);
  padding: 0;
  border-radius: var(--cb-radius-md);
  overflow: hidden;
  touch-action: none;
  border: 10px solid transparent;
  background:
    linear-gradient(var(--cb-surface-0), var(--cb-surface-0)) padding-box,
    linear-gradient(135deg, var(--cb-accent), var(--cb-accent-dark)) border-box;
  box-shadow:
    0 0 60px var(--glow-gold-bright),
    0 0 40px var(--glow-gold-mid),
    0 0 96px rgba(212, 175, 55, 0.12),
    0 20px 50px rgba(0, 0, 0, 0.4),
    inset var(--cb-shadow-inset),
    inset 0 1px 2px rgba(255, 255, 255, 0.06);
  animation: slideUp var(--cb-duration-deliberate) var(--cb-easing-bounce);
  transition: box-shadow var(--cb-duration-normal) var(--cb-easing-ease-out);
}

[dir="rtl"] #board {
  direction: ltr;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: calc(var(--cell) * 0.78);
  line-height: 1;
  overflow: hidden;
  transition: all var(--cb-duration-fast) var(--cb-easing-in-out);
}

.sq.lt {
  background: var(--chess-light);
}

.sq.dk {
  background: var(--chess-dark);
}

.sq:hover {
  filter: brightness(1.12);
}

.sq .pc {
  position: relative;
  z-index: 2;
  pointer-events: none;
  transition: transform var(--cb-duration-fast) ease;
  display: inline-block;
  will-change: transform;
  filter: drop-shadow(var(--chess-piece-glow-white));
}

.sq .pc.w {
  color: #fbf6ee;
  text-shadow:
    0 1px 0 #2c2622,
    0 -1px 0 #2c2622,
    1px 0 0 #2c2622,
    -1px 0 0 #2c2622,
    0 2px 3px rgba(0, 0, 0, 0.35);
}

.sq .pc.b {
  color: #211b18;
  text-shadow:
    0 1px 0 #efe4d0,
    0 -1px 0 #efe4d0,
    1px 0 0 #efe4d0,
    -1px 0 0 #efe4d0,
    0 2px 3px rgba(0, 0, 0, 0.3);
}

.sq.moved .pc {
  animation: pcpop 0.22s var(--cb-easing-bounce);
}

@keyframes pcpop {
  0% { transform: scale(0.82); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.sq .coord {
  position: absolute;
  z-index: 3;
  font-size: calc(var(--cell) * 0.2);
  font-weight: 800;
  opacity: 0.7;
  pointer-events: none;
}

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

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

.sq.lt .coord {
  color: #8a7a60;
}

.sq.dk .coord {
  color: #e8e0d0;
}

.sq.sel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--chess-sel);
  z-index: 1;
  box-shadow:
    inset 0 0 20px var(--chess-sel-glow),
    0 0 20px rgba(56, 224, 139, 0.25);
  animation: selPulse var(--cb-duration-slow) ease-in-out infinite;
}

@keyframes selPulse {
  0%, 100% {
    box-shadow:
      inset 0 0 20px var(--chess-sel-glow),
      0 0 16px rgba(56, 224, 139, 0.15);
  }
  50% {
    box-shadow:
      inset 0 0 24px var(--chess-sel-glow),
      0 0 28px rgba(56, 224, 139, 0.35);
  }
}

.sq.last::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--chess-last);
  z-index: 0;
  box-shadow:
    inset 0 0 16px var(--chess-last-glow),
    0 0 16px rgba(212, 175, 55, 0.2);
}

.sq.check::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(circle at 50% 50%, var(--chess-check), rgba(255, 91, 87, 0) 72%);
  box-shadow: 0 0 20px var(--chess-check-glow);
  animation: checkPulse 0.6s ease-in-out infinite;
}

@keyframes checkPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.sq .tgt {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  animation: pulse var(--cb-duration-deliberate) ease-in-out infinite;
}

.sq.move .tgt {
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: var(--chess-dot);
  box-shadow:
    0 0 0 2px var(--cb-accent),
    0 0 8px rgba(212, 175, 55, 0.4);
}

.sq.capture .tgt {
  inset: 6%;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 4px var(--cb-accent),
    inset 0 0 12px rgba(212, 175, 55, 0.3);
}

#board.locked .sq {
  cursor: default;
}

#dragghost {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.08);
  font-size: calc(min(94vw, 460px) / 8 * 0.82);
  line-height: 1;
  display: none;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.5));
}

#dragghost.w {
  color: #fbf6ee;
  text-shadow:
    0 1px 0 #2c2622,
    0 -1px 0 #2c2622,
    1px 0 0 #2c2622,
    -1px 0 0 #2c2622;
}

#dragghost.b {
  color: #211b18;
  text-shadow:
    0 1px 0 #efe4d0,
    0 -1px 0 #efe4d0,
    1px 0 0 #efe4d0,
    -1px 0 0 #efe4d0;
}

#history {
  width: 100%;
  max-height: 64px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  background: var(--cb-glass-bg);
  border: 1px solid var(--cb-border-medium);
  border-radius: var(--cb-radius-md);
  padding: 8px 10px;
  font-size: 0.82rem;
  color: var(--cb-text-secondary);
  font-variant-numeric: tabular-nums;
  box-shadow:
    0 0 20px var(--glow-green-soft),
    0 0 16px rgba(56, 224, 139, 0.12),
    var(--cb-shadow-inset);
}

#history:empty {
  display: none;
}

#history .mv {
  color: var(--cb-text-primary);
  font-weight: 700;
}

.mv {
  animation: moveIn 0.2s var(--cb-easing-in-out);
}

#history .no {
  opacity: 0.6;
  margin-right: 2px;
}

.game-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-actions button {
  font: inherit;
  font-weight: 800;
  font-size: 0.84rem;
  cursor: pointer;
  border-radius: var(--cb-radius-md);
  padding: 10px 14px;
  border: 1px solid var(--cb-border-medium);
  background: var(--cb-glass-bg);
  color: var(--cb-text-primary);
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
  box-shadow:
    0 0 16px var(--glow-green-soft),
    0 0 12px rgba(56, 224, 139, 0.1),
    var(--cb-shadow-inset);
}

.game-actions button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow:
    0 0 28px var(--glow-green-mid),
    0 0 20px rgba(56, 224, 139, 0.2),
    var(--cb-shadow-inset);
  transform: translateY(-1px);
}

.game-actions button:active {
  transform: scale(0.94);
}

.game-actions button:focus {
  outline: var(--cb-focus-ring);
  outline-offset: 2px;
  box-shadow:
    var(--cb-focus-shadow),
    0 0 20px var(--glow-gold-mid),
    var(--cb-shadow-inset);
}

.game-actions button.pri {
  color: var(--cb-text-on-accent);
  background: linear-gradient(180deg, #f5a623, var(--cb-accent));
  border: 0;
  box-shadow:
    0 0 28px var(--glow-gold-mid),
    0 0 20px rgba(212, 175, 55, 0.3),
    var(--cb-shadow-md);
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
}

.game-actions button.pri:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 40px var(--glow-gold-bright),
    0 0 32px rgba(212, 175, 55, 0.4),
    var(--cb-shadow-lg);
}

.game-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- OVERLAYS & DIALOGS --- */
.ov {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
  background: var(--cb-overlay-bg);
  backdrop-filter: var(--cb-overlay-blur);
  animation: fadeIn var(--cb-duration-normal) var(--cb-easing-in-out);
}

.ov.show {
  display: flex;
}

.dialog {
  width: min(94vw, 420px);
  max-height: 88vh;
  overflow: auto;
  background: var(--cb-glass-bg);
  border: 1px solid var(--cb-border-medium);
  border-radius: var(--cb-radius-xl);
  padding: 22px;
  box-shadow:
    0 0 60px var(--glow-green-bright),
    0 0 40px var(--glow-gold-soft),
    0 0 48px rgba(56, 224, 139, 0.2),
    var(--cb-shadow-xl),
    var(--cb-shadow-inset);
  text-align: center;
  animation: dialogIn var(--cb-duration-slow) var(--cb-easing-bounce);
}

@keyframes dialogIn {
  0% { opacity: 0; transform: scale(0.96) translateY(12px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.dialog h2 {
  margin: 0 0 6px;
  font-size: 1.4rem;
  color: var(--cb-text-primary);
}

.dialog p {
  margin: 0 0 12px;
  color: var(--cb-text-secondary);
  font-size: 0.9rem;
  line-height: 1.55;
}

.dialog .field {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.dialog input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.05rem;
  text-align: center;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 12px;
  border-radius: var(--cb-radius-md);
  border: 1px solid var(--cb-border-medium);
  background: rgba(0, 0, 0, 0.28);
  color: var(--cb-text-primary);
  transition: all var(--cb-duration-fast) var(--cb-easing-in-out);
}

.dialog input:focus {
  outline: 2px solid var(--cb-accent);
  outline-offset: 2px;
  border-color: var(--cb-accent);
}

.dialog input::placeholder {
  color: var(--cb-text-muted);
  letter-spacing: normal;
  text-transform: none;
  font-size: 0.9rem;
}

.dialog .btn {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: var(--cb-radius-md);
  padding: 12px 16px;
  cursor: pointer;
  color: var(--cb-text-on-accent);
  background: linear-gradient(180deg, #f5a623, var(--cb-accent));
  white-space: nowrap;
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
  box-shadow:
    0 0 28px var(--glow-gold-mid),
    0 0 20px rgba(212, 175, 55, 0.3),
    var(--cb-shadow-md);
}

.dialog .btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 40px var(--glow-gold-bright),
    0 0 32px rgba(212, 175, 55, 0.4),
    var(--cb-shadow-lg);
}

.dialog .btn:active {
  transform: translateY(0);
}

.dialog .btn:focus {
  outline: var(--cb-focus-ring);
  outline-offset: 2px;
  box-shadow:
    var(--cb-focus-shadow),
    0 0 40px var(--glow-gold-bright),
    var(--cb-shadow-lg);
}

.dialog .btn.alt {
  color: var(--cb-text-primary);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--cb-border-medium);
  box-shadow:
    0 0 20px var(--glow-green-soft),
    0 0 16px rgba(56, 224, 139, 0.15),
    var(--cb-shadow-inset);
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
}

.dialog .btn.alt:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow:
    0 0 32px var(--glow-green-mid),
    0 0 28px rgba(56, 224, 139, 0.25),
    var(--cb-shadow-inset);
  transform: translateY(-1px);
}

.dialog .btn.ghost {
  color: var(--cb-text-primary);
  background: transparent;
  box-shadow: none;
  border: 1px solid var(--cb-border-medium);
}

.dialog .btn.ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 12px rgba(56, 224, 139, 0.1);
}

.dialog .btn.wide {
  display: block;
  width: 100%;
  margin-top: 10px;
}

.dialog .sep {
  color: var(--cb-text-secondary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin: 16px 0 8px;
}

.over-emoji {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: 2px;
  animation: bounce 0.6s var(--cb-easing-bounce);
}

.promo-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 4px;
}

.promo-btn {
  width: 64px;
  height: 64px;
  border-radius: var(--cb-radius-md);
  border: 1px solid var(--cb-border-medium);
  cursor: pointer;
  background: var(--cb-glass-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  line-height: 1;
  transition: all var(--cb-duration-normal) var(--cb-easing-ease-out);
  box-shadow:
    0 0 20px var(--glow-gold-soft),
    0 0 12px rgba(212, 175, 55, 0.15),
    var(--cb-shadow-inset);
}

.promo-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--cb-accent);
  box-shadow:
    0 0 32px var(--glow-gold-mid),
    0 0 24px rgba(212, 175, 55, 0.35);
  transform: translateY(-2px) scale(1.05);
}

.promo-btn:active {
  transform: scale(0.92);
}

.promo-btn:focus {
  outline: var(--cb-focus-ring);
  outline-offset: 2px;
}

.promo-btn.w {
  color: #fbf6ee;
  text-shadow:
    0 1px 0 #2c2622,
    0 -1px 0 #2c2622,
    1px 0 0 #2c2622,
    -1px 0 0 #2c2622;
}

.promo-btn.b {
  color: #211b18;
  text-shadow:
    0 1px 0 #efe4d0,
    0 -1px 0 #efe4d0,
    1px 0 0 #efe4d0,
    -1px 0 0 #efe4d0;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, calc(20px + var(--cb-safe-bottom, 0)));
  transform: translateX(-50%);
  background: var(--cb-glass-bg);
  border: 1px solid var(--cb-border-medium);
  color: var(--cb-text-primary);
  padding: 11px 16px;
  border-radius: var(--cb-radius-md);
  font-weight: 700;
  font-size: 0.88rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--cb-duration-normal) var(--cb-easing-in-out);
  box-shadow:
    0 0 32px var(--glow-green-mid),
    0 0 24px rgba(56, 224, 139, 0.2),
    var(--cb-shadow-lg),
    var(--cb-shadow-inset);
  max-width: 86vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
}

/* --- MODE CLAIR --- */
@media (prefers-color-scheme: light) {
  :root {
    --cb-text-primary: #1a1f2e;
    --cb-text-secondary: #6d7f99;
    --cb-text-muted: #8a9aaf;
    --cb-surface-0: #f8f9fb;
    --cb-surface-1: #f5f5f5;
    --cb-surface-2: #eeeff2;
    --cb-glass-bg: rgba(248, 249, 251, 0.92);
    --cb-overlay-bg: rgba(245, 245, 245, 0.75);
    --cb-border-medium: rgba(0, 0, 0, 0.12);
    --cb-border-strong: rgba(0, 0, 0, 0.16);
    --chess-light: #f5e8d0;
    --chess-dark: #c4b59d;
  }

  body {
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 50%, #f5f5f5 100%);
  }

  .topbar,
  .brand h1,
  .menu-card h2,
  .hero .logo,
  .hero .glyphs,
  .dialog h2,
  .big-btn.alt {
    color: #1a1f2e;
  }

  .icon-btn.pri,
  .big-btn {
    color: #1a1f2e;
  }

  .pl .nm {
    color: #1a1f2e;
  }

  #status {
    color: #1a1f2e;
  }
}

/* --- RESPECT prefers-reduced-motion --- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .sq.moved .pc {
    animation: none;
  }

  .sq .pc {
    transition: none;
  }

  .big-btn:active,
  .icon-btn:active,
  .diff-chip:active,
  .promo-btn:active {
    transform: none;
  }
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 480px) {
  .brand h1 {
    font-size: 1.15rem;
  }

  #board {
    width: min(92vw, 420px);
  }

  .menu-card,
  .dialog {
    border-radius: var(--cb-radius-lg);
    padding: 14px;
  }

  .game-actions {
    gap: 6px;
  }

  .dialog .btn.wide {
    padding: 10px 12px;
  }
}

/* --- HIGH CONTRAST MODE --- */
@media (prefers-contrast: more) {
  :root {
    --cb-border-medium: rgba(255, 255, 255, 0.2);
    --cb-focus-ring: 2px solid rgba(212, 175, 55, 1);
  }
}
