@layer views {
  /* ── a topic's sheet (parts/concept.js): a drawer on the right; on a phone, the whole screen.
     The head stays put and the body scrolls under it. ── */
  dialog.sheet {
    inset: 0 0 0 auto; margin: 0; padding: 0;
    width: min(480px, 100%); max-width: 100%; height: 100vh; height: 100dvh; max-height: none;
    border: 0; border-left: 1px solid var(--line-2); border-radius: var(--r-card) 0 0 var(--r-card);
    background: var(--surface); color: var(--fg-2); box-shadow: var(--shadow-float);
    overflow: hidden; overscroll-behavior: contain;
    &[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); animation: sheet-in var(--t) var(--ease-liquid); }
  }
  @keyframes sheet-in { from { translate: 32px 0; opacity: 0; } }
  @keyframes sheet-up { from { translate: 0 24px; opacity: 0; } }

  .sheet-head {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 12px;
    padding: 18px 16px 14px 22px; border-bottom: 1px solid var(--line); background: var(--surface);
  }
  .sheet-head-main { display: grid; gap: 4px; min-width: 0; }
  .sheet-close { margin-top: -4px; }
  .sheet-body {
    display: flex; flex-direction: column; gap: 24px; min-height: 0;
    padding: 18px 22px 28px; overflow: hidden auto; overscroll-behavior: contain;
  }

  .cx-back {
    justify-self: start; max-width: 100%; margin-bottom: 4px;
    font-size: var(--fs-sm); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    &:hover { color: var(--fg); }
  }
  .cx-title { font-size: var(--fs-xl); letter-spacing: -0.035em; overflow-wrap: anywhere; }
  .cx-title:focus { outline: none; }
  .cx-statement { color: var(--fg-2); }

  /* each part: a label for a heading, then its content */
  .cx-sec { display: grid; gap: 10px; min-width: 0; }
  .cx-sec-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
  .cx-sub { font-size: var(--fs-meta); color: var(--muted); }
  .cx-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
  /* a part's rows: one list, a hairline between them (a shadow, so a row's own border can go) */
  .cx-list { margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--r-tile); overflow: hidden; }
  .cx-list > * + * { box-shadow: inset 0 1px 0 var(--line); }

  /* the long parts fold (closed to start on a phone); a <details> is laid out as a block */
  .cx-fold { display: block; }
  .cx-fold > summary {
    display: flex; align-items: center; gap: 8px; width: fit-content; cursor: pointer; list-style: none;
    &::-webkit-details-marker { display: none; }
    &::after {
      content: ''; width: 6px; height: 6px; margin-left: 2px; translate: 0 -2px;
      border: solid var(--muted); border-width: 0 1.5px 1.5px 0; rotate: 45deg; transition: rotate var(--t-fast);
    }
    &:hover .cx-h { color: var(--fg); }
  }
  .cx-fold:not([open]) > summary::after { rotate: -45deg; translate: 0 0; }
  .cx-fold-body { display: grid; gap: 8px; margin-top: 10px; }

  /* 1. where you stand: its status, then the facts as plain text */
  .cx-status { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: var(--fs-body-sm); }
  .cx-status .dot { translate: 0 -1px; }
  .cx-status b { color: var(--fg); font-weight: 700; }
  .cx-status[data-status="solid"] b { color: var(--known); }
  .cx-status[data-status="due"] b { color: var(--due); }
  .cx-status[data-status="learning"] b { color: var(--learning); }
  .cx-facts { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0; }
  .cx-facts > div { display: inline-flex; align-items: baseline; gap: 7px; }
  .cx-facts dd { margin: 0; font-size: var(--fs-body-sm); font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }

  /* 2. why it matters */
  .cx-asg > li {
    display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px;
    padding: var(--pad-row);
  }
  .cx-asg-title { min-width: 0; color: var(--fg); font-weight: 700; font-size: var(--fs-body-sm); text-decoration: none; overflow-wrap: anywhere; }
  .cx-asg-title:hover { text-decoration: underline; }
  .cx-asg > li[data-status="done"] .cx-asg-title { color: var(--muted); }
  .cx-exam { font-size: var(--fs-body-sm); color: var(--fg-2); }

  /* 3. the ways to study it: practising leads, the others in a row under it */
  .cx-study { display: grid; gap: 8px; }
  .cx-more { display: flex; flex-wrap: wrap; gap: 8px; }
  .cx-more .pill { flex: 1 1 0; }

  /* 4. your notes: note cards as the list's rows */
  .cx-note-list > .note-card { padding: var(--pad-row); border: 0; border-radius: 0; background: none; }
  .cx-more-notes { justify-self: start; font-size: var(--fs-sm); }

  /* 5. the lesson, in two lines */
  .cx-lesson { display: grid; gap: 8px; padding: 2px 0 2px 14px; border-left: 2px solid var(--line-2); }
  .cx-hook { color: var(--fg); font-weight: 600; }
  .cx-takeaway { display: grid; gap: 2px; font-size: var(--fs-body-sm); color: var(--fg-2); }

  /* 6. where your materials teach it: each passage cut to a few lines until you ask for the rest */
  .src-passage { display: grid; gap: 6px; padding: var(--pad-row); min-width: 0; }
  .src-passage-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; font-size: var(--fs-meta); color: var(--muted); }
  .src-passage-head b { color: var(--fg); font-size: var(--fs-body-sm); overflow-wrap: anywhere; }
  .src-passage-body { font-size: var(--fs-body-sm); color: var(--fg-2); overflow-x: auto; }

  /* 7. recent answers: quiz.js's question rows, as this list's rows, with the mark, when, and "you were sure" stacked at the end */
  .cx-list > .quiz-q { border: 0; border-radius: 0; }
  .cx-attempt > summary { grid-template-columns: auto minmax(0, 1fr) auto; padding: var(--pad-row); font-size: var(--fs-body-sm); }
  .cx-attempt > summary:focus-visible { outline-offset: -2px; }
  .cx-attempt-meta { display: grid; justify-items: end; gap: 2px; text-align: right; }
  .cx-when { white-space: nowrap; }
  .cx-attempt .quiz-q-body { padding: 12px 16px 14px; font-size: var(--fs-body-sm); }

  /* 8. mistakes: yours marked in red, the common ones plain */
  .cx-mistakes { display: grid; gap: 10px; margin: 0; padding: 0; }
  .cx-mistakes > li { display: grid; gap: 3px; padding-left: 12px; border-left: 2px solid var(--line-2); }
  .cx-mistakes[data-whose="yours"] > li { border-left-color: var(--wrong); }
  .cx-mistake { color: var(--fg); font-size: var(--fs-body-sm); font-weight: 600; }
  .cx-fix { font-size: var(--fs-meta); color: var(--fg-2); }

  /* 9. the map: each neighbour opens in this one's place, a row like the class map's */
  .cx-graph { display: grid; gap: 14px; }
  .cx-graph-group { display: grid; gap: 6px; }
  .cx-node {
    display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%;
    padding: var(--pad-row); border: 0; background: transparent;
    color: var(--fg); font-size: var(--fs-body-sm); font-weight: 600; text-align: left;
    transition: background var(--t-fast);
    &:hover { background: var(--surface-2); }
    &:focus-visible { outline-offset: -2px; }
  }
  .cx-node-title { min-width: 0; overflow-wrap: anywhere; }

  /* 10. last, quietly: renaming it, or taking it out of the class */
  .cx-manage { display: flex; flex-wrap: wrap; gap: 8px 20px; padding-top: 4px; font-size: var(--fs-sm); }
  .cx-manage .link-btn { color: var(--muted); font-weight: 500; }
  .cx-manage .link-btn:hover { color: var(--fg); }

  /* while the one fetch is out */
  .cx-skel { display: grid; gap: 10px; }
  .cx-skel > * { display: block; height: 12px; border-radius: 6px; background: var(--surface-2); animation: cx-pulse 1.4s ease-in-out infinite; }
  .cx-skel > .short { width: 60%; }
  .cx-skel > b { height: 64px; margin: 8px 0; border-radius: var(--r-tile); }
  @keyframes cx-pulse { 50% { opacity: .5; } }
  .cx-error { display: grid; gap: 12px; justify-items: start; }

  /* ── shared: a topic's name that opens its sheet (concept-link.js), wherever it shows ── */
  .concept-link {
    display: inline; padding: 0; border: 0; background: none; font: inherit; color: inherit; text-align: inherit;
    text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; overflow-wrap: anywhere;
    &:hover { color: var(--fg); text-decoration-color: currentColor; }
  }
  .concept-link.note-topic { min-width: 0; font-size: var(--fs-meta); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .note-count {
    display: inline-flex; align-items: center; gap: 4px; flex: none;
    font-family: var(--mono); font-size: var(--fs-label); color: var(--muted); font-variant-numeric: tabular-nums;
    & svg { width: 12px; height: 12px; }
  }
  /* a row on the class map (one of a step's list): the whole row opens the sheet */
  .concept-open {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: var(--pad-row); border: 0; border-bottom: 1px solid var(--line); background: transparent;
    color: inherit; text-align: left; transition: background var(--t-fast);
    &:last-child { border-bottom: 0; }
    &:hover { background: var(--surface-2); }
    &:focus-visible { outline-offset: -2px; }
    & .concept-title { flex: 1; }
  }
  /* under a session's feedback: your note on the topic (a quiet aside, not a box), and everything on it */
  .concept-foot { display: grid; gap: 8px; justify-items: start; font-size: var(--fs-meta); }
  .concept-foot-note { display: grid; gap: 2px; justify-self: stretch; padding-left: 12px; border-left: 2px solid var(--line-2); }
  .concept-foot-label { font-family: var(--mono); font-size: var(--fs-label); letter-spacing: var(--track-label); color: var(--muted); }
  .concept-foot-title { color: var(--fg); }
  .concept-foot-body { max-height: 6.5em; overflow: hidden; color: var(--fg-2); }
  .concept-foot-link { font-weight: 600; color: var(--fg-2); }
  /* looking back over a session's or a quiz's questions: misses first, the right ones folded */
  .lookback { display: grid; gap: 6px; }
  .lookback-right { display: grid; gap: 6px; }
  .lookback-right > summary { width: fit-content; padding: 4px 0; cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); }
  .lookback-right > summary:hover { color: var(--fg); }
  /* a miss you were sure of: the kind that needs you now */
  .q-sure {
    display: inline-flex; align-items: center; padding: 1px 8px; border-radius: var(--r-pill); white-space: nowrap;
    border: 1px solid color-mix(in oklch, var(--due) 40%, transparent);
    font-family: var(--mono); font-size: var(--fs-label); font-weight: 500; color: var(--due);
  }
  /* in a question row (quiz.js), under its mark */
  .quiz-q-mark:has(> .q-sure) { display: grid; justify-items: end; gap: 3px; }

  @media (pointer: coarse) {
    .concept-link { padding-block: 8px; margin-block: -8px; }
    .cx-fold > summary { padding-block: 6px; }
    .cx-node { min-height: 44px; }
  }

  /* a phone: the whole screen, clear of the notch and the home bar, with "practise this" held at
     the bottom in reach of a thumb (the other ways stay in the page, where they were) */
  @media (max-width: 640px) {
    dialog.sheet { width: 100%; border: 0; border-radius: 0; box-shadow: none; }
    dialog.sheet[open] { animation-name: sheet-up; }
    .sheet-head {
      padding: calc(12px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) 12px calc(16px + env(safe-area-inset-left, 0px));
    }
    .sheet-body {
      --gutter-l: calc(16px + env(safe-area-inset-left, 0px));
      --gutter-r: calc(16px + env(safe-area-inset-right, 0px));
      gap: 22px; padding: 16px var(--gutter-r) 0 var(--gutter-l);
    }
    .sheet-body::after { content: ''; flex: none; order: 1; height: calc(8px + env(safe-area-inset-bottom, 0px)); }
    .cx-study { display: contents; }
    .cx-practise {
      position: sticky; bottom: 0; z-index: 1; order: 2;
      margin-inline: calc(-1 * var(--gutter-l)) calc(-1 * var(--gutter-r));
      padding: 12px var(--gutter-r) calc(12px + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
      background: var(--surface); border-top: 1px solid var(--line);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    dialog.sheet[open] { animation: none; }
    .cx-skel > * { animation: none; }
    .cx-fold > summary::after { transition: none; }
  }
}
