:root {
  --learn-paper: #f6f3ee;
  --learn-surface: #ffffff;
  --learn-surface-elev: #fdfbf7;
  --learn-ink: #1f1b16;
  --learn-muted: #6b6357;
  --learn-faint: #9c9385;
  --learn-line: #dfd7cb;
  --learn-line-soft: #ece5da;
  --learn-accent: #9b582f;
  --learn-accent-dark: #6e371a;
  --learn-accent-soft: rgba(155, 88, 47, 0.10);
  --learn-success: #1f8a56;
  --learn-error: #c23c30;
  --learn-focus: #205fa5;
  --learn-shadow: 0 20px 60px rgba(50, 38, 26, 0.12);
  --learn-shadow-lg: 0 28px 80px rgba(50, 38, 26, 0.18);
  --board-max-desktop: 760px;
}

* { box-sizing: border-box; }

body.learning-page {
  min-width: 320px;
  margin: 0;
  color: var(--learn-ink);
  background:
    radial-gradient(circle at 10% -5%, rgba(155, 88, 47, 0.12), transparent 36rem),
    radial-gradient(circle at 90% 105%, rgba(32, 95, 165, 0.06), transparent 32rem),
    var(--learn-paper);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, input { font: inherit; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--learn-focus); outline-offset: 3px; }

.sr-only {
  position: absolute!important; width: 1px!important; height: 1px!important;
  padding: 0!important; margin: -1px!important; overflow: hidden!important;
  clip: rect(0,0,0,0)!important; white-space: nowrap!important; border: 0!important;
}

.skip-link {
  position: fixed; z-index: 20; top: 8px; left: 8px;
  min-height: 44px; display: inline-flex; align-items: center;
  padding: 10px 16px; color: #fff; background: var(--learn-focus);
  border-radius: 8px; transform: translateY(-150%);
  transition: transform 0.2s ease;
}
.skip-link:focus { transform: none; }

/* Sticky Header */
.learning-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px max(24px, calc((100vw - 1440px) / 2));
  border-bottom: 1px solid var(--learn-line);
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.learning-brand {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--learn-ink);
  font-weight: 800;
  font-size: 16px;
  text-decoration: none;
  letter-spacing: -.02em;
}
.learning-brand img { border-radius: 50%; }

.learning-exit {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--learn-line);
  background: var(--learn-surface);
  color: var(--learn-muted);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.16s ease;
}
.learning-exit:hover {
  color: var(--learn-ink);
  border-color: var(--learn-accent);
  background: var(--learn-accent-soft);
  transform: translateY(-1px);
}

/* Main Container */
.lesson-main {
  width: min(calc(100% - 48px), 1440px);
  margin: 0 auto;
  padding: 24px 0 48px;
}

/* Skeleton & Error States */
.lesson-state {
  min-height: 480px;
  display: grid;
  align-content: center;
  gap: 16px;
  padding: clamp(28px, 6vw, 70px);
  border: 1px solid var(--learn-line);
  border-radius: 24px;
  background: var(--learn-surface);
  box-shadow: var(--learn-shadow);
}
.lesson-skeleton {
  width: 60%;
  height: 26px;
  border-radius: 10px;
  background: linear-gradient(90deg, #e8e0d5 20%, #f8f4ed 50%, #e8e0d5 80%);
  background-size: 220% 100%;
  animation: lesson-shimmer 1.5s infinite;
}
.lesson-skeleton.is-wide { width: 85%; height: 64px; }
@keyframes lesson-shimmer { to { background-position-x: -220%; } }

.lesson-error h1 { margin: 0; font: 700 clamp(32px, 4.5vw, 52px)/1.05 'Fraunces', Georgia, serif; }
.lesson-error p:not(.lesson-kicker) { max-width: 620px; color: var(--learn-muted); line-height: 1.65; }

/* Lesson Header & Progress */
.lesson-topline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 16px;
}
.lesson-kicker {
  margin: 0 0 6px;
  color: var(--learn-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.lesson-topline h1 {
  margin: 0;
  font: 700 clamp(28px, 3.8vw, 46px)/1.08 'Fraunces', Georgia, serif;
  letter-spacing: -.03em;
  color: var(--learn-ink);
}
.lesson-outcome {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--learn-muted);
  font-size: 14.5px;
  line-height: 1.55;
}
.lesson-progress-copy { min-width: 120px; text-align: right; }
.lesson-progress-copy strong { font-size: 18px; font-weight: 800; color: var(--learn-ink); }
.lesson-progress-copy span { margin-top: 3px; color: var(--learn-muted); font-size: 12px; }

.lesson-progress {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--learn-line-soft);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.06);
}
.lesson-progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--learn-accent), #ca8252);
  transition: width .28s cubic-bezier(0.22, 1, 0.36, 1);
}

