/* =========================================================================
   LESSON FLOW: the lesson player's navigation layer (primary next action,
   progress ring, section map, completion moments, practice sheet, phone
   bottom bar). Loaded after app.css. Every rule is scoped to body.app-mode
   and uses the --app-* tokens so site-wide font / colour changes flow in.
   ========================================================================= */

body.app-mode #course-view [hidden] { display: none !important; }
body.app-mode .lesson-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------- toolbar additions ---------------------------------------------- */
body.app-mode .app-lesson-toolbar { position: sticky; }
body.app-mode .lesson-read-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; }
body.app-mode .lesson-read-progress span { display: block; height: 100%; background: var(--app-primary); transform-origin: left center; transform: scaleX(0); transition: transform .15s linear; }

body.app-mode .lesson-primary-btn { white-space: nowrap; max-width: 260px; gap: 8px; }
body.app-mode .lesson-primary-btn.is-soft { background: var(--app-surface); color: var(--app-primary); border: 1px solid var(--app-border); box-shadow: none; }
body.app-mode .lesson-primary-btn.is-soft:hover:not(:disabled) { border-color: var(--app-primary); color: var(--app-primary); box-shadow: none; }
body.app-mode .lesson-primary-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

body.app-mode .lesson-kbd-hint { display: none; align-items: center; gap: 4px; font: 500 11.5px var(--app-sans); color: var(--app-faint); white-space: nowrap; margin-right: 4px; }
body.app-mode .lesson-kbd-hint kbd { font: 600 10.5px var(--app-mono); color: var(--app-muted); background: var(--app-surface); border: 1px solid var(--app-border); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; }
@media (min-width: 1280px) and (hover: hover) and (pointer: fine) {
  body.app-mode .lesson-kbd-hint { display: inline-flex; }
}

/* ------- progress ring ---------------------------------------------------- */
body.app-mode .lesson-ring { position: relative; display: inline-grid; place-items: center; width: 22px; height: 22px; flex: none; }
body.app-mode .lesson-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); display: block; }
body.app-mode .lesson-ring circle { fill: none; stroke-width: 4; }
body.app-mode .lesson-ring-track { stroke: var(--app-track); }
body.app-mode .lesson-ring-fill { stroke: var(--app-green); stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset .6s ease; }
body.app-mode .lesson-ring--sm { width: 30px; height: 30px; }
body.app-mode .lesson-ring--lg { width: 68px; height: 68px; }
body.app-mode .lesson-ring--lg circle { stroke-width: 3; }
body.app-mode .lesson-ring--lg > i { position: absolute; inset: 0; display: grid; place-items: center; color: var(--app-green); font-size: 22px; }

/* ------- sidebar: week progress, focus, in-lesson section map ------------ */
body.app-mode .sidebar-title { border-bottom: 0; padding-bottom: 6px; margin-bottom: 0; }
body.app-mode .sidebar-week-progress { display: flex; align-items: center; gap: 10px; padding: 0 6px 14px; margin-bottom: 10px; border-bottom: 1px solid var(--app-border); font: 600 12px var(--app-sans); color: var(--app-muted); }
body.app-mode .sidebar-week-progress-track { flex: 1; height: 4px; background: var(--app-track); border-radius: var(--app-pill); overflow: hidden; }
body.app-mode .sidebar-week-progress-track span { display: block; height: 100%; background: var(--app-green); border-radius: inherit; transition: width .4s ease; }
body.app-mode .lesson-item, body.app-mode .module-header { cursor: pointer; }
body.app-mode .lesson-item:focus-visible, body.app-mode .module-header:focus-visible { outline: 3px solid color-mix(in srgb, var(--app-primary) 45%, transparent); outline-offset: -3px; }
body.app-mode .lesson-item .lesson-check { transition: color .3s ease, transform .3s ease; }
body.app-mode .lesson-item.completed .lesson-check { transform: scale(1.05); }

