/*
 * FIELDSETS-ENV.CSS - Element-bubble system + elements-builder shell
 *
 * NOTE: filename is now a misnomer. The environment fieldset (and the
 * v11.0 slot-pair / legacy .fieldset--env theming) was removed — its
 * bubbles moved into the shared element-bubbles overlay. What's left is
 * the SOLE owner of the bubble system: .builder-tag(s) + variants,
 * .tag-* internals, .swatch-* picker, per-bubble .tag-switch, the
 * .builder-tag--frame chip, the
 * .fieldset--elements-builder shell, and the .generating .builder-tag
 * busy rules. Rendered into the chat/card overlay by element-builder.js
 * — not duplicated in any other stylesheet, so it must stay linked.
 * Follow-up: rename/relocate to e.g. element-bubbles.css under
 * carousel/css/ and drop the 5 fieldsets-env.css <link> tags.
 */

/* ═══════════════════════════════════════════════════════════════════
   v11.1 UNIFIED ELEMENT BUILDER
   ═══════════════════════════════════════════════════════════════════ */

.fieldset--elements-builder {
    --accent: var(--primary);
    background: linear-gradient(
        135deg,
        color-mix(in srgb, var(--primary) 15%, var(--card-base)) 0%,
        var(--card-base) 50%,
        var(--card-base) 100%
    );
    border-color: color-mix(in srgb, var(--primary) 25%, rgba(255, 255, 255, 0.08));
}

.fieldset--elements-builder:hover {
    border-color: color-mix(in srgb, var(--primary) 35%, rgba(255, 255, 255, 0.1));
}

.fieldset--elements-builder h2 {
    /* Grey — slot-1 (hair) goes invisible when the character has black hair. */
    color: var(--ui-text-medium);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Tags area for additional elements --- */
.builder-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    min-height: 0;
    padding: 0.25rem 0 0 0;
}

.builder-tags:empty {
    padding: 0;
}

.builder-tag {
    --accent: var(--tag-color);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.88);
    transition: min-width 0.2s ease;
}

.builder-tag:has(.tag-color-dot.has-color),
.builder-tag:has(.tag-icon-circle.has-color) {
    background: color-mix(in srgb, var(--tag-color, rgba(255,255,255,0.08)) 25%, transparent);
    /* Mix the tag color with the same grey baseline used by the default
       .builder-tag border (rgba(255,255,255,0.2)) instead of transparent.
       Mixing with transparent let near-black tags (black hair, brown
       outfit) collapse the border to a 50%-opacity black on a dark
       background — practically invisible. The grey floor keeps a visible
       edge no matter how dark --tag-color is. */
    border-color: color-mix(in srgb, var(--tag-color) 50%, rgba(255, 255, 255, 0.2));
}

.tag-icon-circle.has-color {
    background: var(--tag-color);
    border-color: rgba(180, 180, 180, 0.5);
}

.tag-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    cursor: pointer;
}

.tag-color-dot:hover {
    border-color: rgba(255, 255, 255, 0.6);
}

.tag-color-dot.has-color {
    border-color: transparent;
}

/* Icon circle — emoji inside colored circle, acts as color picker */
.tag-icon-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(160, 160, 160, 0.5);
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.tag-icon-emoji {
    font-size: 13px;
    line-height: 1;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

/* Name-only tags (physique) — same footprint as the color circle but static
   grey: no color picker, no hover/click. */
.tag-icon-static {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(160, 160, 160, 0.5);
    background: rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
}

.tag-icon-circle:hover {
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.1);
}

/* Greyed out when element name is cleared — color inactive until name is typed */
.tag-icon-circle.disabled,
.builder-tag--empty .tag-icon-circle {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(1);
}

/* Frame chip wears the standard .builder-tag look. Inner select2 +
   open/close min-width swap is handled by the same
   .builder-tag .select2-container.builder-tag-select2 rule used by
   hair/eyes; standalone-select2.js wires the resize behavior. */
.builder-tag--frame {
    cursor: pointer;
}

