/* Decision notes polish (Nov 4): direction A refined, at ?notes=a2. Each refinement can be
   switched off from /sketches/note-polish, which puts np-off-<n> on the frame's root. */

@layer sketches {
  /* List 1. The note tucks under the name: the cells beside it span both lines, so the note
     shares the milestone label's line instead of starting under it. */
  .projects__note--a2 {
    display: none;
  }

  @media (min-width: 721px) {
    :root:not(.np-off-1) {
      & .projects__row:has(+ .projects__note-row--a2) > * {
        padding-bottom: var(--space-xs);
      }

      & .projects__row:has(+ .projects__note-row--a2) > [rowspan] {
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--hairline);
      }

      & tbody:last-child .projects__row:has(+ .projects__note-row--a2:last-child) > [rowspan] {
        border-bottom: 0;
      }

      & .projects__note-row--a2 .projects__note-lead {
        display: none;
      }
    }
  }

  /* List 2. A long note never widens a column: its width comes from the columns, not the reverse. */
  :root:not(.np-off-2) .projects__note-row--a2 .projects__note-line {
    contain: inline-size;
  }

  @media (max-width: 720px) {
    .projects__note--a2 {
      display: flex;
      max-width: none;
      color: var(--ink-body);
    }
  }

  /* List 3. The icon hangs in the gutter, so the note's words start on the name's left edge. */
  :root:not(.np-off-3) :is(.projects__note-row--a2 .projects__note-line, .projects__note--a2) .icon {
    position: absolute;
    translate: calc(-100% - var(--space-xs)) 0;
  }

  /* List 4. A bubble with lines: a written note, not a comment thread. */
  .np-icon-refined,
  :root.np-off-4 .np-icon-today {
    display: inline-block;
  }

  .np-icon-today,
  :root.np-off-4 .np-icon-refined {
    display: none;
  }

  /* List 5. Keyboard focus rings both lines of a row with a note, not just the first. */
  @media (min-width: 721px) {
    :root:not(.np-off-5):not(.np-off-1) .projects__row:has(+ .projects__note-row--a2):has(.projects__name:focus-visible, .projects__name.np-focus) {
      --ring: var(--periwinkle);

      outline: none;

      & > * {
        box-shadow: inset 0 2px 0 var(--ring);
      }

      & > [rowspan] {
        box-shadow: inset 0 2px 0 var(--ring), inset 0 -2px 0 var(--ring);
      }

      & > :first-child {
        box-shadow: inset 2px 0 0 var(--ring), inset 0 2px 0 var(--ring), inset 0 -2px 0 var(--ring);
      }

      & > :last-child {
        box-shadow: inset -2px 0 0 var(--ring), inset 0 2px 0 var(--ring), inset 0 -2px 0 var(--ring);
      }
    }

    :root:not(.np-off-5):not(.np-off-1) .projects__row:has(.projects__name:focus-visible) + .projects__note-row--a2 > td,
    :root:not(.np-off-5):not(.np-off-1) .projects__row:has(.projects__name.np-focus) + .projects__note-row--a2 > td {
      box-shadow: inset 0 -2px 0 var(--periwinkle);
    }

    /* The sketch's stand-in for keyboard focus, so the ring shows without a keyboard. */
    .projects__row:has(.projects__name.np-focus) {
      outline: 2px solid var(--periwinkle);
      outline-offset: -2px;
    }
  }

  /* Page 6. No note yet: one quiet line that says what to add, instead of a label over “Add a note”. */
  .decision-note__add {
    display: none;
  }

  :root:not(.np-off-6) .decision-note--empty {
    & .decision-note__title {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
    }

    & .decision-note__text {
      margin-top: 0;
      font-size: var(--text-sm);
    }

    & .decision-note__edit {
      display: none;
    }

    & .decision-note__add {
      display: inline;
      font-weight: var(--weight-emphasis);
      color: var(--blue);
      cursor: pointer;

      &:hover {
        text-decoration: underline;
        text-underline-offset: 3px;
      }
    }
  }

  /* Page 7. Edit and Add take a 33px target without moving a pixel of the text. */
  :root:not(.np-off-7) .decision-note--a2 :is(.decision-note__edit, .decision-note__add) {
    position: relative;
    border-radius: var(--radius-sm);

    &::before {
      content: "";
      position: absolute;
      inset: -0.25rem -0.5rem;
    }
  }

  /* The polish page itself. */
  .np-intro,
  .np-body {
    display: grid;
    gap: var(--space-lg);
    width: 100%;
  }

  .np-intro .sketch__lede {
    max-width: 85ch;
  }

  .np-area {
    display: grid;
    gap: var(--space-sm);
  }

  .np-area__title {
    margin-top: var(--space-lg);
    font-size: var(--text-heading);
    font-weight: var(--weight-display);
    color: var(--ink);
  }

  .np-refinement--fixed {
    cursor: default;
  }

  .np-pair {
    display: grid;
    gap: var(--space-md);
  }

  .np-pair__title {
    font-size: var(--text-md);
    font-weight: var(--weight-emphasis);
    color: var(--ink);
  }

  .np-frame {
    display: grid;
    gap: var(--space-xs);
  }

  .np-frame__label {
    font-size: var(--text-label);
    font-weight: var(--weight-emphasis);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--ink-muted);

    & strong {
      color: var(--navy);
    }
  }

  .np-frame__open {
    margin-left: var(--space-sm);
    color: var(--blue);
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .np-frame__screen {
    display: block;
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
  }

  .np-phones {
    margin-top: 0;
  }

  .np-phone {
    height: 640px;
  }

  .np-caption {
    max-width: 85ch;
    font-size: var(--text-sm);
    color: var(--ink-muted);
  }

  .np-dialogs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr));
    gap: var(--space-lg);
    align-items: start;
  }

  .np-dialogs__item {
    display: grid;
    gap: var(--space-xs);
  }
}

@layer sketches {
  .np .pl-refinement__values {
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0, "calt" 0;
  }

  .np-refinement__spacer {
    width: 1rem;
  }
}
