/* App layout, sidebar, and welcome screen styles.
   /* ===== APP LAYOUT: SIDEBAR + MAIN AREA ===== */
.app-layout {
  display: flex;
  align-items: stretch;
  width: 100%;
  block-size: 100%;
  overflow: hidden;
  position: relative;
  background: var(--hp-bg);
  /* The menu's width (dashboard.css widens it on a wide screen). */
  --nav-w: 228px;
}

.main-content:has(.app-layout) {
  overflow: hidden;
  /* dvh tracks the dynamic mobile browser chrome (URL bar showing/hiding)
     so the layout stays inside the visible viewport instead of bleeding
     past it and triggering a body scroll. */
  height: 100dvh;
  padding-block-start: var(--header-block-size);
}

/* Lock the body while a lesson is being played so the lesson
   doesn't sit on top of a scrollable body — pull-to-scroll on mobile
   would otherwise drift the whole page. Only apply when the lesson
   player is visible (not hidden): `lesson-shown`, which the player sets
   (chess-lesson-player.js; no body:has(), see signed-in.css's head). The
   class twice: the weight of the body:has(.chess-lesson-content:not(.hidden))
   it replaced, which dashboard.css's narrower rules are written against. */
body.lesson-shown.lesson-shown {
  overflow: hidden;
  height: 100dvh;
  /* iOS Safari: prevent rubber-band scroll bouncing past the layout. */
  overscroll-behavior: none;
}

/* ===== COLLAPSIBLE SIDEBAR ===== */
.lessons-sidebar {
  display: flex;
  flex-direction: column;
  transition:
    margin-left 0.3s ease,
    transform 0.3s ease;
  position: relative;
  z-index: 100;
  flex-shrink: 0;
  margin-left: 0; /* Start visible by default */
  width: var(--nav-w);
  min-width: var(--nav-w);
  background: var(--hp-surface);
  border-right: 1px solid var(--hp-border);
  color: var(--hp-text);
}

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

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.55rem 0.7rem 0;
}

.sidebar-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* Hide and pin: small square buttons; pin reads as on while pinned. */
.sidebar-controls {
  display: flex;
  gap: 6px;
}

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

/* Sidebar toggle tab button */
.sidebar-toggle-tab {
  position: fixed;
  left: 0;
  top: var(--header-block-size);
  padding: 0.5rem 0.4rem;
  border: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  font-size: 1.2rem;
  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: var(--hp-selected);
  color: var(--hp-blue);
}

/* 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 {
  /* Was `overflow-y: auto` — that turned this element into a page-level
     scroller whenever the lesson player's column overflowed (long PGN
     comments on mobile). Internal scrolling lives on .chess-info-panel,
     so lock this layer and clip any overflow. */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Allow flexbox shrinking */
  min-height: 0; /* Allow flexbox shrinking inside .app-layout */
}

/* ===== WELCOME / EMPTY STATE ===== */
.lesson-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 1.25rem 1rem;
  min-height: 0;
  overflow: auto;
  color: var(--hp-text);
}

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

.lesson-welcome h2 {
  color: var(--color-text-dark);
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}

.lesson-welcome .lead {
  color: var(--color-text-muted-alt);
  margin-bottom: 2rem;
}

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

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

/* ===== RESPONSIVE: LAYOUT / SIDEBAR ===== */
@media (max-width: 767px) {
  /* Mobile: Sidebar becomes overlay */
  .lessons-sidebar {
    position: fixed;
    block-size: 100%;
    z-index: 1000;
    margin-left: 0;
    transform: translateX(0);
    transition: transform 0.3s ease;
  }

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

  /* 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%;
  }

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

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

@media (max-width: 575px) {
  .sidebar-title {
    font-size: 1rem;
  }

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

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

/* Training session sidebar button — its status (#training-status), the
   server's marks of a session that runs (training_status.html): ▶ to resume
   it, ⏸ while this page is the one playing it (`session-active` on <body>,
   training-session.js). */
.ts-status {
  margin-left: auto;
  display: inline-flex;
}

.ts-status-icon {
  font-size: 0.85rem;
  line-height: 1;
}

.training-session-btn .ts-playing,
body.session-active .training-session-btn .ts-resume {
  display: none;
}

body.session-active .training-session-btn .ts-playing {
  display: inline;
}

/* A session that runs and this page is not playing: to resume. */
body:not(.session-active) .training-session-btn:has(.ts-resume) .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 .ts-resume {
  animation: pulse-icon 1.5s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .training-session-btn .ts-resume {
    animation: none;
  }
}

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

/* A training session's bar, a sibling of <chess-lesson-player> in
   .chess-lesson-area, shown while this page plays a session
   (`session-active` on <body>, training-session.js): its name in the middle,
   Terminare at the right (an empty side of the same share at the left keeps
   the name centred). Its rating, clock and puzzle number are beside the
   board. */
.training-session-bar {
  display: none;
  align-items: center;
  white-space: nowrap;
  flex: none;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 4px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--hp-border);
  border-radius: var(--hp-radius-item);
  background: var(--hp-surface);
  color: var(--hp-text);
  font-size: 1.15rem;
}

@media (max-width: 767px) {
  /* The menu tab is above the bar here, so the bar keeps its own padding
     and one line: the name gives way first. */
  .training-session-bar {
    white-space: normal;
    flex-wrap: nowrap;
    gap: 0.6rem;
    padding: 0.4rem 0.4rem 0.4rem 0.8rem;
    font-size: 1rem;
  }
}

body.session-active .training-session-bar {
  display: flex;
}

.training-session-bar .ts-end-btn {
  color: #fff;
  border: none;
  padding: 0.45rem 1.1rem;
  border-radius: var(--hp-radius-btn);
  background: var(--hp-rating);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
}

.training-session-bar .ts-end-btn:hover {
  background: var(--hp-amber-ink);
}

/* ===== TRAINING SESSION SUMMARY ===== */

.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;
}

/* Sesiune nouă, and under it, as wide, today's training ranking in blue. */
.session-summary-actions {
  text-align: center;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

