/* Field MA AI — interactive learner (cream/teal) */
:root {
  --cream: #f7f3eb;
  --cream-dark: #ebe4d6;
  --ink: #1a2b2e;
  --ink-muted: #4a5c60;
  --teal: #0d6e6e;
  --teal-dark: #0a5555;
  --teal-soft: #d4ecec;
  --accent: #c45c26;
  --accent-soft: #f5e4d8;
  --white: #ffffff;
  --border: #d5cdc0;
  --shadow: 0 8px 28px rgba(26, 43, 46, 0.08);
  --radius: 12px;
  --font-sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --player-sidebar: 280px;
}

.learn-body { background: var(--cream); min-height: 100vh; }

/* —— Player chrome —— */
/* Viewport-locked shell so Continue/Back dock stays on-screen.
   body.is-player is set by player.js (no :has() dependency). */
body.learn-body.is-player {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
body.learn-body.is-player > .site-header,
body.learn-body.is-player > .learn-disclaimer-strip {
  flex-shrink: 0;
}
body.learn-body.is-player #player-root {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.player-app {
  display: grid;
  grid-template-columns: var(--player-sidebar) 1fr;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
@media (max-width: 900px) {
  .player-app { grid-template-columns: 1fr; }
  .player-sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(88vw, 300px);
    transform: translateX(-105%); transition: transform .25s ease;
    z-index: 80; box-shadow: var(--shadow); height: 100dvh; overflow-y: auto;
  }
  .player-sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(26,43,46,.4); z-index: 70;
  }
  .sidebar-backdrop.is-open { display: block; }
}

.player-sidebar {
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 1rem 0.85rem 2rem;
  overflow-y: auto;
}
.player-sidebar h2 {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--teal); margin: 0.5rem 0.6rem 0.75rem; font-family: var(--font-sans);
}
.toc-module {
  display: block; width: 100%; text-align: left;
  border: 1px solid transparent; background: transparent;
  border-radius: 8px; padding: 0.55rem 0.65rem; margin-bottom: 0.25rem;
  cursor: pointer; color: var(--ink); font: inherit;
}
.toc-module:hover { background: var(--cream); }
.toc-module.is-current { background: var(--teal-soft); border-color: #b7dede; }
.toc-module.is-locked { opacity: .65; cursor: not-allowed; }
.toc-module .toc-id { font-weight: 700; color: var(--teal-dark); font-size: 0.85rem; }
.toc-module .toc-title { display: block; font-size: 0.88rem; line-height: 1.3; }
.toc-module .toc-meta { font-size: 0.72rem; color: var(--ink-muted); }
.toc-lock { font-size: 0.75rem; color: var(--accent); }
.toc-steps { list-style: none; margin: 0 0 0.5rem 0.5rem; padding: 0 0 0 0.65rem; border-left: 2px solid var(--cream-dark); display: none; }
.toc-module.is-current + .toc-steps, .toc-steps.is-open { display: block; }
.toc-steps li button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 0.28rem 0.4rem; font-size: 0.8rem; color: var(--ink-muted); cursor: pointer; border-radius: 4px;
}
.toc-steps li button:hover { color: var(--teal-dark); background: var(--cream); }
.toc-steps li button.is-active { color: var(--teal-dark); font-weight: 650; background: var(--teal-soft); }
.toc-steps li button.is-done::before { content: "✓ "; color: var(--teal); }

.player-main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  overflow: hidden; height: 100%;
}
.player-topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem 1rem;
  padding: 0.75rem 1.25rem; background: var(--white); border-bottom: 1px solid var(--border);
  position: relative; top: auto; z-index: 40; flex-shrink: 0;
}
.btn-icon {
  border: 1px solid var(--border); background: var(--cream); border-radius: 8px;
  padding: 0.4rem 0.65rem; cursor: pointer; font: inherit; color: var(--ink);
}
.btn-icon:hover { border-color: var(--teal); color: var(--teal-dark); }
.progress-wrap { flex: 1; min-width: 140px; }
.progress-label { font-size: 0.75rem; color: var(--ink-muted); margin-bottom: 0.2rem; }
.progress-bar {
  height: 8px; background: var(--cream-dark); border-radius: 999px; overflow: hidden;
}
.progress-bar > span {
  display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal), #149494);
  border-radius: 999px; transition: width .45s ease;
}

