/* Lesson presentation player (public/js/present.js).
   Uses the platform tokens from theme.css, so it follows light and dark.

   Design rules (HCD review, v1.4.2):
   - The slide shows keywords and a visual; the narrator says the sentences;
     the caption carries the words. Never the script printed twice.
   - One idea per slide, a 7/5 grid: text left, visual right.
   - Chips appear as they are spoken; nothing is dimmed to low contrast.
   - The deck is the hero of the topic page. */

.pres-mode {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin: 0 0 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.pres-mode button {
  min-height: 34px;
  padding: 6px 16px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
}
.pres-mode button[aria-pressed="true"] { background: var(--surface); color: var(--accent-text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.pres-mode button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* In presentation mode the reading list shows only what the deck does not:
   the videos at the bottom (and the checkpoint progress). Blocks the deck is
   using are moved into it, so they are never hidden from the learner. */
.blocks.is-presenting > .block:not(.block-video) { display: none; }

/* Presenting: the header shrinks to a title row so the deck is above the fold,
   and the header's own "Start learning" steps aside (playing the deck starts
   the topic). */
.topic-detail.is-presenting .topic-header { padding-top: 16px; padding-bottom: 16px; }
.topic-detail.is-presenting .topic-header h2 { font-size: 22px; margin-bottom: 4px; }
.topic-detail.is-presenting .topic-summary { display: none; }
.topic-detail.is-presenting #btn-start { display: none; }
body.pres-in-view .chat-fab { opacity: 0; pointer-events: none; transform: translateY(12px); }
.chat-fab { transition: opacity .2s, transform .2s; }

.pres {
  position: relative;
  margin: 0 0 18px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  outline: none;
}
.pres:focus-visible { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }

.pres-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.pres-kicker { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; letter-spacing: .02em; }
.pres-kicker svg { color: var(--accent-text); }
.pres-count { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--text); }

/* Progress: remaining segments meet 3:1 against the surface; done and current
   differ by size as well as colour. */
.pres-bar { display: flex; align-items: center; gap: 3px; padding: 0 20px 10px; }
.pres-seg {
  flex: 1 1 0;
  min-width: 0;
  height: 16px;
  padding: 6px 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.pres-seg span { display: block; height: 4px; border-radius: 4px; background: #858F99; transition: background .2s, height .2s; }
[data-theme="dark"] .pres-seg span { background: #6B727B; }
.pres-seg.is-done span { background: var(--accent-text); }
.pres-seg.is-current span { background: var(--accent); height: 6px; margin-top: -1px; }
.pres-seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 4px; }

.pres-stage {
  position: relative;
  min-height: clamp(360px, 54vh, 540px);
  display: flex;
  align-items: stretch;
  padding: 8px 20px 4px;
  background:
    radial-gradient(90% 120% at 100% 0%, var(--accent-soft), transparent 55%),
    radial-gradient(60% 80% at 0% 100%, color-mix(in srgb, var(--accent-2, var(--accent)) 7%, transparent), transparent 60%),
    var(--surface);
}
.pres-slide { width: 100%; display: flex; }

.ps {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 22px 12px 26px;
  animation: ps-in .3s ease-out;
}
.ps-grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  align-items: center;
  gap: 24px 36px;
}
.ps-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@keyframes ps-in { from { opacity: 0; } to { opacity: 1; } }

.ps-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-text);
}
.ps-eyebrow-chip {
  align-self: flex-start;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
}
.ps-h {
  margin: 0;
  font-size: clamp(26px, 2.2vw + 12px, 40px);
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: -.02em;
  text-wrap: balance;
  color: var(--text);
}
.ps-h-xl { font-size: clamp(30px, 2.8vw + 12px, 48px); }
.ps-sub { margin: 0; max-width: 58ch; font-size: 17px; line-height: 1.6; color: var(--text-dim); }
.ps-title .btn, .ps-end .btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; }
.ps-note { margin: 0; font-size: 13px; color: var(--text-faint); }
.ps-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* part n of N, instead of "(continued)" */
.ps-parts { display: inline-flex; gap: 4px; margin-left: 12px; vertical-align: middle; }
.ps-parts i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong, var(--border)); }
.ps-parts i.on { background: var(--accent); }

/* keyword chips */
.ps-chips {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ps-chips li {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 19px;
  line-height: 1.45;
  color: var(--text);
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  border: 1px solid transparent;
  transition: background .2s, border-color .2s, transform .24s ease-out, opacity .24s ease-out;
}
.ps-chips strong { font-weight: 750; color: var(--accent-text); }
.ps-chips .ps-lead { color: var(--text); }
.ps-chip-dot { flex: none; width: 10px; height: 10px; margin-top: 9px; border-radius: 3px; transform: rotate(45deg); background: var(--accent); }
.ps-check { flex: none; display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); }

