/* AIPC — Listening Lab
   The audio learning environment. Built to Design Mandate v3: every
   element justifies its presence, materials are restrained, and the
   motion is a signature rather than decoration.

   Depends on css/brand.css for tokens. Nothing here redefines a colour
   that brand.css already owns — the lab is the same institution, in a
   focused room.

   Reduced motion is treated as a first-class rendering mode, not a
   fallback: every transition below has an explicit still state, because
   a learner who needs motion off is often the same learner who most
   needs the transcript to stay legible. */

.lab {
  --lab-surface:      #FFFFFF;
  --lab-sunken:       #F2EEE4;
  --lab-cue-idle:     var(--ink-soft);
  --lab-cue-active:   var(--ink);
  --lab-rail:         rgba(20, 38, 74, .10);
  --lab-wave:         rgba(39, 75, 133, .30);
  --lab-wave-played:  var(--gold);
  --lab-radius:       14px;
  --lab-radius-sm:    9px;
  background: var(--ivory);
  min-height: 100vh;
}

/* ---------- Masthead ------------------------------------------------ */
.lab-head {
  background: linear-gradient(160deg, var(--royal) 0%, var(--royal-deep) 100%);
  color: var(--ivory);
  padding: 2.4rem 0 2.9rem;
  position: relative;
  overflow: hidden;
}
/* A single hairline of gold. The only ornament on the page. */
.lab-head::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--gold-gradient);
  opacity: .85;
}
.lab-head__wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 1.4rem; }
.lab-eyebrow {
  font: 600 .74rem/1 var(--font-body);
  letter-spacing: .17em; text-transform: uppercase;
  color: var(--gold-bright); margin: 0 0 .7rem;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
}
.lab-eyebrow span[data-sep]::before { content: "·"; margin-right: .6rem; opacity: .5; }
.lab-title {
  font: 700 clamp(1.7rem, 3.4vw, 2.6rem)/1.14 var(--font-display);
  margin: 0 0 .55rem; letter-spacing: -.01em;
}
.lab-sub { margin: 0; color: rgba(247,244,236,.76); font-size: .95rem; max-width: 62ch; }

/* ---------- Layout -------------------------------------------------- */
.lab-body {
  max-width: var(--wrap); margin: 0 auto; padding: 1.9rem 1.4rem 5rem;
  display: grid; gap: 1.35rem;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  align-items: start;
}
@media (max-width: 900px) { .lab-body { grid-template-columns: 1fr; } }

.lab-card {
  background: var(--lab-surface);
  border: 1px solid var(--line);
  border-radius: var(--lab-radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.lab-card__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: 1.05rem 1.25rem .8rem;
  border-bottom: 1px solid var(--line);
}
.lab-card__title {
  font: 700 1.03rem/1.2 var(--font-display); margin: 0; color: var(--royal);
}
.lab-card__meta { font-size: .76rem; color: var(--ink-soft); letter-spacing: .04em; }
.lab-card__body { padding: 1.15rem 1.25rem 1.3rem; }

/* ---------- Status banner ------------------------------------------- */
/* Shown when a script exists but the studio recording does not. This is
   a real product state, not an error, and it is styled as information. */
.lab-status {
  display: flex; gap: .85rem; align-items: flex-start;
  padding: .9rem 1.1rem; border-radius: var(--lab-radius-sm);
  background: rgba(199,162,74,.10);
  border: 1px solid var(--line);
  margin: 0 0 1.15rem;
}
.lab-status__dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--gold);
  margin-top: .42rem; flex: none;
}
.lab-status__text { font-size: .87rem; color: var(--ink); line-height: 1.55; margin: 0; }
.lab-status__text strong { color: var(--royal); }

/* ---------- Waveform ------------------------------------------------ */
.wave {
  position: relative;
  height: 84px;
  border-radius: var(--lab-radius-sm);
  background: var(--lab-sunken);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--line);
}
.wave[aria-disabled="true"] { cursor: default; opacity: .55; }
.wave canvas { display: block; width: 100%; height: 100%; }
.wave__playhead {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--red); pointer-events: none;
  transform: translateX(-1px);
  box-shadow: 0 0 10px rgba(163,38,56,.55);
}
/* A-B repeat region */
.wave__region {
  position: absolute; top: 0; bottom: 0;
  background: rgba(199,162,74,.20);
  border-left: 2px solid var(--gold);
  border-right: 2px solid var(--gold);
  pointer-events: none;
}