/* Narration toolbar */
.narration-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.55rem;
  padding: 0.55rem 1.25rem; background: var(--teal-soft); border-bottom: 1px solid #b7dede;
  flex-shrink: 0;
}
.narration-bar .spk {
  width: 1.35rem; height: 1.35rem; border-radius: 50%;
  background: var(--teal); display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 0.7rem;
}
.narration-bar.is-speaking .spk { animation: pulse-spk 1s ease-in-out infinite; }
@keyframes pulse-spk {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(13,110,110,.45); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(13,110,110,0); }
}
.narration-bar button, .narration-bar select, .narration-bar label {
  font-size: 0.82rem; border: 1px solid #9bcbcb; background: var(--white);
  border-radius: 6px; padding: 0.28rem 0.55rem; cursor: pointer; color: var(--ink);
}
.narration-bar label { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.narration-bar input[type=checkbox] { accent-color: var(--teal); }

.player-stage {
  flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto;
  padding: 1.5rem 1.25rem 1.75rem; max-width: 760px; width: 100%; margin: 0 auto;
  box-sizing: border-box;
}
.step-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.5rem 1.4rem 1.35rem;
  animation: step-in .4s ease both;
  max-width: 100%; min-width: 0; overflow-x: hidden; box-sizing: border-box;
}
.step-card.is-active-speak { outline: 2px solid var(--teal); outline-offset: 2px; }
@keyframes step-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .step-card, .progress-bar > span, .wf-stage, .stagger > * { animation: none !important; transition: none !important; }
  .narration-bar.is-speaking .spk { animation: none; }
}
.step-card .step-kicker {
  font-size: 0.75rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--teal);
  margin: 0 0 0.5rem;
}
.step-card h1 { font-size: clamp(1.35rem, 3vw, 1.85rem); margin-bottom: 0.75rem; overflow-wrap: anywhere; }
.prose {
  max-width: 100%; min-width: 0;
  overflow-wrap: anywhere; word-break: break-word;
}
.prose h2 { font-size: 1.25rem; overflow-wrap: anywhere; }
.prose h3 { margin-top: 1.1rem; overflow-wrap: anywhere; }
.prose p, .prose li, .prose td, .prose th, .prose a {
  overflow-wrap: anywhere; word-break: break-word;
}
.prose a { word-break: break-word; }
.table-wrap {
  display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 1rem 0; border-radius: 8px; border: 1px solid var(--border);
}
.prose .table-wrap table { margin: 0; border: 0; }
.prose table {
  width: 100%; max-width: 100%; border-collapse: collapse; font-size: 0.92rem; margin: 1rem 0;
  table-layout: auto;
}
.prose th, .prose td {
  border: 1px solid var(--border); padding: 0.45rem 0.55rem; text-align: left;
  vertical-align: top; hyphens: auto;
}
.prose th { background: var(--cream); }
.prose code {
  background: var(--cream-dark); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.9em;
  overflow-wrap: anywhere; word-break: break-word; white-space: pre-wrap;
}
.prose pre {
  background: #1a2b2e; color: #e8efe8; padding: 1rem; border-radius: 8px;
  max-width: 100%; overflow-x: auto; white-space: pre; box-sizing: border-box;
}
.prose pre code { white-space: inherit; background: transparent; color: inherit; padding: 0; }
.prose img, .prose video, .prose iframe { max-width: 100%; height: auto; }
.stagger > * { animation: fade-up .45s ease both; }
.stagger > *:nth-child(1) { animation-delay: .05s; }
.stagger > *:nth-child(2) { animation-delay: .12s; }
.stagger > *:nth-child(3) { animation-delay: .19s; }
.stagger > *:nth-child(4) { animation-delay: .26s; }
.stagger > *:nth-child(5) { animation-delay: .33s; }
.stagger > *:nth-child(n+6) { animation-delay: .4s; }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Motion intro */
.intro-motion {
  position: relative; overflow: hidden; border-radius: 10px;
  background: linear-gradient(135deg, #0a5555 0%, #0d6e6e 40%, #1a4a4a 100%);
  color: #fff; padding: 1.75rem 1.4rem; margin-bottom: 1.25rem; min-height: 220px;
}
.intro-motion .im-title { font-family: var(--font-serif); font-size: 1.45rem; margin: 0 0 0.35rem; }
.intro-motion .im-sub { opacity: .85; font-size: 0.92rem; margin-bottom: 1.1rem; }
.intro-beats { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.intro-beats li {
  opacity: 0; transform: translateX(-12px);
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px; padding: 0.45rem 0.7rem; font-weight: 500;
}
.intro-motion.is-playing .intro-beats li { animation: beat-in .5s ease forwards; }
.intro-motion.is-playing .intro-beats li:nth-child(1) { animation-delay: .4s; }
.intro-motion.is-playing .intro-beats li:nth-child(2) { animation-delay: 1.6s; }
.intro-motion.is-playing .intro-beats li:nth-child(3) { animation-delay: 2.8s; }
.intro-motion.is-playing .intro-beats li:nth-child(4) { animation-delay: 4s; }
.intro-motion.is-playing .intro-beats li:nth-child(5) { animation-delay: 5.2s; }
@keyframes beat-in {
  to { opacity: 1; transform: translateX(0); }
}
.intro-fiction {
  margin-top: 1rem; font-size: 0.78rem; opacity: 0; animation: beat-in .5s ease 6.2s forwards;
}
.intro-controls { margin-top: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.intro-controls button {
  background: rgba(255,255,255,.95); color: var(--teal-dark); border: 0;
  border-radius: 999px; padding: 0.35rem 0.85rem; font-weight: 600; cursor: pointer; font-size: 0.85rem;
}
.intro-orb {
  position: absolute; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(196,92,38,.35), transparent 70%);
  right: -40px; top: -40px; animation: orb 8s ease-in-out infinite;
  pointer-events: none;
}
@keyframes orb {
  0%, 100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(-20px, 30px) scale(1.15); }
}

/* Workflow animation */
.wf-board {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: stretch; margin: 1rem 0 0.5rem;
}
.wf-stage {
  flex: 1 1 110px; background: var(--cream); border: 2px solid var(--border);
  border-radius: 10px; padding: 0.75rem 0.65rem; text-align: center;
  opacity: .35; transform: scale(.96); transition: all .35s ease;
}
.wf-stage.is-on { opacity: 1; transform: scale(1); border-color: var(--teal); background: var(--teal-soft); }
.wf-stage.is-done { opacity: 1; border-color: #7ab5b5; }
.wf-stage .wf-label { font-weight: 700; color: var(--teal-dark); display: block; }
.wf-stage .wf-detail { font-size: 0.78rem; color: var(--ink-muted); }
.wf-arrow { align-self: center; color: var(--teal); font-weight: 700; display: none; }
@media (min-width: 700px) {
  .wf-arrow { display: block; }
}
.wf-actions { margin-top: 0.75rem; }

/* Quiz */
.quiz-q { margin-bottom: 1.25rem; }
.quiz-q .q-prompt { font-weight: 600; margin-bottom: 0.65rem; }
.quiz-options { display: grid; gap: 0.4rem; }
.quiz-options label {
  display: flex; gap: 0.5rem; align-items: flex-start;
  border: 1px solid var(--border); border-radius: 8px; padding: 0.55rem 0.7rem;
  cursor: pointer; background: var(--cream);
}
.quiz-options label:hover { border-color: var(--teal); }
.quiz-options label.is-correct { border-color: var(--teal); background: var(--teal-soft); }
.quiz-options label.is-wrong { border-color: var(--accent); background: var(--accent-soft); animation: soft-shake .4s ease; }
@keyframes soft-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.quiz-feedback {
  margin-top: 0.55rem; padding: 0.55rem 0.7rem; border-radius: 8px; font-size: 0.92rem;
}
.quiz-feedback.ok { background: var(--teal-soft); color: var(--teal-dark); }
.quiz-feedback.bad { background: var(--accent-soft); color: #7a3514; }
.quiz-feedback .burst { display: inline-block; animation: burst .5s ease; }
@keyframes burst {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}
.short-answer {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.55rem 0.7rem; font: inherit; background: var(--white);
}

/* Nav dock — always visible at bottom of player chrome (not below long cards) */
.player-nav {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.9rem 1.25rem calc(0.9rem + env(safe-area-inset-bottom, 0px));
  background: rgba(247,243,235,.97); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px rgba(26, 43, 46, 0.08);
  z-index: 45;
}
.player-nav .btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.75rem 1.45rem; border-radius: 999px; font-weight: 700; text-decoration: none;
  border: 0; cursor: pointer; font: inherit; font-size: 1rem; min-height: 2.75rem;
}
.player-nav .btn-back { background: var(--white); color: var(--ink); border: 1px solid var(--border); }
.player-nav .btn-continue {
  background: var(--teal); color: #fff;
  box-shadow: 0 4px 14px rgba(13, 110, 110, 0.35);
  min-width: 9.5rem;
}
.player-nav .btn-continue:hover { background: var(--teal-dark); }
.player-nav .btn-continue::after { content: " →"; font-weight: 700; }
.player-nav .btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* Unlock */
.unlock-card { max-width: 28rem; margin: 2rem auto; }
.unlock-card input[type=text] {
  width: 100%; font: inherit; padding: 0.7rem 0.85rem; border-radius: 8px;
  border: 1px solid var(--border); margin: 0.75rem 0;
}
.unlock-success {
  text-align: center; padding: 1.5rem; animation: step-in .5s ease;
}
.unlock-success .lock-open {
  font-size: 2.5rem; display: inline-block; animation: burst .6s ease;
}

/* Library */
.fiction-banner {
  background: var(--accent-soft); border: 1px solid #e0c4b0; border-radius: 8px;
  padding: 0.75rem 1rem; margin: 1rem 0 1.25rem; font-size: 0.92rem;
}
.lib-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: 1.25rem; }
.lib-card {
  display: block; background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; text-decoration: none; color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
.lib-card:hover { border-color: var(--teal); box-shadow: var(--shadow); }
.lib-card.is-locked { opacity: .55; pointer-events: none; position: relative; }
.lib-card.is-locked::after {
  content: "Locked — unlock a package that includes this file";
  display: block; font-size: 0.75rem; color: var(--accent); margin-top: 0.4rem;
}
.library-article { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.csv-pre { overflow-x: auto; font-size: 0.8rem; }
.print-hint { margin-top: 1.5rem; }
.btn-print {
  background: var(--teal); color: #fff; border: 0; border-radius: 999px;
  padding: 0.5rem 1rem; font-weight: 600; cursor: pointer;
}
.gate-banner {
  background: var(--accent-soft); border: 1px solid #e0c4b0; border-radius: 10px;
  padding: 1.25rem; margin: 1rem 0;
}
.hub-resume {
  background: var(--teal-soft); border: 1px solid #b7dede; border-radius: 10px;
  padding: 1rem 1.15rem; margin: 1rem 0 1.5rem; display: flex; flex-wrap: wrap;
  align-items: center; justify-content: space-between; gap: 0.75rem;
}
.mod-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.mod-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; display: flex; flex-direction: column; gap: 0.35rem;
}
.mod-card.is-locked { opacity: .7; }
.badge-row { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.badge-row span {
  font-size: 0.68rem; font-weight: 650; text-transform: uppercase; letter-spacing: .03em;
  background: var(--cream-dark); color: var(--ink-muted); padding: 0.15rem 0.4rem; border-radius: 4px;
}
.site-header .nav a[href*="unlock"] { font-weight: 600; }

/* Atmosphere on learner (no live video class, quiet) */
.learn-body {
  background-color: var(--cream);
  background-image:
    linear-gradient(rgba(247,243,235,0.93), rgba(247,243,235,0.93)),
    url("../assets/motif-path.svg"),
    url("../assets/motif-grid.svg");
  background-size: auto, min(800px, 100vw) auto, 120px 120px;
  background-position: 0 0, right -60px bottom -40px, 0 0;
  background-repeat: no-repeat, no-repeat, repeat;
}
.narration-bar {
  background-image: url("../assets/motif-wave.svg");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 100px 20px;
}

/* Always-visible step counter above lesson card */
.step-count-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin: 0 0 0.85rem; padding: 0.55rem 0.85rem;
  background: var(--teal-soft); border: 1px solid #b7dede; border-radius: 8px;
  font-size: 0.9rem; font-weight: 650; color: var(--teal-dark);
}
.step-count-banner .hint { font-weight: 500; font-size: 0.82rem; color: var(--ink-muted); }


.narration-bar .narr-voice-badge {
  display: inline-flex; align-items: center;
  font-size: 0.78rem; font-weight: 650; color: var(--teal-dark);
  background: #fff; border: 1px solid #9bcbcb; border-radius: 999px;
  padding: 0.28rem 0.7rem; white-space: nowrap;
}
.narration-bar .narr-voice-badge[hidden] { display: none !important; }
.narration-bar .narr-voice-label {
  display: inline-flex; align-items: center; gap: 0.35rem;
  flex: 1 1 12rem; min-width: 10rem;
}
.narration-bar .narr-voice-label[hidden] { display: none !important; }
.narration-bar .narr-voice-label select#narr-voice {
  max-width: min(55vw, 16rem); min-width: 8rem; font-size: 0.78rem;
}
@media (max-width: 640px) {
  .narration-bar .narr-voice-label { flex: 1 1 100%; }
  .narration-bar .narr-voice-label select#narr-voice { max-width: 100%; width: 100%; }
}


.narration-bar .narr-unavailable {
  flex: 1 1 100%;
  color: #8a5a00;
  background: #fff6e5;
  border: 1px solid #f0d9a8;
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  margin-top: 0.25rem;
}
.narration-bar .narr-unavailable[hidden] { display: none !important; }
.narration-bar .narr-mute-legacy { opacity: 0.7; font-size: 0.85rem; }


/* Primary narration transport — always visible (incl. small screens) */
.narration-bar .narr-controls-primary,
.narration-bar button#narr-play,
.narration-bar button#narr-pause,
.narration-bar button#narr-stop,
.narration-bar button#narr-replay {
  flex: 0 0 auto;
  white-space: nowrap;
}
.narration-bar button#narr-replay {
  font-weight: 650;
  border-color: var(--teal);
  color: var(--teal-dark);
  background: #fff;
}
.narration-bar button#narr-replay:hover {
  background: var(--teal-soft);
}
@media (max-width: 640px) {
  .narration-bar {
    row-gap: 0.45rem;
  }
  /* Keep Play/Pause/Stop/Replay on first row; fold secondary prefs below */
  .narration-bar button#narr-play,
  .narration-bar button#narr-pause,
  .narration-bar button#narr-stop,
  .narration-bar button#narr-replay {
    flex: 0 0 auto;
  }
  .narration-bar > label:not(.narr-voice-label) {
    flex: 1 1 auto;
  }
}
