/* ==========================================================================
   PATHASHALA — Custom Loaders & Animations
   Three themed loaders:
     1. .ps-loader-pencil   — a pencil underlines/writes a line (page load)
     2. .ps-loader-flip     — a book page turning (navigating between chapters)
     3. .ps-loader-chalk    — three "chalk dot" pulses (AI tutor is thinking)
   ========================================================================== */

/* ---------------------------------------------------------------------- */
/* 1. Pencil-write loader — for initial page / content loads               */
/* ---------------------------------------------------------------------- */

.ps-loader-pencil {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-6) 0;
}

.ps-loader-pencil svg { width: 64px; height: 64px; }

.ps-loader-pencil .pencil-line {
  stroke: var(--border-strong);
  stroke-width: 3;
  fill: none;
}

.ps-loader-pencil .pencil-line-fill {
  stroke: var(--primary);
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
  stroke-dasharray: 120;
  stroke-dashoffset: 120;
  animation: pencilDraw 1.4s var(--ease-out) infinite;
}

.ps-loader-pencil .pencil-tip {
  transform-origin: 0 0;
  animation: pencilMove 1.4s var(--ease-out) infinite;
}

@keyframes pencilDraw {
  0%   { stroke-dashoffset: 120; }
  60%  { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 0; }
}
@keyframes pencilMove {
  0%   { transform: translateX(0); }
  60%  { transform: translateX(58px); }
  100% { transform: translateX(58px); opacity: 0; }
}

.ps-loader-pencil .label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
}

/* ---------------------------------------------------------------------- */
/* 2. Page-flip loader — for navigating between chapters/lessons           */
/* ---------------------------------------------------------------------- */

.ps-loader-flip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-6) 0;
}

.ps-loader-flip .book {
  position: relative;
  width: 56px;
  height: 40px;
}
.ps-loader-flip .book::before,
.ps-loader-flip .book::after {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 40px;
  background: var(--bg-surface-muted);
  border: 1.5px solid var(--border-strong);
}
.ps-loader-flip .book::before {
  left: 0;
  border-radius: 3px 0 0 3px;
}
.ps-loader-flip .book::after {
  right: 0;
  border-radius: 0 3px 3px 0;
}
.ps-loader-flip .page {
  position: absolute;
  top: 0; right: 28px;
  width: 26px; height: 40px;
  background: var(--bg-surface);
  border: 1.5px solid var(--subj-english);
  border-radius: 0 3px 3px 0;
  transform-origin: left center;
  animation: pageTurn 1.1s var(--ease-out) infinite;
}
@keyframes pageTurn {
  0%   { transform: rotateY(0deg); }
  50%  { transform: rotateY(-160deg); }
  100% { transform: rotateY(-180deg); opacity: 0; }
}

.ps-loader-flip .label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
}

/* ---------------------------------------------------------------------- */
/* 3. Chalk-dot loader — for "AI tutor is thinking" in the chat panel      */
/* ---------------------------------------------------------------------- */

.ps-loader-chalk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-surface-muted);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 2px;
  width: fit-content;
}
.ps-loader-chalk .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--teal);
  animation: chalkPulse 1.2s ease-in-out infinite;
}
.ps-loader-chalk .dot:nth-child(2) { animation-delay: 0.15s; }
.ps-loader-chalk .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chalkPulse {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------------------------------------------------------------------- */
/* Shared micro-interactions                                              */
/* ---------------------------------------------------------------------- */

/* Fade-and-rise entrance for cards streaming into a list */
.ps-enter {
  animation: psEnter var(--dur-slow) var(--ease-out) both;
}
@keyframes psEnter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Respect reduced-motion preferences everywhere */
@media (prefers-reduced-motion: reduce) {
  .ps-loader-pencil .pencil-line-fill,
  .ps-loader-pencil .pencil-tip,
  .ps-loader-flip .page,
  .ps-loader-chalk .dot,
  .ps-ruler-fill,
  .ps-enter {
    animation: none !important;
  }
}
