/* ================================================================
   Learnillion — Viewer chrome (permanent, lesson-independent)
   This stylesheet owns the PAGE. The uploaded lesson's CSS only
   styles things inside .stage-inner (see LessonParser::scopeCssToStage).
   ================================================================ */

:root {
  --l-bg: #f7f5f0;
  --l-card: #ffffff;
  --l-bg-soft: #faf8f3;
  --l-ink: #1a1d29;
  --l-ink-dim: #6b7280;
  --l-ink-soft: #9ca3af;
  --l-accent: #0365f2;
  --l-accent-soft: #e3edfd;
  --l-ok: #059669;
  --l-border: #e5e7eb;
  --l-border-soft: #f0edE8;
  --l-highlight: #fef08a;
  --l-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --l-shadow-md: 0 4px 16px rgba(15, 23, 42, 0.06);
  --l-shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, 0.12);

  /* Compatibility variables — uploaded lesson CSS may reference these
     with the un-prefixed names we used in the template. Map them through
     so stage-scoped styles still render correctly. */
  --accent: var(--l-accent);
  --bg: var(--l-bg);
  --bg-card: var(--l-card);
  --bg-soft: var(--l-bg-soft);
  --ink: var(--l-ink);
  --ink-dim: var(--l-ink-dim);
  --ink-soft: var(--l-ink-soft);
  --border: var(--l-border);
  --border-soft: var(--l-border-soft);
  --ok: var(--l-ok);
  --ok-soft: #d1fae5;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --highlight: var(--l-highlight);
  --shadow-sm: var(--l-shadow-sm);
  --shadow-md: var(--l-shadow-md);
  --shadow-lg: var(--l-shadow-lg);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--l-bg);
  color: var(--l-ink);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ============ HEADER ============ */
header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 24px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--l-border);
  margin-bottom: 28px;
}
.eyebrow {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--l-accent);
  font-weight: 600; margin-bottom: 14px;
}
.eyebrow::before {
  content: ""; width: 6px; height: 6px;
  background: var(--l-accent); border-radius: 50%;
}
h1 {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: clamp(30px, 5.5vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--l-ink);
}
h1 .ital { font-style: italic; color: var(--l-accent); font-weight: 500; }

.duration-card {
  text-align: right; padding: 12px 18px;
  border: 1px solid var(--l-border); background: var(--l-card);
  border-radius: 10px; min-width: 140px;
  box-shadow: var(--l-shadow-sm);
}
.duration-card .label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; letter-spacing: 0.15em;
  color: var(--l-ink-dim); text-transform: uppercase;
}
.duration-card .time {
  font-family: 'Source Serif 4', serif;
  font-size: 26px; font-weight: 600;
  color: var(--l-ink); margin-top: 2px;
}

/* ============ STAGE (the container only — inner content is lesson-scoped) ============ */
.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: var(--l-card);
  border: 1px solid var(--l-border);
  box-shadow: var(--l-shadow-lg);
}
.stage-inner { position: absolute; inset: 0; }

/* Minimal default scene positioning so every lesson scene is centered
   and has consistent padding. Uploaded lesson CSS can override these. */
.stage .scene {
  position: absolute; inset: 0; opacity: 0;
  transition: opacity 0.5s ease;
  display: flex; align-items: center; justify-content: center;
  padding: 56px 32px 36px;
  pointer-events: none;
}
.stage .scene.active { opacity: 1; pointer-events: auto; }
.stage .scene-label {
  position: absolute; top: 20px; left: 24px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; letter-spacing: 0.18em;
  color: var(--l-ink-dim); text-transform: uppercase; z-index: 10;
}
.stage .scene-label span { color: var(--l-accent); font-weight: 600; }
.stage .scene-counter {
  position: absolute; top: 20px; right: 24px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; letter-spacing: 0.15em;
  color: var(--l-ink-soft); z-index: 10;
}

/* ============ COLLAPSIBLE TEXT BOX ============ */
.text-section { margin-top: 28px; position: relative; }
.text-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px;
}
.text-header h2 {
  font-family: 'Source Serif 4', serif;
  font-weight: 600; font-size: clamp(20px, 3vw, 26px);
  letter-spacing: -0.01em; color: var(--l-ink);
}
.toggle-btn {
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  letter-spacing: 0.12em; text-transform: uppercase;
  background: white; color: var(--l-ink);
  border: 1px solid var(--l-border); padding: 10px 14px;
  cursor: pointer; border-radius: 8px;
  transition: all 0.2s; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--l-shadow-sm);
  white-space: nowrap;
}
.toggle-btn:hover { border-color: var(--l-accent); color: var(--l-accent); }
.toggle-btn .chev { transition: transform 0.3s; display: inline-block; }
.text-section.expanded .chev { transform: rotate(180deg); }

.text-box {
  position: relative; border: 1px solid var(--l-border);
  border-radius: 12px; background: white;
  overflow: hidden; max-height: 260px;
  transition: max-height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--l-shadow-sm);
}
.text-section.expanded .text-box { max-height: 5000px; }

