/* A lesson's text (LessonTextComponent): Lexxy with WIRE's look. Lexxy's own CSS (lexxy.css, loaded by the layout
   before the app's) draws the editor; this sets its variables from the tokens, and draws the lesson's blocks the same
   way in the editor and wherever the text is shown (.lexxy-content): the tip, Lexxy's quote block, as a tinted box,
   and the key points, a numbered list, with turquoise numbers. */

.lexxy-content,
.wi-lesson-text {
  --lexxy-font-base: var(--font-family-sans);
  --lexxy-color-ink: var(--text-primary);
  --lexxy-color-text: var(--text-primary);
  --lexxy-color-text-subtle: var(--text-secondary);
  --lexxy-color-ink-medium: var(--text-secondary);
  --lexxy-color-ink-light: var(--text-tertiary);
  --lexxy-color-ink-lighter: var(--border-default);
  --lexxy-color-ink-lightest: var(--border-subtle);
  --lexxy-color-canvas: var(--background-page);
  --lexxy-color-link: var(--text-link);
  --lexxy-color-accent-dark: var(--turquoise-700);
  --lexxy-color-accent-medium: var(--turquoise-600);
  --lexxy-color-accent-light: var(--turquoise-100);
  --lexxy-color-accent-lightest: var(--turquoise-50);
  --lexxy-color-selected: var(--turquoise-50);
  --lexxy-color-selected-hover: var(--turquoise-100);
  --lexxy-color-selected-dark: var(--turquoise-700);
  --lexxy-radius: var(--radius-md);
  --lexxy-focus-ring-color: var(--border-focus);
}

/* The editor is the page: no label around it (Academy prototype), the toolbar in reach on top. The text sits on a
   white card across the page's width (the Academy's design "Rows that say something": a card's radius and shadow,
   the toolbar on a grey strip at its top), tall enough to click into while it is empty; on a phone the card is the
   same, a little closer to its text. */
.wi-lesson-text {
  --lexxy-toolbar-button-size: var(--space-8);
  --lexxy-toolbar-gap: var(--space-0-5);
  --lexxy-toolbar-padding: 0;
  --lexxy-toolbar-spacing: var(--space-1);

  background: var(--background-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.wi-lesson-text lexxy-editor {
  border: 0;
  background: none;
}

.wi-lesson-text .lexxy-editor__content {
  min-height: 20rem;
  padding: var(--wi-lesson-text-padding);
}

/* The dock holds the toolbar, outside the editor (Lexxy's `toolbar` attribute), and Done: on a desktop it stays on top
   of the text as the page scrolls, and Done is not needed. */
.wi-lesson-text__dock {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--background-sunken);
  border-bottom: var(--border-1) solid var(--border-default);
}

/* Lexxy draws its toolbar from inside its editor; outside it, its line and its buttons are ours to set, or a button
   takes the browser's grey. Its group separators come from Lexxy, spaced by the variables above. */
.wi-lesson-text__toolbar {
  --lexxy-toolbar-icon-size: var(--size-icon-sm); /* Lexxy sets it on the toolbar itself */

  flex: 1;
  min-width: 0;
  align-items: center;
  border: 0;
}

.wi-lesson-text__toolbar .lexxy-editor__toolbar-button {
  padding: 0;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}

.wi-lesson-text__toolbar .lexxy-editor__toolbar-button:hover {
  background: var(--background-surface);
  color: var(--text-primary);
}

.wi-lesson-text__toolbar .lexxy-editor__toolbar-button[aria-pressed="true"] {
  background: var(--turquoise-100);
  color: var(--turquoise-900);
}

/* Lexxy fills its own icons; Tabler's are outlines, drawn a little lighter at this size, as the nav's are. */
.wi-lesson-text__toolbar svg {
  fill: none;
  stroke-width: 1.75;
}

/* Tip, Image and File show their names on a desktop. */
.wi-lesson-text__toolbar .wi-lesson-text__button--named {
  aspect-ratio: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding-inline: var(--space-2);
  font-size: var(--font-size-xs);
  line-height: var(--font-line-height-xs);
  font-weight: var(--font-weight-semibold);
}

/* The one shortcut worth knowing, said once under the text. */
.wi-lesson-text__hint {
  margin: 0;
  padding: var(--space-2) var(--space-4);
  border-top: var(--border-1) solid var(--border-subtle);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--background-sunken);
  color: var(--text-tertiary);
  font-size: var(--font-size-xs);
  line-height: var(--font-line-height-xs);
}

