/* ═══════════════════════════════════════════
   ROYAL CHESS — Premium Stylesheet
   Dark walnut & gold luxury aesthetic
═══════════════════════════════════════════ */

:root {
  --gold:        #c9a84c;
  --gold-light:  #e8c97a;
  --gold-dim:    #8a6d2f;
  --bg-deep:     #0d0b09;
  --bg-panel:    #13110e;
  --bg-card:     #1a1612;
  --bg-card2:    #211d18;
  --border:      rgba(201,168,76,0.18);
  --border-soft: rgba(255,255,255,0.06);
  --text:        #e8dcc8;
  --text-dim:    #8a7d6a;
  --text-soft:   #c4b49a;
  --white-sq:    #f0d9b5;
  --black-sq:    #b58863;
  --sq-size:     72px;
  --radius:      10px;
  --shadow-gold: 0 0 30px rgba(201,168,76,0.15);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100vh;
  font-family: 'Crimson Text', Georgia, serif;
  background: var(--bg-deep);
  color: var(--text);
  overflow-x: hidden;
}

/* ── Atmosphere ── */
.bg-layer {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(201,168,76,0.04) 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 80% 90%, rgba(139,90,43,0.06) 0%, transparent 60%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 40px,
      rgba(255,255,255,0.008) 40px,
      rgba(255,255,255,0.008) 41px
    );
}
.vignette {
  position: fixed; inset: 0; z-index: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.7) 100%);
  pointer-events: none;
}

/* ── Layout ── */
.app-wrapper { position: relative; z-index: 1; max-width: 1400px; margin: 0 auto; padding: 20px 16px; }

.header {
  text-align: center;
  padding: 24px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.crown-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 6px; filter: drop-shadow(0 0 12px rgba(201,168,76,0.6)); }
.title {
  font-family: 'Cinzel', serif;
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--gold-light);
  letter-spacing: 0.12em;
  text-shadow: 0 0 40px rgba(201,168,76,0.3);
}
.subtitle {
  font-size: 1rem;
  color: var(--text-dim);
  font-style: italic;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.main-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
}

/* ── Panels ── */
.panel { display: flex; flex-direction: column; gap: 14px; min-width: 200px; }
.panel-left  { width: 210px; flex-shrink: 0; }
.panel-right { width: 210px; flex-shrink: 0; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: border-color 0.2s;
}
.card:hover { border-color: rgba(201,168,76,0.28); }
.card-title {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}

/* Mode Buttons */
.mode-buttons { display: flex; flex-direction: column; gap: 8px; }
.mode-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card2);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--text-soft);
  font-family: 'Crimson Text', serif;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  width: 100%;
}
.mode-btn:hover { border-color: var(--gold-dim); color: var(--text); }
.mode-btn.active {
  background: linear-gradient(135deg, rgba(201,168,76,0.15), rgba(201,168,76,0.06));
  border-color: var(--gold-dim);
  color: var(--gold-light);
  box-shadow: inset 0 0 12px rgba(201,168,76,0.08);
}
.mode-icon { font-size: 1.1rem; }

/* Difficulty */
.difficulty-card { transition: opacity 0.3s; }
.difficulty-card.disabled { opacity: 0.4; pointer-events: none; }
.difficulty-slider-wrap { display: flex; flex-direction: column; gap: 8px; }

input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%; height: 4px;
  background: linear-gradient(to right, var(--gold) 0%, var(--gold) 50%, var(--bg-card2) 50%);
  border-radius: 2px; outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--gold-light);
  box-shadow: 0 0 8px rgba(201,168,76,0.5);
  border: 2px solid var(--bg-deep);
  cursor: pointer;
  transition: transform 0.15s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.difficulty-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
  color: var(--text-dim);
}
.difficulty-display {
  text-align: center;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  color: var(--gold);
  padding: 4px 0;
}