/* While narrating: chips appear as they are spoken (never dimmed). */
.pres.is-playing .ps-chips li:not(.is-reading):not(.is-read) { visibility: hidden; opacity: 0; transform: translateY(8px); }
.pres.is-playing .ps-chips li.is-reading {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.pres.is-playing .ps-recap li.is-read .ps-check { background: var(--accent); color: var(--on-fill, #fff); }

/* visual column */
.ps-visual { display: grid; place-items: center; min-height: 220px; }
.ps-orb {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(150px, 16vw, 210px);
  aspect-ratio: 1;
  border-radius: 50%;
  color: var(--accent-text);
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--accent) 22%, var(--surface)), var(--accent-soft) 70%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent), 0 18px 40px -18px color-mix(in srgb, var(--accent) 55%, transparent);
  animation: ps-orb .45s ease-out;
}
.ps-orb::before, .ps-orb::after {
  content: '';
  position: absolute;
  inset: -18px;
  border-radius: 50%;
  border: 1px dashed color-mix(in srgb, var(--accent) 30%, transparent);
}
.ps-orb::after { inset: -38px; border-style: solid; border-color: color-mix(in srgb, var(--accent) 12%, transparent); }
.ps-orb svg { width: 46%; height: 46%; }
@keyframes ps-orb { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
.ps-visual-hero .ps-orb { width: clamp(170px, 19vw, 240px); }
.ps-visual-stat { justify-items: start; }
.ps-stat {
  font-size: clamp(56px, 6vw, 92px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  color: var(--accent-text);
  font-variant-numeric: tabular-nums;
}

/* analogy */
.ps-quote {
  margin: 0;
  padding: 4px 0 4px 20px;
  border-left: 4px solid var(--accent);
  font-family: var(--font-read, Georgia, serif);
  font-size: clamp(20px, 1.2vw + 12px, 26px);
  font-style: italic;
  line-height: 1.5;
  color: var(--text);
}
.ps-quote p { margin: 0 0 10px; }

/* recap */
.ps-recap-slide { max-width: 860px; }
.ps-recap li { font-size: 18px; }

/* A real block borrowed into a slide keeps its own look; the slide only
   removes the outer card chrome so it doesn't nest a card in a card. */
.ps-block-host > .block { margin: 0; box-shadow: none; }

/* end slide: the videos, inside the slide */
.ps-videos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.ps-video {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 0 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  overflow: hidden;
}
.ps-video:hover { border-color: var(--accent); }
.ps-video:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ps-video-thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--surface-2); }
.ps-video-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ps-video-play { position: absolute; left: 50%; top: 50%; display: grid; place-items: center; width: 44px; height: 32px; margin: -16px 0 0 -22px; border-radius: 10px; background: rgba(0, 0, 0, .72); color: #fff; }
.ps-video-title { padding: 0 12px; font-size: 14px; font-weight: 650; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ps-video-meta { padding: 0 12px; font-size: 12.5px; color: var(--text-faint); }

.pres-caption {
  margin: 0;
  padding: 10px 20px 12px;
  min-height: 2.8em;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.pres-caption:empty { display: none; }

.pres-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.pres-spacer { flex: 1; }
.pres-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.pres-btn:hover:not(:disabled) { background: var(--surface-3, var(--surface-2)); }
.pres-btn:disabled { opacity: .4; cursor: default; }
.pres-btn[aria-pressed="true"] { color: var(--accent-text); border-color: var(--accent); }
.pres-btn:focus-visible, .pres-select select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pres-play { width: 54px; background: var(--btn-fill, var(--accent)); border-color: transparent; color: var(--on-btn, #fff); }
.pres-play:hover:not(:disabled) { background: var(--btn-fill, var(--accent)); filter: brightness(1.08); }
.pres-select select {
  height: 44px;
  max-width: 200px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  .ps, .ps-orb { animation: none; }
  .pres-seg span, .ps-chips li { transition: none; }
  .pres.is-playing .ps-chips li:not(.is-reading):not(.is-read) { visibility: visible; opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .ps-grid { grid-template-columns: minmax(0, 1fr); }
  .ps-visual { order: -1; min-height: 0; justify-items: start; }
  .ps-orb { width: 96px; }
  .ps-orb::before, .ps-orb::after { display: none; }
  .ps-visual-hero .ps-orb { width: 112px; }
  .ps-visual-stat { order: -1; }
}
@media (max-width: 640px) {
  .pres { border-radius: 16px; }
  .pres-stage { min-height: max(300px, calc(100svh - 440px)); padding: 4px 14px; }
  .ps { padding: 16px 4px 20px; gap: 12px; }
  .ps-chips li { font-size: 16px; padding: 10px 12px; gap: 10px; }
  .ps-chip-dot { margin-top: 7px; }
  .ps-sub { font-size: 15.5px; }
  .ps-stat { font-size: 60px; }
  .pres-voice-wrap { display: none; }
  .pres-top { padding: 10px 14px 6px; }
  .pres-bar { padding: 0 14px 8px; }
  .pres-caption { font-size: 14px; line-height: 1.5; padding: 8px 14px 0; margin-bottom: 10px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; max-height: calc(4.5em + 8px); border-bottom: 0; }
  .pres-controls { flex-wrap: nowrap; gap: 5px; padding: 8px 10px; }
  .pres-btn { width: 40px; height: 40px; }
  .pres-play { width: 48px; }
  .pres-select select { height: 40px; max-width: 70px; padding: 0 6px; }
  .ps-h { text-align: left; }
  .topic-detail.is-presenting .topic-header .topic-card-meta { gap: 6px 10px; }
}
