/* ════════════════════════════════════════════════════════════════
 * css/style-builder.css — Custom-Style Builder ("Build Your Own Font")
 *
 * Additive, self-contained. Uses main.css design tokens only (so light-mode
 * is free). Reserves height to prevent CLS (mirrors the gaming-identity /
 * compat-strip discipline). Respects prefers-reduced-motion. The fadeInUp
 * keyframe is declared locally so the module is not coupled to load order.
 * ════════════════════════════════════════════════════════════════ */

/* ── Shell ── */
.sb {
    background: var(--c-surface);
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: var(--r-md);
    padding: var(--s-lg);
    margin-top: var(--s-md);
    /* CLS reserve: header + starter presets row + controls grid + preview +
     * save row + privacy hint + empty saved list are built synchronously by JS
     * at load; this min-height holds the pre-interaction layout so the page
     * below does not jump. Growth after the user types/saves is CLS-exempt
     * (within 500ms of interaction). */
    min-height: 700px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.sb[hidden] { display: none; }

.sb__header { margin-bottom: var(--s-md); }
.sb__title { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.3rem 0; }
.sb__subtitle { font-size: 0.85rem; color: var(--c-text-muted); margin: 0; }

/* ── Controls grid ── */
.sb__controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-md);
    margin-bottom: var(--s-lg);
}
.sb__group { display: flex; flex-direction: column; gap: var(--s-xs); min-width: 0; }
.sb__group--full { grid-column: 1 / -1; }
.sb__label { font-size: 0.78rem; font-weight: 700; color: var(--c-text); }

.sb__select, .sb__input {
    width: 100%; min-height: 44px; padding: 0.65rem 0.9rem;
    border-radius: var(--r-sm); border: 1px solid rgba(168, 85, 247, 0.25);
    background: var(--c-surface-solid, var(--c-surface)); color: var(--c-text);
    font-size: 0.9rem; outline: none; transition: border-color var(--t-fast);
}
.sb__select { cursor: pointer; }
.sb__select:focus, .sb__input:focus { border-color: rgba(168, 85, 247, 0.6); }
.sb__select:focus-visible, .sb__input:focus-visible {
    outline: 2px solid var(--c-purple); outline-offset: 2px;
}

/* ── Reverse pill switch (checkbox) ── */
.sb__switch {
    display: inline-flex; align-items: center; gap: var(--s-sm);
    min-height: 44px; cursor: pointer; user-select: none; font-size: 0.9rem;
    color: var(--c-text);
}
.sb__switch input { width: 20px; height: 20px; accent-color: var(--c-purple); cursor: pointer; }
.sb__switch input:focus-visible { outline: 2px solid var(--c-purple); outline-offset: 2px; }

/* ── Live preview (CLS reserved) ── */
.sb__preview { margin-bottom: var(--s-lg); }
.sb__preview-head {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--s-sm); margin-bottom: var(--s-xs); flex-wrap: wrap;
}
.sb__preview-label { font-size: 0.78rem; font-weight: 700; color: var(--c-text); }
.sb__preview-note { font-size: 0.72rem; color: var(--c-text-muted); }
.sb__preview-row { display: flex; align-items: center; gap: var(--s-sm); flex-wrap: wrap; }
.sb__preview-box {
    flex: 1; min-width: 0; min-height: 56px;     /* reserve so it never collapses */
    display: flex; align-items: center;
    padding: 0.75rem 1rem; border-radius: var(--r-sm);
    border: 1px dashed rgba(168, 85, 247, 0.3);
    background: rgba(255, 255, 255, 0.04);
    font-size: 1.25rem; line-height: 1.5;
    overflow-wrap: anywhere; word-break: break-word;
    color: var(--c-text);
}

/* ── Buttons (mirror .gid__btn family) ── */
.sb__btn {
    padding: 0.7rem 1.1rem; min-height: 44px; border-radius: var(--r-sm);
    border: 1px solid rgba(168, 85, 247, 0.3); background: transparent;
    color: var(--c-text); font-size: 0.9rem; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
.sb__btn:hover { background: rgba(168, 85, 247, 0.12); transform: translateY(-2px); }
.sb__btn:focus-visible { outline: 2px solid var(--c-purple); outline-offset: 2px; }
.sb__btn--primary { border: none; color: #fff; background: var(--grad-brand, var(--c-purple)); }
.sb__btn--primary:hover { box-shadow: 0 4px 16px rgba(168, 85, 247, 0.4); }
.sb__btn--done {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4); color: var(--c-success);
}

/* ── Starter presets row ── */
.sb__presets {
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-sm);
    margin-bottom: var(--s-md);
}
.sb__presets:empty { display: none; }
.sb__presets[hidden] { display: none; }
.sb__presets-label { font-size: 0.78rem; font-weight: 700; color: var(--c-text-muted); }
.sb__chip {
    min-height: 44px; display: inline-flex; align-items: center; padding: 0.35rem 0.85rem; border-radius: 999px;
    border: 1px solid rgba(168, 85, 247, 0.3); background: transparent;
    color: var(--c-text); font-size: 0.8rem; font-weight: 600; cursor: pointer;
    white-space: nowrap; transition: background var(--t-fast), transform var(--t-fast);
}
.sb__chip:hover { background: rgba(168, 85, 247, 0.14); transform: translateY(-1px); }
.sb__chip:focus-visible { outline: 2px solid var(--c-purple); outline-offset: 2px; }

