/* ══════════════════ ENDGAME ACADEMY & TABLEBASE DRILLS STYLES ══════════════════ */

.endgame-container {
  padding: 24px 32px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.endgame-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 15px;
}

.endgame-title-area h2 {
  margin: 0 0 6px 0;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-bright, #fff);
  display: flex;
  align-items: center;
  gap: 10px;
}

.endgame-title-area p {
  margin: 0;
  color: var(--text-muted, #94a3b8);
  font-size: 0.95rem;
}

/* ── Stats Hero Row ── */
.endgame-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 30px;
}

.endgame-stat-card {
  background: rgba(30, 41, 59, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.endgame-stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(56, 189, 248, 0.3);
}

.endgame-stat-icon {
  font-size: 2rem;
  line-height: 1;
}

.endgame-stat-info .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #38bdf8;
  font-family: 'IBM Plex Mono', monospace;
}

.endgame-stat-info .stat-label {
  font-size: 0.8rem;
  color: var(--text-muted, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Section Titles ── */
.endgame-section-title {
  margin-bottom: 16px;
}

.endgame-section-title h3 {
  margin: 0 0 4px 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-bright, #f8fafc);
}

.endgame-section-sub {
  font-size: 0.85rem;
  color: var(--text-muted, #94a3b8);
}

/* ── Grid of Endgame Cards ── */
.endgame-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.endgame-card {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.endgame-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: #38bdf8;
  opacity: 0.5;
  transition: opacity 0.2s ease, width 0.2s ease;
}

.endgame-card:hover {
  transform: translateY(-3px);
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.endgame-card:hover::before {
  opacity: 1;
  width: 6px;
}

.endgame-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.endgame-card-icon {
  font-size: 1.6rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.endgame-card-info h4 {
  margin: 0 0 3px 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #f1f5f9;
}

.endgame-card-info span {
  font-size: 0.8rem;
  color: #94a3b8;
}

.endgame-card-desc {
  font-size: 0.85rem;
  color: #cbd5e1;
  line-height: 1.4;
}

.endgame-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.endgame-goal-tag {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
}

.endgame-goal-tag.win {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.endgame-goal-tag.draw {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.endgame-card-btn {
  font-size: 0.85rem;
  color: #38bdf8;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── 2. ACTIVE DRILL VIEW ── */
.endgame-drill-wrapper {
  display: flex;
  gap: 30px;
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px;
  box-sizing: border-box;
  align-items: flex-start;
  width: 100%;
}

.endgame-board-container {
  flex: 0 0 520px;
  max-width: 520px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.endgame-goal-badge {
  padding: 12px 18px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
}

.endgame-goal-badge.win-mode {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(16, 185, 129, 0.1));
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #4ade80;
  box-shadow: 0 0 15px rgba(34, 197, 94, 0.15);
}

.endgame-goal-badge.draw-mode {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(14, 165, 233, 0.1));
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.15);
}

.endgame-board-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#endgame-board {
  width: 100%;
  height: 100%;
}

.endgame-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: #cbd5e1;
  padding: 4px 6px;
}

.endgame-dtm-badge {
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 8px;
  border-radius: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: #38bdf8;
}

/* ── Panel Container ── */
.endgame-panel-container {
  flex: 1;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.endgame-feedback-card {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px 20px;
  transition: all 0.2s ease;
}

.endgame-feedback-card.correct {
  border-color: rgba(34, 197, 94, 0.5);
  background: rgba(20, 83, 45, 0.3);
}

.endgame-feedback-card.blunder {
  border-color: rgba(239, 68, 68, 0.6);
  background: rgba(127, 29, 29, 0.3);
}

.feedback-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: #f8fafc;
}

.feedback-body {
  font-size: 0.9rem;
  color: #cbd5e1;
  line-height: 1.4;
}

/* ── Theory Drawer ── */
.endgame-theory-card {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
}

.theory-card-header {
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #cbd5e1;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
}

.theory-card-header:hover {
  background: rgba(255, 255, 255, 0.06);
}

.theory-card-body {
  padding: 14px 16px;
  font-size: 0.88rem;
  color: #94a3b8;
  line-height: 1.5;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.theory-card-body p {
  margin: 0;
}

/* ── Moves List ── */
.endgame-moves-card {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 14px 16px;
  max-height: 160px;
  display: flex;
  flex-direction: column;
}

.moves-header {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 8px;
}

.moves-list-scroll {
  overflow-y: auto;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  color: #f1f5f9;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.endgame-move-item {
  padding: 3px 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

/* ── Controls Row ── */
.endgame-controls-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.endgame-controls-row .btn {
  flex: 1;
  min-width: 110px;
}

/* ── Stockfish Panel ── */
.endgame-sf-panel {
  background: rgba(15, 23, 42, 0.9);
  border: 1px dashed rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  padding: 12px 16px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
}

.sf-eval-text {
  color: #38bdf8;
  font-weight: 600;
  margin-bottom: 4px;
}

.sf-best-line {
  color: #94a3b8;
  word-break: break-all;
}

/* ── Custom Material Modal ── */
.endgame-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  box-sizing: border-box;
}

.endgame-modal-box {
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.endgame-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.endgame-modal-header h3 {
  margin: 0;
  font-size: 1.3rem;
  color: #fff;
}

.endgame-modal-close {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: #94a3b8;
  cursor: pointer;
}

.custom-modal-desc {
  font-size: 0.9rem;
  color: #94a3b8;
  margin-top: 0;
  margin-bottom: 18px;
}

.custom-material-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.custom-color-box {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.custom-color-box h4 {
  margin: 0 0 12px 0;
  font-size: 0.95rem;
}

.custom-piece-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.88rem;
  color: #cbd5e1;
}

.custom-piece-row input {
  width: 50px;
  padding: 4px 6px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: #fff;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
}

.custom-total-count {
  margin-top: 16px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}

.custom-total-count.invalid {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.endgame-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

/* ── Mobile Responsive Overrides ── */
@media (max-width: 900px) {
  .endgame-drill-wrapper {
    flex-direction: column;
    align-items: center;
  }
  
  .endgame-board-container {
    max-width: 100%;
    flex: none;
  }
  
  .endgame-panel-container {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .endgame-container {
    padding: 16px;
  }
  
  .endgame-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .custom-material-columns {
    grid-template-columns: 1fr;
  }
}
