/* Loop — application shell and components.
 *
 * Implements the Loop style guide (docs/loop-ux-style-guide.md) for a server-rendered Django app:
 * the header/nav shell, the responsive content grid, and the existing page components. The guide's
 * *colour* tokens (accent + semantic neutrals) and the font stack come from brand.css and are never
 * defined or hard-coded here; this file only consumes them.
 *
 * A small, clearly-marked set of *functional* tokens (danger/warning) lives here because the guide's
 * table defines no error or notice colours and warns that decorative dividers are not sufficient for
 * essential states.
 *
 * No build step, no framework.
 */

/* --- Tokens (guide set) ------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* The guide's colour tokens (--bg, --surface, --text, --muted, --line, --selected, --inverse,
     --focus, --accent) and --font-sans are the brand colour scheme: they live in brand.css. */

  /* Functional extensions (not in the guide's token table). */
  --danger: #b00020;
  --warn-bg: #fff4d6;
  --warn-line: #c98a00;
  /* Success: the purchase-confirmation checkmark ("good to go"). The guide defines no success colour. */
  --success: #1f8a4c;
  --success-on: #ffffff;
  /* Magic dust (purchase-confirmation celebration) — decorative only. */
  --magic: #e8a400;

  /* Shape + layout (guide values). */
  --radius-panel: 12px;
  --radius-chip: 8px;
  --radius-pill: 999px;
  --page-max: 1650px;
  --pad: 34px;
  --gap: 24px;
  /* Height of the sticky site header; measured in JS so the sticky action bar clears it. */
  --header-h: 72px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --danger: #ff7a8a;
  --warn-bg: #2e2712;
  --warn-line: #d6a53a;
  --success: #35c07a;
  --success-on: #06210f;
  --magic: #ffd76a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;

    --danger: #ff7a8a;
    --warn-bg: #2e2712;
    --warn-line: #d6a53a;
    --success: #35c07a;
    --success-on: #06210f;
    --magic: #ffd76a;
  }
}

/* --- Base --------------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* The page itself must never scroll sideways; chip rows may. */
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

/* Long words, emails, and titles must wrap rather than force a horizontal scrollbar. */
h1, h2, h3, h4, p, li, dd, dt, td, th, a, code {
  overflow-wrap: anywhere;
}

img, video, iframe, svg {
  max-width: 100%;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--selected);
  color: var(--inverse);
  border-radius: var(--radius-chip);
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 8px;
}

/* --- Header ------------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.site-header__row {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 8px var(--pad);
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  /* The brand link is a real control: >= 44px in both axes. The negative inline margin keeps the
     logo visually flush with the header padding while the padding provides the hit area. */
  min-height: 44px;
  min-width: 0;
  margin-inline: -6px;
  padding: 8px 6px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}

/* The logo sits to the left of the platform name. 44px keeps the badge legible and the link a real
   target; the height cap stops the header jumping. Its bottom edge is not a sensible baseline, so
   the logo variant centres the name instead. */
.wordmark--logo {
  align-items: center;
}

.wordmark__logo {
  display: block;
  height: 44px;
  width: auto;
}

/* The platform name as text: next to the logo when there is one, and the whole brand when there is
   not. A long name truncates rather than breaking the header. */
.wordmark__mark {
  overflow: hidden;
  text-overflow: ellipsis;
}

.wordmark__tagline {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

/* The provisional-brand note: a small, honest, editorial label. */
.brand-flag {
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.account {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account__email {
  color: var(--muted);
  font-size: 13px;
}

/* --- Search (placeholder) ------------------------------------------------------------------ */
.search {
  flex: 1 1 auto;
  max-width: 560px;
  min-width: 0;
}

.search__input {
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}

.search__input::placeholder {
  color: var(--muted);
}

.search__input:disabled {
  cursor: not-allowed;
}

/* search-as-you-type: while a new query is in flight the previous results stay in place, dimmed, so the
 * page does not flash empty and the layout does not jump. */
#results[aria-busy="true"] {
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

/* `hidden` must beat component `display` rules: author styles win over the user-agent sheet, so any
 * `button { display: inline-flex }` or `.x .y { display: grid }` silently defeats the `hidden`
 * attribute. One `!important` guard fixes the whole class of bug instead of a bespoke `[hidden]` rule
 * per component — a plain `[hidden]` selector is *not* enough once a rule has two class selectors. */
[hidden] {
  display: none !important;
}

/* --- Buttons ------------------------------------------------------------------------------- */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: var(--accent);
}

.button--primary {
  background: var(--selected);
  color: var(--inverse);
  border-color: var(--selected);
}

#theme-toggle[aria-pressed="true"] {
  background: var(--selected);
  color: var(--inverse);
  border-color: var(--selected);
}

/* --- Shell layout -------------------------------------------------------------------------- */
.site-body {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: var(--gap);
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--pad);
}

/* --- Footer and legal pages (privacy-policy) ------------------------------------------------ */
/* One muted line with the privacy link, on every page. It lives inside .site-body, which is a
   two-column grid, so it spans both columns and keeps the shell's own width and padding. */
.site-footer {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.site-footer p {
  margin: 0;
}

/* A legal page is prose: one readable column, generous line height, and no JavaScript. */
.legal {
  max-width: 46rem;
}

.legal__updated {
  margin-top: 32px;
}

.site-nav {
  position: sticky;
  top: 76px;
  align-self: start;
}

.site-nav__list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-chip);
  text-decoration: none;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--surface);
}