/* Timer */
.timers { display: flex; align-items: center; gap: 10px; }
.timer-block {
  flex: 1; text-align: center;
  background: var(--bg-card2);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 10px 8px;
  transition: all 0.3s;
}
.timer-block.active {
  border-color: var(--gold-dim);
  background: rgba(201,168,76,0.08);
  box-shadow: 0 0 14px rgba(201,168,76,0.1);
}
.timer-block.low { border-color: #c0392b; animation: pulse-red 1s infinite; }
@keyframes pulse-red { 0%,100%{ box-shadow:0 0 8px rgba(192,57,43,0.3); } 50%{ box-shadow:0 0 18px rgba(192,57,43,0.7); } }
.timer-label { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 4px; }
.timer-value { font-family: 'Cinzel', serif; font-size: 1.1rem; color: var(--gold-light); letter-spacing: 0.06em; }
.timer-divider { font-family: 'Cinzel', serif; font-size: 0.7rem; color: var(--text-dim); }

/* Controls */
.controls { display: flex; flex-direction: column; gap: 7px; }
.ctrl-btn {
  background: var(--bg-card2);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 9px 14px;
  color: var(--text-soft);
  font-family: 'Crimson Text', serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}
.ctrl-btn:hover { border-color: var(--gold-dim); color: var(--text); transform: translateX(2px); }
.ctrl-btn.primary {
  background: linear-gradient(135deg, rgba(201,168,76,0.2), rgba(201,168,76,0.08));
  border-color: var(--gold-dim);
  color: var(--gold-light);
  font-weight: 600;
  text-align: center;
}
.ctrl-btn.primary:hover { background: linear-gradient(135deg, rgba(201,168,76,0.35), rgba(201,168,76,0.15)); transform: none; }
.ctrl-btn.wide { width: 100%; margin-top: 10px; }

/* ── Board Section ── */
.board-section { display: flex; flex-direction: column; align-items: center; gap: 8px; flex-shrink: 0; }

.status-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 30px;
  min-width: 220px;
  justify-content: center;
}
.status-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
  flex-shrink: 0;
}
.status-indicator.white { background: #f0d9b5; box-shadow: 0 0 8px rgba(240,217,181,0.8); }
.status-indicator.black { background: #3a3028; box-shadow: 0 0 8px rgba(58,48,40,0.8); border: 1px solid #6a5a4a; }
.status-indicator.check  { background: #e74c3c; box-shadow: 0 0 12px rgba(231,76,60,0.8); animation: pulse-check 0.7s infinite; }
@keyframes pulse-check { 0%,100%{ transform: scale(1); } 50%{ transform: scale(1.3); } }
.status-text { font-family: 'Cinzel', serif; font-size: 0.88rem; color: var(--text); letter-spacing: 0.06em; }

.board-container { display: flex; align-items: center; gap: 4px; }

.coords { display: flex; gap: 0; }
.coords-left, .coords-right {
  flex-direction: column;
  justify-content: space-around;
  height: calc(var(--sq-size) * 8);
}
.coords-bottom {
  width: calc(var(--sq-size) * 8);
  justify-content: space-around;
  margin-left: 28px;
}
.coords span {
  font-family: 'Cinzel', serif;
  font-size: 0.68rem;
  color: var(--text-dim);
  width: 20px;
  text-align: center;
  line-height: var(--sq-size);
  height: var(--sq-size);
  display: flex;
  align-items: center;
  justify-content: center;
}
.coords-bottom span {
  width: var(--sq-size);
  height: 20px;
  line-height: normal;
}

/* ── Chess Board ── */
.board-wrap {
  padding: 10px;
  background: linear-gradient(145deg, #3d2b1a, #2a1e0f, #3d2b1a);
  border-radius: 10px;
  box-shadow:
    0 0 0 2px #6b4f32,
    0 0 0 4px #3d2b1a,
    0 0 0 6px #8a6940,
    0 4px 40px rgba(0,0,0,0.8),
    inset 0 1px 3px rgba(255,255,255,0.1);
  position: relative;
}
/* Subtle wood grain overlay */
.board-wrap::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 10px;
  background: repeating-linear-gradient(
    87deg,
    transparent, transparent 6px,
    rgba(255,255,255,0.012) 6px, rgba(255,255,255,0.012) 7px
  );
  pointer-events: none;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq-size));
  grid-template-rows: repeat(8, var(--sq-size));
  border: 1px solid rgba(0,0,0,0.5);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

/* ── Squares ── */
.square {
  width: var(--sq-size);
  height: var(--sq-size);
  position: relative;
  cursor: default;
  transition: filter 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  /* 3D lighting effect per square */
  background-image: linear-gradient(
    160deg,
    rgba(255,255,255,0.06) 0%,
    transparent 40%,
    rgba(0,0,0,0.06) 100%
  );
}
.square.light { background-color: var(--white-sq); }
.square.dark  { background-color: var(--black-sq); }

/* Hover / interaction states */
.square.clickable { cursor: pointer; }
.square.clickable:hover { filter: brightness(1.12); }

/* Selected */
.square.selected::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(100, 180, 80, 0.35);
  border: 3px solid rgba(80,180,50,0.8);
  pointer-events: none;
}

/* Last move highlight */
.square.last-move::after {
  content: '';
  position: absolute; inset: 0;
  background: rgba(255, 215, 0, 0.22);
  pointer-events: none;
}
.square.selected.last-move::after {
  background: rgba(100, 200, 80, 0.35);
  border: 3px solid rgba(80,180,50,0.8);
}

/* Legal move dot */
.square.legal-move::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0,0,0,0.25);
  z-index: 2;
  pointer-events: none;
  animation: dot-appear 0.15s ease-out;
}
@keyframes dot-appear { from { transform: translate(-50%,-50%) scale(0); } to { transform: translate(-50%,-50%) scale(1); } }