.wi-lesson-text__hint b {
  padding: 0 var(--space-1);
  border: var(--border-1) solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--background-surface);
  color: var(--text-primary);
}

.wi-lesson-text__dock .wi-lesson-text__done {
  display: none;
}

/* On a phone the dock shows only while someone writes, on top of the keyboard (the `keyboard_inset` controller says
   how much of the page the keyboard covers); the text keeps room under its last line. The dock takes up the tab bar's
   card (AppShell.css) in the tab bar's place, as wide as the gutters let it be, and the two swap. */
@media (max-width: 767.98px) {
  .wi-lesson-text .lexxy-editor__content {
    min-height: 12rem;
  }

  .wi-lesson-text__button-name,
  .wi-lesson-text__hint {
    display: none;
  }

  .wi-lesson-text__toolbar .wi-lesson-text__button--named {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    inline-size: var(--lexxy-toolbar-button-size);
    padding-inline: 0;
  }

  .wi-lesson-text__dock {
    position: fixed;
    inset-inline: var(--wi-bottom-tab-bar-gutter);
    top: auto;
    bottom: max(calc(var(--wi-keyboard-inset, 0px) + var(--wi-bottom-tab-bar-gutter)), env(safe-area-inset-bottom));
    z-index: 3;
    box-sizing: border-box;
    min-height: var(--wi-bottom-tab-bar-card-height);
    padding: var(--space-0-5) var(--space-1) var(--space-0-5) var(--space-3);
    border: var(--wi-bottom-tab-bar-card-border);
    border-radius: var(--wi-bottom-tab-bar-card-radius);
    background: var(--wi-bottom-tab-bar-card-background);
    box-shadow: var(--wi-bottom-tab-bar-card-shadow);
  }

  /* Room under the text for the dock and its gutter, so the last line stays above it. */
  .wi-lesson-text:focus-within {
    padding-bottom: calc(var(--wi-bottom-tab-bar-card-height) + 2 * var(--wi-bottom-tab-bar-gutter));
  }

  .wi-lesson-text__dock .wi-lesson-text__done {
    display: inline-flex;
    flex: none;
  }

  /* The swap: while someone writes, the tab bar fades out as the dock fades in, and Done plays it back. Both stay in the
     page, hidden (`visibility`), so the swap plays both ways and nothing plays when a page opens; hidden, neither takes
     a tap or the keyboard's focus. The title is typed in the same frame but takes no formatting: its field calls
     neither. Durations aren't tokens. */
  .wi-lesson-text__dock,
  .wi-app-shell:has(.wi-lesson-text) .wi-app-shell__bottom-bar {
    --wi-lesson-text-swap-in: 250ms var(--wi-ease-enter) 50ms;
    --wi-lesson-text-swap-out: 150ms var(--wi-ease-exit);
    --wi-lesson-text-swap: var(--wi-lesson-text-swap-in);
    transition: opacity var(--wi-lesson-text-swap), translate var(--wi-lesson-text-swap), scale var(--wi-lesson-text-swap),
      visibility var(--wi-lesson-text-swap);
  }

  .wi-lesson-text__dock,
  .wi-app-shell:has(.wi-lesson-text:focus-within) .wi-app-shell__bottom-bar {
    --wi-lesson-text-swap: var(--wi-lesson-text-swap-out);
    visibility: hidden;
    opacity: 0;
  }

  .wi-lesson-text:focus-within .wi-lesson-text__dock {
    --wi-lesson-text-swap: var(--wi-lesson-text-swap-in);
    visibility: visible;
    opacity: 1;
  }
}