.nav-link[aria-current="page"] {
  background: var(--selected);
  color: var(--inverse);
}

.nav-link[aria-disabled="true"] {
  color: var(--muted);
  cursor: default;
}

.chip-soon {
  margin-left: auto;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  border-radius: var(--radius-chip);
  white-space: nowrap;
}

.site-main {
  min-width: 0;
}

/* --- Page headings ------------------------------------------------------------------------- */
.page-head {
  margin: 0 0 24px;
}

.page-head h1 {
  margin: 0 0 4px;
  font-size: 36px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.page-head .muted {
  margin: 0;
}

/* --- Cards and grids ----------------------------------------------------------------------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Infinite scroll: the sentinel/“Load more” row at the end of the feed. */
.feed-more {
  display: flex;
  justify-content: center;
  padding: 20px 0 8px;
}

.feed-more__link {
  display: inline-block;
  padding: 10px 18px;
  border: 1px solid var(--border, #ccc);
  border-radius: var(--radius-pill, 999px);
  color: var(--text, currentColor);
  text-decoration: none;
}

.course-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.course-card__link {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-decoration: none;
}

.cover {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--surface);
  border-radius: var(--radius-panel);
}

/* A <picture> only selects a source; `display: contents` keeps the <img> in the same layout box. */
picture {
  display: contents;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
}

.course-card .muted {
  margin: 0;
}

/* Surface panels: no heavy borders or shadows; the content carries the hierarchy. */
.card,
.panel {
  background: var(--surface);
  border-radius: var(--radius-panel);
  padding: 20px;
  margin: 0 0 20px;
}

.card > :first-child,
.panel > :first-child {
  margin-top: 0;
}

.card > :last-child,
.panel > :last-child {
  margin-bottom: 0;
}

.notice {
  margin: 0 0 20px;
  padding: 16px 20px;
  background: var(--warn-bg);
  border-left: 4px solid var(--warn-line);
  border-radius: var(--radius-chip);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

/* --- Rich content (sanitised Markdown descriptions) ---------------------------------------- */
.description {
  margin: 0 0 20px;
}

.description > :first-child {
  margin-top: 0;
}

.description > :last-child {
  margin-bottom: 0;
}

.description h1, .description h2, .description h3,
.description h4, .description h5, .description h6 {
  margin: 20px 0 8px;
  line-height: 1.25;
}

.description ul, .description ol {
  padding-left: 22px;
}

.description blockquote {
  margin: 8px 0;
  padding-left: 12px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.description code {
  padding: 2px 5px;
  font-size: 0.9em;
  background: var(--surface);
  border-radius: 4px;
}

.description pre {
  padding: 12px;
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius-chip);
}

.description pre > code {
  padding: 0;
  background: none;
}

.description table {
  border-collapse: collapse;
  margin: 8px 0;
}

.description th, .description td {
  padding: 4px 10px;
  border: 1px solid var(--line);
}

.description a {
  color: var(--accent);
}

/* --- Lesson lists (course playlist) -------------------------------------------------------- */
.lessons {
  margin: 0;
  padding: 0;
  list-style: none;
}

.lessons li {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.lessons li:last-child {
  border-bottom: 0;
}

.lesson-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.lesson-link {
  font-weight: 600;
  text-decoration: none;
}

.lesson-link:hover {
  text-decoration: underline;
}

.lesson-meta {
  flex-basis: 100%;
}

.lesson-state {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.progress-strip {
  height: 6px;
  margin: 8px 0 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}

.progress-strip > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

/* --- Browse feed (topic chips + lesson cards) ---------------------------------------------- */
.chips {
  display: flex;
  gap: 9px;
  margin: 0 0 20px;
  padding: 2px 2px 6px;
  /* The chip row may scroll horizontally; the page itself must not. */
  overflow-x: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  flex: none;
  min-height: 44px;
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-chip);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.chip--active {
  background: var(--selected);
  border-color: var(--selected);
  color: var(--inverse);
  font-weight: 600;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 32px 0 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.lesson-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lesson-card__link {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-decoration: none;
}

.lesson-card .meta {
  margin: 0;
}

.thumb-wrap {
  position: relative;
  display: block;
}

.badge {
  position: absolute;
  right: 9px;
  bottom: 9px;
  padding: 2px 6px;
  background: rgba(21, 21, 21, 0.87);
  color: #ffffff;
  border-radius: 4px;
  font-size: 11px;
}

.thumb-wrap .progress-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.35);
}

.empty {
  padding: 40px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-panel);
  color: var(--muted);
}

/* --- Learner actions (Watch later + reactions) --------------------------------------------- */
.actions {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  /* Sit immediately under the video and stay reachable while it plays. */
  position: sticky;
  top: var(--header-h, 72px);
  z-index: 15;
  margin: 0 0 16px;
  padding: 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.icon-bookmark {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.action-btn[aria-pressed="true"] .icon-bookmark {
  fill: currentColor;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.action-btn[aria-pressed="true"] {
  background: var(--selected);
  border-color: var(--selected);
  color: var(--inverse);
  font-weight: 600;
}

/* watch-later-count: the aggregate caption sits under the save control, centred on it. */
.action-save {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.action-save__meta {
  font-size: 12px;
  line-height: 1.2;
}

.card-actions {
  display: flex;
  gap: 8px;
}

/* --- Forms --------------------------------------------------------------------------------- */
label {
  display: block;
  margin-top: 16px;
  font-weight: 600;
}

input[type="email"],
input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  margin-top: 4px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-chip);
}

.errorlist {
  padding-left: 0;
  color: var(--danger);
  list-style: none;
}

/* --- Player and viewing state (kept from the MVP slices) ----------------------------------- */
.player-frame {
  position: relative;
  padding-top: 56.25%;
  margin: 16px 0;
  overflow: hidden;
  background: #000;
  border-radius: var(--radius-panel);
}

.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.resume-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
}

.resume-overlay .resume-message {
  margin: 0;
  font-size: 17px;
}

.resume-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.save-indicator {
  min-height: 20px;
  margin: 8px 0 0;
}

.save-indicator[data-state="failed"] {
  color: var(--danger);
}

.save-indicator[data-state="saved"] {
  color: var(--muted);
}

/* --- Comments ------------------------------------------------------------------------------ */
.comments .comment {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.comments .comment:first-of-type {
  border-top: 0;
}

.comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  margin: 0 0 4px;
}

.comment-body {
  margin: 0 0 4px;
}

.comment-body p {
  margin: 4px 0;
}

.comment-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 4px 0 0;
}

.comment-actions form.inline-form {
  display: inline;
  margin: 0;
}

.comment-edit-form {
  margin-top: 8px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}

.messages {
  padding-left: 0;
  list-style: none;
}

#comment-form {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* Inline comment feedback (comment-interactions-ui).
 *
 * The box above the composer is **deployment-tunable**: every value below is a default that a brand
 * or deployment can override (for example in `brand.css`) without touching this file. The defaults
 * reserve one line of space, so an announcement or a cleared error never moves the field or the
 * Post button; see `docs/branding.md`.
 */
:root {
  --comment-feedback-gap: 8px;
  --comment-feedback-min-height: 1.5em;
  --comment-feedback-padding: 12px 16px;
  --comment-feedback-radius: var(--radius-chip);
  --comment-error-bg: var(--warn-bg);
  --comment-error-line: var(--warn-line);
  --comment-error-color: var(--danger);
}

.comment-feedback {
  display: grid;
  gap: var(--comment-feedback-gap);
  min-height: var(--comment-feedback-min-height);
  margin: 0 0 var(--comment-feedback-gap);
}

/* The retry control is a normal button beside the error, not a full-width bar. */
.comment-feedback #comments-retry {
  justify-self: start;
}

.comment-error {
  margin: 0;
  padding: var(--comment-feedback-padding);
  border-left: 4px solid var(--comment-error-line);
  border-radius: var(--comment-feedback-radius);
  background: var(--comment-error-bg);
  color: var(--comment-error-color);
}

.comments-status {
  margin: 0;
}

.comments .comment:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button[aria-busy="true"] {
  opacity: 0.7;
}

/* --- Watch page (watch-page-ui) ----------------------------------------------------------- */
:root {
  /* Guide, Watch page: a flexible player/content column beside a 350px column holding the course
     playlist and then related lessons. Tunable per deployment without touching the grid. */
  --watch-sidebar-width: 350px;
  --watch-gap: 24px;
  /* The side panel reads like the YouTube playlist card: rounded, bordered, thumbnail rows. */
  --watch-thumb-width: 112px;
  --watch-row-gap: 10px;
  --watch-panel-pad: 12px;
}

.watch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--watch-sidebar-width);
  gap: var(--watch-gap);
  align-items: start;
}

