/* ============================================================
   CHESS GAME — Premium Dark Theme
   ============================================================ */

/* ---- Variables ---- */
:root {
  --bg-base:        #0d0f14;
  --bg-panel:       #13161f;
  --bg-card:        #1a1e2a;
  --bg-card-hover:  #1f2435;
  --border:         rgba(255,255,255,0.07);
  --border-glow:    rgba(168,139,250,0.3);

  --accent:         #a78bfa;   /* violet */
  --accent-light:   #c4b5fd;
  --accent-dark:    #7c3aed;
  --gold:           #f59e0b;
  --gold-light:     #fcd34d;

  --white-sq:       #e8d5b0;
  --black-sq:       #8b5e3c;
  --sq-selected:    rgba(168,139,250,0.55);
  --sq-legal:       rgba(168,139,250,0.30);
  --sq-last-from:   rgba(245,158,11,0.35);
  --sq-last-to:     rgba(245,158,11,0.50);
  --sq-check:       rgba(239,68,68,0.65);

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  20px;
  --radius-xl:  28px;

  --shadow-glow: 0 0 40px rgba(168,139,250,0.12);
  --shadow-card: 0 4px 24px rgba(0,0,0,0.4);

  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
  --transition-slow: 0.4s cubic-bezier(0.4,0,0.2,1);

  --piece-white: #f8fafc;
  --piece-black: #0f172a;
  --piece-white-shadow: 0 2px 6px rgba(0,0,0,0.7);
  --piece-black-shadow: 0 2px 6px rgba(0,0,0,0.9);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
}

/* ---- Background orbs ---- */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
  animation: orbFloat 12s ease-in-out infinite alternate;
}
.orb1 { width: 600px; height: 600px; background: var(--accent-dark); top: -200px; left: -200px; animation-delay: 0s; }
.orb2 { width: 400px; height: 400px; background: #2563eb; bottom: -100px; right: -100px; animation-delay: -4s; }
.orb3 { width: 300px; height: 300px; background: var(--gold); top: 40%; left: 50%; animation-delay: -8s; }

@keyframes orbFloat {
  from { transform: translate(0,0) scale(1); }
  to   { transform: translate(30px, 20px) scale(1.05); }
}

/* ---- App wrapper ---- */
.app-wrapper {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0 16px 8px;
}

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  font-size: 2rem;
  filter: drop-shadow(0 0 12px var(--accent));
  animation: iconPulse 3s ease-in-out infinite;
}
@keyframes iconPulse {
  0%, 100% { filter: drop-shadow(0 0 12px var(--accent)); }
  50%       { filter: drop-shadow(0 0 24px var(--accent-light)); }
}
.brand-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.7rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand-dedication {
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 500;
  background: linear-gradient(135deg, var(--gold-light), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-left: 8px;
  letter-spacing: 0.03em;
}

/* ---- Main layout ---- */
.main-layout {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  gap: 18px;
  flex: 1;
  min-height: 0;
  padding: 12px 0;
  align-items: center;
}

/* ---- Side panels ---- */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  max-height: 620px;
  justify-content: center;
}

/* ---- Player card ---- */
.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  position: relative;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.player-card.active {
  border-color: var(--border-glow);
  box-shadow: 0 0 20px rgba(168,139,250,0.15);
}
.player-avatar {
  font-size: 2rem;
  line-height: 1;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}
.white-avatar { background: rgba(248,250,252,0.1); color: var(--piece-white); text-shadow: var(--piece-white-shadow); }
.black-avatar { background: rgba(15,23,42,0.6);   color: var(--text-primary); }
.player-info { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.player-name { font-weight: 600; font-size: 0.95rem; }
.player-status { font-size: 0.75rem; color: var(--text-muted); }
.active-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition), box-shadow var(--transition);
}
.active-dot.on {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  animation: dotPulse 1.4s ease-in-out infinite;
}
@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 8px #22c55e; }
  50%       { box-shadow: 0 0 16px #22c55e; }
}

/* ---- Status box ---- */
.status-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
}
.status-box.check    { border-color: rgba(239,68,68,0.5);  background: rgba(239,68,68,0.08); }
.status-box.checkmate{ border-color: rgba(245,158,11,0.5); background: rgba(245,158,11,0.08); }
.status-box.draw     { border-color: rgba(100,116,139,0.5);}
.status-icon { font-size: 1.6rem; margin-bottom: 6px; }
.status-text { font-size: 0.82rem; color: var(--text-secondary); font-weight: 500; }

/* ---- New game button ---- */
.btn-new-game {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent-dark), #4f46e5);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
  box-shadow: 0 4px 20px rgba(124,58,237,0.35);
}
.btn-new-game:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(124,58,237,0.55);
  filter: brightness(1.1);
}
.btn-new-game:active { transform: translateY(0); }
.btn-icon { font-size: 1.1rem; }

/* ---- Board wrapper ---- */
.board-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.board-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  filter: drop-shadow(0 8px 40px rgba(0,0,0,0.6));
}