/* Swatch popup — 3×5 grid of color squares. Anchored to the icon's
   left edge (not centered on it) so the grid always grows rightward.
   Centered popups on near-edge bubbles (chat overlay, narrow containers)
   used to hang off the left and clip; this anchors them predictably. */
.swatch-popup {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 6px;
    display: grid;
    grid-template-columns: repeat(5, 28px);
    gap: 3px;
    padding: 6px;
    background: var(--card-base);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    z-index: 1000;
}

/* When a swatch popup is open, elevate its entire builder-tag above sibling
   tags. Without this, hovering a swatch propagates :hover up to the
   .tag-icon-circle which scales (creating a stacking context) — that traps
   the popup's z-index inside the icon's local context, so sibling tags'
   select2's paint above it. Lifting the whole tag keeps the popup on top. */
.builder-tag:has(.swatch-popup) {
    position: relative;
    z-index: 100;
}
.swatch-cell {
    width: 28px;
    height: 30px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    transition: transform 0.1s, border-color 0.1s;
}
.swatch-cell:hover {
    transform: scale(1.15);
    border-color: rgba(255, 255, 255, 0.7);
    z-index: 1;
}
.swatch-cell--light {
    border-color: rgba(100, 100, 100, 0.4);
}

.tag-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    opacity: 0.5;
    white-space: nowrap;
}

.tag-name {
    white-space: nowrap;
}

/* Legacy text input — kept for non-select2 fallback */
.tag-name-input {
    background: transparent;
    border: none;
    outline: none;
    color: inherit;
    font: inherit;
    padding: 0;
    min-width: 3em;
    width: auto;
    max-width: 16em;
    field-sizing: content;
}

.tag-name-input::placeholder {
    color: rgba(255, 255, 255, 0.25);
    font-style: italic;
}

.tag-name-input:focus {
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

/* ══════════════════════════════════════════════════════════════════
   Select2 inside builder tags — STRIPPED TO BARE MINIMUM
   Let select2 render its defaults so we can see what we're aligning to.
   ══════════════════════════════════════════════════════════════════ */

/* Container — fill space between icon and × */
.builder-tag .select2-container.builder-tag-select2 {
    flex: 1 1 auto;
    min-width: 0;
}


.builder-tag--empty {
    opacity: 0.5;
    border-style: dotted;
}

.builder-tag--empty:hover,
.builder-tag--empty:focus-within {
    opacity: 0.8;
}

/* Disabled — value preserved, excluded from prompt. Distinct from --empty:
   the bubble keeps its color and name, just dimmed and desaturated so the
   user can see what's being held back. */
.builder-tag--disabled {
    opacity: 0.55;
    filter: saturate(0.4);
}

.builder-tag--disabled:hover,
.builder-tag--disabled:focus-within {
    opacity: 0.85;
}

/* Disable builder tag interactions during generation */
.generating .builder-tag {
    pointer-events: none;
    opacity: 0.4;
}

.generating .builder-tag .tag-icon-circle {
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════
   PER-BUBBLE TOGGLE — tinted by the bubble's --tag-color so each slot's
   switch picks up its own accent.
   ═══════════════════════════════════════════════════════════════════ */

.tag-switch {
    position: relative;
    width: 24px;
    height: 14px;
    border-radius: 7px;
    background: color-mix(in srgb, var(--tag-color, transparent) 20%, rgba(255, 255, 255, 0.1));
    border: 1px solid color-mix(in srgb, var(--tag-color, transparent) 35%, rgba(255, 255, 255, 0.18));
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

.tag-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--tag-color, transparent) 55%, rgba(255, 255, 255, 0.4));
    transition: left 0.2s, background 0.2s;
}

.tag-switch.on {
    background: color-mix(in srgb, var(--tag-color, transparent) 35%, rgba(255, 255, 255, 0.1));
    border-color: color-mix(in srgb, var(--tag-color, transparent) 55%, rgba(255, 255, 255, 0.25));
}

.tag-switch.on .tag-knob {
    left: 12px;
    background: var(--tag-color, rgba(255, 255, 255, 0.7));
}