/* The primary column holds the player/content *and* the comments, so the comments always follow
   the description — a long course playlist can no longer push them down. */
.watch__primary {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  display: grid;
  gap: var(--watch-gap);
  align-content: start;
}

.watch__main {
  min-width: 0;
}

.watch__side {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.watch__comments {
  min-width: 0;
}

.watch__byline {
  margin-top: -6px;
}

/* The panel: one encapsulated component (playlist + related lessons). */
.watch-panel {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--bg);
  overflow: hidden;
}

.watch-panel__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px 8px;
  padding: var(--watch-panel-pad);
  border-bottom: 1px solid var(--line);
}

.watch-panel__title {
  margin: 0;
  font-size: 18px;
}

.watch-panel__close {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.watch-panel__close:hover {
  background: var(--highlight-hover);
}

.watch-panel__meta {
  grid-column: 1;
  margin: 0;
}

.watch-panel__body {
  display: grid;
  gap: 4px;
  padding: var(--watch-panel-pad);
}

.watch-panel__section {
  display: grid;
  gap: 8px;
}

.watch-panel__subtitle {
  margin: 8px 0 0;
  font-size: 15px;
}

.watch-panel__note {
  margin: 0;
}

/* Rows: index/play marker, 16:9 media with a duration badge, then a two-line text block. */
.watch-rows,
.watch-rows__list {
  display: grid;
  gap: var(--watch-row-gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

.watch-rows__group {
  display: grid;
  gap: 6px;
}

.watch-rows__module {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.watch-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  border-radius: var(--radius-chip);
}

/* Hover and "current" are the same kind of thing: a tint behind the row, keeping the normal ink.
   (This used `--selected` with no `--inverse` ink, which made the current lesson's title
   invisible.) */
.watch-row:hover {
  background: var(--highlight-hover);
}

.watch-row.is-current,
.watch-row.is-current:hover {
  background: var(--highlight);
}

/* Related rows have no playlist number, so they start at the media edge. */
.watch-row--related {
  grid-template-columns: minmax(0, 1fr);
}

.watch-row__index {
  padding-top: 22px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.watch-row__play {
  color: var(--text);
}

.watch-row__link {
  display: grid;
  grid-template-columns: var(--watch-thumb-width) minmax(0, 1fr);
  gap: 8px;
  padding: 4px;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-chip);
}

.watch-row__link:hover .watch-row__title {
  text-decoration: underline;
}

.watch-row__thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-chip);
  background: var(--surface);
}

.watch-row__cover {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.watch-row__duration {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}

/* Watched progress reads like YouTube's red bar across the bottom of the thumbnail. */
.watch-row__progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.4);
}