/* ---- Coordinate labels ---- */
.col-labels {
  display: grid;
  grid-template-columns: 22px repeat(8, 1fr) 22px;
  width: calc(8 * var(--sq-size) + 44px);
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.05em;
  text-align: center;
  user-select: none;
}
.board-and-ranks {
  display: flex;
  align-items: center;
  gap: 6px;
}
.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  user-select: none;
  width: 16px;
  text-align: center;
}

/* ---- Chess board ---- */
:root { --sq-size: 72px; }

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq-size));
  grid-template-rows:    repeat(8, var(--sq-size));
  border: 3px solid rgba(168,139,250,0.25);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.05),
    0 0 60px rgba(0,0,0,0.5);
}

/* ---- Squares ---- */
.sq {
  width: var(--sq-size);
  height: var(--sq-size);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
}
.sq.light { background: var(--white-sq); }
.sq.dark  { background: var(--black-sq); }

/* Hover shimmer */
.sq:not(.no-piece):hover::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.08);
  pointer-events: none;
}

/* Selection states */
.sq.selected { background: var(--sq-selected) !important; }
.sq.legal-move { background: var(--sq-legal) !important; }
.sq.last-from  { background: var(--sq-last-from) !important; }
.sq.last-to    { background: var(--sq-last-to) !important; }
.sq.in-check   { background: var(--sq-check) !important; }

/* Legal move dot / capture ring */
.sq.legal-move::before {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(168,139,250,0.6);
  pointer-events: none;
  transition: transform 0.15s ease;
}
.sq.legal-move.has-piece::before {
  width: 90%; height: 90%;
  background: transparent;
  border: 3px solid rgba(168,139,250,0.7);
  border-radius: 50%;
}
.sq.legal-move:hover::before { transform: scale(1.15); }

/* ---- Pieces ---- */
.piece {
  font-size: calc(var(--sq-size) * 0.72);
  line-height: 1;
  user-select: none;
  position: relative;
  z-index: 2;
  transition: transform var(--transition);
  cursor: grab;
}
.piece.white-piece {
  color: var(--piece-white);
  text-shadow: var(--piece-white-shadow);
  -webkit-text-stroke: 1px #b0b8c8;
}
.piece.black-piece {
  color: var(--piece-black);
  text-shadow: 0 1px 0 #fff3, var(--piece-black-shadow);
  -webkit-text-stroke: 0.5px #334155;
}
.sq:hover .piece { transform: scale(1.08); }

/* Move animation */
@keyframes pieceDrop {
  from { transform: scale(1.2) translateY(-6px); opacity: 0.6; }
  to   { transform: scale(1) translateY(0);      opacity: 1;   }
}
.piece.just-moved { animation: pieceDrop 0.25s ease-out; }

/* ---- Right panel — Move history ---- */
.history-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.history-icon { font-size: 1.1rem; }
.history-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }

.move-list-wrapper {
  flex: 1;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  min-height: 0;
}
.move-list {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dark) transparent;
}
.move-list::-webkit-scrollbar { width: 4px; }
.move-list::-webkit-scrollbar-thumb { background: var(--accent-dark); border-radius: 4px; }

.move-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 4px;
  align-items: center;
  padding: 3px 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.move-row:hover { background: var(--bg-card-hover); }
.move-row:last-child { background: rgba(168,139,250,0.08); border: 1px solid rgba(168,139,250,0.15); }

.move-num  { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }
.move-white, .move-black {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: default;
}
.move-white { color: var(--text-primary); }
.move-black { color: var(--text-muted); }

.move-list-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 24px;
}

.history-footer {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* ---- Promotion modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
}
.modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-xl);
  padding: 32px 36px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  transform: scale(0.9);
  transition: transform var(--transition-slow);
}
.modal-overlay.visible .modal-card { transform: scale(1); }
.modal-title { font-family: 'Playfair Display', serif; font-size: 1.4rem; margin-bottom: 6px; }
.modal-subtitle { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 24px; }

.promo-choices {
  display: flex;
  gap: 14px;
  justify-content: center;
}
.promo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 18px;
  background: var(--bg-base);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 2.4rem;
  color: var(--text-primary);
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.promo-btn:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(168,139,250,0.3);
}
.promo-btn span { font-size: 0.72rem; color: var(--text-muted); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  border-radius: 50px;
  padding: 10px 24px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 200;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  :root { --sq-size: 60px; }
  .main-layout { grid-template-columns: 180px 1fr 180px; gap: 12px; }
  .side-panel { max-height: 540px; }
}
@media (max-width: 900px) {
  :root { --sq-size: 52px; }
  .main-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .left-panel, .right-panel { max-height: 160px; flex-direction: row; flex-wrap: wrap; justify-content: center; }
  html, body { overflow: auto; }
  .app-wrapper { height: auto; overflow: auto; }
  .board-wrapper { padding: 8px 0; }
}