.text-content {
  padding: 28px 32px; font-size: 16px; line-height: 1.7;
  color: var(--l-ink); font-family: 'Source Serif 4', serif;
}
.text-content p { margin-bottom: 18px; }
.text-content h3 {
  font-family: 'Source Serif 4', serif; font-weight: 700;
  font-size: 22px; margin-top: 30px; margin-bottom: 12px;
  letter-spacing: -0.01em; color: var(--l-ink);
}
.text-content .step-num {
  color: var(--l-accent); font-family: 'JetBrains Mono', monospace;
  font-size: 12px; letter-spacing: 0.15em; margin-right: 8px;
  font-weight: 600;
}
.text-content .hl {
  background: var(--l-highlight);
  padding: 1px 3px; border-radius: 2px;
  font-weight: 500;
}
.text-content blockquote {
  border-left: 3px solid var(--l-accent);
  padding: 6px 0 6px 18px; margin: 20px 0;
  font-family: 'Source Serif 4', serif; font-style: italic;
  font-size: 19px; color: var(--l-ink);
  font-weight: 500;
}

/* Word highlighting during playback */
.text-content .word {
  display: inline;
  border-radius: 3px;
  transition: background-color 0.1s ease, color 0.1s ease;
  padding: 1px 1px;
}
.text-content .word.active {
  background: var(--l-accent);
  color: white;
  font-weight: 500;
}

.fade-mask {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 120px;
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 50%, white 100%);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  pointer-events: none; transition: opacity 0.3s;
}
.text-section.expanded .fade-mask { opacity: 0; pointer-events: none; }
.fade-hint {
  position: absolute; bottom: 16px; left: 50%;
  transform: translateX(-50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; letter-spacing: 0.15em;
  color: var(--l-ink-dim); text-transform: uppercase;
  pointer-events: none; transition: opacity 0.3s;
  font-weight: 600;
}
.text-section.expanded .fade-hint { opacity: 0; }

/* ============ AUDIO PLAYER — sticky at bottom ============ */
.player {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  border-top: 1px solid var(--l-border);
  border-radius: 0;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
  margin: 0;
  display: flex; justify-content: center;
}
.player-contents {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 18px; align-items: center;
  width: 100%;
  max-width: 1100px;
}

/* Body padding so last content isn't hidden by the sticky player */
body {
  padding-bottom: 100px;
}

.play-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--l-accent); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(3, 101, 242, 0.3);
  flex-shrink: 0;
}
.play-btn:hover { transform: scale(1.05); box-shadow: 0 6px 18px rgba(3, 101, 242, 0.4); }
.play-btn svg { width: 18px; height: 18px; fill: white; }
.player-mid { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.player-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; letter-spacing: 0.15em;
  color: var(--l-ink-dim); text-transform: uppercase;
  display: flex; justify-content: space-between; font-weight: 600;
}
.player-title .status { color: var(--l-accent); }
.progress-track {
  height: 4px; background: var(--l-border);
  border-radius: 2px; overflow: hidden;
  cursor: pointer;
}
.progress-fill {
  height: 100%;
  background: var(--l-accent);
  width: 0%; transition: width 0.2s linear; border-radius: 2px;
}
.time-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--l-ink-dim);
  letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600;
  white-space: nowrap;
}
.speed-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; font-weight: 600;
  color: var(--l-ink);
  background: var(--l-bg-soft);
  border: 1px solid var(--l-border);
  padding: 7px 10px; min-width: 50px;
  border-radius: 8px; cursor: pointer;
  transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0.02em;
}
.speed-btn:hover {
  border-color: var(--l-accent);
  color: var(--l-accent);
  background: var(--l-accent-soft);
}
.speed-btn.active-speed {
  border-color: var(--l-accent);
  color: var(--l-accent);
  background: var(--l-accent-soft);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .wrap { padding: 24px 16px 60px; }
  header { grid-template-columns: 1fr; gap: 16px; }
  .duration-card { text-align: left; min-width: 0; max-width: 180px; }
  .stage { aspect-ratio: 4 / 5; }
  .stage .scene { padding: 50px 20px 28px; }
  .stage .scene-label { font-size: 9px; left: 16px; top: 16px; }
  .stage .scene-counter { font-size: 9px; right: 16px; top: 16px; }

  .text-content { padding: 22px 20px; font-size: 15px; line-height: 1.65; }
  .text-content h3 { font-size: 19px; margin-top: 22px; }
  .text-content blockquote { font-size: 17px; }

  .player { padding: 10px 16px; }
  .player-contents {
    grid-template-columns: auto 1fr auto;
    gap: 10px;
  }
  .time-display { display: none; } /* hide on mobile to save space */
  .play-btn { width: 44px; height: 44px; }
  .play-btn svg { width: 16px; height: 16px; }
  .speed-btn { min-width: 46px; padding: 6px 9px; font-size: 11px; }
  body { padding-bottom: 82px; }

  .text-header { flex-wrap: wrap; }
  .toggle-btn { padding: 8px 12px; font-size: 10px; }
}

@media (max-width: 420px) {
  h1 { font-size: 30px; }
  .stage { aspect-ratio: 3 / 4; }
  .stage .scene { padding: 46px 14px 24px; }
}