/* With motion, the tab bar also sinks a little, and the dock rises and widens from the tab bar's width. */
@media (max-width: 767.98px) and (prefers-reduced-motion: no-preference) {
  .wi-lesson-text__dock,
  .wi-app-shell:has(.wi-lesson-text:focus-within) .wi-app-shell__bottom-bar {
    translate: 0 var(--space-3);
  }

  .wi-lesson-text__dock {
    scale: 0.9 1;
  }

  .wi-lesson-text:focus-within .wi-lesson-text__dock {
    translate: none;
    scale: none;
  }
}

/* The lesson's blocks, the same in the editor and wherever the text is read: paragraphs, lists aligned with them, the
   tip as a tinted box, and the key points with their number in a turquoise circle. A list item stays a line of text
   (its number is placed beside it, not in a grid cell), so bold words and the cursor sit where they should. */
.lexxy-content {
  --wi-lesson-text-line-height: calc(var(--font-line-height-base) + var(--space-0-5));
  --wi-lesson-text-gap: calc(var(--space-4) + var(--space-0-5));
  /* Around the text, in the editor and wherever it is read, so it sits at the same place in both. */
  --wi-lesson-text-padding: calc(var(--space-6) + var(--space-1)) var(--space-8) calc(var(--space-8) + var(--space-1));

  font-size: var(--font-size-base);
  line-height: var(--wi-lesson-text-line-height);
}

.lexxy-content p {
  margin: 0 0 var(--wi-lesson-text-gap);
  color: var(--text-primary);
}

/* A phone's text a little tighter, as the design draws it. */
@media (max-width: 767.98px) {
  .lexxy-content {
    --wi-lesson-text-line-height: var(--font-line-height-base);
    --wi-lesson-text-gap: calc(var(--space-3) + var(--space-0-5));
    --wi-lesson-text-padding: var(--space-4);
  }
}

/* The label opens the tip's first line: Lexxy writes the tip's text in paragraphs. */
.lexxy-content blockquote > p {
  margin: 0;
  color: inherit;
}

.lexxy-content blockquote > p:first-child {
  display: inline;
}

.lexxy-content blockquote::before {
  content: var(--wi-lesson-text-tip, "");
  color: var(--turquoise-700);
  font-weight: var(--font-weight-bold);
}

.lexxy-content blockquote {
  margin: var(--wi-lesson-text-gap) 0;
  padding: var(--space-3) var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--turquoise-50);
  color: var(--turquoise-900);
  font-style: normal;
}

.lexxy-content ul {
  margin: 0 0 var(--wi-lesson-text-gap);
  padding-inline-start: var(--space-5);
}

.lexxy-content ol {
  margin: 0 0 var(--wi-lesson-text-gap);
  padding: 0;
  list-style: none;
  counter-reset: key-point;
}

.lexxy-content ol > li {
  position: relative;
  min-height: var(--space-6);
  margin: 0 0 var(--space-2);
  padding-inline-start: var(--space-8);
  counter-increment: key-point;
}

.lexxy-content ol > li::before {
  content: counter(key-point);
  position: absolute;
  inset-inline-start: 0;
  top: calc((var(--wi-lesson-text-line-height) - var(--space-6)) / 2);
  display: grid;
  place-items: center;
  width: var(--space-6);
  height: var(--space-6);
  border-radius: var(--radius-full);
  background: var(--turquoise-50);
  color: var(--turquoise-700);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
}

/* Only the key points are numbered in circles: a list inside one counts a, b, c, and a list deeper i, ii, iii, in the
   circles' colour. The editor holds a nested list in an item of its own (lexxy-nested-listitem), which is no point:
   it neither counts nor shows a number, and keeps its level's indent so the list starts under the point's text. */
.lexxy-content li.lexxy-nested-listitem {
  min-height: 0;
  counter-increment: none;
}

.lexxy-content ol ol > li {
  min-height: 0;
  padding-inline-start: 0;
  counter-increment: none;
}

.lexxy-content li.lexxy-nested-listitem::before,
.lexxy-content ol ol > li::before {
  content: none;
}