.watch-row__progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.watch-row__text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.watch-row__title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.watch-row__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.watch-row__flag {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* The collapsed state: one box naming the lesson that plays next. */
.watch-next {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 8px;
  padding: var(--watch-panel-pad);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
}

.watch-next__link {
  display: grid;
  gap: 2px;
  color: inherit;
  text-decoration: none;
}

.watch-next__link:hover .watch-next__title {
  text-decoration: underline;
}

.watch-next__title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 600;
}

.watch-next__expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  /* Same pairing as the active nav item: `--inverse` is the only readable ink on `--selected`. */
  background: var(--selected);
  color: var(--inverse);
  cursor: pointer;
}

/* Stacked watch page: player -> title/actions/description -> panel -> comments. `display: contents`
   dissolves the primary wrapper and `order` restores the guide's order, since the source order is
   now main -> comments -> sidebar. */
@media (max-width: 900px) {
  .watch {
    grid-template-columns: minmax(0, 1fr);
  }

  .watch__primary {
    display: contents;
  }

  .watch__main,
  .watch__side,
  .watch__comments {
    grid-column: 1;
    grid-row: auto;
  }

  .watch__main { order: 1; }
  .watch__side { order: 2; }
  .watch__comments { order: 3; }
}

@media (max-width: 600px) {
  :root {
    --watch-thumb-width: 96px;
  }
}

/* --- Downloadable files -------------------------------------------------------------------- */
.download-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
}

.download-row + .download-row {
  border-top: 1px solid var(--line);
}

.download-link {
  font-weight: 600;
}

.download-meta {
  flex-basis: 100%;
}

/* --- Auth / error pages -------------------------------------------------------------------- */
.narrow {
  max-width: 26rem;
  margin: 0 auto;
}

/* --- Responsive (guide breakpoints) -------------------------------------------------------- */
@media (max-width: 1550px) {
  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1200px) {
  :root {
    --pad: 24px;
    --gap: 20px;
  }

  .site-body {
    grid-template-columns: 160px minmax(0, 1fr);
  }

  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Compact header/sidebar: drop the supplementary brand text and the account email so the
     essential controls (search, theme, account action) never wrap or get crushed. The platform
     name stays, smaller and width-capped, so the search keeps room. */
  .wordmark__tagline,
  .brand-flag,
  .account__email {
    display: none;
  }

  .wordmark__mark {
    font-size: 16px;
  }

  .brand {
    max-width: 280px;
  }

  .nav-link {
    padding: 8px 10px;
    font-size: 14px;
  }

  .chip-soon {
    padding: 2px 6px;
    font-size: 10px;
  }
}

@media (max-width: 900px) {
  .page-head h1 {
    font-size: 30px;
  }
}

@media (max-width: 600px) {
  :root {
    --pad: 16px;
    --gap: 16px;
  }

  .site-header__row {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  /* Search drops to its own second header row. */
  .search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .brand-flag {
    display: none;
  }

  /* The logo alone carries the brand on phones; without a logo the name text stays. */
  .wordmark--logo .wordmark__mark {
    display: none;
  }

  /* Navigation becomes a horizontal row above the content. */
  .site-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .site-nav {
    position: static;
  }

  .site-nav__list {
    flex-direction: row;
    overflow-x: auto;
  }

  .nav-link {
    white-space: nowrap;
  }

  .card-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-head h1 {
    font-size: 30px;
  }
}

/* --- Motion -------------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Preview gate (login-flow-browse-ui) --------------------------------------------------- */
.preview-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}