/* ---------- Transport ----------------------------------------------- */
.transport {
  display: flex; align-items: center; gap: .55rem; flex-wrap: wrap;
  margin-top: .95rem;
}
.tbtn {
  appearance: none; border: 1px solid var(--line); background: var(--paper);
  color: var(--royal); border-radius: 999px; cursor: pointer;
  font: 600 .82rem/1 var(--font-body);
  padding: .58rem .9rem; display: inline-flex; align-items: center; gap: .4rem;
  transition: background var(--dur-fast) var(--ease-premium),
              border-color var(--dur-fast) var(--ease-premium),
              transform var(--dur-fast) var(--ease-premium);
}
.tbtn:hover:not(:disabled) { background: #fff; border-color: var(--gold); transform: translateY(-1px); }
.tbtn:active:not(:disabled) { transform: translateY(0); }
.tbtn:disabled { opacity: .45; cursor: not-allowed; }
.tbtn:focus-visible { outline: 3px solid var(--royal-bright); outline-offset: 2px; }
.tbtn--primary {
  background: var(--royal); color: var(--ivory); border-color: var(--royal);
  min-width: 106px; justify-content: center;
}
.tbtn--primary:hover:not(:disabled) { background: var(--royal-bright); border-color: var(--royal-bright); }
.tbtn--rec { background: var(--red); border-color: var(--red); color: #fff; }
.tbtn--rec:hover:not(:disabled) { background: var(--red-bright); border-color: var(--red-bright); }
.tbtn[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: var(--royal-deep); }

.transport__time {
  font: 600 .8rem/1 var(--font-body); color: var(--ink-soft);
  font-variant-numeric: tabular-nums; margin-left: auto;
}

/* Speed control — a real select, restyled, so keyboard and screen
   readers get native behaviour rather than a div pretending. */
.speed { display: inline-flex; align-items: center; gap: .4rem; }
.speed label { font: 600 .76rem/1 var(--font-body); color: var(--ink-soft); }
.speed select {
  font: 600 .8rem/1 var(--font-body); color: var(--royal);
  border: 1px solid var(--line); background: var(--paper);
  border-radius: 999px; padding: .5rem .7rem; cursor: pointer;
}
.speed select:focus-visible { outline: 3px solid var(--royal-bright); outline-offset: 2px; }

/* ---------- Transcript ---------------------------------------------- */
.cues { list-style: none; margin: 0; padding: 0; }
.cue {
  display: grid; grid-template-columns: auto 1fr auto; gap: .5rem .85rem;
  align-items: start;
  padding: .7rem .8rem; border-radius: var(--lab-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-premium),
              border-color var(--dur-fast) var(--ease-premium);
}
.cue + .cue { margin-top: .18rem; }
.cue:hover { background: var(--lab-sunken); }
.cue:focus-visible { outline: 3px solid var(--royal-bright); outline-offset: 1px; }
.cue__speaker {
  font: 700 .7rem/1.5 var(--font-body); letter-spacing: .08em; text-transform: uppercase;
  color: var(--royal-bright); white-space: nowrap; padding-top: .12rem;
}
.cue__text { font-size: .94rem; line-height: 1.62; color: var(--lab-cue-idle); }
.cue__mark {
  border: 0; background: none; cursor: pointer; padding: .1rem .25rem;
  color: var(--lab-rail); font-size: .95rem; line-height: 1;
  transition: color var(--dur-fast) var(--ease-premium), transform var(--dur-fast) var(--ease-premium);
}
.cue__mark:hover { color: var(--gold); transform: scale(1.15); }
.cue__mark[aria-pressed="true"] { color: var(--gold); }
.cue__mark:focus-visible { outline: 2px solid var(--royal-bright); outline-offset: 2px; border-radius: 4px; }

/* The signature interaction: the active line lifts, warms, and gains a
   gold rule on its leading edge. One state change, three coordinated
   properties, all on the same easing curve. */
.cue.is-active {
  background: var(--paper);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}
.cue.is-active .cue__text { color: var(--lab-cue-active); font-weight: 500; }
.cue.is-active .cue__speaker { color: var(--royal); }
.cue.is-active::before {
  content: ""; position: absolute; /* placed by grid below */
}
.cue { position: relative; }
.cue.is-active { padding-left: 1.05rem; }
.cue.is-active::before {
  left: .35rem; top: .62rem; bottom: .62rem; width: 3px;
  border-radius: 2px; background: var(--gold-gradient);
}

/* ---------- Notes & bookmarks --------------------------------------- */
.notes textarea {
  width: 100%; min-height: 116px; resize: vertical;
  font: 400 .9rem/1.6 var(--font-body); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--lab-radius-sm);
  padding: .75rem .85rem; background: var(--paper);
}
.notes textarea:focus-visible { outline: 3px solid var(--royal-bright); outline-offset: 1px; }
.notes__row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-top: .6rem; }
.notes__saved { font-size: .78rem; color: var(--ink-soft); }