.stage-nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 12px 0 24px;
}
.stage-pill {
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 6px 10px;
  border: 1px solid var(--learn-line);
  border-radius: 10px;
  color: var(--learn-muted);
  background: rgba(255, 253, 248, 0.7);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .02em;
  transition: all 0.16s ease;
}
.stage-pill.is-active {
  border-color: var(--learn-accent);
  color: var(--learn-accent-dark);
  background: var(--learn-accent-soft);
  box-shadow: 0 4px 12px rgba(155, 88, 47, 0.12);
}
.stage-pill.is-done {
  color: var(--learn-success);
  border-color: rgba(31, 138, 86, 0.35);
  background: rgba(31, 138, 86, 0.05);
}

/* ==========================================================================
   2-COLUMN VIEWPORT-FITTED CHESS.COM SCALE GRID
   ========================================================================== */
.lesson-grid {
  display: grid;
  grid-template-columns: minmax(440px, auto) minmax(360px, 1fr);
  gap: 32px;
  align-items: start;
}

/* Left Column — The Grand Board Stage */
.lesson-visual {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--learn-surface);
  border: 1px solid var(--learn-line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--learn-shadow);
  position: sticky;
  top: 84px;
}

.lesson-board-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Responsive Board Frame sizing (Calculated to fill screen without scroll) */
.lesson-board-frame {
  width: min(calc(100vh - 220px), calc(100vw - 480px), var(--board-max-desktop));
  height: min(calc(100vh - 220px), calc(100vw - 480px), var(--board-max-desktop));
  min-width: 320px;
  min-height: 320px;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(35, 26, 16, 0.28);
  border: 1px solid rgba(0, 0, 0, 0.2);
  display: flex;
}

/* Board inside */
.learning-page .puzzle-board:not(.poodle-board-host),
.learning-page #lessonBoard:not(.poodle-board-host) {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
}

