/* Chess-specific styles for chess board and game interface using chessboard.js */

/* ===== APP LAYOUT: SIDEBAR + MAIN AREA ===== */
.app-layout {
  display: flex;
  width: 100%;
  height: calc(100vh - 56px);
  margin-top: 56px;
  overflow: hidden;
  position: relative;
}

/* Make the parent main-content fixed only when app-layout is present */
.main-content:has(.app-layout) {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  height: 100vh;
  padding-top: 0;
}

/* ===== COLLAPSIBLE SIDEBAR ===== */
.lessons-sidebar {
  width: 320px;
  min-width: 320px;
  background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  flex-direction: column;
  transition:
    margin-left 0.3s ease,
    transform 0.3s ease;
  position: relative;
  z-index: 100;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  margin-left: 0; /* Start visible by default */
}

/* Collapsed state - slides out to the left */
.lessons-sidebar.collapsed {
  margin-left: -320px;
}

/* When pinned, sidebar stays visible and won't auto-hide */
.lessons-sidebar.pinned {
  margin-left: 0;
}

.sidebar-header {
  padding: 1rem;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.sidebar-controls {
  display: flex;
  gap: 0.5rem;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

/* Sidebar toggle tab button */
.sidebar-toggle-tab {
  position: fixed;
  left: 0;
  top: 56px;
  background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0.5rem 0.4rem;
  border: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  font-size: 1.2rem;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  line-height: 1;
  width: 30px;
  height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

/* Toggle tab visibility controlled by class */
.sidebar-toggle-tab {
  display: none;
}

.sidebar-toggle-tab.show {
  display: flex;
}

.sidebar-toggle-tab:hover {
  background: linear-gradient(180deg, #7c8ff0 0%, #8658aa 100%);
  transform: scale(1.1);
}

/* Pin button styling */
#pin-sidebar-btn {
  transition:
    transform 0.2s ease,
    background-color 0.2s ease;
}

.lessons-sidebar.pinned #pin-sidebar-btn {
  transform: rotate(45deg);
  background-color: rgba(255, 255, 255, 0.3);
}

/* Collapse button - hide when collapsed */
#collapse-sidebar-btn {
  transition: opacity 0.2s ease;
}

.lessons-sidebar.collapsed #collapse-sidebar-btn {
  display: none;
}

/* Remove hover effect from sidebar itself */

/* ===== MAIN CHESS LESSON AREA ===== */
.chess-lesson-area {
  flex: 1;
  background: #f8f9fa;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Allow flexbox shrinking */
}

.lesson-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem;
  text-align: center;
  background: white;
}

.welcome-icon {
  font-size: 5rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.lesson-welcome h2 {
  color: #2c3e50;
  margin-bottom: 1rem;
}

.lesson-welcome .lead {
  color: #7f8c8d;
  margin-bottom: 2rem;
}

.welcome-tips {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 2rem;
  max-width: 500px;
}

.tip-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(102, 126, 234, 0.05);
  border-radius: 8px;
  border-left: 4px solid #667eea;
}

.tip-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.chess-lesson-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
}

.lesson-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;
}

.lesson-title-display {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
  text-align: center;
  flex: 1;
}

#close-lesson-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.25rem 0.6rem;
  transition: all 0.2s ease;
}

#close-lesson-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.1);
}

/* ===== CHESS LAYOUT ===== */
.chess-panels-container {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #f8f9fa;
}

.chess-board-panel {
  flex: 1 1 70%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  border-right: 1px solid #dee2e6;
  background-color: #fff;
  min-width: 0;
}

.chess-info-panel {
  flex: 0 0 350px;
  height: 100%;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 280px;
}

/* ===== CHESSBOARD ===== */
.chessboard-container {
  width: 100%;
  max-width: min(750px, 75vh);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  position: relative;
  touch-action: manipulation;
}

#chessboard {
  transform-origin: center center;
  transition: transform 0.2s ease;
  width: 100% !important;
  height: 100% !important;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 10;
  /* Maintain aspect ratio */
  aspect-ratio: 1 / 1;
}

/* Square colors */
.white-1e1d7 {
  background-color: #f0d9b5 !important;
}

.black-3c85d {
  background-color: #b58863 !important;
}

/* Selected square highlight for click-to-move */
.square-55d63.selected-square {
  box-shadow: inset 0 0 0 4px rgba(255, 215, 0, 0.8) !important;
  position: relative;
}

.square-55d63.selected-square::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 215, 0, 0.3);
  pointer-events: none;
}

/* Legal move hints */
.square-55d63.legal-move {
  position: relative;
}

.square-55d63.legal-move::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 25%;
  height: 25%;
  background-color: rgba(102, 126, 234, 0.6);
  border-radius: 50%;
  pointer-events: none;
  transition: all 0.2s ease;
}

.square-55d63.legal-move:hover::after {
  width: 35%;
  height: 35%;
  background-color: rgba(102, 126, 234, 0.8);
}

/* Legal capture hints */
.square-55d63.legal-capture {
  position: relative;
}

