@layer components {
  /* The check page: photo, checking and result (checks/new), in PhotoAiD's order
   * (founder's picks, 17 Nov 2026; design-explorations/add-photo, checking and check-result, A). */
  .checker__step {
    display: flex;
    flex-direction: column;
    gap: 24px;

    @media (min-width: 761px) {
      gap: 36px;
    }
  }

  /* A problem with the check itself, not a verdict on the photo: the warm neutral.
   * It takes the lead's place, so the buttons don't move. */
  .checker__problem {
    background: var(--color-warm);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font: var(--text-small);
    padding: 12px 14px;
    text-align: start;

    .btn { align-self: flex-start; }
  }

  /* ---- Step 2: the photo ---- */

  /* On a phone one column in PhotoAiD's order, the main and aside columns opened up;
   * on a desktop the drop area on the left, the example and the tips on the right. */
  .photo-step {
    @media (max-width: 899px) {
      &.flow__columns { gap: 20px; }

      .flow__main,
      .flow__aside {
        display: contents;
      }
    }
  }

  .photo-step__heading {
    @media (max-width: 899px) { order: 0; }

    &:has(.checker__problem:not([hidden])) .flow__lead {
      display: none;
    }
  }

  .photo-step__example,
  .photo-step__privacy {
    @media (max-width: 760px) { text-align: center; }
  }

  .photo-step__example { @media (max-width: 899px) { order: 2; } }
  .photo-step__privacy { @media (max-width: 899px) { order: 4; } }

  /* One button for the camera and the library, on a touch screen only. */
  .photo-step__bar {
    @media (max-width: 899px) { order: 6; }

    @media (pointer: fine) {
      &.flow__bar { display: none; }
    }
  }

  /* One photo, half as taken and half as made for the document. */
  .split-photo {
    aspect-ratio: 1;
    background: var(--color-placeholder);
    border: 1px solid var(--color-hairline);
    border-radius: 12px;
    inline-size: 100%;
    margin: 0;
    overflow: hidden;
    position: relative;

    @media (max-width: 899px) {
      margin-inline: auto;
      max-inline-size: 244px;
      order: 1;
    }

    &::after {
      border-inline-start: 1.5px dashed rgb(23 22 20 / 55%);
      content: "";
      inset-block: 0;
      inset-inline-start: calc(50% - 0.75px);
      position: absolute;
    }
  }

  .split-photo__image {
    block-size: 100%;
    inline-size: 100%;
    inset: 0;
    object-fit: cover;
    position: absolute;
  }

  .split-photo__image--after {
    clip-path: inset(0 0 0 50%);
  }

  .split-photo__tab {
    background: var(--color-ink);
    border-start-end-radius: 8px;
    color: var(--color-on-ink);
    font: 500 11px/16px var(--font-mono);
    inset-block-end: 0;
    inset-inline-start: 0;
    letter-spacing: 0.06em;
    padding: 5px 10px;
    position: absolute;
    text-transform: uppercase;
    z-index: 1;
  }

  .split-photo__tab--after {
    border-radius: 0;
    border-start-start-radius: 8px;
    inset-inline: auto 0;
  }

  /* Where the photo comes in on a desktop: a drop area with a file button, the QR code under it.
   * On a touch screen only its note stays; the button is pinned to the bottom. */
  .drop {
    align-items: center;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: center;

    @media (max-width: 899px) { order: 3; }

    @media (pointer: fine) {
      background: var(--color-surface);
      border: 1.5px dashed var(--color-muted);
      border-radius: 14px;
      padding: 28px 24px;
    }
  }

  .drop--over {
    border-color: var(--color-ink);
    border-style: solid;
  }

  .drop__icon,
  .drop__title,
  .btn.drop__button {
    @media (pointer: coarse) {
      display: none;
    }
  }

  .drop__icon {
    --icon-size: 36px;
  }

  .drop__title {
    font: var(--text-h3);
  }

  .qr {
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-hairline);
    border-radius: 14px;
    display: grid;
    gap: 16px;
    grid-template-columns: 104px minmax(0, 1fr);
    padding: 14px 16px;

    @media (max-width: 899px) { order: 3; }

    @media (pointer: coarse) {
      display: none;
    }
  }

  .qr__code {
    block-size: 104px;
    color: var(--color-ink);
    inline-size: 104px;
  }

  .qr__text {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .qr__title {
    font-size: 17px;
    font-weight: 600;
    line-height: 24px;
  }

  .flow-card.tips {
    gap: 10px;
    padding: 14px 16px;

    @media (max-width: 899px) { order: 5; }
  }

  .tips__title {
    font: 600 17px/24px var(--font-text);
  }

  .tips__list {
    display: flex;
    flex-direction: column;
    gap: 12px;

    li {
      display: grid;
      font-size: 16px;
      gap: 10px;
      grid-template-columns: 26px minmax(0, 1fr);
      line-height: 24px;
    }
  }

  .tips__number {
    color: var(--color-muted);
    font: 500 13px/24px var(--font-mono);
  }

  /* On the order page, the tip that answers the expert's reason. */
  .tips__item--named {
    background: var(--color-warm);
    border-radius: 8px;
    margin-inline: -8px;
    padding: 8px;
  }

  .tips__named {
    color: var(--color-muted);
    font: 500 11px/16px var(--font-mono);
    grid-column: 2;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* ---- Step 3: the check running ---- */

  /* The photo where the result will put it, the heading under it, the stages, and on a
   * phone the stage running now pinned where the result's button will be. */
  .checking {
    display: flex;
    flex-direction: column;
    gap: 20px;

    @media (min-width: 900px) {
      align-items: center;
      column-gap: 72px;
      display: grid;
      grid-template-areas: "heading photo" "stages photo";
      grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
      row-gap: 28px;
    }
  }

  .checking__photo { grid-area: photo; }
  .checking__heading { grid-area: heading; }
  .checking__stages { grid-area: stages; }

  /* On a desktop the list shows the stage, so the bar shows only while the check
   * waits for the checker's files, under the list. */
  .checking__bar {
    @media (min-width: 761px) {
      &.flow__bar { display: none; }
      &.flow__bar:has(.checking__now--download:not([hidden])) { display: flex; }
    }
  }

  .checking__now {
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-hairline);
    border-radius: 10px;
    display: flex;
    gap: 12px;
    min-block-size: 54px;
    overflow: hidden;
    padding: 0 16px;
    position: relative;

    b {
      flex: 1;
      font-size: 16px;
      font-weight: 600;
      line-height: 22px;
      min-inline-size: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    span:last-child {
      color: var(--color-muted);
      font: 500 13px/18px var(--font-mono);
    }

    /* A fifth of the line for each stage reached. */
    &::after {
      background: var(--color-ink);
      block-size: 3px;
      content: "";
      inline-size: calc(var(--stage, 0) * 20%);
      inset-block-end: 0;
      inset-inline-start: 0;
      position: absolute;
      transition: inline-size 0.4s ease-out;
    }
  }

  /* What has arrived of the checker's files, under its label so both fit a
   * phone's width, and a line that fills with it. */
  .checking__now--download {
    display: grid;
    gap: 0 12px;
    grid-template-columns: auto minmax(0, 1fr);
    padding-block: 7px;

    .checking__ring { grid-row: span 2; }

    &::after { inline-size: calc(var(--arrived, 0) * 100%); }
  }

  .checking__ring {
    animation: turn 3s linear infinite;
    block-size: 20px;
    border: 2px dashed var(--color-ink);
    border-radius: 50%;
    flex-shrink: 0;
    inline-size: 20px;
  }

  /* The photo in a white card, a band sweeping down it. */
  .scan {
    aspect-ratio: 1;
    background: var(--color-surface);
    border-radius: 22px;
    box-shadow: 0 10px 30px rgb(23 22 20 / 9%);
    inline-size: 220px;
    margin-inline: auto;
    position: relative;

    @media (min-width: 900px) {
      border-radius: 28px;
      inline-size: 300px;
    }

    &::before {
      background: var(--color-placeholder);
      border-radius: 14px;
      content: "";
      inset: 10px;
      position: absolute;
    }
  }

  .scan__photo {
    block-size: calc(100% - 20px);
    border-radius: 14px;
    inline-size: calc(100% - 20px);
    inset: 10px;
    object-fit: cover;
    position: absolute;
  }

  .scan__band {
    border-radius: 14px;
    inset: 10px;
    overflow: hidden;
    position: absolute;

    &::before {
      animation: sweep 2.6s ease-in-out -1s infinite;
      background: linear-gradient(rgb(23 22 20 / 0%), rgb(23 22 20 / 26%));
      block-size: 36%;
      content: "";
      inset-inline: 0;
      position: absolute;
      translate: 0 -100%;
    }
  }

  /* The line reaches past the card, as the result's brackets do. */
  .scan__line {
    animation: sweep-line 2.6s ease-in-out -1s infinite;
    background:
      linear-gradient(var(--color-ink), var(--color-ink)) left center / 1.5px 12px no-repeat,
      linear-gradient(var(--color-ink), var(--color-ink)) right center / 1.5px 12px no-repeat;
    block-size: 12px;
    inset-inline: -29px;
    margin-block-start: -6px;
    position: absolute;

    &::before {
      border-block-start: 1.5px dashed var(--color-ink);
      content: "";
      inset-block-start: 5px;
      inset-inline: 0;
      position: absolute;
    }
  }

  @keyframes sweep {
    0% { opacity: 0; inset-block-start: 0%; }
    12%, 88% { opacity: 1; }
    100% { opacity: 0; inset-block-start: 100%; }
  }

  @keyframes sweep-line {
    0% { opacity: 0; inset-block-start: 10px; }
    12%, 88% { opacity: 1; }
    100% { opacity: 0; inset-block-start: calc(100% - 10px); }
  }

  @keyframes turn {
    to { rotate: 360deg; }
  }

  @keyframes halo {
    to { box-shadow: 0 0 0 7px var(--color-placeholder); }
  }

  @media (prefers-reduced-motion: reduce) {
    .scan__band::before,
    .scan__line,
    .checking__ring,
    .stages__item[data-state="now"] .stages__dot {
      animation: none;
    }
  }

  /* The stages of the check: a tick when done, the number of the one running. */
  .stages {
    display: flex;
    flex-direction: column;
  }

  .stages__item {
    align-items: center;
    display: grid;
    gap: 0 14px;
    grid-template-columns: 32px minmax(0, 1fr);
    padding: 6px 0;
    position: relative;

    @media (min-width: 900px) {
      gap: 0 18px;
      grid-template-columns: 36px minmax(0, 1fr);
      padding: 9px 0;
    }

    &::before {
      background: var(--color-hairline);
      content: "";
      inline-size: 2px;
      inset-block: 0;
      inset-inline-start: 15px;
      position: absolute;

      @media (min-width: 900px) { inset-inline-start: 17px; }
    }

    &[data-state="done"]::before { background: var(--color-ink); }
    &:first-child::before { inset-block-start: 50%; }
    &:last-child::before { inset-block-end: 50%; }
  }

  .stages__dot {
    --icon-size: 15px;

    align-items: center;
    background: var(--color-ground);
    block-size: 32px;
    border: 2px solid var(--color-hairline);
    border-radius: 50%;
    color: var(--color-surface);
    display: flex;
    font-size: 15px;
    font-weight: 600;
    inline-size: 32px;
    justify-content: center;
    position: relative;

    @media (min-width: 900px) {
      block-size: 36px;
      font-size: 16px;
      inline-size: 36px;
    }

    .icon,
    .stages__number { display: none; }

    [data-state="done"] > &,
    [data-state="now"] > & {
      background: var(--color-ink);
      border-color: var(--color-ink);
    }

    [data-state="done"] > & .icon { display: inline-block; }

    [data-state="now"] > & {
      animation: halo 1.4s ease-in-out infinite alternate;
      box-shadow: 0 0 0 4px var(--color-placeholder);

      .stages__number { display: inline; }
    }
  }

  .stages__title {
    color: var(--color-muted);
    font-size: 17px;
    line-height: 22px;

    @media (min-width: 900px) {
      font-size: 19px;
      line-height: 26px;
    }

    [data-state="now"] > & {
      color: var(--color-ink);
      font-weight: 600;
    }
  }

  .stages__detail {
    color: var(--color-muted);
    display: none;
    font: 500 13px/18px var(--font-mono);
    grid-column: 2;

    [data-state="now"] > & { display: block; }
  }

  /* ---- Step 3: the result ---- */

  /* On a phone the photo, the verdict, the checks, then the button pinned to the bottom;
   * on a desktop the checks on the left, the photo on the right, a button under each. */
  .result {
    display: flex;
    flex-direction: column;
    gap: 20px;

    @media (min-width: 900px) {
      align-items: start;
      column-gap: 72px;
      display: grid;
      grid-template-areas: "heading photo" "rows photo" "bar retake" "notes caption";
      grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
      grid-template-rows: auto 1fr auto auto;
      row-gap: 22px;
    }
  }

  .result__photo { grid-area: photo; order: 1; }
  .result__heading { grid-area: heading; order: 2; }

  .result__caption {
    grid-area: caption;
    order: 3;

    @media (max-width: 760px) { text-align: center; }
  }

  /* A photo that fails has no outline button under it: on a desktop its caption follows it. */
  .result:has(.preview__flag:not([hidden])) {
    @media (min-width: 900px) {
      grid-template-areas: "heading photo" "rows photo" "rows caption" "bar ." "notes .";
      grid-template-rows: auto auto 1fr auto auto;
    }
  }

  .result__rows { grid-area: rows; order: 4; }
  .result__retake { grid-area: retake; order: 5; }
  .result__notes { display: flex; flex-direction: column; gap: 10px; grid-area: notes; order: 6; }
  .result__bar { grid-area: bar; order: 7; }

  .result__bar,
  .result__retake {
    @media (min-width: 900px) {
      .flow__button {
        inline-size: 100%;
        min-inline-size: 0;
      }
    }
  }

  .result__retake .flow__button {
    inline-size: 100%;
  }

  .result__reasons {
    display: contents;
  }

  /* The photo, with room around it for the size and head marks. */
  .preview {
    margin: 0;
    padding-block-start: 30px;

    @media (min-width: 900px) {
      padding-block-start: 34px;
    }

    &:has(.preview__flag:not([hidden])) {
      padding-block-start: 0;
    }
  }

  .preview__frame {
    inline-size: min(200px, calc(100% - 160px));
    margin-inline: auto;
    position: relative;

    @media (min-width: 900px) {
      inline-size: min(280px, calc(100% - 140px));
    }

    .preview:has(.preview__flag:not([hidden])) & {
      inline-size: min(228px, 100%);

      @media (min-width: 900px) { inline-size: min(320px, 100%); }
    }
  }

  .preview__canvas {
    aspect-ratio: 1;
    background: var(--color-placeholder);
    border: 1px solid var(--color-hairline);
    border-radius: 12px;
    display: block;
    inline-size: 100%;
  }

  .preview__marks,
  .preview__measure,
  .preview__flag {
    inset: 0;
    pointer-events: none;
    position: absolute;
  }

  /* The file's size: a bracket over the photo and one at its side. */
  .preview__width {
    background: linear-gradient(var(--color-ink), var(--color-ink)) center / 100% 1.5px no-repeat;
    block-size: 11px;
    border-inline: 1.5px solid var(--color-ink);
    inset-block-start: -20px;
    inset-inline: 0;
    position: absolute;
  }

  .preview__height {
    background: linear-gradient(var(--color-ink), var(--color-ink)) center / 1.5px 100% no-repeat;
    border-block: 1.5px solid var(--color-ink);
    inline-size: 11px;
    inset-block: 0;
    inset-inline-start: -36px;
    position: absolute;
  }

  /* The head's height: two guides across the photo, at the crown and the chin, and a bracket beside it. */
  .preview__head {
    border-block: 1px dashed rgb(23 22 20 / 55%);
    inset-block-end: calc((1 - var(--chin, 0.7)) * 100%);
    inset-block-start: calc(var(--crown, 0.1) * 100%);
    inset-inline: 0 -17px;
    position: absolute;

    &::after {
      background: linear-gradient(var(--color-ink), var(--color-ink)) center / 1.5px 100% no-repeat;
      border-block: 1.5px solid var(--color-ink);
      content: "";
      inline-size: 12px;
      inset-block: -1px;
      inset-inline-end: 0;
      position: absolute;
    }

    /* The tag starts at the bracket, clear of the photo. */
    .preview__tag {
      inset-inline: calc(100% - 6px) auto;
      translate: 0 -50%;
      z-index: 1;
    }
  }

  .preview__tag {
    background: var(--color-ink);
    border-radius: 3px;
    color: var(--color-on-ink);
    font: 500 11px/14px var(--font-mono);
    inset-block-start: 50%;
    inset-inline-start: 50%;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    position: absolute;
    text-transform: uppercase;
    translate: -50% -50%;
    white-space: nowrap;
  }

  .preview__tag--open {
    background: var(--color-ground);
    box-shadow: inset 0 0 0 1.5px var(--color-ink);
    color: var(--color-ink);
  }

  /* What failed, on the photo as taken: a bar along the head that doesn't fit, and the label. */
  .preview__flag-bar {
    background: var(--color-fail);
    inline-size: 3px;
    inset-block-end: calc((1 - var(--bottom, 1)) * 100%);
    inset-block-start: calc(var(--top, 0) * 100%);
    inset-inline-end: 3.5%;
    position: absolute;

    &::before,
    &::after {
      background: var(--color-fail);
      block-size: 3px;
      content: "";
      inline-size: 13px;
      inset-inline-start: -5px;
      position: absolute;
    }

    &::before { inset-block-start: 0; }
    &::after { inset-block-end: 0; }
  }

  .preview__flag-tab {
    background: var(--color-fail);
    color: var(--color-surface);
    font: 500 11px/16px var(--font-mono);
    inset-block-start: 5%;
    inset-inline-end: 3.5%;
    letter-spacing: 0.06em;
    padding: 4px 8px;
    position: absolute;
    white-space: nowrap;
  }

  /* The checks between hairlines: the name with its measurement under it on a phone,
   * beside it on a desktop, and the verdict. */
  .check-rows {
    border-block-end: 1px solid var(--color-hairline);
    display: flex;
    flex-direction: column;
  }

  .check-row {
    align-items: center;
    border-block-start: 1px solid var(--color-hairline);
    display: grid;
    gap: 2px 12px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px 0;

    @media (min-width: 900px) {
      gap: 0 16px;
      grid-template-columns: 140px minmax(0, 1fr) auto;
      padding: 11px 0;
    }

    &:has(.chip--fail:not([hidden])) .check-row__name {
      color: var(--color-fail);
    }
  }

  .check-row__name {
    font-size: 17px;
    font-weight: 600;
    line-height: 22px;
  }

  .check-row__value {
    color: var(--color-muted);
    font: 500 13px/18px var(--font-mono);
    grid-column: 1;

    @media (min-width: 900px) { grid-column: 2; grid-row: 1; }
  }

  .check-row__verdict {
    grid-column: 2;
    grid-row: 1 / span 2;

    @media (min-width: 900px) { grid-column: 3; grid-row: 1; }
  }

  /* On the check page in retake mode: the expert's verdict, so its chip, and what to change. */
  .retake-notice {
    align-items: flex-start;
    background: var(--color-fail-tint);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    font: var(--text-small);
    gap: 6px;
    padding: 12px 14px;
  }
}