.marks { list-style: none; margin: .2rem 0 0; padding: 0; }
.marks li {
  display: flex; align-items: center; gap: .6rem;
  padding: .48rem .2rem; border-bottom: 1px dashed var(--lab-rail);
  font-size: .86rem;
}
.marks li:last-child { border-bottom: 0; }
.marks button {
  border: 0; background: none; color: var(--royal-bright); cursor: pointer;
  font: 600 .8rem/1 var(--font-body); padding: .2rem .3rem; text-align: left; flex: 1;
}
.marks button:hover { text-decoration: underline; }
.marks .drop { color: var(--ink-soft); flex: none; }

/* ---------- Pronunciation targets ----------------------------------- */
.target { padding: .85rem 0; border-bottom: 1px solid var(--lab-rail); }
.target:last-child { border-bottom: 0; padding-bottom: 0; }
.target__focus {
  display: inline-block; font: 700 .66rem/1 var(--font-body);
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--royal); background: rgba(199,162,74,.16);
  border-radius: 999px; padding: .32rem .6rem; margin-bottom: .5rem;
}
.target__t { font: 700 .98rem/1.4 var(--font-display); color: var(--royal-deep); margin: 0 0 .3rem; }
.target__e { font-size: .9rem; color: var(--ink); margin: 0 0 .35rem; font-style: italic; }
.target__g { font-size: .85rem; color: var(--ink-soft); line-height: 1.6; margin: 0; }