body.app-mode .lesson-toc { list-style: none; margin: 4px 0 10px 16px; padding: 2px 0 2px 10px; border-left: 1px solid var(--app-border); }
body.app-mode .lesson-toc li { margin: 0; }
body.app-mode .lesson-toc-item {
  position: relative; display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  font: 500 12.5px/1.35 var(--app-sans); color: var(--app-muted); padding: 0 8px; margin: 3px 0; border-radius: var(--app-r-xs);
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
body.app-mode .lesson-toc-item:hover { color: var(--app-ink); }
body.app-mode .lesson-toc-item.is-active { color: var(--app-primary-dark); font-weight: 600; }
body.app-mode .lesson-toc-item.is-active::before { content: ""; position: absolute; left: -12px; top: 2px; bottom: 2px; width: 3px; border-radius: 2px; background: var(--app-primary); }
@media (min-width: 1024px) {
  /* end the sticky list above the chat button instead of under it */
  body.app-mode .sidebar-panel { max-height: calc(100vh - var(--app-nav-h) - 168px); }
}

/* ------- lesson body ------------------------------------------------------ */
@keyframes lessonEnter { from { opacity: 0; } to { opacity: 1; } }
body.app-mode .lesson-panel.lesson-enter { animation: lessonEnter .28s ease both; }
body.app-mode.custom-lesson-mode.lesson-title-dup .lesson-main-title { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* objectives / notes: tag names and `code` from course data show as code */
body.app-mode .objectives-list code, body.app-mode .notes-content code { font-family: var(--app-mono); font-size: .88em; background: var(--app-surface-2); border: 1px solid var(--app-border); color: var(--app-primary-dark); padding: 1px 5px; border-radius: 4px; }

/* end-of-lesson "Up next" card inside the completion footer */
body.app-mode .lesson-upnext { display: grid; gap: 3px; justify-items: center; text-align: center; width: min(440px, 100%); padding: 14px 20px; margin: 4px 0 6px; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--app-r); }
body.app-mode .lesson-upnext-eyebrow { font: 700 11px var(--app-sans); letter-spacing: .1em; text-transform: uppercase; color: var(--app-violet-ink); }
body.app-mode .lesson-upnext-title { font-family: var(--app-serif); font-weight: 400; font-size: 19px; line-height: 1.3; color: var(--app-ink); }
body.app-mode .lesson-upnext-meta { font: 500 12.5px var(--app-sans); color: var(--app-muted); }
body.app-mode .lesson-upnext-meta i { margin-right: 4px; }
body.app-mode [data-theme="cm-dark"] .lesson-upnext { background: var(--app-surface); }

/* slides: the last "Next" turns into the finish action */
body.app-mode .slide-nav-btn.is-finish { background: var(--app-primary-grad); color: #fff; border-color: transparent; box-shadow: var(--app-shadow-primary); }
body.app-mode .slide-nav-btn.is-finish:hover:not(:disabled) { background: var(--app-primary-grad); color: #fff; border-color: transparent; }

@keyframes lessonNudge { 0%, 100% { transform: none; } 30% { transform: translateX(5px); } 60% { transform: translateX(-3px); } }
body.app-mode .lesson-nudge { animation: lessonNudge .45s ease; box-shadow: 0 0 0 4px var(--app-primary-tint) !important; }

/* narration: unmistakable playing state */
body.app-mode .bl-narration-player.is-playing .bl-narr-play { box-shadow: 0 0 0 4px var(--app-primary-tint), var(--app-shadow-primary); }
body.app-mode .bl-narr-play[aria-pressed="true"] { animation: none; }

/* ------- transient status pill ("Lesson complete", "Picked up where...") */
body.app-mode .lesson-flash {
  position: fixed; left: 50%; top: calc(var(--app-nav-h) + 72px); z-index: 960;
  display: flex; align-items: center; gap: 10px; width: max-content; max-width: calc(100vw - 32px);
  padding: 8px 10px 8px 16px; background: var(--app-surface); color: var(--app-ink);
  border: 1px solid var(--app-border); border-radius: var(--app-pill); box-shadow: var(--app-shadow-hover);
  font: 500 13.5px/1.35 var(--app-sans); opacity: 0; transform: translate(-50%, -8px); pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
body.app-mode .lesson-flash:empty { display: none; }
body.app-mode .lesson-flash.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
body.app-mode .lesson-flash > i { color: var(--app-green); }
body.app-mode .lesson-flash .fa-bookmark { color: var(--app-violet); }
body.app-mode .lesson-flash-sub { color: var(--app-muted); }
body.app-mode .lesson-flash-btn { background: none; border: 0; color: var(--app-primary); font: 600 13px var(--app-sans); padding: 5px 10px; border-radius: var(--app-pill); cursor: pointer; white-space: nowrap; }
body.app-mode .lesson-flash-btn:hover { background: var(--app-primary-tint); }

/* ------- week / course done card ---------------------------------------- */
body.app-mode .lesson-done { position: fixed; inset: 0; z-index: 1300; display: none; place-items: center; padding: 16px; }
body.app-mode .lesson-done.is-open { display: grid; }
@keyframes ldcFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ldcIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
body.app-mode .ldc-backdrop { position: absolute; inset: 0; background: rgba(36, 16, 90, .32); animation: ldcFade .2s ease both; }
body.app-mode .ldc-card {
  position: relative; width: min(460px, 100%); display: grid; justify-items: center; gap: 10px; text-align: center;
  background: var(--app-surface); border-radius: var(--app-r-lg); box-shadow: var(--app-shadow-modal); padding: 34px 28px 24px;
  animation: ldcIn .32s cubic-bezier(.2, .8, .2, 1) both;
}
body.app-mode .ldc-close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: none; color: var(--app-muted); cursor: pointer; font-size: 16px; }
body.app-mode .ldc-close:hover { background: var(--app-surface-2); color: var(--app-ink); }
body.app-mode .ldc-title { font-family: var(--app-serif); font-weight: 400; font-size: 26px; line-height: 1.2; color: var(--app-ink); margin: 6px 0 0; }
body.app-mode .ldc-body { font-size: 14.5px; line-height: 1.55; color: var(--app-muted); margin: 0; max-width: 36ch; }
body.app-mode .ldc-next { width: 100%; display: grid; gap: 3px; text-align: left; margin-top: 6px; padding: 14px 16px; background: var(--app-lavender); border: 1px solid var(--app-border); border-radius: var(--app-r); }
body.app-mode .ldc-next-eyebrow { font: 700 11px var(--app-sans); letter-spacing: .1em; text-transform: uppercase; color: var(--app-violet-ink); }
body.app-mode .ldc-next strong { font-family: var(--app-serif); font-weight: 400; font-size: 18px; line-height: 1.3; color: var(--app-ink); }
body.app-mode .ldc-next-meta { font: 500 12.5px var(--app-sans); color: var(--app-muted); }
body.app-mode .ldc-actions { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; margin-top: 8px; }
body.app-mode .ldc-actions .app-btn { flex: 1 1 160px; justify-content: center; min-height: 44px; }

/* ------- phone bottom bar (hidden on desktop) ---------------------------- */
body.app-mode .lesson-actionbar { display: none; }
body.app-mode .lesson-sheet-handle { display: none; }
body.app-mode .lesson-sheet-backdrop { display: none; }

/* lesson view: the radio pill competes with lesson narration and sits on the
   practice panel / bottom bar, so it steps aside while a lesson is open. */
body.app-mode:has(#course-view[style*="block"]) #hf-radio-widget { display: none !important; }
body.app-mode.lesson-done-open #cw-widget { display: none; }

@media (max-width: 1023px) {
  body.app-mode #course-view { --lab-h: 64px; }
  body.app-mode .app-lesson-tools > :not(.app-lesson-sidebar-toggle) { display: none !important; }
  body.app-mode .slide-controls .slide-nav-btn { display: none; }
  body.app-mode .slide-controls { justify-content: center; }
  body.app-mode .course-view-container,
  body.app-mode.custom-lesson-mode .course-view-container { padding-bottom: calc(var(--lab-h) + 96px + env(safe-area-inset-bottom)); }
  body.app-mode .lesson-flash { top: calc(var(--app-nav-h) + 64px); }

  body.app-mode .lesson-actionbar {
    display: flex; align-items: center; gap: 8px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 950;
    min-height: var(--lab-h); padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--app-surface) 94%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--app-border); box-shadow: 0 -8px 24px rgba(32, 32, 42, .06);
  }
  body.app-mode .lab-btn {
    flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; min-width: 44px; padding: 0 12px;
    background: var(--app-surface); color: var(--app-ink); border: 1px solid var(--app-border); border-radius: var(--app-r-sm);
    font: 600 13px var(--app-sans); cursor: pointer; position: relative;
  }
  body.app-mode .lab-prev { padding: 0; width: 44px; }
  body.app-mode .lab-btn:disabled { opacity: .4; cursor: default; }
  body.app-mode .lab-pos { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 4px 2px; background: none; border: 0; text-align: left; color: var(--app-ink); cursor: pointer; border-radius: var(--app-r-sm); }
  body.app-mode .lab-pos-text { display: flex; flex-direction: column; min-width: 0; }
  body.app-mode .lab-pos-text strong, body.app-mode .lab-pos-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body.app-mode .lab-pos-text strong { font: 600 13px/1.25 var(--app-sans); }
  body.app-mode .lab-pos-text small { font: 500 11.5px/1.3 var(--app-sans); color: var(--app-muted); }
  body.app-mode .lab-dot { display: none; position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--app-orange); box-shadow: 0 0 0 2px var(--app-surface); }
  body.app-mode .lab-practice.has-task { border-color: var(--app-orange-line); background: var(--app-orange-tint); color: var(--app-orange-ink); }
  body.app-mode .lab-practice.has-task .lab-dot { display: block; }
  body.app-mode .lab-primary {
    flex: 0 1 auto; min-width: 0; max-width: 56vw; height: 44px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--app-primary-grad); color: #fff; border: 0; border-radius: var(--app-r-sm); box-shadow: var(--app-shadow-primary);
    font: 600 14px var(--app-sans); cursor: pointer; white-space: nowrap;
  }
  body.app-mode .lab-primary:active, body.app-mode .lab-btn:active { transform: scale(.97); }

  /* narration pill sits just above the bar, left; chat button to its right */
  body.app-mode .bl-narration-player { left: 12px; transform: none; bottom: calc(var(--lab-h) + 10px + env(safe-area-inset-bottom)); max-width: calc(100vw - 84px); z-index: 940; }
  body.app-mode:has(#course-view[style*="block"]) #cw-widget { right: 12px; left: auto; bottom: calc(var(--lab-h, 64px) + 15px + env(safe-area-inset-bottom)); }
  body.app-mode:has(#course-view[style*="block"]) #cw-btn { width: 48px; height: 48px; }
  body.app-mode.lesson-practice-open #cw-widget, body.app-mode.app-sidebar-open:has(#course-view[style*="block"]) #cw-widget, body.app-mode.lesson-done-open #cw-widget { display: none; }
  body.app-mode:has(#course-view[style*="block"]) #toast-container { bottom: calc(64px + 84px + env(safe-area-inset-bottom)); }

  /* practice panel becomes a bottom sheet */
  body.app-mode .playground-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1160; margin: 0;
    max-height: min(88vh, calc(100vh - var(--app-nav-h) - 8px)); max-height: min(88dvh, calc(100dvh - var(--app-nav-h) - 8px)); overflow-y: auto; overscroll-behavior: contain;
    border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); box-shadow: var(--app-shadow-modal);
    transform: translateY(105%); visibility: hidden; transition: transform .26s ease, visibility 0s linear .26s;
  }
  body.app-mode.lesson-practice-open .playground-panel { transform: none; visibility: visible; transition: transform .26s ease, visibility 0s; }
  body.app-mode .lesson-sheet-handle {
    display: grid; place-items: center; position: sticky; top: 0; z-index: 2; width: 100%; height: 26px; padding: 0;
    background: var(--app-surface); border: 0; border-radius: 20px 20px 0 0; cursor: pointer;
  }
  body.app-mode .lesson-sheet-handle span { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--app-border-strong); }
  body.app-mode .lesson-sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 1150; background: rgba(36, 16, 90, .35); opacity: 0; pointer-events: none; transition: opacity .22s; }
  body.app-mode.lesson-practice-open .lesson-sheet-backdrop { opacity: 1; pointer-events: auto; }

  /* done card rises from the bottom like a sheet */
  body.app-mode .lesson-done { place-items: end center; padding: 0; }
  body.app-mode .ldc-card { width: 100%; border-radius: 22px 22px 0 0; padding: 30px 20px calc(20px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) {
  body.app-mode .lab-practice-label { display: none; }
  body.app-mode .lab-practice { width: 44px; padding: 0; }
  body.app-mode .lab-pos .lesson-ring { display: none; }
}
@media (min-width: 721px) and (max-width: 1023px) {
  body.app-mode .bl-narration-player { left: 50%; transform: translateX(-50%); max-width: calc(100vw - 160px); }
}

@media (prefers-reduced-motion: reduce) {
  body.app-mode .lesson-ring-fill, body.app-mode .lesson-read-progress span, body.app-mode .playground-panel, body.app-mode .lesson-flash { transition: none !important; }
  body.app-mode .lesson-panel.lesson-enter, body.app-mode .ldc-card, body.app-mode .ldc-backdrop, body.app-mode .lesson-nudge { animation: none !important; }
}