.square-55d63.legal-capture::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 4px solid rgba(220, 53, 69, 0.7);
  border-radius: 50%;
  pointer-events: none;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.square-55d63.legal-capture:hover::after {
  border-width: 6px;
  border-color: rgba(220, 53, 69, 0.9);
}

.king-piece-icon {
  height: 2em;
  width: auto;
  vertical-align: middle;
  margin: 0 0.25em;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
  position: relative;
  z-index: 1;
}

.moves-history-container {
  margin: 10px 0;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background-color: #fff;
  max-height: 150px;
  overflow-y: auto;
}

.moves-header {
  padding: 8px 12px;
  background-color: #e9ecef;
  border-bottom: 1px solid #dee2e6;
  font-weight: 600;
  font-size: 0.9rem;
  color: #495057;
}

.moves-history-list {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #495057;
  padding: 10px 12px;
  overflow-wrap: break-word;
  word-break: break-word;
  font-family: "Courier New", monospace;
}

.move-pair {
  display: inline-block;
  margin-right: 10px;
  margin-bottom: 5px;
}

.move-number {
  font-weight: bold;
  color: #343a40;
}

.score-pulse {
  animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
}

/* Points gained indicator animation */
@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translateY(-5px);
  }
  20% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-10px);
  }
}

#points-gained-indicator {
  color: #28a745;
  font-weight: bold;
  font-size: 1.2em;
  margin-left: 8px;
  animation: fadeInOut 1s ease-in-out;
  display: inline-block;
}

.white-move,
.black-move {
  display: inline-block;
  margin: 0 2px;
}

.move-comment-container {
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background-color: #fff;
  max-height: 350px;
  overflow-y: auto;
}

.comment-header {
  padding: 8px 12px;
  background-color: #e9ecef;
  border-bottom: 1px solid #dee2e6;
  font-weight: 600;
  font-size: 0.9rem;
  color: #495057;
  position: relative;
  z-index: 1;
}

.move-comment-text {
  font-size: 0.9rem;
  line-height: 1.5;
  color: #495057;
  padding: 10px 12px;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Audio controls */
#audio-controls-container {
  position: relative;
  z-index: 1;
}

/* Comment type styles */
.move-comment-container.comment-success {
  border-color: #c3e6cb;
  background-color: #f8fff9;
}

.move-comment-container.comment-success .comment-header {
  background-color: #d4edda;
  color: #155724;
  border-bottom-color: #c3e6cb;
  font-weight: 600;
}

.move-comment-container.comment-success .comment-header::before {
  content: "✅ ";
  margin-right: 4px;
}

.move-comment-container.comment-success .move-comment-text {
  color: #155724;
}

.move-comment-container.comment-error {
  border-color: #dc3545;
  border-width: 2px;
  background-color: #fff5f5;
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.15);
}

.move-comment-container.comment-error .comment-header {
  background-color: #f8d7da;
  color: #721c24;
  border-bottom-color: #dc3545;
  font-weight: 700;
}

.move-comment-container.comment-error .comment-header::before {
  content: "⚠️ ";
  margin-right: 4px;
}

.move-comment-container.comment-error .move-comment-text {
  color: #721c24;
  font-weight: 600;
}

.move-comment-container.comment-neutral {
  border-color: #b8daff;
  background-color: #f8fbff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.move-comment-container.comment-neutral .comment-header::before {
  content: "📖 ";
  margin-right: 4px;
}

.move-comment-container.comment-neutral .move-comment-text {
  color: #495057;
}

/* ===== MOVE CONTROLS ===== */
.move-controls {
  margin-top: auto;
  padding-top: 10px;
}

@media (max-width: 991px) {
  .move-controls {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #f8f9fa;
    padding: 10px 0;
    margin-top: 0;
  }
}

#next-computer-move-btn {
  background-color: #28a745;
  border-color: #28a745;
  font-weight: 600;
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
  animation: pulse-green 2s infinite;
  white-space: normal;
  line-height: 1.2;
}

#next-computer-move-btn:hover {
  background-color: #218838;
  border-color: #1e7e34;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Continue button styling (when lesson is complete) */
#next-computer-move-btn.btn-lg {
  font-size: 1.1rem;
  padding: 1rem 1.5rem;
  animation: none; /* Remove pulse when showing continue button */
}

#next-computer-move-btn.btn-secondary {
  animation: none;
}

#back-move-btn {
  background-color: #6c757d;
  border-color: #6c757d;
  font-weight: 600;
  padding: 0.75rem 1rem;
  transition: all 0.2s ease;
}

#back-move-btn:hover {
  background-color: #5a6268;
  border-color: #545b62;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

@keyframes pulse-green {
  0% {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
  }
}

/* ===== COMPLETION CHECKBOX ===== */
.lesson-completed-checkbox {
  display: inline-block;
  margin-right: 0.5rem;
  font-size: 1.2rem;
  animation: checkboxPop 0.5s ease-out;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.lesson-completed-checkbox.pulse-animation {
  animation:
    checkboxPop 0.5s ease-out,
    gentlePulse 1.5s ease-in-out infinite 0.5s;
}

@keyframes checkboxPop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes gentlePulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.9;
  }
}

