@layer tokens, base, ui, shell, surface;
/* The components (client/ui/*.js), with the original's class names and values: buttons, fields, the
   composer, avatar, popover menus, dialogs, search, segmented, rows, pills, sheets, prose. */
@layer ui {
  /* ---- buttons (docs/archive/design-language.md §5.2) ---------------------------------
     Everything you press is a pill without an outline. Default = raised (lifted
     white pill); --primary = act (Lit); --tonal = ink fill; --quiet = ghost. */

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-height);
    padding: 0 var(--space-4);
    border-radius: var(--radius-pill);
    border: 0;
    background: var(--color-surface-raised);
    box-shadow: var(--shadow-lift);
    color: var(--color-ink);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    transition:
      background var(--dur-fast) var(--ease),
      box-shadow var(--dur-fast) var(--ease),
      transform var(--dur-press) var(--ease-press),
      filter var(--dur-fast) var(--ease);
    user-select: none;
  }

  @media (hover: hover) {
    .btn:hover {
      transform: translateY(var(--hover-lift));
      box-shadow: var(--shadow-lift-hover);
    }
  }
  .btn:active {
    transform: scale(var(--press-scale));
  }

  .btn--primary,
  .btn--act {
    background: var(--grad-lit);
    color: var(--color-on-accent);
    box-shadow: 0 1px 2px var(--color-shadow);
  }

  @media (hover: hover) {
    .btn--primary:hover,
    .btn--act:hover {
      transform: none;
      filter: brightness(1.07);
      box-shadow: 0 4px 14px color-mix(in srgb, var(--color-accent-fill) 35%, transparent);
    }
  }
  .btn--tonal {
    background: var(--color-fill);
    box-shadow: none;
  }

  @media (hover: hover) {
    .btn--tonal:hover {
      transform: none;
      background: var(--color-fill-strong);
      box-shadow: none;
    }
  }
  .btn--full {
    width: 100%;
  }

  .btn--quiet,
  .btn--ghost {
    background: transparent;
    box-shadow: none;
    color: var(--color-ink-secondary);
  }

  @media (hover: hover) {
    .btn--quiet:hover,
    .btn--ghost:hover {
      transform: none;
      background: var(--color-fill);
      box-shadow: none;
      color: var(--color-ink);
    }
  }
  /* Quiet action rows (the tank list's "New think tank" / "Join with code") are
     disabled by attribute only, so without this they keep full ink and still
     light up on hover — :hover matches disabled buttons too. Dimmed, no hover,
     and the title tooltip stays reachable (unlike .btn[disabled], which kills
     pointer events and with it the reason the row is blocked). */
  .btn--quiet:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  @media (hover: hover) {
    .btn--quiet:disabled:hover {
      background: transparent;
      color: var(--color-ink-secondary);
    }
  }
  .btn--danger {
    background: var(--color-danger);
    box-shadow: 0 1px 2px var(--color-shadow);
    color: var(--color-on-danger);
  }

  @media (hover: hover) {
    .btn--danger:hover {
      transform: none;
      background: var(--color-danger-hover);
    }
  }
  .btn[disabled] {
    opacity: 0.4;
    box-shadow: none;
    pointer-events: none;
  }

  /* Small: 26px (docs/ui.md §3). */
  .btn--sm {
    min-height: var(--h-control-sm);
    padding: 0 var(--space-3);
    font-size: var(--text-xs);
    gap: var(--space-1);
  }
  /* Icon-only: a square the height of its size. */
  .btn--icon {
    width: var(--control-height);
    padding: 0;
  }
  .btn--icon.btn--sm {
    width: var(--h-control-sm);
  }

  .btn--xs {
    min-height: var(--control-height-compact);
    padding: 0 var(--space-3);
    font-size: var(--text-xs);
    gap: var(--space-1);
  }

  .icon-btn {
    display: grid;
    place-items: center;
    width: var(--control-height);
    height: var(--control-height);
    border-radius: var(--radius-pill);
    color: var(--color-ink-secondary);
    transition:
      background var(--dur-fast) var(--ease),
      color var(--dur-fast) var(--ease),
      transform var(--dur-press) var(--ease-press);
  }

  @media (hover: hover) {
    .icon-btn:hover {
      background: var(--color-fill);
      color: var(--color-ink);
    }
  }
  .icon-btn:active {
    transform: scale(var(--press-scale));
  }

  .icon-btn.icon-btn--danger {
    color: var(--color-danger);
  }

  @media (hover: hover) {
    .icon-btn.icon-btn--danger:hover {
      color: var(--color-danger);
    }
  }
  @media (prefers-reduced-motion: reduce) {
    .btn:active,
    .icon-btn:active {
      transform: none;
    }

    @media (hover: hover) {
      .btn:hover {
        transform: none;
      }
    }
  }

  /* ---- fields ------------------------------------------------------------------- */

  .field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .field__label {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-ink-faint);
  }

  /* Inputs are fill pills: no outline, act wash + ring on focus. */
  .input {
    height: var(--h-field);
    padding: 0 var(--space-4);
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--field-paint);
    box-shadow: var(--field-shadow);
    color: var(--color-ink);
    font-size: var(--text-sm);
    transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  }

  .input::placeholder {
    color: var(--color-ink-faint);
  }

  @media (hover: hover) {
    .input:hover {
      background: var(--color-fill-strong);
    }
  }
  .input:focus-visible {
    outline: none;
    background: var(--color-wash);
    box-shadow: 0 0 0 2px var(--color-accent-fill);
  }

  textarea.input {
    height: auto;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-bubble);
  }

  /* ---- chat input --------------------------------------------------------------------- */

  .chat {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    height: auto;
    min-height: var(--chat-height);
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
    background: var(--color-fill);
    border: none;
    border-radius: var(--radius-pill);
    transition:
      border-radius var(--dur-fast) var(--ease),
      background-color var(--dur-fast) var(--ease),
      box-shadow var(--dur-fast) var(--ease);
  }

  .chat:focus-within {
    background: var(--color-wash);
    box-shadow: 0 0 0 2px var(--color-accent-fill);
  }

  /* Multi-line composer: bubble radius (not stadium). */
  .chat.is-multiline {
    border-radius: var(--radius-bubble);
  }

  .chat__input {
    flex: 1;
    min-width: 0;
    min-height: 0;
    border: none;
    background: transparent;
    font-size: var(--text-sm);
  }

  .chat__input:focus-visible {
    box-shadow: none;
  }

  .chat__attach, .chat__mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: var(--radius-pill);
    color: var(--color-ink-secondary);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }

  @media (hover: hover) {
    .chat__attach:hover, .chat__mark:hover {
      background: var(--color-fill);
      color: var(--color-ink);
    }
  }
  .chat__mic {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: var(--radius-pill);
    color: var(--color-ink-secondary);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }

  @media (hover: hover) {
    .chat__mic:hover {
      background: var(--color-fill);
      color: var(--color-ink);
    }
  }
  /* Listening is act (teal), not red: red is failure only. */
  .chat__mic.is-recording {
    color: var(--color-accent-text);
    background: var(--color-wash);
    animation: chat-mic-pulse 1.2s ease-in-out infinite;
  }

  /* Marking on the page: on while the person picks a spot. */
  .chat__mark.is-on {
    color: var(--color-accent-text);
    background: var(--color-wash);
  }
  /* Pictures waiting to go with the message (a marked screenshot). */
  .chat__pictures {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 16px 8px;
  }
  .chat__picture {
    position: relative;
    width: 96px;
    height: 72px;
    border-radius: var(--radius-inner, 10px);
    overflow: hidden;
    background: var(--color-surface-sunken);
    box-shadow: inset 0 0 0 1px var(--color-hairline, rgba(0,0,0,.08));
  }
  .chat__picture img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  .chat__picture-x {
    position: absolute;
    top: 3px;
    right: 3px;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-pill);
    color: #fff;
    background: rgba(0,0,0,.55);
  }
  /* Files waiting to go with the message: cards in the tank (a chip each). */
  .chat__card {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
    height: 32px;
    padding: 0 30px 0 10px;
    position: relative;
    border-radius: var(--radius-inner, 10px);
    background: var(--color-surface-sunken);
    box-shadow: inset 0 0 0 1px var(--color-hairline, rgba(0,0,0,.08));
    font-size: 13px;
  }
  .chat__card-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat__card.is-pending { color: var(--color-ink-secondary); padding-right: 10px; }
  .chat__card .chat__picture-x { top: 6px; right: 5px; }
  .chat__mic.is-busy {
    pointer-events: none;
    color: var(--color-ink-secondary);
    cursor: wait;
  }

  @keyframes chat-mic-pulse {
    0%,
    100% {
      box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-accent-fill) 35%, transparent);
    }
    50% {
      box-shadow: 0 0 0 6px transparent;
    }
  }

  .chat__send {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: var(--radius-pill);
    background: var(--grad-lit);
    color: var(--color-on-accent);
    transition: filter var(--dur-fast) var(--ease), transform var(--dur-press) var(--ease-press);
  }

  @media (hover: hover) {
    .chat__send:hover {
      filter: brightness(1.07);
    }
  }
  .chat__send:active {
    transform: scale(var(--press-scale));
  }

  .avatar {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-pill);
    background: var(--color-ink);
    color: var(--color-bg);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    overflow: hidden;
  }

  .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .empty-hint {
    font-size: var(--text-sm);
    color: var(--color-ink-faint);
  }

  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-5) 0;
  }

  .empty-state__icon {
    display: grid;
    place-items: center;
    color: var(--color-ink-faint);
  }

  /* ---- popover (anchored floating layer, appended to <body>) -------------------------------- */

  .popover {
    position: fixed;
    z-index: var(--z-popover);
    min-width: 180px;
    max-width: min(320px, calc(100vw - 2 * var(--space-panel-gap)));
    max-height: min(320px, calc(100dvh - 2 * var(--space-panel-gap)));
    overflow-y: auto;
    padding: var(--space-1);
    background: var(--grad-face);
    border-radius: var(--radius-popover);
    box-shadow: var(--shadow-pop), 0 0 0 var(--line-width) var(--color-border-soft);
    /* It grows out of its anchor (overlay.js sets the origin) and settles; it goes quicker. */
    transition: opacity var(--dur-control) var(--ease-enter),
      transform var(--dur-med) var(--ease-spring);
  }
  .popover.is-enter {
    opacity: 0;
    transform: translateY(-4px) scale(var(--pop-scale));
  }
  .popover.is-enter[data-side="above"] {
    transform: translateY(4px) scale(var(--pop-scale));
  }
  .popover.is-enter[data-side="beside"] {
    transform: translateX(-4px) scale(var(--pop-scale));
  }
  .popover.is-leave {
    opacity: 0;
    transform: scale(var(--pop-scale));
    transition: opacity var(--dur-overlay-out) var(--ease-exit),
      transform var(--dur-overlay-out) var(--ease-exit);
    pointer-events: none;
  }

  /* subtle cue that more content is below when the menu overflows */
  .popover--fade-bottom::after {
    content: "";
    position: sticky;
    bottom: -5px;
    display: block;
    height: 3rem;
    margin-top: calc(-1 * var(--space-5));
    background: linear-gradient(to bottom, transparent, var(--color-surface));
    pointer-events: none;
    border-radius: 0 0 var(--radius-popover) var(--radius-popover);
  }

  .popover .menu__label {
    padding: var(--space-1) var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-ink-faint);
  }

  .popover .menu__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    min-height: var(--control-height);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-row);
    text-align: left;
    font-size: var(--text-sm);
  }

  .popover .menu__item--danger {
    color: var(--color-danger);
  }

  .popover .menu__item:focus-visible {
    background: var(--color-fill);
  }

  @media (hover: hover) {
    .popover .menu__item:hover {
      background: var(--color-fill);
    }
  }
  .popover .menu__item-hint {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-ink-faint);
    white-space: nowrap;
  }
  /* section divider inside a menu (e.g. starters | custom | more in the New menu) */
  .popover .menu__sep {
    height: 1px;
    margin: var(--space-1) calc(-1 * var(--space-1));
    background: var(--color-border);
  }

  /* a menu with nothing to offer -- e.g. the blueprint picker inside a shared
     folder the sharer has not put anything in yet */
  .popover .menu__empty {
    margin: 0;
    padding: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-ink-faint);
  }
  /* ---- dialog (styled confirm / notice) ------------------------------------------------------ */

  .dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    display: grid;
    place-items: center;
    padding: var(--space-panel-gap);
    /* edge to edge (viewport-fit=cover): keep the dialog off the notch and home bar */
    padding: max(var(--space-panel-gap), env(safe-area-inset-top, 0px))
      max(var(--space-panel-gap), env(safe-area-inset-right, 0px))
      max(var(--space-panel-gap), var(--kb-inset, 0px), env(safe-area-inset-bottom, 0px))
      max(var(--space-panel-gap), env(safe-area-inset-left, 0px));
    background: var(--color-scrim);
    /* solid scrim only — backdrop-filter blurs the full canvas underneath and stalls open */
    animation: dialog-fade var(--dur-med) var(--ease-enter);
    contain: layout style;
    /* tall dialogs (share/publish/export) must scroll on short phone viewports */
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* Component display rules (.field, .btn are flex) outrank the UA's [hidden],
     so a dialog section hidden by attribute still showed; same fix as .admin. */
  .dialog [hidden] {
    display: none !important;
  }

  .dialog {
    /* width: 380px; */
    max-width: 100%;
    /* auto margin keeps centering while allowing scroll when taller than
       the viewport (place-items:center alone clips the top off-screen) */
    margin: auto;
    max-height: calc(100dvh - 2 * var(--space-panel-gap));
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5);
    background: var(--grad-face);
    border: var(--border-hairline);
    border-radius: var(--radius-popover);
    box-shadow: var(--shadow-pop);
    animation: dialog-rise var(--dur-slow) var(--ease-spring);
    contain: layout style;
  }

  /* Closing (dialog.js dismissDialogLayer): the scrim fades while what it holds settles out. */
  .dialog-overlay.is-leave {
    animation: dialog-fade-out var(--dur-overlay-out) var(--ease-exit) forwards;
  }
  .dialog-overlay.is-leave > * {
    animation: dialog-fall var(--dur-overlay-out) var(--ease-exit) forwards;
  }

  .dialog--wide {
    width: 440px;
  }

  .dialog__title {
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
  }

  .dialog__body {
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    color: var(--color-ink-secondary);
    /* Bodies built from lines (a version's changes, a list of effects) keep their breaks. */
    white-space: pre-line;
  }

  /* Informed-consent callout (e.g. table-ref grant fan-out in folder shares). */
  .dialog__body--warn {
    color: var(--color-measure-text);
  }

  .dialog__section {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
  }

  .dialog__section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
  }

  .dialog__section-label {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-ink-secondary);
  }

  .dialog__plans {
    max-height: min(40vh, 280px);
    overflow: auto;
    margin: 0 calc(-1 * var(--space-1));
    padding: 0 var(--space-1);
  }

  .dialog__hint {
    font-size: var(--text-xs);
    line-height: var(--leading-normal);
    color: var(--color-ink-secondary);
  }

  .dialog__hint.is-hidden {
    display: none;
  }

  .dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-2);
  }

  .dialog__field {
    margin-top: var(--space-1);
  }

  /* ---- search input ---------------------------------------------------------------------------- */

  .search {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .search > svg {
    position: absolute;
    left: var(--space-2);
    color: var(--color-ink-faint);
    pointer-events: none;
  }

  .search__input {
    width: 100%;
    height: var(--control-height);
    padding: 0 var(--space-6) 0 calc(var(--space-2) + 20px);
    border: none;
    border-radius: var(--radius-pill);
    background: var(--color-fill);
    font-size: var(--text-sm);
    transition: background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    margin-right: var(--space-1);
  }

  @media (hover: hover) {
    .search__input:hover {
      background: var(--color-fill-strong);
    }
  }
  .search__input:focus-visible {
    background: var(--color-wash);
    box-shadow: 0 0 0 2px var(--color-accent-fill);
    outline: none;
  }

  .search__clear {
    position: absolute;
    right: var(--space-1);
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-pill);
    color: var(--color-ink-faint);
  }

  @media (hover: hover) {
    .search__clear:hover {
      background: var(--color-fill);
      color: var(--color-ink);
    }
  }

  /* ============================================================================
     The kit, v2 (docs/ui.md §3): one component of each kind. .btn, .input, .popover .menu__item,
     .dialog and .empty-state above are the button, field, menu, dialog and empty state; these add
     the rest. ui-kit.html draws every one in every theme.
     ========================================================================== */

  /* Segmented: a pill track, the selection raised. */
  .seg {
    display: inline-flex;
    flex: none;
    gap: 2px;
    padding: 3px;
    border-radius: var(--radius-pill);
    background: var(--color-fill);
  }
  .seg > button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: var(--h-control-sm);
    padding: 0 var(--space-3);
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--color-ink-secondary);
    font: var(--weight-medium) var(--type-12) / 1 var(--font-sans);
    cursor: pointer;
  }
  .seg > button:hover {
    color: var(--color-ink);
  }
  .seg > button.is-on,
  .seg > button[aria-checked="true"],
  .seg > button[aria-pressed="true"] {
    background: var(--tone-raised);
    color: var(--raised-ink);
    box-shadow: var(--shadow-lift);
  }

  /* A segmented pick changing glides (segGlide.js): a ghost pill travels behind the labels while
     the new pick holds its own fill back. */
  .has-seg-glide {
    isolation: isolate;
  }
  .has-seg-glide > :not(.seg-glide) {
    position: relative;
    z-index: 1;
  }
  .seg-glide {
    position: absolute;
    z-index: 0;
    pointer-events: none;
  }
  .is-seg-gliding {
    background: transparent !important;
    box-shadow: none !important;
  }
  .seg > button {
    transition: color var(--dur-control) var(--ease), background var(--dur-control) var(--ease),
      box-shadow var(--dur-control) var(--ease), transform var(--dur-press) var(--ease-press);
  }
  .seg > button:active {
    transform: scale(var(--press-scale));
  }

  /* Disclosures open and shut by height where the browser can ease to auto (Chromium); elsewhere
     they snap as before. The clip margin keeps rings and shadows inside from being cut. */
  @supports (interpolate-size: allow-keywords) {
    details {
      interpolate-size: allow-keywords;
    }
    details::details-content {
      height: 0;
      overflow: clip;
      overflow-clip-margin: 6px;
      transition: height var(--dur-layout) var(--ease),
        content-visibility var(--dur-layout) allow-discrete;
    }
    details[open]::details-content {
      height: auto;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    details::details-content {
      transition: none;
    }
  }

  /* Row: a glyph tile, a title over its subline, mono meta, a trailing action. 36px. */
  .row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--h-row);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-row);
    color: var(--color-ink);
    text-align: left;
  }
  button.row,
  a.row {
    width: 100%;
    border: 0;
    background: transparent;
    font: inherit;
    text-decoration: none;
    cursor: pointer;
  }
  .row:is(:hover, .is-on) {
    background: var(--color-fill);
  }
  .row.is-on {
    background: var(--color-wash);
  }
  .row__glyph {
    display: grid;
    flex: none;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-row);
    background: color-mix(in srgb, var(--kind, var(--color-ink-secondary)) 12%, transparent);
    color: var(--kind, var(--color-ink-secondary));
  }
  .row__main {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
  }
  .row__title,
  .row__sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .row__title {
    font-size: var(--type-13);
    font-weight: var(--weight-medium);
  }
  .row__sub {
    color: var(--color-ink-faint);
    font-size: var(--type-12);
  }
  .row__meta {
    flex: none;
    color: var(--color-ink-faint);
    font: var(--weight-regular) var(--type-11) / 1 var(--font-mono);
  }

  /* Empty state: a line-art plate, a title, one sentence, one action. */
  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    max-width: 36ch;
    margin: var(--space-6) auto;
    text-align: center;
  }
  .empty__plate {
    width: 120px;
    max-width: 100%;
    margin-bottom: var(--space-2);
    color: var(--color-ink-faint);
  }
  .empty__title {
    margin: 0;
    color: var(--color-ink);
    font: var(--weight-medium) var(--type-16) / 1.3 var(--font-display);
    text-wrap: balance;
  }
  .empty__text {
    margin: 0 0 var(--space-2);
    color: var(--color-ink-secondary);
    font-size: var(--type-13);
    line-height: 1.5;
  }

  /* Kbd: a key, as hints and the finder show it. */
  .kbd {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--radius-row);
    background: var(--tone-raised);
    box-shadow: 0 1px 0 var(--color-border-strong);
    color: var(--color-ink-secondary);
    font: var(--weight-medium) var(--type-11) / 1 var(--font-mono);
  }

  /* pills (inline refs in messages / journal bubbles) */
  .pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 8px 1px 6px;
    margin: 0 1px;
    border-radius: var(--radius-pill);
    border: var(--line-width) solid var(--color-border);
    background: var(--color-surface);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    vertical-align: baseline;
    line-height: 1.4;
  }
  /* A research or media index chip while its job still works (refPill.js followJobChip): a
     pulsing act dot before the title; a failed one reads in danger. */
  .pill[data-job-state="running"]::before {
    content: "";
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: var(--radius-pill);
    background: var(--color-accent-fill);
    animation: assistant-pulse 1.6s ease-in-out infinite;
  }

  .pill[data-job-state="failed"] {
    color: var(--color-danger);
    border-color: color-mix(in srgb, var(--color-danger) 40%, transparent);
  }

  @media (prefers-reduced-motion: reduce) {
    .pill[data-job-state="running"]::before {
      animation: none;
    }
  }

  /* The label truncates, not the pill: a flex box can't end its text in "…" (refPill.js
     setPillText), so a capped pill cut its name mid-letter against the edge. */
  .pill {
    min-width: 0;
  }
  /* In a message a pill scales with the words around it, a step smaller so it sits in the line. */
  :is(.msg-ai__text, .msg-user) .pill:not(.pill--quote) {
    font-size: 0.875em;
    line-height: 1.3;
    /* A long file name ends in an ellipsis inside the bubble instead of running past its edge. */
    max-width: 100%;
  }
  .pill__text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* A quoted part (refPill.js pillifyBoardRefs): its words are part of the sentence, so they wrap
     with it as underlined link text in the thing's colour, not a box (a box's padding at each line
     end pushed the text past the edge). */
  .pill.pill--quote,
  .assistant-production .pill.pill--quote {
    display: inline;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
    white-space: normal;
    overflow-wrap: anywhere;
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    cursor: pointer;
  }
  .pill.pill--quote:hover {
    text-decoration-color: currentColor;
  }
  .pill.pill--quote .pill__text {
    overflow: visible;
    white-space: normal;
  }

  .pill svg {
    width: 11px;
    height: 11px;
  }
  .pill--card {
    color: var(--entity-card);
    border-color: color-mix(in srgb, var(--entity-card) 30%, transparent);
    background: color-mix(in srgb, var(--entity-card) 6%, transparent);
  }
  .pill--highlight,
  .pill--latent {
    color: var(--entity-highlight);
    border-color: color-mix(in srgb, var(--entity-highlight) 30%, transparent);
    background: color-mix(in srgb, var(--entity-highlight) 6%, transparent);
  }
  .pill--latent {
    border-style: dashed;
  }

  .pill--view {
    color: var(--entity-view);
    border-color: color-mix(in srgb, var(--entity-view) 30%, transparent);
    background: color-mix(in srgb, var(--entity-view) 6%, transparent);
  }
  .pill--blueprint {
    color: var(--color-ink);
  }
  .pill--folder,
  .pill--group {
    color: var(--color-ink-secondary);
  }
  .pill--canvas,
  .pill--element {
    color: var(--color-ink-secondary);
  }
  .pill--asset {
    color: var(--color-ink-secondary);
    border-style: dashed;
  }
  .pill--coord {
    color: var(--color-ink-secondary);
    font-family: var(--font-mono);
  }
  .pill--nav {
    cursor: pointer;
    max-width: 50ch;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  @media (hover: hover) {
    .pill--nav:hover {
      filter: brightness(0.97);
      border-color: color-mix(in srgb, currentColor 35%, var(--color-border));
    }
  }
  .pill--nav:focus-visible {
    outline: var(--focus-outline);
    outline-offset: 1px;
  }
  .pill--stale {
    opacity: 0.45;
    text-decoration: line-through;
  }
  .pill--stale.pill--nav {
    cursor: default;
  }
  .pill--more {
    color: var(--color-ink-faint);
    border-style: dashed;
  }
  .pill--busy {
    opacity: 0.55;
    animation: pill-busy 1.2s ease-in-out infinite;
  }
  @keyframes pill-busy {
    50% {
      opacity: 0.3;
    }
  }

  /* ---- icons (ui/icon.js) ----------------------------------------------------------------- */
  .icon {
    display: block;
    flex: none;
  }

  /* ---- the composer (ui/composer.js): the original's production composer ------------------ */
  .assistant-composer {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 100%;
    min-width: 0;
  }
  .assistant-composer [hidden] {
    display: none !important;
  }
  .assistant-composer > .chat {
    flex-shrink: 0;
    width: calc(100% - 32px);
    margin: 10px 16px 6px;
    padding: 5px 5px 5px 20px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--color-fill);
    box-shadow: none;
  }
  .assistant-composer .chat__input {
    font-size: var(--type-14);
    line-height: 1.6;
  }
  .assistant-composer .chat__send {
    width: 38px;
    height: 38px;
  }
  .chat__input--rich {
    height: auto;
    align-self: center;
    padding: 4px 0;
    white-space: pre-wrap;
    overflow-x: hidden;
    overflow-y: auto;
    word-break: break-word;
    min-height: 1.9em;
    max-height: calc(1.9em * 6 + 8px);
    outline: none;
    cursor: text;
    line-height: 1.9;
  }
  /* A pill in the message being written (a thing picked with @, or a part pointed at in Highlight
     mode): one piece, in the line with the words. */
  .chat__input .chat-pill {
    max-width: min(26ch, 100%);
    margin: 0 2px;
    padding-block: 0;
    font-size: 0.86em;
    line-height: 1.5;
    vertical-align: 1px;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
  }
  .chat__input--rich:empty::before {
    content: attr(data-placeholder);
    color: var(--color-ink-faint);
    pointer-events: none;
  }
  .assistant-composer > .chat__tray {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 16px 12px;
    padding: 0 4px;
  }
  .chat__tray-start {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
  }
  .chat__tray :is(.chat__attach, .chat__mark, .chat__mic) {
    width: 30px;
    height: 30px;
    background: transparent;
    box-shadow: none;
    color: var(--color-ink-secondary);
  }
  .chat__levels {
    --level-index: 0;
    position: relative;
    display: inline-grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    flex: none;
    height: 30px;
    padding: 2px;
    border-radius: var(--radius-pill);
    background: var(--color-fill);
  }
  .chat__levels-thumb {
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 2px;
    width: calc((100% - 4px) / 3);
    border-radius: var(--radius-pill);
    background: var(--color-surface-raised);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.12), 0 0 0 0.5px rgb(0 0 0 / 0.06);
    transform: translateX(calc(var(--level-index) * 100%));
    transition: transform 260ms var(--ease);
    pointer-events: none;
  }
  :root[data-material="glass"] .chat__levels-thumb {
    background: var(--color-overlay-raised);
  }
  .chat__level {
    position: relative;
    min-width: 52px;
    padding: 0 10px;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--color-ink-secondary);
    font-size: var(--type-12);
    font-weight: 500;
    white-space: nowrap;
    transition: color var(--dur-fast) var(--ease);
  }
  .chat__level:is(:hover, :focus-visible),
  .chat__level[aria-checked="true"] {
    color: var(--color-ink);
  }

  /* ---- empty states (ui/empty.js plate) ---------------------------------------------------- */
  .plate-empty {
    position: relative;
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    padding: var(--space-6) var(--space-5);
    overflow: hidden;
    isolation: isolate;
  }
  .plate-empty__body {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    max-width: 320px;
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-hold);
    text-align: center;
  }
  .plate-empty__title {
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    letter-spacing: -0.015em;
    color: var(--color-ink);
  }
  .engine-empty {
    min-height: max(360px, 70cqh);
  }
  .engine-empty .plate-empty__body {
    gap: var(--space-3);
    max-width: 420px;
  }
  .engine-empty .plate-empty__title {
    font-size: clamp(22px, 5cqw, 30px);
    font-weight: var(--weight-semibold);
    line-height: 1.12;
    letter-spacing: -0.035em;
  }
  .engine-empty__ask {
    display: block;
    font-weight: var(--weight-medium);
    color: var(--color-ink-faint);
  }

  /* ---- the sheet (ui/sheet.js): a bottom sheet, the phone's overlay ------------------------ */
  .mk-sheet-layer {
    position: fixed;
    inset: 0;
    z-index: var(--mk-z-layer, 60);
    font-family: var(--font-sans);
    color: var(--color-ink);
  }
  .mk-scrim {
    position: absolute;
    inset: 0;
    border: 0;
    background: var(--color-scrim);
    animation: ui-fade var(--dur-med) var(--ease-enter);
  }
  .mk-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: var(--kb-inset, 0px);
    margin: 0 auto;
    max-width: 640px;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - var(--space-2));
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--grad-face);
    border-radius: var(--radius-popover) var(--radius-popover) 0 0;
    box-shadow: var(--shadow-pop);
    overscroll-behavior: contain;
    outline: none;
    animation: ui-rise var(--dur-med) var(--ease-enter);
  }
  .mk-sheet.is-full {
    top: env(safe-area-inset-top, 0px);
    max-height: none;
  }
  .mk-sheet__grab {
    position: relative;
    flex-shrink: 0;
    width: 36px;
    height: 5px;
    margin: var(--space-2) auto var(--space-1);
    border-radius: var(--radius-pill);
    background: var(--color-border-strong);
    touch-action: none;
  }
  .mk-sheet__grab::before {
    content: "";
    position: absolute;
    left: -40px;
    right: -40px;
    top: -8px;
    height: 22px;
  }
  .mk-sheet__head {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    min-height: var(--touch-target);
    padding: var(--space-1) var(--space-2) var(--space-2) var(--space-4);
  }
  .mk-sheet__title {
    flex: 1;
    min-width: 0;
    margin: 0;
    font: 600 var(--pt-headline, 17px) / 1.2 var(--font-sans);
  }
  .mk-sheet__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  @keyframes ui-fade {
    from {
      opacity: 0;
    }
  }
  @keyframes ui-rise {
    from {
      transform: translateY(24px);
      opacity: 0;
    }
  }

  /* ---- prose (ui/prose.js): reply text -------------------------------------------------------- */
  .msg-ai__text--md {
    white-space: normal;
    min-width: 0;
    overflow-wrap: break-word;
  }
  .msg-ai__text--md > :first-child {
    margin-top: 0;
  }
  .msg-ai__text--md :is(p, ul, ol, blockquote, pre) {
    margin: 0 0 0.45em;
  }
  .msg-ai__text--md :is(p, ul, ol, blockquote, pre):last-child {
    margin-bottom: 0;
  }
  .msg-ai__text--md :is(ul, ol) {
    padding-left: 1.25em;
  }
  .msg-ai__text--md li + li {
    margin-top: 0.15em;
  }
  .msg-ai__text--md a {
    color: var(--color-accent-fill);
    text-decoration: underline;
    word-break: break-word;
  }
  .msg-ai__text--md strong {
    font-weight: var(--weight-semibold);
  }
  .msg-ai__text--md code {
    font-size: 0.9em;
    padding: 0.1em 0.3em;
    border-radius: var(--radius-inner);
    background: var(--color-surface-sunken);
  }
  .msg-ai__text--md :is(h3, h4) {
    margin: 0.65em 0 0.3em;
    font-size: 1em;
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight, 1.25);
  }
  .msg-ai__text--md .pill {
    vertical-align: baseline;
    max-width: min(30ch, 100%);
  }
  .msg-ai__text--md h3 {
    font-size: 1.08em;
  }
  .msg-ai__text--md :is(h3, h4):first-child {
    margin-top: 0;
  }
  .msg-ai__text--md :is(.md-table, .md-picture, hr) {
    margin: 0.6em 0;
  }
  .msg-ai__text--md > :is(.md-table, .md-picture, hr):last-child {
    margin-bottom: 0;
  }
  /* Tables: their own scroller when wider than the reply; a hairline grid, a quiet header. */
  .msg-ai__text--md .md-table {
    max-width: 100%;
    overflow-x: auto;
    border: var(--line-width) solid var(--color-border);
    border-radius: var(--radius-inner);
    scrollbar-width: thin;
  }
  /* As wide as its words need (each column readable), scrolling sideways in a narrow panel. */
  .msg-ai__text--md table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.92em;
    font-variant-numeric: tabular-nums;
  }
  .msg-ai__text--md :is(th, td) {
    min-width: 7em;
    max-width: 16em;
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
    border-bottom: var(--line-width) solid var(--color-border-soft);
  }
  .msg-ai__text--md th {
    font-weight: var(--weight-semibold);
    background: var(--color-surface-sunken);
  }
  .msg-ai__text--md tbody tr:last-child td {
    border-bottom: 0;
  }
  .msg-ai__text--md pre.md-code {
    overflow-x: auto;
    padding: 10px 12px;
    border-radius: var(--radius-inner);
    background: var(--color-surface-sunken);
    font-size: 0.86em;
    line-height: 1.5;
    scrollbar-width: thin;
  }
  .msg-ai__text--md pre.md-code code {
    padding: 0;
    background: none;
    font-size: inherit;
    white-space: pre;
  }
  .msg-ai__text--md blockquote {
    margin-left: 0;
    padding-left: 12px;
    border-left: 3px solid var(--color-border-strong);
    border-radius: 0;
    color: var(--color-ink-secondary);
  }
  .msg-ai__text--md hr {
    border: 0;
    border-top: var(--line-width) solid var(--color-border);
  }
  .msg-ai__text--md s {
    color: var(--color-ink-secondary);
  }
  .msg-ai__text--md .md-tasks {
    list-style: none;
    padding-left: 0.2em;
  }
  .msg-ai__text--md .md-check {
    display: inline-grid;
    place-items: center;
    width: 14px;
    height: 14px;
    margin-right: 7px;
    border: 1.5px solid var(--color-border-strong);
    border-radius: 4px;
    font-size: 10px;
    line-height: 1;
    vertical-align: -2px;
  }
  .msg-ai__text--md .md-check.is-done {
    border-color: var(--color-accent-fill);
    background: var(--color-accent-fill);
    color: var(--color-on-accent);
  }
  .msg-ai__text--md .md-picture img {
    display: block;
    max-width: 100%;
    max-height: 320px;
    border-radius: var(--radius-inner);
    background: var(--color-surface-sunken);
  }
  .msg-ai__text--md .md-picture figcaption {
    margin-top: 4px;
    color: var(--color-ink-secondary);
    font-size: 0.86em;
  }
  .msg-ai__text--md .md-picture.is-missing img {
    display: none;
  }
  /* A block of a streaming reply arriving: it sweeps in behind a soft edge running left to right (the
     original's msg-sweep). No mask is left behind (it would clip popovers). */
  .msg-ai__text--md > .is-sweeping {
    mask-image: linear-gradient(100deg, #000 40%, rgba(0, 0, 0, 0.25) 52%, transparent 60%);
    mask-size: 300% 100%;
    mask-repeat: no-repeat;
    animation: md-sweep 650ms cubic-bezier(0.45, 0, 0.25, 1) backwards;
  }
  @keyframes md-sweep {
    from { mask-position: 100% 0; opacity: 0.4; }
    to { mask-position: 0 0; opacity: 1; }
  }
  /* More of the reply is on its way. */
  .msg-ai__more {
    display: flex;
    gap: 4px;
    padding: 6px 0 2px;
  }
  .msg-ai__more i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--color-ink-faint);
    animation: md-more 1.2s ease-in-out infinite;
  }
  .msg-ai__more i:nth-child(2) { animation-delay: 0.15s; }
  .msg-ai__more i:nth-child(3) { animation-delay: 0.3s; }
  @keyframes md-more {
    0%, 100% { opacity: 0.25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
  }
  @media (prefers-reduced-motion: reduce) {
    .msg-ai__text--md > .is-sweeping { animation: none; mask-image: none; }
    .msg-ai__more i { animation: none; opacity: 0.6; }
  }

  /* ---- surface placeholders and loading ------------------------------------------------------ */
  .surface-empty {
    display: grid;
    place-content: center;
    height: 100%;
    min-height: 200px;
    padding: var(--space-5);
    color: var(--color-ink-secondary);
    font-size: var(--text-sm);
    text-align: center;
  }
  .surface-error {
    padding: var(--space-5);
    color: var(--color-danger);
    font-size: var(--text-sm);
  }


  /* ---- the Geist mark (ui/mark.js), from the original mark.css ---- */
  /* ============================================================================
     The Geist mark's states (docs/archive/design-language.md §6.3), for js/ui/mark/geistMark.js.
     The origin is the core: every group transforms around (0,0) of the -800..800 viewBox.
     The 8 large petals carry motion; the 8 small blades (.gm-slot) carry meaning.
     ========================================================================== */

  .gm {
    --gm-ink: currentColor;
    /* A theme's logo colours (themes.css), falling back to the ink and act around the mark. */
    --gm-act: var(--logo-act, var(--color-accent-fill));
    --gm-measure: var(--color-measure);
    --gm-danger: var(--color-danger);
    --gm-empty: var(--color-signal-empty);
    display: inline-block;
    flex: none;
    overflow: visible;
    vertical-align: middle;
    color: var(--logo-ink, var(--color-ink));
  }

  .gm use,
  .gm g,
  .gm circle {
    transform-box: view-box;
    transform-origin: 0 0;
  }

  .gm use {
    fill: var(--gm-ink);
    transition: fill var(--dur-control) var(--ease), opacity var(--dur-control) var(--ease);
  }

  /* The centre: the platform may colour it (the extension shows the browser mode there). */
  .gm .gm-core {
    fill: var(--mark-core, var(--gm-ink));
  }

  .gm-ripple {
    fill: none;
    stroke: var(--gm-act);
    stroke-width: 22;
    opacity: 0;
  }

  /* ---- slot signals (data-slots) -------------------------------------------- */

  .gm .gm-slot[data-signal="running"] {
    fill: var(--gm-act);
    animation: gm-led 1.2s ease-in-out infinite;
  }

  .gm .gm-slot[data-signal="needs"] {
    fill: var(--gm-measure);
    animation: gm-led 2s ease-in-out infinite;
  }

  .gm .gm-slot[data-signal="failed"] {
    fill: var(--gm-danger);
  }

  .gm .gm-slot[data-signal="done"] {
    fill: var(--gm-ink);
  }

  .gm .gm-slot[data-signal="empty"] {
    fill: var(--gm-empty);
  }

  /* The signal mark: small blades in act at rest (empty states beside a plate). */
  .gm--signal .gm-slot:not([data-signal]) {
    fill: var(--gm-act);
  }

  /* ---- idle: Breathe ---------------------------------------------------------- */

  .gm[data-mark-state="idle"] .gm-all {
    animation: gm-breathe 3.4s ease-in-out infinite;
  }

  /* ---- sending: Draw (the outline drafted blade by blade, filled, cleared) ------- */

  .gm[data-mark-state="sending"] use {
    stroke: currentColor;
    /* A 0.5 px hairline on screen (0.8 read heavy on the small blades): non-scaling-stroke is lost
       on <use> clones, so the width is given in the blades' units (viewBox 1600, blade transform
       ×0.1) for the mark's size. */
    stroke-width: calc(8000px / var(--gm-size, 20));
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    fill-opacity: 0;
    animation: gm-draw 3.6s cubic-bezier(0.6, 0, 0.3, 1) infinite;
    animation-delay: calc(var(--i, 0) / 16 * 0.5s);
  }

  /* ---- planning: Bloom (all blades out in unison, core draws in) ---------------- */

  .gm[data-mark-state="planning"] .gm-petal,
  .gm[data-mark-state="planning"] .gm-slot {
    animation: gm-bloom 2.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
  }

  .gm[data-mark-state="planning"] .gm-core {
    animation: gm-bloom-core 2.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
  }

  /* ---- running: Chase (brightness runs clockwise round all 16 blades) -----------
     Every blade takes part so the loop still reads at 16 px, where the small blades
     alone are a couple of pixels. */

  .gm[data-mark-state="running"] .gm-petal,
  .gm[data-mark-state="running"] .gm-slot:not([data-signal]) {
    animation: gm-chase 1.3s linear infinite;
    animation-delay: calc(var(--i) / 16 * 1.3s - 1.3s);
  }

  .gm[data-mark-state="running"] .gm-slot:not([data-signal]) {
    fill: var(--gm-act);
  }

  /* ---- delegating: three small blades fly out, grow ×1.9, return --------------- */

  .gm[data-mark-state="delegating"] .gm-slot-1,
  .gm[data-mark-state="delegating"] .gm-slot-4,
  .gm[data-mark-state="delegating"] .gm-slot-7 {
    animation: gm-dispatch 3.2s cubic-bezier(0.5, 0, 0.2, 1) infinite;
  }

  .gm[data-mark-state="delegating"] .gm-slot-1:not([data-signal]),
  .gm[data-mark-state="delegating"] .gm-slot-4:not([data-signal]),
  .gm[data-mark-state="delegating"] .gm-slot-7:not([data-signal]) {
    fill: var(--gm-act);
  }

  .gm[data-mark-state="delegating"] .gm-slot-4 {
    animation-delay: -0.12s;
  }

  .gm[data-mark-state="delegating"] .gm-slot-7 {
    animation-delay: -0.24s;
  }

  .gm[data-mark-state="delegating"] .gm-petal {
    animation: gm-hold 3.2s ease-in-out infinite;
  }

  .gm[data-mark-state="delegating"] .gm-core {
    animation: gm-merge 3.2s ease-out infinite;
  }

  /* ---- writing: Trace (act travels round the small blades only) ----------------- */

  .gm[data-mark-state="writing"] .gm-slot:not([data-signal]) {
    fill: var(--gm-empty);
    animation: gm-trace 1.2s linear infinite;
    animation-delay: calc(var(--k) / 8 * 1.2s - 1.2s);
  }

  /* ---- needs: still; the waiting slot pulses amber ------------------------------ */

  .gm[data-mark-state="needs"]:not([data-slots]) .gm-slot {
    fill: var(--gm-measure);
    animation: gm-led 2s ease-in-out infinite;
  }

  /* ---- listening: small blades act, core swells with --voice-level, ripples ----- */

  .gm[data-mark-state="listening"] .gm-petal {
    opacity: 0.45;
  }

  .gm[data-mark-state="listening"] .gm-slot {
    fill: var(--gm-act);
  }

  .gm[data-mark-state="listening"] .gm-core {
    transform: scale(calc(1 + var(--voice-level, 0) * 0.3));
    transition: transform 90ms linear;
  }

  .gm[data-mark-state="listening"] .gm-ripple {
    animation: gm-ripple 1.8s ease-out infinite;
  }

  .gm[data-mark-state="listening"] .gm-ripple--2 {
    animation-delay: -0.9s;
  }

  /* ---- done: Settle once ----------------------------------------------------------- */

  .gm[data-mark-state="done"] .gm-core {
    animation: gm-settle 1.2s cubic-bezier(0.3, 1.5, 0.5, 1) 1;
  }

  .gm[data-mark-state="done"] .gm-petal,
  .gm[data-mark-state="done"] .gm-slot {
    animation: gm-snap 0.6s ease-out 1;
  }

  /* ---- failed / stopped / offline: still ------------------------------------------ */

  .gm[data-mark-state="failed"]:not([data-slots]) .gm-slot {
    fill: var(--gm-danger);
  }

  .gm[data-mark-state="stopped"] {
    opacity: 0.55;
  }

  .gm[data-mark-state="stopped"] .gm-slot:not([data-signal]) {
    fill: var(--gm-empty);
  }

  .gm[data-mark-state="offline"] {
    opacity: 0.4;
  }

  .gm[data-mark-state="offline"] .gm-slot {
    fill: none;
    stroke: currentColor;
    stroke-width: 1px;
    vector-effect: non-scaling-stroke;
  }

  /* ---- keyframes -------------------------------------------------------------------- */

  @keyframes gm-breathe {
    0%,
    100% {
      transform: scale(0.94);
      opacity: 0.72;
    }
    50% {
      transform: scale(1);
      opacity: 1;
    }
  }

  /* The outline hands over to the fill: a stroke left on the filled blades fattened them and
     closed the gaps between them, so the drawn mark wasn't quite the logo. */
  @keyframes gm-draw {
    0% {
      stroke-dashoffset: 1;
      stroke-opacity: 1;
      fill-opacity: 0;
      opacity: 1;
    }
    40% {
      stroke-dashoffset: 0;
      stroke-opacity: 1;
      fill-opacity: 0;
    }
    55%,
    82% {
      stroke-dashoffset: 0;
      stroke-opacity: 0;
      fill-opacity: 1;
      opacity: 1;
    }
    100% {
      stroke-dashoffset: 0;
      stroke-opacity: 0;
      fill-opacity: 1;
      opacity: 0;
    }
  }

  @keyframes gm-bloom {
    0%,
    100% {
      transform: translate(0, 0);
    }
    50% {
      transform: translate(calc(var(--ux) * 208px), calc(var(--uy) * 208px));
    }
  }

  @keyframes gm-bloom-core {
    0%,
    100% {
      transform: scale(1);
    }
    50% {
      transform: scale(0.78);
    }
  }

  @keyframes gm-chase {
    0% {
      opacity: 1;
    }
    55%,
    100% {
      opacity: 0.16;
    }
  }

  /* Out 264 units along the blade's radius and ×1.9 around its own centroid (r ≈ 668). */
  @keyframes gm-dispatch {
    0%,
    8%,
    84%,
    100% {
      transform: translate(0px, 0px) scale(1) translate(0px, 0px);
    }
    30%,
    62% {
      transform: translate(calc(var(--ux) * 932px), calc(var(--uy) * 932px)) scale(1.9)
        translate(calc(var(--ux) * -668px), calc(var(--uy) * -668px));
    }
  }

  @keyframes gm-hold {
    0%,
    8%,
    84%,
    100% {
      opacity: 1;
    }
    30%,
    62% {
      opacity: 0.35;
    }
  }

  @keyframes gm-merge {
    0%,
    84% {
      transform: scale(1);
    }
    90% {
      transform: scale(1.18);
    }
    100% {
      transform: scale(1);
    }
  }

  @keyframes gm-trace {
    0% {
      fill: var(--gm-act);
    }
    40%,
    100% {
      fill: var(--gm-empty);
    }
  }

  @keyframes gm-led {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.35;
    }
  }

  @keyframes gm-ripple {
    0% {
      transform: scale(1);
      opacity: 0.7;
    }
    100% {
      transform: scale(4.2);
      opacity: 0;
    }
  }

  @keyframes gm-settle {
    0% {
      transform: scale(0.7);
    }
    60% {
      transform: scale(1.15);
    }
    100% {
      transform: scale(1);
    }
  }

  @keyframes gm-snap {
    0% {
      transform: translate(calc(var(--ux) * 48px), calc(var(--uy) * 48px));
      opacity: 0.4;
    }
    100% {
      transform: none;
      opacity: 1;
    }
  }

  /* Reduced motion: no loops; colour still carries the state. */
  @media (prefers-reduced-motion: reduce) {
    .gm *,
    .gm .gm-slot[data-signal] {
      animation: none !important;
      transition: none !important;
    }

    .gm[data-mark-state="running"] .gm-slot:not([data-signal]),
    .gm[data-mark-state="delegating"] .gm-slot:not([data-signal]),
    .gm[data-mark-state="writing"] .gm-slot:not([data-signal]),
    .gm[data-mark-state="listening"] .gm-slot:not([data-signal]) {
      fill: var(--gm-act);
      opacity: 1;
    }

    .gm[data-mark-state="sending"] use {
      stroke-dasharray: none;
      fill-opacity: 1;
    }
  }


  /* The sprite the marks draw from, out of the flow. */
  .gm-sprite {
    position: absolute;
  }
  /* + and the mic sit in the tray on a desktop; in the field on a phone (phone.css). */
  .assistant-composer > .chat > :is(.chat__attach--field, .chat__mark--field, .chat__mic--field) {
    display: none;
  }

  /* Menus whose items lead with an icon: icon and label on one line. */
  .popover .menu--icons .menu__item > span:first-child {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
  }
  .popover .menu--icons .menu__item > span:first-child svg {
    flex-shrink: 0;
    color: var(--color-ink-faint);
  }
  /* Glass behind the floating faces (the original's theme-surfaces.css). */
  :where(:root[data-material="glass"]) :where(.popover, .dialog, .mk-sheet) {
    -webkit-backdrop-filter: blur(var(--material-blur)) saturate(var(--material-sat));
    backdrop-filter: blur(var(--material-blur)) saturate(var(--material-sat));
  }

  /* ---- toast (ui/toast.js) -------------------------------------------------------------- */
  .gx-toast { position: absolute; left: 50%; bottom: var(--space-4); z-index: 30; max-width: min(420px, calc(100% - 32px)); padding: var(--space-2) var(--space-4); border-radius: var(--radius-pill); background: var(--color-ink); color: var(--color-surface-raised); font-size: var(--text-sm); box-shadow: var(--shadow-pop); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
  .gx-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

  /* ---- drop target and draggable cards (ui/drop.js, ui/drag.js) -------------------------- */
  .is-dropping { position: relative; }
  .gx-drop { position: absolute; inset: 6px; z-index: 40; display: grid; place-items: center; border: 2px dashed var(--color-accent-text); border-radius: var(--radius-hold); background: color-mix(in srgb, var(--color-surface) 82%, transparent); pointer-events: none; }
  .gx-drop__label { padding: var(--space-2) var(--space-4); border-radius: var(--radius-pill); background: var(--color-accent-text); color: var(--color-surface-raised); font-size: var(--text-sm); font-weight: 600; box-shadow: var(--shadow-pop); }
  .gx-draggable { -webkit-user-drag: element; }
  .gx-draggable.is-dragging { opacity: .55; }
}