.preview-gate__panel {
  max-width: 34rem;
  width: 100%;
  background: var(--surface, #fff);
  color: var(--ink, #111);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.preview-gate__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

/* --- Checkout moved to checkout.css (checkout-page) ---------------------------------------- */
/* The plan cards and the payment column are one design now, loaded only on the purchase route. */

/* The author `display` above would beat the UA's [hidden] rule, so make hidden authoritative. */
.preview-gate[hidden] {
  display: none;
}

.tier-badge {
  display: inline-block;
  margin: 0;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--accent-soft, #e8f0ff);
}
.tier-badge[data-tier="free"] {
  background: transparent;
  padding-left: 0;
}

/* --- Preview affordances (login-flow-browse-ui) -------------------------------------------- */
.thumb-banner {
  position: absolute;
  top: 9px;
  left: 9px;
  padding: 3px 9px;
  background: #175cd3;
  color: #ffffff;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.preview-note {
  color: #175cd3;
}

/* When a preview is spent there is no token to load, so show the course art at video size. */
.player-frame--poster {
  background: #000;
}

.player-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.6;
}

.player-poster__note {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 600;
  text-align: center;
  padding: 1rem;
}

/* Instructor byline (lms-admin-ops): avatar or a deterministic initials placeholder. */
.byline { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.byline__person { display: inline-flex; align-items: center; gap: 0.3rem; }
.byline__avatar {
  width: 20px; height: 20px; border-radius: 999px; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
}
.byline__avatar--initials {
  background: var(--surface-2, rgba(127, 127, 127, 0.18));
  color: var(--text, currentColor);
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.02em; line-height: 1;
}

/* --- Migrated images (kajabi-video-transfer) -------------------------------------------------
   Uploaded images live in the assets storage alias; each surface shows the most specific one it
   has, falling back to the generated course cover. `--thumb-w` keeps every list thumbnail the same
   size so playlists and module lists line up. */
:root {
  --thumb-w: 112px;
}

/* The course page leads with the videos, not the cover: a compact header (small thumbnail +
   title/meta/description) and then a browse-style card grid per module. */
.course-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.course-head__thumb {
  display: block;
  flex: 0 0 auto;
  width: 160px;
  height: 90px;
  object-fit: cover;
  background: var(--surface);
  border-radius: var(--radius-chip);
}

.course-head__body {
  min-width: 0;
}

.course-head__body h1 {
  margin: 0 0 4px;
}

.course-head__meta {
  margin: 0 0 8px;
}

.module-head__text {
  min-width: 0;
}

.module-head__text h2 {
  margin: 0;
}

.module-head__text .description {
  margin: 4px 0 0;
}

.course-module {
  margin-bottom: 40px;
}

@media (max-width: 640px) {
  .course-head {
    gap: 12px;
  }

  .course-head__thumb {
    width: 112px;
    height: 63px;
  }
}

/* The module header is a soft shaded band. With one shade per module the eye can find where one
   module ends and the next begins without dividers, borders or extra chrome. */
.module-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  margin-bottom: 20px;
  background: var(--surface);
  border-radius: var(--radius-panel);
}

.module-head__count {
  margin-left: auto;
  white-space: nowrap;
}

.module-image {
  display: block;
  flex: 0 0 auto;
  width: var(--thumb-w);
  height: calc(var(--thumb-w) * 9 / 16);
  object-fit: cover;
  background: var(--surface);
  border-radius: var(--radius-chip);
}

.lesson-thumb {
  display: block;
  flex: 0 0 auto;
  align-self: center;
  width: var(--thumb-w);
  height: calc(var(--thumb-w) * 9 / 16);
  overflow: hidden;
  border-radius: var(--radius-chip);
  background: var(--surface);
}

.lesson-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (max-width: 480px) {
  :root {
    --thumb-w: 88px;
  }
}

/* Watch-page breadcrumb: course › module. The module appears only here on a lesson page — its
   image and tagline belong to the course page's module header, not to the lesson. */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

.crumbs__sep {
  opacity: 0.55;
}

.crumbs__here {
  font-weight: 600;
}

/* --- PDF-only lesson document stage (pdf-only-lessons) ------------------------------------------
   The stage reuses `.player-frame`'s 16:9 footprint so the watch grid never reflows between a video
   lesson and a document lesson; the matte replaces the video letterbox and the toolbar floats like
   player chrome. Colors are brand tokens only. */
:root {
  /* The document stage is taller than the 16:9 video stage: a portrait page needs vertical room. */
  --doc-frame-h: clamp(440px, 80vh, 1060px);
}

.doc-frame {
  /* Override .player-frame's 16:9 padding box: a document is portrait, not 16:9. */
  padding-top: 0;
  height: var(--doc-frame-h);
  background: var(--matte);
}

.doc-canvas {
  position: absolute;
  inset: 0;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 16px;
  padding: 20px;
  overflow: auto;
  background: var(--matte);
  -webkit-overflow-scrolling: touch;
}

.doc-page {
  /* Fit a full page to the stage where there is room; cap the width on narrow screens. */
  height: calc(var(--doc-frame-h) - 44px);
  width: auto;
  max-width: 100%;
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 10px 28px var(--shadow);
}

.doc-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 12px;
}

.doc-preview-note {
  margin: 0 0 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.pill--preview {
  background: var(--warn-bg);
  color: var(--text);
  border: 1px solid var(--warn-line);
}

.doc-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.download-link--locked {
  color: var(--muted);
}

.download-lock {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 3px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-pill);
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.badge--pdf {
  letter-spacing: 0.06em;
}

.badge--pdf::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 10px;
  margin-right: 4px;
  vertical-align: -1px;
  border: 1.5px solid currentColor;
  border-radius: 1px;
}

/* --- Lesson resources (lesson-pdf-resources) ----------------------------------------------------
   A PDF resource is a collapsible document stage so a video lesson stays compact; other attachments
   are plain download rows. */
.resources {
  display: grid;
  gap: 12px;
}

.resource {
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 8px 12px;
}

.resource__summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  cursor: pointer;
}

.resource__title {
  font-weight: 600;
}