.lexxy-content ol ol {
  margin: var(--space-2) 0 0;
  padding-inline-start: var(--space-5);
  list-style: lower-alpha;
}

.lexxy-content ol ol ol {
  list-style: lower-roman;
}

.lexxy-content ol ol > li::marker {
  color: var(--turquoise-700);
  font-weight: var(--font-weight-bold);
}

/* A person mentioned ("@Ana Sousa", users/_mention): in the line, set apart by its weight, the same in the editor and
   wherever the text is read. */
.lexxy-content .wi-lesson-text__mention {
  font-weight: var(--font-weight-semibold);
}

/* A diagram or an image sits where it is mentioned, at the start of the line, no wider than a column of text, with
   its caption under it; a PDF is a row across the text, its name first. */
.lexxy-content p:has(.attachment) {
  text-align: start;
}

/* Not on a card of its own: the text's background shows through. */
.lexxy-content .attachment {
  margin-inline: 0;
  background: none;
}

.lexxy-content .attachment--preview {
  max-inline-size: min(100%, 21.25rem);
  padding: 0;
}

.lexxy-content .attachment__caption {
  color: var(--text-tertiary);
  font-size: var(--font-size-xs);
  line-height: var(--font-line-height-xs);
}

.lexxy-content .attachment--file {
  inline-size: 100%;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: var(--border-1) solid var(--border-default);
  border-radius: var(--radius-md);
}

/* A PDF's row (Academy prototype): Tabler's file icon in an orange tile, then its name, then "PDF" and its size. Lexxy
   writes the file's extension in the tile; the icon replaces it. A stylesheet can't call the `icon` helper, so the
   icon is a mask copied from app/icons/file-text.svg, path for path (test/lib/used_icons_test.rb). */
.lexxy-content .attachment--file .attachment__icon {
  position: relative;
  block-size: var(--space-8);
  aspect-ratio: 1;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--orange-100);
  font-size: 0;
}

.lexxy-content .attachment--file .attachment__icon::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: var(--size-icon-xs);
  height: var(--size-icon-xs);
  background: var(--orange-900);
  mask: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M14%203v4a1%201%200%200%200%201%201h4%22%2F%3E%3Cpath%20d%3D%22M17%2021h-10a2%202%200%200%201%20-2%20-2v-14a2%202%200%200%201%202%20-2h7l5%205v11a2%202%200%200%201%20-2%202%22%2F%3E%3Cpath%20d%3D%22M9%209l1%200%22%2F%3E%3Cpath%20d%3D%22M9%2013l6%200%22%2F%3E%3Cpath%20d%3D%22M9%2017l6%200%22%2F%3E%3C%2Fsvg%3E") center / contain no-repeat;
}

.lexxy-content .attachment--file .attachment__caption {
  padding: 0;
}

.lexxy-content .attachment--file .attachment__name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.lexxy-content .attachment--file .attachment__size {
  color: var(--text-tertiary);
  font-size: var(--font-size-xs);
}

.lexxy-content .attachment--pdf .attachment__size::before {
  content: "PDF · ";
}

/* Lexxy's own toolbar on a selected image or file (its Remove): inside its top-right corner, with room around it, not
   on the edge. */
.wi-lesson-text lexxy-attachment-toolbar:not([data-presentation="inline"], [data-node-type="horizontal_divider"]) {
  transform: translate(calc(-100% - var(--space-2)), var(--space-2));
}

/* A file where the text is read (active_storage/blobs/_blob): its name opens it, and so does the whole row. */
.lexxy-content .attachment--file:has(a.attachment__name) {
  position: relative;
}

.lexxy-content a.attachment__name {
  color: var(--text-primary);
  text-decoration: none;
}

.lexxy-content a.attachment__name::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
}

.lexxy-content .attachment--file:has(a.attachment__name:hover) {
  background: var(--background-surface);
}

.lexxy-content a.attachment__name:focus-visible {
  outline: none;
}

.lexxy-content a.attachment__name:focus-visible::after {
  box-shadow: var(--focus-ring);
}
