/* App layout, sidebar, and welcome screen styles.
/* ===== APP LAYOUT: SIDEBAR + MAIN AREA ===== */
.app-layout {
  display: flex;
  width: 100%;
  block-size: 100%;
  overflow: hidden;
  position: relative;
}

.main-content:has(.app-layout) {
  overflow: hidden;
  height: 100vh;
  padding-block-start: var(--header-block-size);
}

/* ===== COLLAPSIBLE SIDEBAR ===== */
.lessons-sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--color-accent-gradient-vertical);
  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: var(--header-block-size);
  background: var(--color-accent-gradient-vertical);
  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,
    var(--color-accent-light) 0%,
    var(--color-accent-dark-hover) 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;
}

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

/* ===== WELCOME / EMPTY STATE ===== */
.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: var(--color-text-dark);
  margin-bottom: 1rem;
}

.lesson-welcome .lead {
  color: var(--color-text-muted-alt);
  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 var(--color-accent);
}

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

/* ===== SCORE / POINTS INDICATOR ===== */
.score-pulse {
  animation: pulse 0.5s ease-in-out;
}

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

@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);
  }
}

.score-container {
  position: relative;
  font-size: 0.8em;
  margin-right: -0.4rem;
}

#elo-change-indicator,
#points-gained-indicator {
  color: var(--color-success);
  font-weight: bold;
  font-size: 0.84em;
  animation: fadeInOut 1.5s ease-in-out;
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
}

#elo-change-indicator .rating-negative,
#points-gained-indicator .rating-negative {
  color: var(--color-danger);
}

#ts-rating-change-indicator {
  color: var(--color-success);
  font-weight: bold;
  font-size: 0.53em;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
}

#ts-rating-change-indicator .rating-negative {
  color: var(--color-danger);
}

/* ===== RESPONSIVE: LAYOUT / SIDEBAR ===== */
@media (max-width: 991px) {
  /* 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;
    block-size: 100%;
    inline-size: 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 {
    height: 100%;
  }

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

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

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

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

@media (max-width: 575px) {
  .lessons-sidebar {
    width: 260px;
  }

  .sidebar-header {
    padding: 0.75rem;
  }

  .sidebar-title {
    font-size: 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) {
  .lessons-sidebar {
    width: 240px;
  }
}

/* Training session sidebar button — status icon */
.ts-status-icon {
  margin-left: auto;
  font-size: 0.85rem;
  line-height: 1;
}

/* Training session sidebar button — active state */
.training-session-btn.training-session-active .lesson-content {
  background: rgba(40, 167, 69, 0.55);
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px rgba(40, 167, 69, 0.8);
}

/* Training session sidebar button — paused state */
.training-session-btn.training-session-paused .lesson-content {
  background: rgba(255, 193, 7, 0.35);
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px rgba(255, 193, 7, 0.7);
}

.training-session-btn.training-session-paused .ts-status-icon {
  animation: pulse-icon 1.5s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* Training session bar (lesson header) */
.training-session-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.9);
  margin-left: auto;
  margin-right: 0.5rem;
}
.training-session-bar .ts-stat {
  position: relative;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.training-session-bar .ts-divider {
  opacity: 0.4;
}
.training-session-bar .ts-giveup-btn {
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
  line-height: 1.2;
  color: #fff;
  background: rgba(220, 53, 69, 0.7);
  border: none;
  border-radius: 3px;
}
.training-session-bar .ts-giveup-btn:hover {
  background: rgba(220, 53, 69, 1);
}
.training-session-bar .ts-end-btn {
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
  line-height: 1.2;
  color: #fff;
  background: var(--color-success, #28a745);
  border: none;
  border-radius: 3px;
}
.training-session-bar .ts-end-btn:hover {
  background: #218838;
}

/* ===== TRAINING SESSION SUMMARY ===== */
.training-session-summary {
  padding: 1rem;
}

.session-summary-title {
  text-align: center;
  margin-bottom: 1rem;
}

.session-stats {
  margin-bottom: 1.25rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e9ecef;
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-row .stat-label {
  color: #6c757d;
  font-size: 0.95rem;
}

.stat-row .stat-value {
  font-weight: 700;
  font-size: 1.1rem;
  color: #212529;
  margin-left: 2rem;
}

.session-summary-actions {
  text-align: center;
  margin-top: 1rem;
}

/* On narrow screens when the training bar is visible, hide the title and
   attribution so the session controls + close button fit in one row. */
@media (max-width: 600px) {
  .lesson-header-bar:has(.training-session-bar[style*="flex"])
    .lesson-title-display,
  .lesson-header-bar:has(.training-session-bar[style*="flex"])
    .lichess-attribution {
    display: none !important;
  }
}