.resource[open] .resource__summary {
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

/* --- Hidden lessons (hide-unavailable-lessons) --------------------------------------------------
   A retired lesson is gone from every learner surface and 404s at its URL; an admin viewer still
   sees it, always clearly marked. This is a review aid, not a learner affordance. */
.thumb-banner--hidden {
  left: auto;
  right: 9px;
  background: #3f3f46;
}

.hidden-banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid #3f3f46;
  border-radius: 6px;
  background: var(--paper);
  font-size: 14px;
}

.watch-row__flag--hidden {
  border-color: #3f3f46;
  background: #3f3f46;
  color: #ffffff;
}

/* The furthest pick: the panel's built-in test of "closer is better". It has to look *deliberately*
   different from the other suggestions, not like another status pill -- a dashed accent outline says
   "this one was chosen to be unlike the rest". (Styled with the brand tokens only, so a rebrand keeps
   working; the class was referenced by the template for a while before this rule existed, which is
   what made a live check of the feature look like a missing feature.) */
.watch-row__flag--different {
  border-style: dashed;
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
}

/* --- Purchase confirmation (purchase-confirmation) ----------------------------------------- */
/* The one-time post-purchase band: a green "good to go" check, a sprinkle of magic dust plus three
   firework bursts (the sequence runs >= 5 s), then exactly three next steps. Colours come only from
   brand/guide tokens (plus the functional success/magic tokens above); the whole animation is
   neutralised by prefers-reduced-motion, and the band content needs no JavaScript. */
.celebrate {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  margin: 0 0 28px;
  padding: 26px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  animation: celebrate-in 380ms ease-out both;
}

/* The celebration layer: dust + fireworks, behind the content, never clickable. */
.celebrate__fx {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.celebrate__art,
.celebrate__body {
  position: relative;
  z-index: 1;
}

.celebrate__art {
  position: relative;
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
}

.celebrate__badge {
  width: 64px;
  height: 64px;
  position: relative;
  z-index: 1;
  animation: celebrate-badge 520ms ease-out both;
}

/* Green: the purchase is complete and the account is good to go (never the red accent). */
.celebrate__badge-disc {
  fill: var(--success);
}

.celebrate__badge-check {
  fill: none;
  stroke: var(--success-on);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 44;
  stroke-dashoffset: 44;
  animation: celebrate-check 560ms 180ms ease-out forwards;
}

.celebrate__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--success);
  opacity: 0;
  animation: celebrate-ring 1100ms ease-out forwards;
}

/* Magic dust: 16 glowing specks, each drifting out and fading; the last finishes ~6.8 s in. */
.celebrate__spark {
  position: absolute;
  top: var(--top, 50%);
  left: var(--left, 50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 0%, var(--spark, var(--magic)) 42%, transparent 72%);
  box-shadow: 0 0 6px 1px var(--spark, var(--magic));
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.2);
  animation: celebrate-dust var(--dur, 3.6s) var(--delay, 0s) ease-out forwards;
}