/* ---------- Recorder ------------------------------------------------ */
.rec { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.rec__meter {
  flex: 1; min-width: 130px; height: 8px; border-radius: 999px;
  background: var(--lab-sunken); overflow: hidden; border: 1px solid var(--line);
}
.rec__meter i {
  display: block; height: 100%; width: 0%;
  background: var(--gold-gradient);
  transition: width 90ms linear;
}
.rec__time { font: 600 .82rem/1 var(--font-body); font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.takes { list-style: none; margin: .9rem 0 0; padding: 0; }
.takes li {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  padding: .6rem 0; border-top: 1px solid var(--lab-rail); font-size: .85rem;
}
.takes .n { font-weight: 700; color: var(--royal); }
.takes audio { height: 32px; flex: 1; min-width: 180px; }
.fb {
  width: 100%; margin-top: .4rem; padding: .6rem .75rem;
  background: rgba(39,75,133,.07); border-radius: var(--lab-radius-sm);
  font-size: .84rem; color: var(--ink); line-height: 1.55;
}
.fb .who { font-weight: 700; color: var(--royal); }
.fb .scores { display: flex; gap: .8rem; flex-wrap: wrap; margin-top: .35rem; font-size: .78rem; color: var(--ink-soft); }

/* ---------- Comprehension ------------------------------------------- */
.q { padding: .95rem 0; border-bottom: 1px solid var(--lab-rail); }
.q:last-of-type { border-bottom: 0; }
.q__p { font-weight: 600; font-size: .93rem; color: var(--ink); margin: 0 0 .6rem; line-height: 1.5; }
.q__opts { display: grid; gap: .35rem; }
.opt {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--lab-radius-sm);
  cursor: pointer; font-size: .89rem; background: var(--paper);
  transition: background var(--dur-fast) var(--ease-premium), border-color var(--dur-fast) var(--ease-premium);
}
.opt:hover { background: #fff; border-color: var(--gold); }
.opt input { margin-top: .2rem; accent-color: var(--royal); }
.opt:focus-within { outline: 3px solid var(--royal-bright); outline-offset: 1px; }
.q__replay {
  border: 0; background: none; color: var(--royal-bright); cursor: pointer;
  font: 600 .78rem/1 var(--font-body); padding: .35rem 0 0; text-decoration: underline;
}
.q.is-right .opt input:checked + span { color: #1B6B3A; font-weight: 600; }
.q.is-wrong .opt input:checked + span { color: var(--red); font-weight: 600; }

.result {
  margin-top: 1rem; padding: .9rem 1.05rem; border-radius: var(--lab-radius-sm);
  background: var(--lab-sunken); border: 1px solid var(--line);
  font-size: .9rem; color: var(--ink);
}
.result strong { color: var(--royal); }

/* ---------- Progress ------------------------------------------------ */
.dims { display: grid; gap: .7rem; }
.dim { display: grid; grid-template-columns: 8.2rem 1fr auto; gap: .7rem; align-items: center; font-size: .84rem; }
.dim__n { color: var(--ink-soft); }
.dim__bar { height: 7px; border-radius: 999px; background: var(--lab-sunken); overflow: hidden; border: 1px solid var(--line); }
.dim__bar i { display: block; height: 100%; background: var(--gold-gradient); width: 0; transition: width var(--dur-slow) var(--ease-premium); }
.dim__v { font-weight: 700; color: var(--royal); font-variant-numeric: tabular-nums; }
.dim--weak .dim__n { color: var(--red); font-weight: 600; }
.dim--none .dim__v { color: var(--ink-soft); font-weight: 400; }

/* ---------- Utility -------------------------------------------------- */
.lab-note { font-size: .82rem; color: var(--ink-soft); line-height: 1.6; margin: .8rem 0 0; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.lab-offline {
  display: none; align-items: center; gap: .5rem;
  font-size: .8rem; color: var(--red); font-weight: 600;
}
body.is-offline .lab-offline { display: inline-flex; }

/* ---------- Motion --------------------------------------------------- */
/* The signature entrance: cards settle upward on load, staggered. */
@media (prefers-reduced-motion: no-preference) {
  .lab-card { animation: labRise var(--dur-slow) var(--ease-premium) both; }
  .lab-card:nth-child(2) { animation-delay: .06s; }
  .lab-card:nth-child(3) { animation-delay: .12s; }
  .lab-card:nth-child(4) { animation-delay: .18s; }
  @keyframes labRise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
  /* Not "animations off" — an explicit still state. Every element that
     animates above has a defined resting appearance here, so nothing
     depends on a transition having run. */
  .lab-card { animation: none !important; opacity: 1; transform: none; }
  .tbtn, .cue, .opt, .dim__bar i, .rec__meter i, .cue__mark {
    transition: none !important;
  }
  .tbtn:hover:not(:disabled) { transform: none; }
  .cue__mark:hover { transform: none; }
}

/* ---------- Loading states ------------------------------------------ */
/* A skeleton that matches the shape of what is arriving, not a spinner.
   A spinner tells a learner to wait; a skeleton tells them what they are
   waiting for, and makes the transition to real content feel like the
   page settling rather than swapping. */
.lab-skel {
  border-radius: var(--lab-radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(100deg, transparent 20%, rgba(255,255,255,.75) 40%, transparent 60%),
    var(--lab-sunken);
  background-size: 220% 100%, auto;
  background-position: 120% 0, 0 0;
}
@media (prefers-reduced-motion: no-preference) {
  .lab-skel { animation: labSheen 1.5s var(--ease-premium) infinite; }
  @keyframes labSheen { to { background-position: -60% 0, 0 0; } }
}
@media (prefers-reduced-motion: reduce) {
  /* Still, but still legible as a placeholder — not an empty box. */
  .lab-skel { animation: none; background: var(--lab-sunken); }
}
.cue-skel { height: 42px; border-radius: var(--lab-radius-sm); margin-bottom: .3rem; }

/* Content arriving replaces skeletons with a settle, not a flash. */
@media (prefers-reduced-motion: no-preference) {
  .lab-in { animation: labIn var(--dur-med) var(--ease-premium) both; }
  @keyframes labIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) { .lab-in { animation: none; } }

/* ---------- Download management ------------------------------------- */
.dl {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin-top: .85rem; padding-top: .85rem; border-top: 1px solid var(--lab-rail);
}
.dl__state { font-size: .8rem; color: var(--ink-soft); }
.dl__state[data-on="true"] { color: #1B6B3A; font-weight: 600; }

/* ---------- Listening progress -------------------------------------- */
.prog { display: grid; gap: .45rem; }
.prog__row {
  display: grid; grid-template-columns: 2.1rem 1fr auto; gap: .6rem; align-items: center;
  font-size: .83rem;
}
.prog__n { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.prog__bar { height: 6px; border-radius: 999px; background: var(--lab-sunken); overflow: hidden; border: 1px solid var(--line); }
.prog__bar i { display: block; height: 100%; background: var(--gold-gradient); width: 0; transition: width var(--dur-slow) var(--ease-premium); }
.prog__v { font-weight: 700; color: var(--royal); font-variant-numeric: tabular-nums; min-width: 3.1rem; text-align: right; }
.prog__v[data-none="true"] { color: var(--ink-soft); font-weight: 400; }
@media (prefers-reduced-motion: reduce) { .prog__bar i { transition: none; } }

.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-bottom: .9rem;
}
.summary div {
  background: var(--lab-sunken); border: 1px solid var(--line);
  border-radius: var(--lab-radius-sm); padding: .7rem .8rem; text-align: center;
}
.summary b { display: block; font: 700 1.25rem/1.1 var(--font-display); color: var(--royal); }
.summary span { font-size: .72rem; color: var(--ink-soft); letter-spacing: .04em; }
@media (max-width: 460px) { .summary { grid-template-columns: 1fr; } }

/* ---------------- Auth gate ----------------
   Inserted by js/portal-guard.js while a Clerk session is being
   checked, and only on real deployments — with no publishable key
   configured this markup is never created. Mirrors the rules in
   dashboard.css so the Lab and the Student Portal show the same gate;
   these two pages load brand.css + listening-lab.css only, so the
   rules have to exist here too. Uses brand.css's btn-spin keyframe. */
.auth-gate {
  position: fixed; inset: 0; z-index: 300; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; background: var(--paper);
}
.auth-gate__spinner {
  width: 34px; height: 34px; border: 3px solid rgba(20,38,74,.15); border-top-color: var(--royal-deep);
  border-radius: 50%; animation: btn-spin .8s linear infinite;
}
.auth-gate__text { font-size: .86rem; color: var(--ink-soft); }
@media (prefers-reduced-motion: reduce) { .auth-gate__spinner { animation-duration: 1.6s; } }

/* ---------------------------------------------------------------------
   THE COLLEGE, INSIDE THE APPLICATION
   ---------------------------------------------------------------------
   The audit found six application pages with no link back to the
   College at all. A learner crossing from the marketing site into the
   Listening Lab lost the institution entirely: no crest, no wordmark, no
   way back short of the browser's back button.

   That is a continuity failure rather than a missing link. The pages a
   learner spends the most time in were the only pages that did not say
   whose they were — so the College's name appeared everywhere except
   where the actual teaching happens.

   Matches .vfy-crest on the verification pages deliberately: one mark,
   one behaviour, wherever a person is standing. */
.app-crest {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  min-height: 44px;
  color: inherit;
  text-decoration: none;
  font: 700 .9rem/1.15 var(--font-body, Inter, sans-serif);
  letter-spacing: .01em;
  margin-bottom: 1.1rem;
  opacity: .92;
  transition: opacity var(--dur-fast, .18s) var(--ease-premium, ease);
}
.app-crest:hover { opacity: 1; }
.app-crest:focus-visible {
  outline: 2px solid var(--gold, #C7A24A);
  outline-offset: 4px;
  border-radius: 4px;
}
.app-crest small {
  display: block;
  font-weight: 400;
  opacity: .7;
  font-size: .74rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
@media (max-width: 560px) { .app-crest { margin-bottom: .8rem; } }