/* ── Ghost (secondary) button — Reset ── */
.sb__btn--ghost { color: var(--c-text-muted); }
.sb__btn--ghost:hover { background: rgba(168, 85, 247, 0.1); color: var(--c-text); }

/* ── Save row ── */
.sb__save {
    display: flex; flex-direction: column; gap: var(--s-xs);
    padding-top: var(--s-md); margin-bottom: var(--s-md);
    border-top: 1px solid rgba(168, 85, 247, 0.12);
}
.sb__save-label { color: var(--c-text-muted); }
.sb__save-row {
    display: flex; gap: var(--s-sm); flex-wrap: wrap; align-items: center;
}
.sb__save-row .sb__input { flex: 1; min-width: 180px; width: auto; }

/* ── Trust / privacy hint ── */
.sb__hint {
    font-size: 0.72rem; color: var(--c-text-muted);
    margin: var(--s-sm) 0 0 0; line-height: 1.4;
}

/* ── Saved list (CLS reserved) ── */
.sb__saved-title { font-size: 1rem; font-weight: 700; margin: 0 0 var(--s-md) 0; }
.sb__saved-list { display: flex; flex-direction: column; gap: var(--s-sm); min-height: 120px; }
.sb__placeholder {
    text-align: center; color: var(--c-text-muted);
    padding: var(--s-xl) var(--s-md); font-size: 0.95rem; margin: 0;
}

.sb__saved-card {
    display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-sm);
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(168, 85, 247, 0.12);
    border-left: 3px solid var(--c-purple);     /* fixed tint — set at build, no reflow */
    border-radius: var(--r-sm); padding: 0.7rem 0.9rem;
    animation: sbFadeInUp 0.3s ease both;
    transition: border-color var(--t-fast);
}
.sb__saved-card:hover { border-color: rgba(168, 85, 247, 0.4); }
.sb__saved-card--unavailable { border-left-color: var(--c-text-muted); opacity: 0.85; }
.sb__saved-main { display: flex; flex-direction: column; gap: 0.15rem; flex: 1 1 50%; min-width: 0; }
.sb__saved-name { font-size: 0.75rem; font-weight: 700; color: var(--c-text-muted); }
.sb__saved-text { font-size: 1.1rem; overflow-wrap: anywhere; min-width: 0; color: var(--c-text); }
.sb__saved-text--muted { font-size: 0.85rem; font-style: italic; color: var(--c-text-muted); }
/* Self-describing recipe summary (e.g. "Bold · Underline · ♡ · reversed"). */
.sb__saved-recipe {
    font-size: 0.7rem; color: var(--c-text-muted); overflow-wrap: anywhere;
    min-width: 0; margin-top: 0.1rem;
}
.sb__saved-actions { display: flex; gap: var(--s-xs); flex-shrink: 0; flex-wrap: wrap; }

.sb__card-btn {
    min-height: 44px; padding: 0.4rem 0.9rem; border-radius: 6px;
    border: 1px solid rgba(168, 85, 247, 0.3); background: transparent;
    color: var(--c-text); font-size: 0.8rem; cursor: pointer; white-space: nowrap;
    transition: background var(--t-fast);
}
.sb__card-btn:hover { background: rgba(168, 85, 247, 0.15); }
.sb__card-btn:focus-visible { outline: 2px solid var(--c-purple); outline-offset: 2px; }
.sb__card-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.sb__card-btn--edit:hover { background: rgba(56, 189, 248, 0.15); color: var(--c-cyan); }
.sb__card-btn--delete:hover { background: rgba(255, 45, 120, 0.15); color: var(--c-pink); }
.sb__card-btn--done {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4); color: var(--c-success);
}
/* Two-step delete confirm ("Delete? Tap again") */
.sb__card-btn--confirm {
    background: rgba(255, 45, 120, 0.18);
    border-color: rgba(255, 45, 120, 0.5); color: var(--c-pink); font-weight: 700;
}

@keyframes sbFadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Mobile ── */
@media (max-width: 600px) {
    /* Drop the costly full-surface blur on mid-tier mobile GPUs (perf). */
    .sb { min-height: 900px; backdrop-filter: none; -webkit-backdrop-filter: none; }
    .sb__controls { grid-template-columns: 1fr; }
    .sb__save-row { flex-direction: column; align-items: stretch; }
    .sb__save-row .sb__btn, .sb__save-row .sb__input { width: 100%; }
    .sb__preview-row { flex-wrap: wrap; }
    .sb__preview-box { font-size: 1.1rem; }
    .sb__preview-row .sb__btn { flex: 1; }
    .sb__saved-actions { width: 100%; }
    .sb__card-btn { flex: 1; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .sb__saved-card { animation: none; }
    .sb__btn:hover { transform: none; }
    .sb__chip:hover { transform: none; }
}
