@layer components {
  /* The Review page (reviews/show) and a review's findings there and in the Review tab on Write. Two sizes of text:
     the page's, and --text-small inside a criterion and a finding, with labels in grey; color only in the signs of the
     grades. What folds has the arrow of icons.css (.fold-chevron). */
  .review-banner {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background-color: var(--color-warning-soft);
    color: var(--color-warning);
    font-size: var(--text-small);
  }

  .review-meta {
    color: var(--color-muted);
    font-size: var(--text-small);
  }

  /* How many checks got each grade, under the summary */
  .review-counts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    font-size: var(--text-small);

    > span {
      display: inline-flex;
      align-items: center;
      gap: var(--space-1);
    }
  }

  /* A grade as a sign in a circle: met, partly met, not met in color; the rest grey */
  .review-glyph {
    display: inline-grid;
    flex: none;
    place-items: center;
    inline-size: 1.25rem; /* the circle, a little larger than the small text beside it; the indents below count with it */
    block-size: 1.25rem;
    border-radius: 50%;
    background-color: var(--color-surface-soft);
    color: var(--color-muted);
    font-size: var(--text-xx-small);
    font-weight: var(--font-weight-bold);
    line-height: 1;
  }

  .review-glyph--met { background-color: var(--color-positive-soft); color: var(--color-positive); }
  .review-glyph--partly { background-color: var(--color-warning-soft); color: var(--color-warning); }
  .review-glyph--not { background-color: var(--color-negative-soft); color: var(--color-negative); }

  /* A line that folds open: since the last review, a criterion, a check or finding in it. Grey under the pointer. */
  :is(.review-row, .review-criterion, .review-check, .review-finding) > summary {
    border-radius: var(--radius-sm);

    &:hover { background-color: var(--color-surface-soft); }
  }

  .review-row {
    font-size: var(--text-small);

    > summary {
      display: flex;
      align-items: center;
      gap: var(--space-2);
      padding: var(--space-1);
    }
  }

  .review-row__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2) 0 var(--space-1) var(--space-4);
  }

  .review-line {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--space-2);
    align-items: baseline;
  }

  /* The catalogue: a criterion per row, a sign per check at its end; opened, its checks and findings */
  .review-criterion {
    border-block-start: var(--border);
    scroll-margin-block-start: var(--space-4);

    &:first-child { border-block-start: 0; }

    > summary {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr) auto auto;
      align-items: center;
      gap: var(--space-2) var(--space-3);
      padding: var(--space-2) var(--space-1);
    }
  }

  .review-criterion__name {
    font-weight: var(--font-weight-medium);
  }

  /* As wide as six signs, the most a criterion has, so the rows start in one column */
  .review-criterion__grades {
    display: flex;
    gap: var(--space-1);
    min-inline-size: calc(6 * 1.25rem + 5 * var(--space-1));
  }

  @media (max-width: 40rem) {
    .review-criterion__grades { display: none; }
  }

  .review-criterion__status {
    min-inline-size: 7rem; /* as wide as "3 open" and "All met", so the signs before it stand in one column */
    font-size: var(--text-small);
    text-align: end;
  }

  .review-criterion__open {
    color: var(--color-warning);
    font-weight: var(--font-weight-semibold);
  }

  /* Indented by the arrow (1rem) and the gap after it */
  .review-criterion__body {
    display: flex;
    flex-direction: column;
    padding: 0 var(--space-1) var(--space-3) calc(1rem + var(--space-3));
    font-size: var(--text-small);

    > p { padding-block-end: var(--space-2); }
  }

  /* Each check of an opened criterion a row of its own between lines, a finding as one that folds too (open until it
     is done): arrow, sign, title; opened, its parts below the title */
  .review-criterion__body > :is(.review-check, .review-finding) {
    display: block;
    padding: 0;
    border-block-start: var(--border);

    > summary {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: var(--space-1) var(--space-2);
      padding: var(--space-2) var(--space-1);
    }
  }

  /* The labels begin under the title (after the arrow, the sign and their gaps), so the column of signs stays free */
  .review-criterion__body :is(.review-check__body, .review-finding__body) {
    margin: var(--space-1) var(--space-1) var(--space-3) calc(var(--space-1) + 1em + 1.25rem + 2 * var(--space-2));
  }

  /* The parts of a finding or check (Your text, Passages, Met if, To think about …), each beside its label in a column
     of its own. Where there is little room (on Write), each label above its part. */
  .review-finding,
  .review-check {
    container-type: inline-size;
  }

  .review-parts {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr); /* as wide as the longest label, "To think about" */
    gap: var(--space-2) var(--space-3);
    margin: 0;

    > dt {
      color: var(--color-muted);
      font-weight: var(--font-weight-semibold);
    }

    > dd {
      display: flex;
      flex-direction: column;
      gap: var(--space-2);
      min-inline-size: 0;
      margin: 0;
    }

    > .review-parts__actions {
      grid-column: 2;
      flex-direction: row;
      padding-block-start: var(--space-1);
    }
  }

  /* Narrower than this, a label beside its part leaves too little room for the part */
  @container (max-width: 28rem) {
    .review-parts {
      grid-template-columns: minmax(0, 1fr);
      gap: var(--space-1);

      > dd:not(:last-child) { margin-block-end: var(--space-2); }
      > .review-parts__actions { grid-column: 1; }
    }
  }

  /* A passage a grade rests on, word for word, with its chapter and "Show in Write" */
  .review-passage {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-1) var(--space-2);
    margin: 0;
    padding-inline-start: var(--space-3);
    border-inline-start: var(--border-width-2) solid var(--color-border);

    q { flex: 1 1 100%; }
  }

  /* "All" or "Open" above the catalogue; Open shows only the open findings (review-filter controller) */
  .review-filter {
    flex: none;
  }

  .review-catalog.is-open-only {
    .review-check,
    .review-criterion__body > p,
    .review-finding.is-closed,
    .review-criterion:not(:has(.review-finding:not(.is-closed))) {
      display: none;
    }
  }

  /* A finding (review_checks/_finding): always the same parts, on the Review page and on Write. One the student dealt
     with is faded, as a disabled button is (base.css). */
  .review-finding {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-1);
    border-radius: var(--radius-sm);
    font-size: var(--text-small);
    scroll-margin-block-start: var(--space-4);

    &.is-closed .review-finding__body { opacity: 0.6; }
  }

  .review-finding__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
  }

  /* Under its title too where it has no arrow (before the first review); on Write the column is too narrow */
  .review-finding__body {
    margin-inline-start: calc(1.25rem + var(--space-2));
  }

  .review-finding__state {
    margin-inline-start: auto;
  }

  /* Possible directions: folded under the question, so thinking comes first */
  .review-finding__ways {
    > summary {
      display: inline-flex;
      align-items: center;
      gap: var(--space-1);
      color: var(--color-muted);
      font-weight: var(--font-weight-semibold);
    }

    ul {
      margin: var(--space-1) 0;
      padding-inline-start: var(--space-4);
    }
  }

  /* "I see it differently" as a button; opened, the reason's field below the buttons */
  .review-finding__dispute {
    summary { display: inline-flex; }

    &[open] {
      flex-basis: 100%;

      summary { margin-block-end: var(--space-1); }
    }
  }

  .review-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-2);

    > form {
      display: contents;
    }
  }

  .review-missing[hidden],
  .write-tabs [hidden] {
    display: none;
  }

  .review-missing {
    color: var(--color-warning);
    font-weight: var(--font-weight-semibold);
  }

  /* A correction of the language check on Write: the passage struck out, what replaces it underlined, as Ask AI marks
     what goes and what is new (write.css, ::highlight(text-rewrite-removed) and .text-rewrite__changed). Not green:
     that is a citation's wording. */
  .review-quote {
    margin: 0;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    background-color: var(--color-surface-soft);

    del {
      color: var(--color-negative);
      text-decoration: line-through 1.5px;
    }

    ins {
      text-decoration: underline 2px var(--color-blue-accent);
      text-underline-offset: 3px;
    }
  }

  /* A card that folds: how the thesis developed, what a finding looks like */
  .review-fold > summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
  }

  /* How the thesis developed: open findings per criterion and review */
  .review-history {
    overflow-x: auto;
    margin-block-start: var(--space-3);

    table {
      inline-size: 100%;
      min-inline-size: 28rem; /* a criterion's name and four reviews; narrower, the table scrolls */
      border-collapse: separate;
      border-spacing: 3px; /* a thin gap between the cells, below the spacing scale */
      font-size: var(--text-small);
    }

    th {
      font-weight: var(--font-weight-normal);
      text-align: start;
    }

    thead th {
      color: var(--color-muted);
      text-align: center;
    }
  }

  .review-cell {
    display: block;
    padding: 2px 0; /* a cell as low as a line of small text */
    border-radius: var(--radius-sm);
    font-weight: var(--font-weight-semibold);
    text-align: center;
  }

  .review-cell--none { background-color: var(--color-positive-soft); color: var(--color-positive); }
  .review-cell--one { background-color: var(--color-selected); color: var(--color-link); }
  .review-cell--more { background-color: var(--color-warning-soft); color: var(--color-warning); }
  .review-cell--not-yet { background-color: var(--color-surface-soft); color: var(--color-muted); }

  /* What a review costs, before it is asked for (reviews/_form): the text and the bar side by side, the bar below
     where they don't fit */
  .review-cost {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background-color: var(--color-surface-soft);

    > :first-child {
      flex: 1 1 18rem; /* the text: two lines at most beside the bar */
    }
  }

  /* The allowance used, and what this review adds (striped) */
  .review-meter {
    display: flex;
    flex: 1 1 12rem; /* the bar: long enough to read a share of a few percent */
    block-size: 10px; /* a thin bar, like the usage bar in the sidebar */
    overflow: hidden;
    border: var(--border);
    border-radius: var(--radius-pill);
    background-color: var(--color-surface-raised);
  }

  .review-meter__used {
    background-color: var(--color-link);
  }

  .review-meter__this {
    background: repeating-linear-gradient(-45deg, var(--color-link) 0 4px, var(--color-selected) 4px 8px); /* stripes */
  }

  /* Before the first review (reviews/_about) */
  .review-about__list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-inline-size: 72ch; /* a line that reads well */
    margin: 0;
    padding-inline-start: var(--space-4);
  }

  /* Write's right column: the tabs (write-tabs controller), a thin rim around them as around a segmented control */
  .write-tabs__bar {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-1);
    display: flex;
    gap: 2px; /* below the spacing scale, as .segmented-control */
    margin: var(--space-2) var(--space-2) 0;
    padding: 2px;
    border-radius: var(--radius-md);
    background-color: var(--color-surface-soft);

    /* Three in a narrow column: they share its width, a label too long for its share is cut with an ellipsis */
    button {
      display: inline-flex;
      flex: 1 1 auto; /* each as wide as it needs, the rest shared */
      align-items: center;
      justify-content: center;
      gap: 2px; /* the count close to its label */
      min-inline-size: 0;
      padding: var(--space-1) 2px; /* hardly any at the sides, so the three labels fit */
      border: 0;
      white-space: nowrap;
      border-radius: var(--radius-sm);
      background: none;
      color: var(--color-muted);
      font-size: var(--text-small);
      font-weight: var(--font-weight-semibold);
    }

    button[aria-selected="true"] {
      background-color: var(--color-surface-raised);
      color: var(--color-ink);
      box-shadow: var(--shadow-sm);
    }
  }

  .write-tabs__bar button > :not(.write-tabs__label) {
    flex: none;
  }

  /* In a narrow column (its default width is a fifth of the window) the labels a step smaller, so all three fit */
  .write-tabs {
    container-type: inline-size;
  }

  @container (max-width: 17rem) {
    .write-tabs__bar { margin-inline: var(--space-1); }
    .write-tabs__bar button { font-size: var(--text-x-small); }
  }

  .write-tabs__label {
    min-inline-size: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* The number of what is open on a tab */
  .write-tabs__count {
    padding: 0 var(--space-1);
    border-radius: var(--radius-pill);
    background-color: var(--color-link);
    color: var(--color-ink-inverted);
    font-size: var(--text-xx-small);
  }

  /* The Language and Review tabs on Write (write/_language, write/_review), laid out like the citations: groups that
     fold, with the look of the citations' chapters (write.css, .write-citations__summary). The switch off: what is done
     goes (a finding looked at, a correction applied or dismissed), and so does a group with nothing else; with nothing
     left at all, the hint shows. Each group counts its open items; on, all of them.
     Long German words broken where they don't fit, so the narrow column doesn't scroll sideways. Positioned, so what is
     there only for screen readers (.sr-only, placed absolutely) stays in the column: placed against the page, it sat far
     down the list and made the whole page scroll into empty space below the app. */
  .write-review,
  .write-language {
    position: relative;
    overflow-wrap: anywhere;

    &:not(:has(.switch input:checked)) {
      :is(.review-finding, .language-point).is-closed,
      :is(.write-review__group, .write-language__group):not(:has(:is(.review-finding, .language-point):not(.is-closed))),
      [data-total-count] {
        display: none;
      }
    }

    &:has(.switch input:checked) :is([data-open-count], .write-review__empty, .write-language__empty),
    &:has(:is(.review-finding, .language-point):not(.is-closed)) :is(.write-review__empty, .write-language__empty) {
      display: none;
    }
  }

  /* Without a subscription: what comes with one */
  .write-tabs__lock {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: var(--border-dashed);
    border-radius: var(--radius-md);
  }

  /* A finding or correction in the narrow column: a card, the sign beside the title, the parts below it at full
     width */
  .write-review .review-finding,
  .language-point {
    padding: var(--space-2) var(--space-3);
    border: var(--border);
    border-radius: var(--radius-md);
    background-color: var(--color-surface-raised);
  }

  .write-review .review-finding__head {
    flex-wrap: nowrap;
    align-items: flex-start;
  }

  .write-review .review-finding__body {
    margin-inline-start: 0;
  }

  /* A correction of the chapter's language check, red at its start as its wavy line in the text */
  .language-point {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    border-inline-start: var(--border-width-2) solid var(--color-negative);
    font-size: var(--text-small);

    &.is-closed {
      border-inline-start-color: var(--color-border);
      opacity: 0.6;
    }
  }

  /* In the sidebar: a review being made, or one done and not opened yet */
  .nav-badge {
    margin-inline-start: auto;
    flex: none;
  }

  .nav-dot {
    inline-size: var(--space-2);
    block-size: var(--space-2);
    border-radius: 50%;
    background-color: var(--color-link);
  }

  /* In the text on Write: the open corrections while the Language tab is open, and the passage last shown. The
     browser's custom highlights, set by the passages controller (nothing in the editor's content) */
  ::highlight(language-points) {
    text-decoration: underline wavy var(--color-negative);
  }

  ::highlight(review-finding-active) {
    background-color: var(--color-selected);
    text-decoration: none;
  }
}