/* Right Column — Lesson Card with independent scroll */
.lesson-card {
  min-width: 0;
  border: 1px solid var(--learn-line);
  border-radius: 20px;
  background: var(--learn-surface);
  box-shadow: var(--learn-shadow);
  padding: clamp(24px, 3vw, 36px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.lesson-card h2 {
  margin: 0;
  font: 700 clamp(22px, 2.5vw, 32px)/1.15 'Fraunces', Georgia, serif;
  letter-spacing: -.02em;
  color: var(--learn-ink);
}

.lesson-copy {
  color: var(--learn-muted);
  font-size: 15px;
  line-height: 1.68;
}
.lesson-copy p { margin: 0 0 12px; }
.lesson-copy p:last-child { margin-bottom: 0; }

/* Interactive Choices */
.choice-list {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}
.choice-option { position: relative; }
.choice-option input { position: absolute; opacity: 0; }
.choice-option label {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border: 1.5px solid var(--learn-line);
  border-radius: 14px;
  background: var(--learn-surface-elev);
  cursor: pointer;
  line-height: 1.4;
  font-weight: 600;
  font-size: 14px;
  color: var(--learn-ink);
  transition: all 0.16s ease;
}
.choice-option label::before {
  content: "";
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid #a89c8f;
  border-radius: 50%;
  transition: all 0.16s ease;
}
.choice-option label:hover {
  border-color: var(--learn-accent);
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(155, 88, 47, 0.08);
}
.choice-option input:checked + label {
  border-color: var(--learn-accent);
  background: var(--learn-accent-soft);
  color: var(--learn-accent-dark);
}
.choice-option input:checked + label::before {
  border: 5px solid var(--learn-accent);
  background: #fff;
}
.choice-option input:focus-visible + label {
  outline: 3px solid var(--learn-focus);
  outline-offset: 2px;
}

/* Prompts and Feedback */
.move-prompt {
  margin-top: 6px;
  padding: 14px 18px;
  border-radius: 12px;
  border-left: 4px solid var(--learn-accent);
  background: var(--learn-accent-soft);
  color: var(--learn-accent-dark);
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.55;
}
.move-prompt p { margin: 0; }

.lesson-feedback {
  margin-top: 8px;
  padding: 18px 20px;
  border: 1.5px solid rgba(31, 138, 86, 0.4);
  border-radius: 14px;
  background: rgba(31, 138, 86, 0.08);
  animation: feedbackIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes feedbackIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.lesson-feedback.is-error {
  border-color: rgba(194, 60, 48, 0.4);
  background: rgba(194, 60, 48, 0.08);
}
.lesson-feedback strong {
  display: block;
  font-size: 14.5px;
  font-weight: 800;
  color: var(--learn-success);
}
.lesson-feedback.is-error strong { color: var(--learn-error); }
.lesson-feedback p {
  margin: 6px 0 0;
  color: var(--learn-muted);
  font-size: 13.5px;
  line-height: 1.55;
}

/* Action Buttons */
.lesson-actions {
  min-height: 52px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--learn-line-soft);
}
.lesson-button {
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 800;
  font-size: 13.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.16s ease;
}
.lesson-button.is-primary {
  margin-left: auto;
  color: #fff;
  border-color: var(--learn-accent-dark);
  background: var(--learn-accent-dark);
  box-shadow: 0 4px 14px rgba(110, 55, 26, 0.25);
}
.lesson-button.is-primary:hover {
  background: #5a2c14;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(110, 55, 26, 0.35);
}
.lesson-button.is-secondary {
  color: var(--learn-ink);
  border-color: var(--learn-line);
  background: var(--learn-surface);
}
.lesson-button.is-secondary:hover {
  border-color: var(--learn-muted);
  background: var(--learn-surface-elev);
}
.lesson-button.is-quiet {
  color: var(--learn-accent-dark);
  border-color: rgba(155, 88, 47, 0.28);
  background: var(--learn-accent-soft);
}
.lesson-button.is-quiet:hover {
  background: rgba(155, 88, 47, 0.18);
}
.lesson-button:disabled { opacity: .45; cursor: not-allowed; transform: none !important; }

/* Concept Panel (theory without board) */
.concept-panel {
  max-width: 480px;
  text-align: center;
  color: var(--learn-muted);
  line-height: 1.6;
  padding: 48px 24px;
}
.concept-mark {
  display: block;
  color: var(--learn-accent);
  font-size: 96px;
  line-height: 1;
  margin-bottom: 16px;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */
@media (max-width: 1040px) {
  .lesson-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .lesson-visual {
    position: static;
  }
  .lesson-board-frame {
    width: min(calc(100vw - 64px), 580px);
    height: min(calc(100vw - 64px), 580px);
  }
  .lesson-card {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .learning-header { padding-inline: 14px; min-height: 56px; }
  .lesson-main { width: min(calc(100% - 20px), 1440px); padding-top: 16px; }
  .stage-nav { gap: 4px; margin-bottom: 16px; }
  .stage-pill { min-height: 44px; padding-inline: 4px; font-size: 9.5px; }
  .lesson-card, .lesson-visual { border-radius: 16px; padding: 16px; }
  .lesson-board-frame {
    width: calc(100vw - 40px);
    height: calc(100vw - 40px);
    min-width: 0;
    min-height: 0;
  }
  .lesson-button { flex: 1 1 auto; }
  .lesson-button.is-primary { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