/* ===== ANIMATIONS ===== */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1199px) {
  .chessboard-container {
    max-width: min(650px, 80vh);
  }

  .chess-info-panel {
    flex: 0 0 320px;
  }
}

@media (max-width: 991px) {
  .chess-panels-container {
    flex-direction: column;
    gap: 0;
  }

  .chess-board-panel {
    flex: 1 1 auto;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #dee2e6;
    padding: 15px 15px 5px 15px;
    max-height: 60vh;
  }

  .chess-info-panel {
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-width: 0;
    padding: 10px 15px;
  }

  .chessboard-container {
    max-width: 500px;
  }

  /* Sidebar adjustments for tablets */
  .lessons-sidebar {
    width: 280px;
  }

  .sidebar-content {
    padding: 0.75rem;
  }
}

@media (max-width: 767px) {
  /* Mobile: Sidebar becomes overlay */
  .lessons-sidebar {
    position: fixed;
    top: 56px;
    height: calc(100vh - 56px);
    width: 280px;
    z-index: 1000;
    margin-left: 0;
    transform: translateX(0);
    transition: transform 0.3s ease;
  }

  .lessons-sidebar.collapsed {
    transform: translateX(-280px);
  }

  .lessons-sidebar:not(.collapsed) {
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
  }

  /* Make tab larger on mobile for easier tapping */
  .sidebar-toggle-tab {
    width: 44px;
    height: 44px;
    font-size: 1.4rem;
  }

  .app-layout {
    margin-top: 56px;
    height: calc(100vh - 56px);
  }

  .chess-lesson-area {
    width: 100%;
  }

  .chessboard-container {
    max-width: 400px;
  }

  .chess-board-panel {
    padding: 10px 10px 0 10px;
  }

  .chess-info-panel {
    padding: 5px 10px 10px 10px;
    gap: 0;
  }

  .move-controls {
    padding-top: 0;
    margin-top: 0;
  }

  #next-computer-move-btn,
  #back-move-btn {
    padding: 8px;
    font-size: 0.9rem;
  }

  /* Hide moves history, comments, and game status on mobile */
  .moves-history-container {
    display: none !important;
  }

  .lesson-welcome {
    padding: 2rem 1rem;
  }

  .welcome-icon {
    font-size: 3rem;
  }

  .tip-item {
    padding: 0.75rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 575px) {
  .chessboard-container {
    max-width: 315px;
  }

  .chess-board-panel {
    padding: 5px 8px 0 8px;
  }

  .chess-info-panel {
    padding: 5px 8px 8px 8px;
  }

  .comment-header,
  .moves-header {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .move-comment-text,
  .moves-history-list {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .comment-header,
  .moves-header {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  #next-computer-move-btn,
  #back-move-btn {
    padding: 6px;
    font-size: 0.85rem;
  }

  .completion-message {
    padding: 10px;
  }

  .completion-message h4 {
    font-size: 1rem;
    margin-bottom: 5px;
  }

  .completion-message p {
    font-size: 0.85rem;
    margin-bottom: 10px;
  }

  .lessons-sidebar {
    width: 260px;
  }

  .sidebar-header {
    padding: 0.75rem;
  }

  .sidebar-title {
    font-size: 1rem;
  }

  .lesson-header-bar {
    padding: 0.75rem 1rem;
  }

  .lesson-title-display {
    font-size: 1.1rem;
  }

  .lesson-welcome h2 {
    font-size: 1.5rem;
  }

  .tip-item {
    font-size: 0.85rem;
    padding: 0.5rem;
  }

  .tip-icon {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .chessboard-container {
    max-width: 90%;
    touch-action: manipulation;
  }

  #chessboard {
    transform-origin: top center;
  }

  .square-55d63 {
    touch-action: manipulation;
  }

  #next-computer-move-btn,
  #back-move-btn {
    min-height: 44px;
  }

  .lessons-sidebar {
    width: 240px;
  }
}

/* ===== DRAGGING FIX ===== */
/* Fix for dragged piece in body - ensure it's visible above modal while dragging */
body > .piece-417db[style*="position: absolute"]:not([style*="display: none"]) {
  z-index: 999999 !important;
  opacity: 0.8 !important;
  pointer-events: none !important;
}

/* ===== FOOTER STYLES ===== */
.app-footer,
.welcome-footer {
  background: #343a40;
  color: #f8f9fa;
  padding: 1rem 0;
  flex-shrink: 0;
}

.app-footer .footer-link,
.welcome-footer .footer-link {
  color: #f8f9fa;
  text-decoration: none;
  transition: color 0.2s ease;
}

.app-footer .footer-link:hover,
.welcome-footer .footer-link:hover {
  color: #adb5bd;
}

/* ===== PRINT STYLES ===== */
@media print {
  .lesson-header-bar {
    display: none !important;
  }

  #chessboard {
    max-width: 100%;
    page-break-inside: avoid;
  }
}
