/* ============================================
   HOW STORM WORKS (/how-it-works)
   ============================================
   The static reference page reached from the account menu. Same layering
   convention as admin-allowlist.css / members.css:
   - @layer components: structural rules only, so sizing, positioning,
     grid/flex, padding/margin, font-size/weight, border-radius.
   - @layer theme: all color / surface / border-color / background /
     box-shadow rules. Theme runs later in the cascade than components
     (see base.css `@layer reset, base, components, utilities, theme,
     overrides`) so dark-mode palettes win without specificity wars.

   Shared `.page` / `.page-bg` / `.page-header` / `.section-head` / `.card`
   chrome lives in shared/css/base.css and is reused verbatim; this file only
   adds the four screen-specific blocks (numbered steps, the after-invite
   flow, the where-things-live map, and the tour replay card).
   ============================================ */

@layer components {
  .how-it-works-page {
    padding-block: var(--space-xl);
    position: relative;
    overflow: hidden;
    /* Narrower than the allowlist's table page: this is prose, and a
       measure much past ~72ch stops being readable as a paragraph. One rule
       on the root — rather than repeating it on .page-header and each
       section — so every direct child, including ones added later, lands
       in the same centered column automatically. +2rem compensates for
       base.css's .page { padding: 1rem }: under the global box-sizing:
       border-box, max-inline-size caps the whole border box, so without
       this the root's own padding would eat into the 860px of text space
       rather than sit outside it. Centered because #main-content has no
       width cap of its own — without margin-inline: auto this column would
       sit flush left and dump all the leftover space on the right on a
       wide screen. */
    max-inline-size: calc(860px + 2rem);
    margin-inline: auto;

    & > section {
      margin-block-end: var(--space-xl);
      position: relative;
      z-index: 1;
    }

    .section-head {
      display: flex;
      align-items: center;
      gap: var(--space-sm);
      margin-block-end: var(--space-md);

      h2 {
        font-size: var(--fs-body);
        margin: 0;
      }

      .section-icon {
        display: inline-flex;
        justify-content: center;
        align-items: center;
        inline-size: 28px;
        block-size: 28px;
        border-radius: 8px;
      }
    }

    .card {
      padding: var(--space-lg);
      border-radius: 12px;
    }

    /* ── The four steps ───────────────────────────────────────────── */
    .hiw-steps {
      list-style: none;
      margin: 0;
      padding: 0;
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
    }

    .hiw-step {
      display: grid;
      grid-template-columns: 32px 1fr;
      gap: var(--space-md);
      align-items: start;

      /* The rule between steps reads as a divider, so the last one drops it
         rather than fencing the card's own padding. */
      padding-block-end: var(--space-lg);

      &:last-child {
        padding-block-end: 0;
      }
    }

    .hiw-step-number {
      display: inline-flex;
      justify-content: center;
      align-items: center;
      inline-size: 32px;
      block-size: 32px;
      border-radius: 50%;
      font-size: var(--fs-small);
      font-weight: var(--fw-semibold);
      font-variant-numeric: tabular-nums;
    }

    .hiw-step-body {
      h3 {
        margin: 0 0 var(--space-2xs);
        font-size: var(--fs-body);
        font-weight: var(--fw-semibold);
      }

      p {
        margin: 0 0 var(--space-sm);
        font-size: var(--fs-small);
        line-height: 1.6;

        &:last-child {
          margin-block-end: 0;
        }
      }
    }

    .hiw-step-note {
      padding-inline-start: var(--space-sm);
      border-inline-start: 2px solid transparent;
    }

    /* ── After the invite, and the page map ───────────────────────── */
    .hiw-flow {
      list-style: none;
      margin: 0;
      padding: 0;
      display: flex;
      flex-direction: column;
      gap: var(--space-md);

      li {
        font-size: var(--fs-small);
        line-height: 1.6;
      }

      strong {
        display: block;
        font-weight: var(--fw-semibold);
        margin-block-end: var(--space-3xs);
      }
    }

    .hiw-map {
      margin: 0;
      display: grid;
      gap: var(--space-xs) var(--space-lg);

      dt {
        font-size: var(--fs-small);
        font-weight: var(--fw-semibold);
      }

      dd {
        margin: 0 0 var(--space-md);
        font-size: var(--fs-small);
        line-height: 1.6;

        &:last-child {
          margin-block-end: 0;
        }
      }
    }

    /* ── Tour replay ──────────────────────────────────────────────── */
    .hiw-tour-card {
      p {
        margin: 0 0 var(--space-md);
        font-size: var(--fs-small);
        line-height: 1.6;

        &:last-child {
          margin-block-end: 0;
        }
      }

      code {
        padding: 1px 5px;
        border-radius: 4px;
        font-size: 0.9em;
      }
    }

    .hiw-tour-note {
      font-size: var(--fs-xsmall);
    }

    /* On a narrow screen the step number stops earning its own column and
       sits above the text instead. */
    @media (max-width: 640px) {
      .hiw-step {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
      }

      .hiw-map {
        gap: var(--space-2xs);
      }
    }
  }
}

@layer theme {
  .how-it-works-page {
    .section-head {
      .section-icon {
        background: light-dark(oklch(0% 0 0 / 0.03), oklch(100% 0 0 / 0.05));
        color: var(--accent-primary);
      }
    }

    .card {
      background: light-dark(oklch(0% 0 0 / 0.02), oklch(100% 0 0 / 0.03));
      border: 1px solid oklch(from var(--glass-tint) l c h / 0.06);
    }

    .hiw-step {
      border-block-end: 1px solid oklch(from var(--glass-tint) l c h / 0.06);

      &:last-child {
        border-block-end: none;
      }
    }

    .hiw-step-number {
      background: light-dark(
        oklch(from var(--accent-primary) l c h / 0.1),
        oklch(from var(--accent-primary) l c h / 0.16)
      );
      color: var(--accent-primary);
    }

    .hiw-step-body {
      h3 {
        color: var(--text-primary);
      }

      p {
        color: var(--text-secondary);
      }
    }

    .hiw-step-note {
      border-inline-start-color: oklch(from var(--accent-primary) l c h / 0.3);
      color: var(--text-secondary);

      strong {
        color: var(--text-primary);
      }
    }

    .hiw-flow {
      color: var(--text-secondary);

      strong {
        color: var(--text-primary);
      }
    }

    .hiw-map {
      dt {
        color: var(--text-primary);
      }

      dd {
        color: var(--text-secondary);
      }
    }

    .hiw-tour-card {
      p {
        color: var(--text-secondary);
      }

      code {
        background: light-dark(oklch(0% 0 0 / 0.05), oklch(100% 0 0 / 0.08));
        color: var(--text-primary);
      }
    }

    .hiw-tour-note {
      color: var(--text-secondary);
    }
  }
}