.celebrate__dust .celebrate__spark:nth-child(1)  { --left:  7%; --top: 24%; --dx:  26px; --dy:  44px; --delay: 0.05s; --dur: 3.8s; --spark: var(--magic); }
.celebrate__dust .celebrate__spark:nth-child(2)  { --left: 14%; --top: 70%; --dx: -20px; --dy:  30px; --delay: 0.5s;  --dur: 3.4s; --spark: #ffffff; }
.celebrate__dust .celebrate__spark:nth-child(3)  { --left: 22%; --top: 40%; --dx:  30px; --dy:  26px; --delay: 0.9s;  --dur: 3.6s; --spark: var(--focus); }
.celebrate__dust .celebrate__spark:nth-child(4)  { --left: 30%; --top: 80%; --dx:  18px; --dy: -24px; --delay: 1.3s;  --dur: 3.2s; --spark: var(--magic); }
.celebrate__dust .celebrate__spark:nth-child(5)  { --left: 38%; --top: 20%; --dx:  24px; --dy:  40px; --delay: 1.7s;  --dur: 3.6s; --spark: #ffffff; }
.celebrate__dust .celebrate__spark:nth-child(6)  { --left: 46%; --top: 62%; --dx: -22px; --dy:  34px; --delay: 2.0s;  --dur: 3.4s; --spark: var(--success); }
.celebrate__dust .celebrate__spark:nth-child(7)  { --left: 54%; --top: 34%; --dx:  28px; --dy:  30px; --delay: 2.3s;  --dur: 3.6s; --spark: var(--magic); }
.celebrate__dust .celebrate__spark:nth-child(8)  { --left: 62%; --top: 76%; --dx: -24px; --dy: -20px; --delay: 0.3s;  --dur: 3.8s; --spark: #ffffff; }
.celebrate__dust .celebrate__spark:nth-child(9)  { --left: 70%; --top: 22%; --dx:  20px; --dy:  42px; --delay: 0.7s;  --dur: 3.5s; --spark: var(--focus); }
.celebrate__dust .celebrate__spark:nth-child(10) { --left: 78%; --top: 58%; --dx: -28px; --dy:  30px; --delay: 1.1s;  --dur: 3.7s; --spark: var(--magic); }
.celebrate__dust .celebrate__spark:nth-child(11) { --left: 86%; --top: 32%; --dx:  22px; --dy:  36px; --delay: 1.5s;  --dur: 3.3s; --spark: #ffffff; }
.celebrate__dust .celebrate__spark:nth-child(12) { --left: 93%; --top: 72%; --dx: -18px; --dy: -22px; --delay: 1.9s;  --dur: 3.6s; --spark: var(--success); }
.celebrate__dust .celebrate__spark:nth-child(13) { --left: 12%; --top: 46%; --dx: -26px; --dy:  24px; --delay: 2.6s;  --dur: 3.5s; --spark: var(--magic); }
.celebrate__dust .celebrate__spark:nth-child(14) { --left: 50%; --top: 14%; --dx:  24px; --dy:  30px; --delay: 2.9s;  --dur: 3.6s; --spark: #ffffff; }
.celebrate__dust .celebrate__spark:nth-child(15) { --left: 34%; --top: 56%; --dx: -20px; --dy:  40px; --delay: 3.1s;  --dur: 3.7s; --spark: var(--focus); }
.celebrate__dust .celebrate__spark:nth-child(16) { --left: 66%; --top: 46%; --dx:  26px; --dy:  28px; --delay: 3.0s;  --dur: 3.8s; --spark: var(--magic); }

/* Fireworks: three small bursts that expand and fade, at ~0.2 / 1.4 / 2.6 s. */
.celebrate__burst {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  opacity: 0;
  animation: celebrate-firework 2.4s ease-out forwards;
}

.celebrate__burst:nth-child(2) { left: 26%; top: 30%; animation-delay: 0.2s; }
.celebrate__burst:nth-child(3) { left: 58%; top: 26%; animation-delay: 1.4s; }
.celebrate__burst:nth-child(4) { left: 80%; top: 64%; animation-delay: 2.6s; }

.celebrate__kicker {
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--success);
}

.celebrate__title { margin: 0 0 6px; }
.celebrate__lead { margin: 0 0 16px; color: var(--muted); }

.celebrate__steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.celebrate__step { display: flex; gap: 12px; align-items: flex-start; }

.celebrate__num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--selected);
  color: var(--inverse);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.celebrate__step-text { display: flex; flex-direction: column; gap: 1px; }
.celebrate__link { font-weight: 600; }
.celebrate__detail { color: var(--muted); font-size: 0.9rem; }

@keyframes celebrate-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes celebrate-badge { 0% { transform: scale(0.4); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes celebrate-check { to { stroke-dashoffset: 0; } }
@keyframes celebrate-ring { 0% { opacity: 0.8; transform: scale(0.4); } 100% { opacity: 0; transform: scale(1.6); } }
@keyframes celebrate-dust {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.25); }
  12%  { opacity: 1; }
  70%  { opacity: 0.9; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(0.5); }
}
@keyframes celebrate-firework {
  0%   { opacity: 0; transform: scale(0.2); box-shadow: 0 0 0 0 var(--success); }
  14%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1); box-shadow: 0 0 0 56px rgba(0, 0, 0, 0); }
}

@media (max-width: 640px) {
  .celebrate { grid-template-columns: 1fr; }
  .celebrate__art { justify-self: start; }
}

/* --- First-visit welcome banner (first-visit-welcome) --------------------------------------- */
/* One-time, cookie-gated, at the top of the content. Functional only: no overlay and nothing to
   dismiss before the learner can reach the player the message points at. Styled after the
   purchase-confirmation band — a tri-colour rule, firework bursts and a little magic dust — so it is
   noticed rather than scrolled past. Every colour comes from a token; the whole animation is
   neutralised by the global prefers-reduced-motion rule, and none of it needs JavaScript. */
.welcome-banner {
  position: relative;
  overflow: hidden;
  margin: 0 0 16px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
  /* A soft accent glow rising from the bottom edge: colour without a flat block. */
  box-shadow: inset 0 -38px 64px -46px var(--accent);
  animation: welcome-in 420ms ease-out both;
}

/* A tri-colour rule across the top, so it reads as an announcement before it even animates. */
.welcome-banner::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 2;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--magic) 52%, var(--focus));
}

/* Decoration: bursts + dust, behind the text, never clickable. */
.welcome-banner__fx {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.welcome-banner__head,
.welcome-banner__line,
.welcome-banner__actions {
  position: relative;
  z-index: 1;
}

.welcome-banner__head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.welcome-banner__badge {
  position: relative;
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
}

.welcome-banner__wave {
  font-size: 26px;
  line-height: 1;
  transform-origin: 72% 78%;
  animation: welcome-wave 1.5s 300ms ease-in-out 2;
}

.welcome-banner__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: welcome-ring 1200ms 500ms ease-out 2;
}

.welcome-banner__title {
  flex: 1 1 14ch;
  margin: 0;
  font-size: 17px;
  color: var(--accent);
}

.welcome-banner__dismiss {
  flex: none;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.welcome-banner__line {
  margin: 8px 0 0;
}

.welcome-banner__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* Fireworks: three small bursts that expand and fade, at ~0.15 / 0.8 / 1.4 s. */
.welcome-banner__burst {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  animation: welcome-firework 1.8s ease-out forwards;
}

.welcome-banner__burst:nth-child(1) { left:  9%; top: 30%; color: var(--accent); animation-delay: 0.15s; }
.welcome-banner__burst:nth-child(2) { left: 46%; top: 18%; color: var(--magic);  animation-delay: 0.8s; }
.welcome-banner__burst:nth-child(3) { left: 88%; top: 34%; color: var(--focus);  animation-delay: 1.4s; }

/* Magic dust: a dozen specks drifting out and fading. */
.welcome-banner__spark {
  position: absolute;
  top: var(--top, 50%);
  left: var(--left, 50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 0%, var(--spark, var(--magic)) 44%, transparent 72%);
  box-shadow: 0 0 6px 1px var(--spark, var(--magic));
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.2);
  animation: welcome-dust var(--dur, 3s) var(--delay, 0s) ease-out forwards;
}