/* Capture ring */
.square.legal-capture::before {
  content: '';
  position: absolute; inset: 4px;
  border-radius: 50%;
  border: 5px solid rgba(0,0,0,0.22);
  z-index: 2;
  pointer-events: none;
  background: transparent;
  animation: ring-appear 0.15s ease-out;
}
@keyframes ring-appear { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Check highlight */
.square.in-check {
  background-image: radial-gradient(circle at center, rgba(231,76,60,0.65) 0%, transparent 75%) !important;
}

/* ── Chess Pieces ── */
.piece {
  width: 90%;
  height: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--sq-size) * 0.72);
  line-height: 1;
  cursor: grab;
  user-select: none;
  position: relative;
  z-index: 3;
  transition: transform 0.12s ease, filter 0.12s ease;
  /* 3D text shadow to simulate lighting */
}
.piece.white-piece {
  filter:
    drop-shadow(0 2px 4px rgba(0,0,0,0.5))
    drop-shadow(0 1px 1px rgba(0,0,0,0.8));
  text-shadow: none;
  /* bright lighting from top-left */
}
.piece.black-piece {
  filter:
    drop-shadow(0 2px 5px rgba(0,0,0,0.7))
    drop-shadow(0 1px 2px rgba(0,0,0,0.9));
}
.piece:hover { transform: scale(1.08) translateY(-2px); }
.piece.selected-piece { transform: scale(1.12) translateY(-4px); filter: drop-shadow(0 6px 12px rgba(0,0,0,0.6)) brightness(1.1); }
.piece.moving {
  animation: piece-move 0.22s cubic-bezier(0.22,1,0.36,1);
  z-index: 10;
}
@keyframes piece-move {
  from { transform: scale(1.15) translateY(-6px); filter: drop-shadow(0 10px 18px rgba(0,0,0,0.7)); }
  to   { transform: scale(1) translateY(0); }
}

/* ── Captured Pieces ── */
.captured-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  padding: 0 6px;
}
.captured-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}
.captured-label { font-size: 0.75rem; color: var(--text-dim); font-style: italic; white-space: nowrap; }
.captured-pieces { font-size: 1.1rem; letter-spacing: 2px; flex: 1; }

/* ── Move History ── */
.history-card { flex: 1; }
.history-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 2px; }
.history-empty { color: var(--text-dim); font-style: italic; font-size: 0.85rem; text-align: center; padding: 20px 0; }

.history-move-pair {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 4px;
  align-items: center;
  padding: 3px 4px;
  border-radius: 4px;
  transition: background 0.15s;
}
.history-move-pair:hover { background: var(--bg-card2); }
.history-num { font-size: 0.7rem; color: var(--text-dim); font-family: 'Cinzel', serif; }
.history-move {
  font-size: 0.82rem;
  color: var(--text-soft);
  padding: 2px 5px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Crimson Text', serif;
}
.history-move:hover { background: rgba(201,168,76,0.12); color: var(--gold); }
.history-move.current { background: rgba(201,168,76,0.18); color: var(--gold-light); }

/* ── Info Panel ── */
.info-rows { display: flex; flex-direction: column; gap: 8px; }
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-soft);
}
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 0.78rem; color: var(--text-dim); }
.info-val { font-family: 'Cinzel', serif; font-size: 0.82rem; color: var(--gold); }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8), var(--shadow-gold);
  animation: slide-up 0.25s cubic-bezier(0.22,1,0.36,1);
  min-width: 300px;
}
@keyframes slide-up { from { transform: translateY(20px) scale(0.95); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-title {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  color: var(--gold-light);
  margin-bottom: 6px;
}
.modal-sub { font-size: 1rem; color: var(--text-dim); font-style: italic; margin-bottom: 20px; }

.promo-choices {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.promo-piece {
  font-size: 3rem;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid var(--border-soft);
  background: var(--bg-card2);
  transition: all 0.18s;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
}
.promo-piece:hover {
  border-color: var(--gold);
  transform: scale(1.15) translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
}

.gameover-box { min-width: 340px; }
.gameover-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px rgba(201,168,76,0.6));
  animation: trophy-bounce 0.6s 0.2s cubic-bezier(0.22,1,0.36,1) both;
}
@keyframes trophy-bounce { from { transform: scale(0) rotate(-10deg); } to { transform: scale(1) rotate(0); } }

/* ── AI Thinking Spinner ── */
.thinking-dot {
  display: inline-block;
  animation: thinking 1.2s infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinking { 0%,100%{ opacity: 0.2; } 50%{ opacity: 1; } }

/* ── Responsive ── */
@media (max-width: 1100px) {
  :root { --sq-size: 60px; }
  .panel-left, .panel-right { width: 180px; }
}

@media (max-width: 900px) {
  :root { --sq-size: 52px; }
  .main-layout { flex-direction: column; align-items: center; }
  .panel-left, .panel-right { width: 100%; max-width: 600px; }
  .panel { flex-direction: row; flex-wrap: wrap; }
  .card { flex: 1; min-width: 150px; }
  .history-list { max-height: 180px; }
}

@media (max-width: 600px) {
  :root { --sq-size: 42px; }
  .title { font-size: 1.8rem; }
  .piece { font-size: calc(var(--sq-size) * 0.72); }
}