@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * BANNER
 * ----------------------------------------
 * Full-width, page-level notification strip. Stretches the inline size of
 * its parent container — to bleed edge-to-edge of the viewport, render
 * outside any max-width content column.
 *
 * No motion is defined in v1; if entry/exit animation is added later, it
 * must be gated on `prefers-reduced-motion: no-preference`.
 * ======================================== */

  .cinder-banner {
    display: grid;
    /* The glyph, the message, the actions and the dismiss button share the first row. The banner
     * is its own inline-size container: below 560px of its own width, whatever the viewport, the
     * actions drop under the message on the next row and their track collapses to nothing, so the
     * buttons never squeeze or overlap the words. An absent glyph, action or dismiss button leaves
     * its track at zero width, and the gaps are margins on the parts so nothing is left behind.
     * (Owner decision 2026-11-13, reversing COR-2314's actions-under-the-message at every width.) */
    container-type: inline-size;
    container-name: cinder-banner;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    column-gap: 0;
    row-gap: var(--cinder-space-3);
    align-items: start;
    inline-size: 100%;
    /* The distance from the border to the first ink on top, and from the last ink to the border
     * below: letters and button faces are what a person measures, not the line boxes that hold
     * them. The ink insets below take each line's own air out of this. */
    --_cinder-banner-inset: var(--cinder-space-3);
    padding-block: var(--_cinder-banner-inset);
    padding-inline: var(--cinder-space-4);
    border-block: var(--cinder-border-width) solid var(--cinder-border);
    background: var(--cinder-surface);
    color: var(--cinder-text-default);
    font-size: var(--cinder-text-sm);
    line-height: var(--cinder-leading-normal);
  }

  /* ----------------------------------------
 * Ink insets
 * The first ink sits as far under the top border as the last ink sits over the bottom one, as in
 * Callout. A line box has air round its letters (half of what its height leaves beside the
 * capitals), so a plain inset reads heavier above the capitals than below a button: the air above
 * the first line is taken out of the top inset, and when no action row follows, or the row holds
 * only links, the air under the last baseline is taken out of the bottom one. An action row that
 * ends in a button face is a box with no air to take out. `1cap` and `1lh` follow the text's own
 * size. The feature banner has its own block with art and keeps its padding.
 * ---------------------------------------- */

  .cinder-banner:not([data-cinder-variant='feature']) {
    --_cinder-banner-first-air: calc((1lh - 1cap) / 2);
    --_cinder-banner-last-air: calc((1lh - 1cap) / 2);
    /* The first line starts on a whole pixel from the top edge, so the glyph (whose offset from
     * the baseline is rounded too) and the text sit on the pixel grid and the 2px stroke is not
     * blurred across two rows; the ink moves by under half a pixel. The first value is the
     * unrounded inset, for a browser without `round()`. */
    padding-block-start: calc(var(--_cinder-banner-inset) - var(--_cinder-banner-first-air));
    padding-block-start: round(
      calc(var(--_cinder-banner-inset) - var(--_cinder-banner-first-air)),
      1px
    );
  }

  .cinder-banner:not([data-cinder-variant='feature']):not(:has(> .cinder-banner__actions)) {
    padding-block-end: calc(var(--_cinder-banner-inset) - var(--_cinder-banner-last-air));
  }

  /* An action row of links ends in text, which has leading under its letters like any line: the
   * air comes off the bottom here too. A row with a button, a field or a select ends in a box. */
  .cinder-banner:not([data-cinder-variant='feature']):has(
      > .cinder-banner__actions .cinder-link
    ):not(:has(> .cinder-banner__actions :is(button, input, select, textarea, .cinder-button))) {
    padding-block-end: calc(var(--_cinder-banner-inset) - var(--_cinder-banner-last-air));
  }

  /* The dismiss button keeps its place against the border. */
  .cinder-banner:not([data-cinder-variant='feature']) > .cinder-banner__dismiss {
    margin-block-start: var(--_cinder-banner-first-air);
  }

  @media (prefers-reduced-motion: no-preference) {
    .cinder-banner {
      transition:
        background-color var(--cinder-duration-fast) var(--cinder-ease-standard),
        border-color var(--cinder-duration-fast) var(--cinder-ease-standard);
    }
  }

  :root:is([data-cinder-reduced-motion='false'], [data-reduced-motion='off']) .cinder-banner {
    transition:
      background-color var(--cinder-duration-fast) var(--cinder-ease-standard),
      border-color var(--cinder-duration-fast) var(--cinder-ease-standard);
  }

  /* ----------------------------------------
 * Content area
 * ---------------------------------------- */

  .cinder-banner__content {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    /* A line of words stays readable: the message never runs wider than the owner's ninety-character
     * measure, and it wraps so that its last line is never a lone word (the owner chose `pretty`
     * over `balance`, 2026-11-29), so a wrapped banner reads as deliberate. The actions stay at the
     * band's trailing edge in their own grid track. */
    max-inline-size: 90ch;
    text-wrap: pretty;
  }

  /* A glyph at the start, beside the first line of the message, not centred on a two-line message.
   * The glyph is an inline box in a line of the message's own font and line height, so it shares
   * the message's baseline, and it is centred on the capitals, not on the line box: a 13px line's
   * box centre sits a third of a pixel below the capitals' centre, and a 16px glyph centred in a
   * 19.5px line lands on a fractional pixel (x.75), which blurs its 2px stroke. Its offset from
   * the baseline is rounded to a whole pixel, so the glyph sits on the pixel grid wherever the
   * baseline does. */
  .cinder-banner__icon {
    display: block;
    grid-column: 1;
    grid-row: 1;
    margin-inline-end: var(--cinder-space-3);
    align-self: start;
  }

  .cinder-banner__icon > :where(svg) {
    display: inline-block;
    inline-size: 1rem;
    block-size: 1rem;
    /* The glyph's centre on the capitals' centre: its bottom half a glyph minus half a cap height
     * below the baseline. The first value is that offset for the default 13px type, for a browser
     * without the `cap` unit or `round()`. */
    vertical-align: -3px;
    vertical-align: round(calc(0.5cap - 0.5rem), 1px);
  }

  /* The bold lead keeps the tone's colour; the sentence after it reads in the default text
   * colour, so only the lead is amber or blue. A page's own children keep the status colour. */
  .cinder-banner__title {
    font-weight: var(--cinder-font-semibold);
  }

  .cinder-banner__title[data-cinder-title-layout='stacked'] {
    display: block;
  }

  .cinder-banner__text {
    color: var(--cinder-text-default);
  }

  /* The stale-data notice sits on its own line beneath the message, a step smaller. It keeps
   * the status foreground colour so contrast on the tinted surface is unchanged. */
  .cinder-banner__stale {
    display: block;
    font-size: var(--cinder-text-xs);
  }

  /* ----------------------------------------
 * Actions region
 * ---------------------------------------- */

  /* At the inline end of the message's row, before the dismiss button, on one line and centred on
   * the row, so a one-line message and its buttons share a centre line. A button label never wraps
   * inside its button. */
  .cinder-banner > .cinder-banner__actions {
    display: flex;
    flex-wrap: nowrap;
    grid-column: 3;
    grid-row: 1;
    align-items: center;
    align-self: center;
    justify-self: end;
    gap: var(--cinder-space-2);
    margin-inline-start: var(--cinder-space-4);
  }

  .cinder-banner__actions button,
  .cinder-banner__actions a {
    white-space: nowrap;
  }

  .cinder-banner__message {
    display: contents;
  }

  /* When actions sit beside the message, center the text and its glyph as one group. The glyph
   * stays beside the first line when the message wraps. Subgrid shares the icon and text columns
   * with the outer banner so narrow actions still align with the text. */
  @supports (grid-template-columns: subgrid) {
    .cinder-banner__message {
      display: grid;
      grid-template-columns: subgrid;
      grid-column: 1 / 3;
      grid-row: 1;
    }

    @container cinder-banner (min-width: 35rem) {
      .cinder-banner:has(> .cinder-banner__actions):not(
          :has(> .cinder-banner__actions[data-cinder-stacked='true'])
        )
        > .cinder-banner__message {
        align-self: center;
      }
    }
  }

  /* Below 560px of the banner's own width, the actions drop under the message in its column, in a
   * row that wraps: several actions break onto lines of their own rather than squeezing. */
  @container cinder-banner (max-width: 34.99rem) {
    .cinder-banner > .cinder-banner__actions {
      flex-wrap: wrap;
      grid-column: 2;
      grid-row: 2;
      align-self: start;
      justify-self: start;
      margin-inline-start: 0;
    }
  }

  /* Touch: an action that is a Button reaches 44 by 44 through the Button's own pseudo-element hit
   * area, so it keeps its painted height. */

  /* A narrow banner that stacks the actions puts them under the message and gives each its own
   * full line, so the buttons are as wide as the words. The threshold is the phone breakpoint
   * (640px) less the banner's 2rem of inline padding, because a size query measures the content
   * box: a full-width banner switches at the same viewport width it always did, and a banner in a
   * narrow column switches too. */
  @container cinder-banner (max-width: 37.99rem) {
    .cinder-banner > .cinder-banner__actions[data-cinder-stacked='true'] {
      flex-direction: column;
      flex-wrap: nowrap;
      grid-column: 2;
      grid-row: 2;
      align-items: stretch;
      align-self: start;
      justify-self: stretch;
      inline-size: 100%;
      margin-inline-start: 0;
    }

    .cinder-banner__actions[data-cinder-stacked='true'] > :is(button, a) {
      justify-content: center;
    }
  }

  /* ----------------------------------------
 * Sticky
 * ---------------------------------------- */

  .cinder-banner[data-cinder-sticky='true'] {
    position: sticky;
    inset-block-start: 0;
    z-index: 1;
  }

  /* A stuck banner sits below its scroll container's top padding, and rows scrolled under it
     showed through that gap (s4#17). The banner covers the band above it with the page canvas, a
     page's top padding deep (space-4), so nothing reads between the banner and the edge. Before
     it sticks the band falls on that same padding, so it draws nothing a reader sees. */
  .cinder-banner[data-cinder-sticky='true']::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    /* Above the 1px top border, which the inset alone would cover (it measures from the padding
       box). */
    inset-block-end: calc(100% + 1px);
    block-size: var(--cinder-space-4);
    background: var(--cinder-surface-canvas);
    pointer-events: none;
  }

  /* ----------------------------------------
 * Dismiss button
 * Mirrors .cinder-alert__dismiss rule-for-rule.
 * ---------------------------------------- */

  /* Box-model reset, hit-area, and idle :hover live on .cinder-_dismiss-button
 * (see src/styles/components.css). Only Banner-specific layout positioning,
 * the motion-gated transition, and status-driven focus chrome live here. */
  .cinder-banner__dismiss {
    grid-column: 4;
    grid-row: 1;
    margin-inline-start: var(--cinder-space-3);
    align-self: center;
  }

  @media (prefers-reduced-motion: no-preference) {
    .cinder-banner__dismiss {
      transition:
        background-color var(--cinder-duration-fast) var(--cinder-ease-standard),
        box-shadow var(--cinder-duration-fast) var(--cinder-ease-standard);
    }
  }

  :root:is([data-cinder-reduced-motion='false'], [data-reduced-motion='off'])
    .cinder-banner__dismiss {
    transition:
      background-color var(--cinder-duration-fast) var(--cinder-ease-standard),
      box-shadow var(--cinder-duration-fast) var(--cinder-ease-standard);
  }

  .cinder-banner__dismiss:focus-visible {
    outline: var(--cinder-ring-width) solid transparent;
    box-shadow:
      0 0 0 var(--cinder-ring-offset) var(--cinder-ring-offset-color),
      0 0 0 calc(var(--cinder-ring-offset) + var(--cinder-ring-width))
        var(--_cinder-banner-ring, var(--cinder-ring-color));
  }

  .cinder-banner__dismiss-icon {
    width: 1rem;
    height: 1rem;
  }

  /* ----------------------------------------
 * Status variants
 *
 * The soft-surface color algebra (background, border, foreground) lives in the
 * shared `_status-surface.css` partial, consumed via `.cinder-_status-surface`
 * + `.cinder-_status-surface-border` on the root (see banner.svelte). Banner
 * draws no inline-start stripe, so it does not compose the stripe class. Each
 * variant sets the partial's inputs (base color + per-variant foreground chroma)
 * plus the banner-local focus-ring color.
 *
 * NOTE (CSS audit, Batch D): the soft surface is synthesized rather than read
 * from the `--cinder-color-{status}-{bg,fg,border}` triples because the
 * dark-theme triple background sits ~8 oklch-L points lighter (28% vs 20% L),
 * exceeding the 0.02 ΔL threshold. See documentation/css-audit/status-triple-equivalence.md.
 * ---------------------------------------- */

  /* Neutral is a notice, not a status, so it tints from the accent hue rather than a status hue,
   * through the same recipe as every tone: one edge treatment (the border painted in the fill)
   * for all of them. The neutral tokens drew a visible grey border no other tone had, and a grey
   * fill a point off the page that read as faded in light (2026-11-28 review). */
  .cinder-banner[data-cinder-variant='neutral'] {
    --_cinder-banner-ring: var(--cinder-ring-color);
    --_cinder-status-base: var(--cinder-accent-solid);
    --_cinder-status-fg-chroma-light: 0.08;
    --_cinder-status-fg-chroma-dark: 0.06;
  }

  .cinder-banner[data-cinder-variant='info'] {
    --_cinder-banner-ring: var(--cinder-status-info-text);
    --_cinder-status-base: var(--cinder-status-info-solid);
    --_cinder-status-fg-chroma-light: 0.12;
    --_cinder-status-fg-chroma-dark: 0.12;
  }

  .cinder-banner[data-cinder-variant='success'] {
    --_cinder-banner-ring: var(--cinder-status-success-text);
    --_cinder-status-base: var(--cinder-status-success-solid);
    --_cinder-status-fg-chroma-light: 0.14;
    --_cinder-status-fg-chroma-dark: 0.12;
  }

  .cinder-banner[data-cinder-variant='warning'] {
    --_cinder-banner-ring: var(--cinder-status-warning-text);
    --_cinder-status-base: var(--cinder-status-warning-solid);
    --_cinder-status-fg-chroma-light: 0.16;
    --_cinder-status-fg-chroma-dark: 0.14;
  }

  .cinder-banner[data-cinder-variant='danger'] {
    --_cinder-banner-ring: var(--cinder-status-danger-text);
    --_cinder-status-base: var(--cinder-status-danger-solid);
    --_cinder-status-fg-chroma-light: 0.18;
    --_cinder-status-fg-chroma-dark: 0.16;
  }

  /* ----------------------------------------
 * Feature
 *
 * An announcement, not a status (COR-2363): a rounded block with an indigo wash (the accent mixed
 * 9% over the surface) and a soft radial glow at the inline end, with no border and no status
 * colour. The glyph art sits in a 48px accent disc with an 8px translucent halo, the title is
 * 16px bold over one muted line, and the actions trail at the inline end, dropping under the
 * words below 560px of the banner's own width, as on every banner.
 * ---------------------------------------- */

  .cinder-banner[data-cinder-variant='feature'] {
    --_cinder-banner-ring: var(--cinder-ring-color);
    --_cinder-banner-glow-at: 100% 50%;
    align-items: center;
    padding-block: var(--cinder-space-4);
    padding-inline: var(--cinder-space-5);
    border: 0;
    border-radius: var(--cinder-radius-surface);
    /* The wash is the accent mixed over the surface: 9% in light, 18% in dark, where the same 9%
     * of a dim accent over a dark surface reads as a plain dark card (COR-2441). The glow is the
     * accent at 18% in light and 25% in dark (32% would drop the muted words under 4.5:1 at the
     * glow's peak). `light-dark()` takes colours, so each arm is a whole mix. */
    /* cinder-allow-raw-color: structural-pattern — a theme-arm mix amount of the accent, not a colour literal */
    --_cinder-banner-glow: light-dark(
      color-mix(in oklch, var(--cinder-accent-solid) 18%, transparent),
      color-mix(in oklch, var(--cinder-accent-solid) 25%, transparent)
    );
    /* cinder-allow-raw-color: structural-pattern — a theme-arm mix amount of the accent, not a colour literal */
    --_cinder-banner-wash: light-dark(
      color-mix(in oklch, var(--cinder-surface), var(--cinder-accent-solid) 9%),
      color-mix(in oklch, var(--cinder-surface), var(--cinder-accent-solid) 18%)
    );
    background:
      radial-gradient(
        ellipse 45% 140% at var(--_cinder-banner-glow-at),
        var(--_cinder-banner-glow),
        transparent 70%
      ),
      var(--_cinder-banner-wash);
    color: var(--cinder-text-default);
  }

  .cinder-banner[data-cinder-variant='feature']:is([dir='rtl'], [dir='rtl'] *):where(
      :not([dir='rtl'] [dir='ltr'], [dir='rtl'] [dir='ltr'] *)
    ) {
    --_cinder-banner-glow-at: 0% 50%;
  }

  /* One icon in a 48px accent disc, with an 8px translucent halo the margin leaves room for. */
  .cinder-banner__art {
    display: inline-flex;
    grid-column: 1;
    grid-row: 1;
    align-items: center;
    justify-content: center;
    inline-size: 3rem;
    block-size: 3rem;
    margin: var(--cinder-space-2);
    margin-inline-end: calc(var(--cinder-space-2) + var(--cinder-space-4));
    border-radius: var(--cinder-radius-full);
    background: var(--cinder-accent-solid);
    color: var(--cinder-accent-contrast);
    box-shadow: 0 0 0 var(--cinder-space-2)
      color-mix(in oklch, var(--cinder-accent-solid) 16%, transparent);
  }

  .cinder-banner__art > :where(svg) {
    inline-size: 1.5rem;
    block-size: 1.5rem;
  }

  /* The words read muted under a 16px bold title in the default text colour. */
  .cinder-banner[data-cinder-variant='feature'] > .cinder-banner__content {
    color: var(--cinder-text-muted);
  }

  .cinder-banner[data-cinder-variant='feature'] .cinder-banner__title {
    color: var(--cinder-text-default);
    font-size: var(--cinder-text-lg);
    font-weight: var(--cinder-font-bold);
    line-height: var(--cinder-leading-snug);
  }

  .cinder-banner[data-cinder-variant='feature'] .cinder-banner__text {
    color: var(--cinder-text-muted);
  }

  /* Below 560px of its own width the feature banner stops giving the art a column of its own: the
   * art is a 32px disc with no halo on the title's line, the title steps in beside it, and the
   * words and the actions start at the banner's leading padding, under the art's left edge, so a
   * phone's width goes to the words. The dismiss button sits on the title's line. */
  @container cinder-banner (max-width: 34.99rem) {
    .cinder-banner[data-cinder-variant='feature'] {
      grid-template-columns: 2rem minmax(0, 1fr) auto;
      align-items: start;
      padding-inline: var(--cinder-space-4);
    }

    .cinder-banner[data-cinder-variant='feature'] > .cinder-banner__art {
      grid-column: 1;
      grid-row: 1;
      align-self: start;
      inline-size: 2rem;
      block-size: 2rem;
      margin: 0;
      box-shadow: none;
    }

    .cinder-banner[data-cinder-variant='feature'] > .cinder-banner__art > :where(svg) {
      inline-size: 1rem;
      block-size: 1rem;
    }

    .cinder-banner[data-cinder-variant='feature'] > .cinder-banner__content {
      grid-column: 1 / 3;
      grid-row: 1;
    }

    .cinder-banner[data-cinder-variant='feature'] .cinder-banner__title {
      display: block;
      box-sizing: border-box;
      min-block-size: 2rem;
      align-content: center;
      padding-inline-start: calc(2rem + var(--cinder-space-3));
      /* The title's second line, if it wraps, stays beside the art. */
    }

    .cinder-banner[data-cinder-variant='feature'] > .cinder-banner__actions {
      grid-column: 1 / 3;
      grid-row: 2;
    }

    .cinder-banner[data-cinder-variant='feature'] > .cinder-banner__dismiss {
      grid-column: 3;
      grid-row: 1;
      align-self: start;
      margin-block-start: calc((2rem - 1.5rem) / 2);
    }
  }

  /* ----------------------------------------
 * Forced-colors / high-contrast
 * ---------------------------------------- */

  @media (forced-colors: active) {
    .cinder-banner {
      border-block: 1px solid CanvasText;
    }

    /* The feature banner draws no border and paints its wash with color-mix, which forced colours
     * drop; give it the system edge and canvas instead. */
    .cinder-banner[data-cinder-variant='feature'] {
      border: 1px solid CanvasText;
      background: Canvas;
    }

    .cinder-banner__art {
      border: 1px solid CanvasText;
      box-shadow: none;
    }

    /* `color-mix` against transparent is unreliable in forced-colors mode; pin to ButtonFace.
   * Nested under @media (hover: hover) to suppress sticky-hover on touch. */
    @media (hover: hover) {
      .cinder-banner__dismiss:hover {
        background: ButtonFace;
      }
    }

    .cinder-banner__dismiss:focus-visible {
      outline: var(--cinder-ring-width) solid ButtonText;
      outline-offset: 3px;
      box-shadow: none;
    }
  }
}