.welcome-banner__dust .welcome-banner__spark:nth-child(1)  { --left:  7%; --top: 30%; --dx:  20px; --dy:  30px; --delay: 0.1s; --dur: 2.9s; --spark: var(--accent); }
.welcome-banner__dust .welcome-banner__spark:nth-child(2)  { --left: 16%; --top: 68%; --dx: -18px; --dy:  24px; --delay: 0.5s; --dur: 2.6s; --spark: #ffffff; }
.welcome-banner__dust .welcome-banner__spark:nth-child(3)  { --left: 25%; --top: 42%; --dx:  22px; --dy:  20px; --delay: 0.9s; --dur: 2.8s; --spark: var(--focus); }
.welcome-banner__dust .welcome-banner__spark:nth-child(4)  { --left: 34%; --top: 78%; --dx:  16px; --dy: -20px; --delay: 1.3s; --dur: 2.5s; --spark: var(--magic); }
.welcome-banner__dust .welcome-banner__spark:nth-child(5)  { --left: 43%; --top: 24%; --dx:  18px; --dy:  30px; --delay: 1.7s; --dur: 2.8s; --spark: #ffffff; }
.welcome-banner__dust .welcome-banner__spark:nth-child(6)  { --left: 52%; --top: 62%; --dx: -20px; --dy:  26px; --delay: 2.0s; --dur: 2.6s; --spark: var(--accent); }
.welcome-banner__dust .welcome-banner__spark:nth-child(7)  { --left: 61%; --top: 34%; --dx:  22px; --dy:  22px; --delay: 2.3s; --dur: 2.8s; --spark: var(--magic); }
.welcome-banner__dust .welcome-banner__spark:nth-child(8)  { --left: 70%; --top: 74%; --dx: -18px; --dy: -18px; --delay: 0.3s; --dur: 2.9s; --spark: #ffffff; }
.welcome-banner__dust .welcome-banner__spark:nth-child(9)  { --left: 79%; --top: 26%; --dx:  16px; --dy:  30px; --delay: 0.7s; --dur: 2.7s; --spark: var(--focus); }
.welcome-banner__dust .welcome-banner__spark:nth-child(10) { --left: 87%; --top: 58%; --dx: -22px; --dy:  24px; --delay: 1.1s; --dur: 2.8s; --spark: var(--magic); }
.welcome-banner__dust .welcome-banner__spark:nth-child(11) { --left: 94%; --top: 36%; --dx:  16px; --dy:  28px; --delay: 1.5s; --dur: 2.5s; --spark: #ffffff; }
.welcome-banner__dust .welcome-banner__spark:nth-child(12) { --left: 48%; --top: 14%; --dx:  20px; --dy:  24px; --delay: 2.5s; --dur: 2.7s; --spark: var(--accent); }

@keyframes welcome-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes welcome-wave {
  0%, 100% { transform: rotate(0deg); }
  15% { transform: rotate(18deg); }
  30% { transform: rotate(-8deg); }
  45% { transform: rotate(14deg); }
  60% { transform: rotate(-5deg); }
}
@keyframes welcome-ring { 0% { opacity: 0.7; transform: scale(0.5); } 100% { opacity: 0; transform: scale(1.6); } }
@keyframes welcome-dust {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.25); }
  15%  { opacity: 1; }
  70%  { opacity: 0.9; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(0.5); }
}
@keyframes welcome-firework {
  0%   { opacity: 0; transform: scale(0.2); box-shadow: 0 0 0 0 currentColor; }
  14%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1); box-shadow: 0 0 0 52px rgba(0, 0, 0, 0); }
}

/* --- Missing page banner (oikosofyseries-import/not-found-catchall) ---------------------------
   What a stranger sees when an old oikosofyseries.net URL no longer resolves: the home page is
   rendered underneath (same feed, same queries) with this at the top, as a real 404. It borrows the
   welcome banner's shell -- same width, radius and surface -- but not its celebration: a warn-toned
   rule instead of the tri-colour one, no animation, and a monospace path so the reader can see which
   link was wrong. Deliberately not a full-page interstitial: the lessons are the point, so they start
   immediately below. */
.page-missing {
  position: relative;
  overflow: hidden;
  margin: 0 0 16px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: inset 0 -38px 64px -46px var(--warn-line);
}

.page-missing::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--warn-line);
}

.page-missing__title {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.25;
}

.page-missing__line {
  margin: 0 0 8px;
  max-width: 68ch;
}

.page-missing__line:last-of-type {
  margin-bottom: 12px;
}

/* The path is user input: it can be long, have no spaces, and never wrap without this. */
.page-missing__path {
  padding: 1px 6px;
  border-radius: var(--radius-chip);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  font-size: 13px;
  word-break: break-all;
}

.page-missing__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
