@layer bubble {
  .bubble-stage {
    align-items: stretch;
    padding: clamp(16px, 4vw, 36px);
  }

  .bubble-showcase {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(100%, 780px);
    gap: 16px;
    align-items: start;
  }

  .bubble-example {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    background: var(--card);
    color: var(--card-foreground);
    box-shadow: var(--shadow-xs);
  }

  .bubble-example-header {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }

  .bubble-example-header h2 {
    font-size: 14px;
    font-weight: 650;
    line-height: 1.25;
    letter-spacing: -0.01em;
  }

  .bubble-eyebrow {
    margin-bottom: 2px;
    color: var(--muted-foreground);
    font-size: 10px;
    font-weight: 650;
    letter-spacing: .08em;
    text-transform: uppercase;
  }

  .bubble-status {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 5px;
    color: var(--muted-foreground);
    font-size: 11px;
  }

  .bubble-status > span {
    width: 7px;
    height: 7px;
    border: 1.5px solid var(--card);
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 1px #22c55e;
  }

  .bubble-thread {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 28px;
    padding: 22px 16px 28px;
  }

  .bubble-variant-thread {
    gap: 27px;
  }

  .bubble-group {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 8px;
  }

  .bubble-item {
    position: relative;
    display: flex;
    width: fit-content;
    max-width: 80%;
    min-width: 0;
    flex-direction: column;
    gap: 4px;
  }

  .bubble-item[data-align="end"] {
    align-self: flex-end;
  }

  .bubble-item[data-variant="ghost"] {
    width: 100%;
    max-width: 100%;
  }

  .bubble-content {
    display: block;
    width: fit-content;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: 24px;
    padding: 9px 12px;
    color: inherit;
    font: inherit;
    font-size: 14px;
    line-height: 1.625;
    overflow-wrap: anywhere;
    text-align: left;
    text-decoration: none;
  }

  button.bubble-content,
  a.bubble-content {
    cursor: pointer;
    appearance: none;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, opacity 150ms ease;
  }

  button.bubble-content:focus-visible,
  a.bubble-content:focus-visible,
  .bubble-icon-button:focus-visible,
  .bubble-collapsible > summary:focus-visible {
    outline: 0;
    border-color: var(--ring);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
  }

  .bubble-item[data-variant="default"] > .bubble-content {
    background: var(--primary);
    color: var(--primary-foreground);
  }

  .bubble-item[data-variant="default"] > :is(button, a).bubble-content:hover {
    background: color-mix(in srgb, var(--primary) 80%, transparent);
  }

  .bubble-item[data-variant="secondary"] > .bubble-content {
    background: var(--secondary);
    color: var(--secondary-foreground);
  }

  .bubble-item[data-variant="muted"] > .bubble-content {
    background: var(--muted);
    color: var(--foreground);
  }

  .bubble-item[data-variant="secondary"] > :is(button, a).bubble-content:hover,
  .bubble-item[data-variant="muted"] > :is(button, a).bubble-content:hover {
    background: color-mix(in srgb, var(--muted) 94%, var(--foreground));
  }

  .bubble-item[data-variant="tinted"] > .bubble-content {
    background: color-mix(in srgb, var(--primary) 8%, var(--background));
    color: var(--foreground);
  }

  .bubble-item[data-variant="tinted"] > :is(button, a).bubble-content:hover {
    background: color-mix(in srgb, var(--primary) 13%, var(--background));
  }

  .bubble-item[data-variant="outline"] > .bubble-content {
    border-color: var(--border);
    background: var(--background);
  }

  .bubble-item[data-variant="outline"] > :is(button, a).bubble-content:hover {
    background: var(--muted);
  }

  .bubble-item[data-variant="destructive"] > .bubble-content {
    background: color-mix(in srgb, var(--destructive) 10%, transparent);
    color: var(--destructive);
  }

  .bubble-item[data-variant="ghost"] > .bubble-content {
    width: 100%;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 0;
  }

  .bubble-item[data-disabled="true"] {
    opacity: .5;
  }

  .bubble-content:disabled {
    cursor: not-allowed;
  }

  .bubble-prose {
    display: grid;
    gap: 8px;
  }

  .bubble-prose code {
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--muted);
    padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .86em;
  }

  .bubble-reactions,
  .bubble-popover {
    position: absolute;
    z-index: 3;
  }

  .bubble-reactions {
    display: flex;
    width: fit-content;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-radius: 999px;
    background: var(--muted);
    padding: 2px 6px;
    box-shadow: 0 0 0 3px var(--card);
    color: var(--foreground);
    font-size: 14px;
    line-height: 21px;
    white-space: nowrap;
  }

  .bubble-reactions[data-side="bottom"] {
    bottom: 0;
    transform: translateY(75%);
  }

  .bubble-reactions[data-side="top"] {
    top: 0;
    transform: translateY(-75%);
  }

  .bubble-reactions[data-align="start"] { left: 12px; }
  .bubble-reactions[data-align="end"] { right: 12px; }

  .bubble-action-reaction {
    padding: 0;
  }

  .bubble-icon-button {
    display: inline-flex;
    width: 24px;
    height: 24px;
    flex: none;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--foreground);
    cursor: pointer;
  }

  .bubble-icon-button:hover,
  .bubble-popover[open] > summary {
    background: var(--accent);
    color: var(--accent-foreground);
  }

  .bubble-icon-button svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
  }

  .bubble-tooltip-wrap {
    position: relative;
    display: flex;
  }

  .bubble-tooltip {
    position: absolute;
    z-index: 8;
    right: -6px;
    bottom: calc(100% + 7px);
    width: max-content;
    max-width: 180px;
    border-radius: 6px;
    background: var(--primary);
    padding: 4px 8px;
    color: var(--primary-foreground);
    font-size: 11px;
    line-height: 1.4;
    opacity: 0;
    pointer-events: none;
    transform: translateY(2px);
    transition: opacity 120ms ease, transform 120ms ease;
  }

  .bubble-tooltip::after {
    position: absolute;
    top: 100%;
    right: 12px;
    border: 4px solid transparent;
    border-top-color: var(--primary);
    content: "";
  }

  .bubble-tooltip-wrap:hover .bubble-tooltip,
  .bubble-tooltip-wrap:focus-within .bubble-tooltip {
    opacity: 1;
    transform: translateY(0);
  }

  .bubble-popover {
    right: 10px;
    bottom: 0;
    transform: translateY(75%);
  }

  .bubble-popover > summary {
    list-style: none;
    box-shadow: 0 0 0 3px var(--card);
    background: var(--muted);
  }

  .bubble-popover > summary::-webkit-details-marker { display: none; }

  .bubble-popover-card {
    position: absolute;
    z-index: 10;
    top: calc(100% + 8px);
    left: 0;
    width: 250px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--popover);
    padding: 12px;
    color: var(--popover-foreground);
    box-shadow: var(--shadow-sm);
    font-size: 12px;
    line-height: 1.45;
    transform: translateX(-44%);
  }

  .bubble-popover-card strong {
    display: block;
    margin-bottom: 3px;
    font-size: 12px;
  }

  .bubble-popover-card p { color: var(--muted-foreground); }

  .bubble-collapsible > summary {
    border: 1px solid transparent;
    border-radius: 8px;
    list-style: none;
    cursor: pointer;
  }

  .bubble-collapsible > summary::-webkit-details-marker { display: none; }
  .bubble-expanded, .bubble-less { display: none; }
  .bubble-collapsible[open] .bubble-preview, .bubble-collapsible[open] .bubble-more { display: none; }
  .bubble-collapsible[open] .bubble-expanded, .bubble-collapsible[open] .bubble-less { display: inline; }

  .bubble-show-label {
    display: flex;
    width: fit-content;
    align-items: center;
    gap: 3px;
    margin-top: 5px;
    color: var(--muted-foreground);
    font-size: 12px;
    font-weight: 550;
  }

  .bubble-show-label svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    transition: transform 150ms ease;
  }

  .bubble-collapsible[open] .bubble-show-label svg { transform: rotate(180deg); }

  @media (prefers-color-scheme: dark) {
    .bubble-item[data-variant="tinted"] > .bubble-content {
      background: color-mix(in srgb, var(--primary) 18%, var(--background));
    }
    .bubble-item[data-variant="tinted"] > :is(button, a).bubble-content:hover {
      background: color-mix(in srgb, var(--primary) 23%, var(--background));
    }
    .bubble-item[data-variant="destructive"] > .bubble-content {
      background: color-mix(in srgb, var(--destructive) 20%, transparent);
    }
  }

  @media (max-width: 760px) {
    .bubble-showcase { grid-template-columns: minmax(0, 1fr); max-width: 430px; }
  }

  @media (max-width: 420px) {
    .bubble-stage { padding-inline: 10px; }
    .bubble-example-header { padding-inline: 13px; }
    .bubble-thread { padding-inline: 12px; }
    .bubble-item { max-width: 86%; }
    .bubble-item[data-variant="ghost"] { max-width: 100%; }
    .bubble-tooltip { right: auto; left: -65px; }
    .bubble-tooltip::after { right: auto; left: 76px; }
    .bubble-popover-card {
      right: -4px;
      left: auto;
      width: min(240px, calc(100vw - 62px));
      transform: none;
    }
  }
}
